當前位置: 首頁>>代碼示例>>Java>>正文


Java Vec2.length方法代碼示例

本文整理匯總了Java中org.jbox2d.common.Vec2.length方法的典型用法代碼示例。如果您正苦於以下問題:Java Vec2.length方法的具體用法?Java Vec2.length怎麽用?Java Vec2.length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jbox2d.common.Vec2的用法示例。


在下文中一共展示了Vec2.length方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
/**
 * Initialize the bodies, anchors, and length using the world anchors.
 * 
 * @param b1 First body
 * @param b2 Second body
 * @param anchor1 World anchor on first body
 * @param anchor2 World anchor on second body
 */
public void initialize(final Body b1, final Body b2, final Vec2 anchor1, final Vec2 anchor2) {
  bodyA = b1;
  bodyB = b2;
  localAnchorA.set(bodyA.getLocalPoint(anchor1));
  localAnchorB.set(bodyB.getLocalPoint(anchor2));
  Vec2 d = anchor2.sub(anchor1);
  length = d.length();
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:17,代碼來源:DistanceJointDef.java

示例2: initialize

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
/**
 * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
 */
public void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, float r) {
  bodyA = b1;
  bodyB = b2;
  groundAnchorA = ga1;
  groundAnchorB = ga2;
  localAnchorA = bodyA.getLocalPoint(anchor1);
  localAnchorB = bodyB.getLocalPoint(anchor2);
  Vec2 d1 = anchor1.sub(ga1);
  lengthA = d1.length();
  Vec2 d2 = anchor2.sub(ga2);
  lengthB = d2.length();
  ratio = r;
  assert (ratio > Settings.EPSILON);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:18,代碼來源:PulleyJointDef.java

示例3: getCurrentLengthA

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public float getCurrentLengthA() {
  final Vec2 p = pool.popVec2();
  m_bodyA.getWorldPointToOut(m_localAnchorA, p);
  p.subLocal(m_groundAnchorA);
  float length = p.length();
  pool.pushVec2(1);
  return length;
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:9,代碼來源:PulleyJoint.java

示例4: getCurrentLengthB

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public float getCurrentLengthB() {
  final Vec2 p = pool.popVec2();
  m_bodyB.getWorldPointToOut(m_localAnchorB, p);
  p.subLocal(m_groundAnchorB);
  float length = p.length();
  pool.pushVec2(1);
  return length;
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:9,代碼來源:PulleyJoint.java

示例5: getLength1

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public float getLength1() {
  final Vec2 p = pool.popVec2();
  m_bodyA.getWorldPointToOut(m_localAnchorA, p);
  p.subLocal(m_groundAnchorA);

  float len = p.length();
  pool.pushVec2(1);
  return len;
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:10,代碼來源:PulleyJoint.java

示例6: getLength2

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public float getLength2() {
  final Vec2 p = pool.popVec2();
  m_bodyB.getWorldPointToOut(m_localAnchorB, p);
  p.subLocal(m_groundAnchorB);

  float len = p.length();
  pool.pushVec2(1);
  return len;
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:10,代碼來源:PulleyJoint.java

示例7: updateLineShape

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
protected void updateLineShape(PShape shp, Vec2 p0, Vec2 p1){
  Vec2 AB = p1.sub(p0);
  
  // https://github.com/processing/processing/blob/master/core/src/processing/opengl/PShapeOpenGL.java#L1348
  float ab_len = AB.length() + 0.0000001f; 
  
  shp.resetMatrix();
  shp.scale(ab_len, 1);
  shp.rotate((float) Math.atan2(AB.y, AB.x));
  shp.translate(p0.x, p0.y);
}
 
開發者ID:diwi,項目名稱:LiquidFunProcessing,代碼行數:12,代碼來源:DwWorld.java

示例8: solvePositionConstraints

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
@Override
  public boolean solvePositionConstraints(final SolverData data) {
    final Rot qA = pool.popRot();
    final Rot qB = pool.popRot();
    final Vec2 rA = pool.popVec2();
    final Vec2 rB = pool.popVec2();
    final Vec2 uA = pool.popVec2();
    final Vec2 uB = pool.popVec2();
    final Vec2 temp = pool.popVec2();
    final Vec2 PA = pool.popVec2();
    final Vec2 PB = pool.popVec2();

    Vec2 cA = data.positions[m_indexA].c;
    float aA = data.positions[m_indexA].a;
    Vec2 cB = data.positions[m_indexB].c;
    float aB = data.positions[m_indexB].a;

    qA.set(aA);
    qB.set(aB);

    Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA);
    Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB);

    uA.set(cA).addLocal(rA).subLocal(m_groundAnchorA);
    uB.set(cB).addLocal(rB).subLocal(m_groundAnchorB);

    float lengthA = uA.length();
    float lengthB = uB.length();

    if (lengthA > 10.0f * Settings.linearSlop) {
      uA.mulLocal(1.0f / lengthA);
    } else {
      uA.setZero();
    }

    if (lengthB > 10.0f * Settings.linearSlop) {
      uB.mulLocal(1.0f / lengthB);
    } else {
      uB.setZero();
    }

    // Compute effective mass.
    float ruA = Vec2.cross(rA, uA);
    float ruB = Vec2.cross(rB, uB);

    float mA = m_invMassA + m_invIA * ruA * ruA;
    float mB = m_invMassB + m_invIB * ruB * ruB;

    float mass = mA + m_ratio * m_ratio * mB;

    if (mass > 0.0f) {
      mass = 1.0f / mass;
    }

    float C = m_constant - lengthA - m_ratio * lengthB;
    float linearError = MathUtils.abs(C);

    float impulse = -mass * C;

    PA.set(uA).mulLocal(-impulse);
    PB.set(uB).mulLocal(-m_ratio * impulse);

    cA.x += m_invMassA * PA.x;
    cA.y += m_invMassA * PA.y;
    aA += m_invIA * Vec2.cross(rA, PA);
    cB.x += m_invMassB * PB.x;
    cB.y += m_invMassB * PB.y;
    aB += m_invIB * Vec2.cross(rB, PB);

//    data.positions[m_indexA].c.set(cA);
    data.positions[m_indexA].a = aA;
//    data.positions[m_indexB].c.set(cB);
    data.positions[m_indexB].a = aB;

    pool.pushRot(2);
    pool.pushVec2(7);

    return linearError < Settings.linearSlop;
  }
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:80,代碼來源:PulleyJoint.java

示例9: createChain

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public void createChain(Vec2 ankerA, Vec2 ankerB, float radius, float spacing){
  Vec2 AB = ankerB.sub(ankerA);
  float distance = AB.length();
  
  int count = 1 + (int) (distance / (radius * 2 + spacing));
  float dist = distance / (count-1);
  Vec2 step = AB.mul(dist / distance);

  CircleShape cshape = new CircleShape();
  cshape.m_p.set(0,0);
  cshape.m_radius = radius;
  
  int col = color(255);
  
  Body body_prev = null;
  for(int i = 0; i < count; i++){
    BodyDef bdef = new BodyDef();
    bdef.position = ankerA.add(step.mul(i));
    
    if(i == 0 || i == count-1 || i % 20 == 0){
      bdef.type = BodyType.STATIC;
    } else {
      bdef.type = BodyType.DYNAMIC;
    }
    
    Body body_curr = world.createBody(bdef);
    body_curr.createFixture(cshape, 0);
    world.bodies.add(body_curr, true, col, true, 0xFF000000, 1f);
    
    if(body_prev != null){
      DistanceJointDef djointdef = new DistanceJointDef();      
      djointdef.initialize(body_prev, body_curr, body_prev.m_xf.p, body_curr.m_xf.p);
      djointdef.dampingRatio = 0.3f;
      djointdef.frequencyHz = 15f;
      DistanceJoint djoint = (DistanceJoint) world.createJoint(djointdef);
      world.bodies.add(djoint, false, col, true, col, 5);
    }

    body_prev = body_curr;
  }
  
}
 
開發者ID:diwi,項目名稱:LiquidFunProcessing,代碼行數:43,代碼來源:liquidfun_Chain_DistanceJoints_LiquidFx.java


注:本文中的org.jbox2d.common.Vec2.length方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。