Package org.jbox2d.dynamics

Examples of org.jbox2d.dynamics.Body


  /**
   * @see org.jbox2d.dynamics.joints.Joint#initVelocityConstraints(org.jbox2d.dynamics.TimeStep)
   */
  @Override
  public void initVelocityConstraints(TimeStep step) {
    Body b1 = m_bodyA;
    Body b2 = m_bodyB;
   
    final Vec2 r1 = pool.popVec2();
    final Vec2 r2 = pool.popVec2();
    final Vec2 p1 = pool.popVec2();
    final Vec2 p2 = pool.popVec2();
    final Vec2 s1 = pool.popVec2();
    final Vec2 s2 = pool.popVec2();
   
    r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
    r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
   
    Mat22.mulToOut(b1.getTransform().R, r1, r1);
    Mat22.mulToOut(b2.getTransform().R, r2, r2);
   
    p1.set(b1.m_sweep.c).addLocal(r1);
    p2.set(b2.m_sweep.c).addLocal(r2);
   
    s1.set(m_groundAnchor1);
View Full Code Here


  /**
   * @see org.jbox2d.dynamics.joints.Joint#solveVelocityConstraints(org.jbox2d.dynamics.TimeStep)
   */
  @Override
  public void solveVelocityConstraints(TimeStep step) {
    Body b1 = m_bodyA;
    Body b2 = m_bodyB;
   
    final Vec2 r1 = pool.popVec2();
    final Vec2 r2 = pool.popVec2();
   
    r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
    r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
   
    Mat22.mulToOut(b1.getTransform().R, r1, r1);
    Mat22.mulToOut(b2.getTransform().R, r2, r2);
   
    if (m_state == LimitState.AT_UPPER) {
      final Vec2 v1 = pool.popVec2();
      final Vec2 v2 = pool.popVec2();
     
View Full Code Here

  /**
   * @see org.jbox2d.dynamics.joints.Joint#solvePositionConstraints(float)
   */
  @Override
  public boolean solvePositionConstraints(float baumgarte) {
    Body b1 = m_bodyA;
    Body b2 = m_bodyB;
   
    final Vec2 s1 = pool.popVec2();
    final Vec2 s2 = pool.popVec2();
   
    s1.set(m_groundAnchor1);
    s2.set(m_groundAnchor2);
   
    float linearError = 0.0f;
   
    if (m_state == LimitState.AT_UPPER) {
      final Vec2 r1 = pool.popVec2();
      final Vec2 r2 = pool.popVec2();
      final Vec2 p1 = pool.popVec2();
      final Vec2 p2 = pool.popVec2();
     
      r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
      r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
     
      Mat22.mulToOut(b1.getTransform().R, r1, r1);
      Mat22.mulToOut(b2.getTransform().R, r2, r2);
     
      p1.set(b1.m_sweep.c).addLocal(r1);
      p2.set(b2.m_sweep.c).addLocal(r2);
     
      // Get the pulley axes.
      m_u1.set(p1).subLocal(s1);
      m_u2.set(p2).subLocal(s2);
     
      float length1 = m_u1.length();
      float length2 = m_u2.length();
     
      if (length1 > Settings.linearSlop) {
        m_u1.mulLocal(1.0f / length1);
      }
      else {
        m_u1.setZero();
      }
     
      if (length2 > Settings.linearSlop) {
        m_u2.mulLocal(1.0f / length2);
      }
      else {
        m_u2.setZero();
      }
     
      float C = m_constant - length1 - m_ratio * length2;
      linearError = MathUtils.max(linearError, -C);
     
      C = MathUtils.clamp(C + Settings.linearSlop, -Settings.maxLinearCorrection, 0.0f);
      float impulse = -m_pulleyMass * C;
     
      final Vec2 P1 = pool.popVec2();
      final Vec2 P2 = pool.popVec2();
      final Vec2 temp = pool.popVec2();
     
      P1.set(m_u1).mulLocal(-impulse);
      P2.set(m_u2).mulLocal(-m_ratio * impulse);
     
      temp.set(P1).mulLocal(b1.m_invMass);
      b1.m_sweep.c.addLocal(temp);
      b1.m_sweep.a += b1.m_invI * Vec2.cross(r1, P1);
     
      temp.set(P2).mulLocal(b2.m_invMass);
      b2.m_sweep.c.addLocal(temp);
      b2.m_sweep.a += b2.m_invI * Vec2.cross(r2, P2);
     
      b1.synchronizeTransform();
      b2.synchronizeTransform();
     
      pool.pushVec2(7);
    }
   
    if (m_limitState1 == LimitState.AT_UPPER) {
      final Vec2 r1 = pool.popVec2();
      final Vec2 p1 = pool.popVec2();
     
      r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
     
      Mat22.mulToOut(b1.getTransform().R, r1, r1);
     
      p1.set(b1.m_sweep.c).addLocal(r1);
     
      m_u1.set(p1).subLocal(s1);
     
      float length1 = m_u1.length();
     
      if (length1 > Settings.linearSlop) {
        m_u1.mulLocal(1.0f / length1);
      }
      else {
        m_u1.setZero();
      }
     
      float C = m_maxLength1 - length1;
      linearError = MathUtils.max(linearError, -C);
      C = MathUtils.clamp(C + Settings.linearSlop, -Settings.maxLinearCorrection, 0.0f);
      float impulse = -m_limitMass1 * C;
     
      final Vec2 P1 = pool.popVec2();
      final Vec2 temp = pool.popVec2();
     
      P1.set(m_u1).mulLocal(-impulse);
     
      temp.set(P1).mulLocal(b1.m_invMass);
      b1.m_sweep.c.addLocal(temp);
      b1.m_sweep.a += b1.m_invI * Vec2.cross(r1, P1);
     
      b1.synchronizeTransform();
     
      pool.pushVec2(4);
    }
   
    if (m_limitState2 == LimitState.AT_UPPER) {
      final Vec2 r2 = pool.popVec2();
      final Vec2 p2 = pool.popVec2();
     
      r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
     
      Mat22.mulToOut(b2.getTransform().R, r2, r2);
     
      p2.set(b2.m_sweep.c).addLocal(r2);
     
      // Get the pulley axes.
      m_u2.set(p2).subLocal(s2);
     
      float length2 = m_u2.length();
     
      if (length2 > Settings.linearSlop) {
        m_u2.mulLocal(1.0f / length2);
      }
      else {
        m_u2.setZero();
      }
     
      float C = m_maxLength2 - length2;
      linearError = MathUtils.max(linearError, -C);
      C = MathUtils.clamp(C + Settings.linearSlop, -Settings.maxLinearCorrection, 0.0f);
      float impulse = -m_limitMass2 * C;
     
      final Vec2 P2 = pool.popVec2();
      final Vec2 temp = pool.popVec2();
     
      P2.set(m_u2).mulLocal(-impulse);
     
      temp.set(P2).mulLocal(b2.m_invMass);
      b2.m_sweep.c.addLocal(temp);
      b2.m_sweep.a += b2.m_invI * Vec2.cross(r2, P2);
     
      b2.synchronizeTransform();
     
      pool.pushVec2(4);
    }
    pool.pushVec2(2);
   
View Full Code Here

  /**
   * @see org.jbox2d.dynamics.joints.Joint#initVelocityConstraints(org.jbox2d.dynamics.TimeStep)
   */
  @Override
  public void initVelocityConstraints(TimeStep step) {
    Body bA = m_bodyA;
    Body bB = m_bodyB;
   
    // Compute the effective mass matrix.
    final Vec2 rA = pool.popVec2();
    final Vec2 rB = pool.popVec2();
   
    rA.set(m_localAnchorA).subLocal(bA.getLocalCenter());
    rB.set(m_localAnchorB).subLocal(bB.getLocalCenter());
    Mat22.mulToOut(bA.getTransform().R, rA, rA);
    Mat22.mulToOut(bB.getTransform().R, rB, rB);
   
    // J = [-I -r1_skew I r2_skew]
    // [ 0 -1 0 1]
    // r_skew = [-ry; rx]
   
View Full Code Here

  /**
   * @see org.jbox2d.dynamics.joints.Joint#solveVelocityConstraints(org.jbox2d.dynamics.TimeStep)
   */
  @Override
  public void solveVelocityConstraints(TimeStep step) {
    Body bA = m_bodyA;
    Body bB = m_bodyB;
   
    final Vec2 vA = bA.m_linearVelocity;
    float wA = bA.m_angularVelocity;
    final Vec2 vB = bB.m_linearVelocity;
    float wB = bB.m_angularVelocity;
   
    float mA = bA.m_invMass, mB = bB.m_invMass;
    float iA = bA.m_invI, iB = bB.m_invI;
   
    final Vec2 rA = pool.popVec2();
    final Vec2 rB = pool.popVec2();
   
    rA.set(m_localAnchorA).subLocal(bA.getLocalCenter());
    rB.set(m_localAnchorB).subLocal(bB.getLocalCenter());
    Mat22.mulToOut(bA.getTransform().R, rA, rA);
    Mat22.mulToOut(bB.getTransform().R, rB, rB);
   
    // Solve angular friction
    {
      float Cdot = wB - wA;
      float impulse = -m_angularMass * Cdot;
 
View Full Code Here

 
  @Override
  public void initVelocityConstraints(final TimeStep step) {
   
    // TODO: fully inline temp Vec2 ops
    final Body b1 = m_bodyA;
    final Body b2 = m_bodyB;
   
    Vec2 r1 = pool.popVec2();
    Vec2 r2 = pool.popVec2();
   
    // Compute the effective mass matrix.
    r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
    r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
    Mat22.mulToOut(b1.getTransform().R, r1, r1);
    Mat22.mulToOut(b2.getTransform().R, r2, r2);
   
    m_u.x = b2.m_sweep.c.x + r2.x - b1.m_sweep.c.x - r1.x;
    m_u.y = b2.m_sweep.c.y + r2.y - b1.m_sweep.c.y - r1.y;
   
    // Handle singularity.
View Full Code Here

    pool.pushVec2(2);
  }
 
  @Override
  public void solveVelocityConstraints(final TimeStep step) {
    final Body b1 = m_bodyA;
    final Body b2 = m_bodyB;
   
    final Vec2 r1 = pool.popVec2();
    final Vec2 r2 = pool.popVec2();
   
    r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
    r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
    Mat22.mulToOut(b1.getTransform().R, r1, r1);
    Mat22.mulToOut(b2.getTransform().R, r2, r2);
   
    final Vec2 v1 = pool.popVec2();
    final Vec2 v2 = pool.popVec2();
   
    // Cdot = dot(u, v + cross(w, r))
View Full Code Here

  public boolean solvePositionConstraints(float baumgarte) {
    if (m_frequencyHz > 0.0f) {
      return true;
    }
   
    final Body b1 = m_bodyA;
    final Body b2 = m_bodyB;
   
    final Vec2 r1 = pool.popVec2();
    final Vec2 r2 = pool.popVec2();
    final Vec2 d = pool.popVec2();
   
    r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
    r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
    Mat22.mulToOut(b1.getTransform().R, r1, r1);
    Mat22.mulToOut(b2.getTransform().R, r2, r2);
   
    d.x = b2.m_sweep.c.x + r2.x - b1.m_sweep.c.x - r1.x;
    d.y = b2.m_sweep.c.y + r2.y - b1.m_sweep.c.y - r1.y;
   
    float length = d.normalize();
    float C = length - m_length;
    C = MathUtils.clamp(C, -Settings.maxLinearCorrection, Settings.maxLinearCorrection);
   
    float impulse = -m_mass * C;
    m_u.set(d);
    float Px = impulse * m_u.x;
    float Py = impulse * m_u.y;
   
    b1.m_sweep.c.x -= b1.m_invMass * Px;
    b1.m_sweep.c.y -= b1.m_invMass * Py;
    b1.m_sweep.a -= b1.m_invI * (r1.x * Py - r1.y * Px);// b2Cross(r1, P);
   
    b2.m_sweep.c.x += b2.m_invMass * Px;
    b2.m_sweep.c.y += b2.m_invMass * Py;
    b2.m_sweep.a += b2.m_invI * (r2.x * Py - r2.y * Px);// b2Cross(r2, P);
   
    b1.synchronizeTransform();
    b2.synchronizeTransform();
   
    pool.pushVec2(3);
   
    return MathUtils.abs(C) < Settings.linearSlop;
  }
View Full Code Here

    return inv_dt * m_impulse.y;
  }
 
  // / Get the current joint translation, usually in meters.
  public float getJointTranslation() {
    Body b1 = m_bodyA;
    Body b2 = m_bodyB;
   
    Vec2 p1 = pool.popVec2();
    Vec2 p2 = pool.popVec2();
    Vec2 axis = pool.popVec2();
   
    b1.getWorldPointToOut(m_localAnchor1, p1);
    b2.getWorldPointToOut(m_localAnchor2, p2);
    p2.subLocal(p1);
    b1.getWorldVectorToOut(m_localXAxis1, axis);
   
    float translation = Vec2.dot(p2, axis);
   
View Full Code Here

    return translation;
  }
 
  // / Get the current joint translation speed, usually in meters per second.
  public float getJointSpeed() {
    Body b1 = m_bodyA;
    Body b2 = m_bodyB;
   
    Vec2[] pc = pool.popVec2(9);
    Vec2 temp = pc[0];
    Vec2 r1 = pc[1];
    Vec2 r2 = pc[2];
    Vec2 p1 = pc[3];
    Vec2 p2 = pc[4];
    Vec2 d = pc[5];
    Vec2 axis = pc[6];
    Vec2 temp2 = pc[7];
    Vec2 temp3 = pc[8];
   
    temp.set(m_localAnchor1).subLocal(b1.getLocalCenter());
    Mat22.mulToOut(b1.getTransform().R, temp, r1);
   
    temp.set(m_localAnchor2).subLocal(b2.getLocalCenter());
    Mat22.mulToOut(b2.getTransform().R, temp, r2);
   
    p1.set(b1.m_sweep.c).addLocal(r1);
    p2.set(b2.m_sweep.c).addLocal(r2);
   
    d.set(p2).subLocal(p1);
View Full Code Here

TOP

Related Classes of org.jbox2d.dynamics.Body

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.