Package org.jbox2d.common

Examples of org.jbox2d.common.Vec2


    if (m_gamma != 0.0f){
      m_gamma = 1.0f / m_gamma;
    }
    m_beta = step.dt * k * m_gamma;

    Vec2 r = pool.popVec2();
   
    // Compute the effective mass matrix.
    //Vec2 r = Mul(b.getTransform().R, m_localAnchor - b.getLocalCenter());
    r.set(m_localAnchor).subLocal(b.getLocalCenter());
    Mat22.mulToOut(b.getTransform().R, r, r);
   
    // K    = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
    //      = [1/m1+1/m2     0    ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
    //        [    0     1/m1+1/m2]           [-r1.x*r1.y r1.x*r1.x]           [-r1.x*r1.y r1.x*r1.x]
    float invMass = b.m_invMass;
    float invI = b.m_invI;

    Mat22 K1 = pool.popMat22();
    K1.col1.x = invMass;  K1.col2.x = 0.0f;
    K1.col1.y = 0.0f;    K1.col2.y = invMass;

    Mat22 K2 = pool.popMat22();
    K2.col1.x =  invI * r.y * r.y;  K2.col2.x = -invI * r.x * r.y;
    K2.col1.y = -invI * r.x * r.y;  K2.col2.y =  invI * r.x * r.x;

    Mat22 K = pool.popMat22();
    K.set(K1).addLocal(K2);
    K.col1.x += m_gamma;
    K.col2.y += m_gamma;

    K.invertToOut(m_mass);

    m_C.set(b.m_sweep.c).addLocal(r).subLocal(m_target);

    // Cheat with some damping
    b.m_angularVelocity *= 0.98f;

    // Warm starting.
    m_impulse.mulLocal(step.dtRatio);
    // pool
    Vec2 temp = pool.popVec2();
    temp.set(m_impulse).mulLocal(invMass);
    b.m_linearVelocity.addLocal(temp);
    b.m_angularVelocity += invI * Vec2.cross(r, m_impulse);
   
    pool.pushVec2(2);
    pool.pushMat22(3);
View Full Code Here


  @Override
  public void solveVelocityConstraints(TimeStep step) {
    Body b = m_bodyB;

    Vec2 r = pool.popVec2();

    r.set(m_localAnchor).subLocal(b.getLocalCenter());
    Mat22.mulToOut(b.getTransform().R, r, r);
   
    // Cdot = v + cross(w, r)
    Vec2 Cdot = pool.popVec2();
    Vec2.crossToOut(b.m_angularVelocity, r, Cdot);
    Cdot.addLocal(b.m_linearVelocity);
   
    Vec2 impulse = pool.popVec2();
    Vec2 temp = pool.popVec2();
   
    //Mul(m_mass, -(Cdot + m_beta * m_C + m_gamma * m_impulse));
    impulse.set(m_C).mulLocal(m_beta);
    temp.set(m_impulse).mulLocal(m_gamma);
    temp.addLocal(impulse).addLocal(Cdot).mulLocal(-1);
    Mat22.mulToOut(m_mass, temp, impulse);

    Vec2 oldImpulse = temp;
    oldImpulse.set(m_impulse);
    m_impulse.addLocal(impulse);
    float maxImpulse = step.dt * m_maxForce;
    if (m_impulse.lengthSquared() > maxImpulse * maxImpulse){
      m_impulse.mulLocal(maxImpulse / m_impulse.length());
    }
    impulse.set(m_impulse).subLocal(oldImpulse);

    // pooling
    oldImpulse.set(impulse).mulLocal(b.m_invMass);
    b.m_linearVelocity.addLocal(oldImpulse);
    b.m_angularVelocity += b.m_invI * Vec2.cross(r, impulse);
   
    pool.pushVec2(4);
  }
View Full Code Here

    frequencyHz = def.frequencyHz;
    dampingRatio = def.dampingRatio;

    normals = new Vec2[bodies.length];
    for (int i = 0; i < normals.length; ++i) {
      normals[i] = new Vec2();
    }

    this.m_bodyA = bodies[0];
    this.m_bodyB = bodies[1];
    this.m_collideConnected = false;
View Full Code Here

      normals[i].x = dy / dist;
      normals[i].y = -dx / dist;
      perimeter += dist;
    }

    final Vec2 delta = pool.popVec2();

    float deltaArea = targetVolume - getArea();
    float toExtrude = 0.5f * deltaArea / perimeter; // *relaxationFactor
    // float sumdeltax = 0.0f;
    boolean done = true;
    for (int i = 0; i < bodies.length; ++i) {
      final int next = (i == bodies.length - 1) ? 0 : i + 1;
      delta.set(toExtrude * (normals[i].x + normals[next].x), toExtrude
          * (normals[i].y + normals[next].y));
      // sumdeltax += dx;
      float norm = delta.length();
      if (norm > Settings.maxLinearCorrection) {
        delta.mulLocal(Settings.maxLinearCorrection / norm);
      }
      if (norm > Settings.linearSlop) {
        done = false;
      }
      bodies[next].m_sweep.c.x += delta.x;
View Full Code Here

  @Override
  public void solveVelocityConstraints(final TimeStep step) {
    float crossMassSum = 0.0f;
    float dotMassSum = 0.0f;

    final Vec2 d[] = pool.getVec2Array(bodies.length);

    for (int i = 0; i < bodies.length; ++i) {
      final int prev = (i == 0) ? bodies.length - 1 : i - 1;
      final int next = (i == bodies.length - 1) ? 0 : i + 1;
      d[i].set(bodies[next].getWorldCenter());
View Full Code Here

   * @see org.jbox2d.dynamics.joints.Joint#getReactionTorque(float)
   */
  @Override
  public float getReactionTorque(float inv_dt) {
   
    final Vec2 r = pool.popVec2();
    final Vec2 p = pool.popVec2();
   
    r.set(m_localAnchor2).subLocal(m_bodyB.getLocalCenter());
    Mat22.mulToOut(m_bodyB.getTransform().R, r, r);
    p.set(m_J.linearB).mulLocal(m_impulse);
    float L = m_impulse * m_J.angularB - Vec2.cross(r, p);
   
    pool.pushVec2(2);
    return inv_dt * L;
  }
 
View Full Code Here

    if (m_revolute1 != null) {
      m_J.angularA = -1.0f;
      K += b1.m_invI;
    }
    else {
      final Vec2 ug = pool.popVec2();
      final Vec2 r = pool.popVec2();
      Mat22.mulToOut(g1.getTransform().R, m_prismatic1.m_localXAxis1, ug);
     
      r.set(m_localAnchor1).subLocal(b1.getLocalCenter());
      Mat22.mulToOut(b1.getTransform().R, r, r);
      float crug = Vec2.cross(r, ug);
      m_J.linearA.set(ug).negateLocal();
      m_J.angularA = -crug;
      K += b1.m_invMass + b1.m_invI * crug * crug;
      pool.pushVec2(2);
    }
   
    if (m_revolute2 != null) {
      m_J.angularB = -m_ratio;
      K += m_ratio * m_ratio * b2.m_invI;
    }
    else {
      final Vec2 ug = pool.popVec2();
      final Vec2 r = pool.popVec2();
     
      Mat22.mulToOut(g2.getTransform().R, m_prismatic2.m_localXAxis1, ug);
     
      r.set(m_localAnchor2).subLocal(b2.getLocalCenter());
      Mat22.mulToOut(b2.getTransform().R, r, r);
      float crug = Vec2.cross(r, ug);
      m_J.linearB.set(ug).mulLocal(-m_ratio);
      m_J.angularB = -m_ratio * crug;
      K += m_ratio * m_ratio * (b2.m_invMass + b2.m_invI * crug * crug);
     
      pool.pushVec2(2);
    }
   
    // Compute effective mass.
    m_mass = K > 0.0f ? 1.0f / K : 0.0f;
   
    if (step.warmStarting) {
      final Vec2 temp = pool.popVec2();
      // Warm starting.
      temp.set(m_J.linearA).mulLocal(b1.m_invMass).mulLocal(m_impulse);
      b1.m_linearVelocity.addLocal(temp);
      b1.m_angularVelocity += b1.m_invI * m_impulse * m_J.angularA;
     
      temp.set(m_J.linearB).mulLocal(b2.m_invMass).mulLocal(m_impulse);
      b2.m_linearVelocity.addLocal(temp);
      b2.m_angularVelocity += b2.m_invI * m_impulse * m_J.angularB;
     
      pool.pushVec2(1);
    }
 
View Full Code Here

    float Cdot = m_J.compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
   
    float impulse = m_mass * (-Cdot);
    m_impulse += impulse;
   
    final Vec2 temp = pool.popVec2();
    temp.set(m_J.linearA).mulLocal(b1.m_invMass).mulLocal(impulse);
    b1.m_linearVelocity.addLocal(temp);
    b1.m_angularVelocity += b1.m_invI * impulse * m_J.angularA;
   
    temp.set(m_J.linearB).mulLocal(b2.m_invMass).mulLocal(impulse);
    b2.m_linearVelocity.addLocal(temp);
    b2.m_angularVelocity += b2.m_invI * impulse * m_J.angularB;
   
    pool.pushVec2(1);
  }
 
View Full Code Here

   
    float C = m_constant - (coordinate1 + m_ratio * coordinate2);
   
    float impulse = m_mass * (-C);
   
    final Vec2 temp = pool.popVec2();
    temp.set(m_J.linearA).mulLocal(b1.m_invMass).mulLocal(impulse);
    b1.m_sweep.c.addLocal(temp);
    b1.m_sweep.a += b1.m_invI * impulse * m_J.angularA;
   
    temp.set(m_J.linearB).mulLocal(b2.m_invMass).mulLocal(impulse);
    b2.m_sweep.c.addLocal(temp);
    b2.m_sweep.a += b2.m_invI * impulse * m_J.angularB;
   
    b1.synchronizeTransform();
    b2.synchronizeTransform();
 
View Full Code Here

            level.addElement(s);

            s.gl.add(new res.guns.GunQueen());
            s.gl.get(0).ammo = 10;
            s.gl.get(0).owner = s;
            s.applySpeed(new Vec2(sin * 20, cos * 20));
            s.lifeTime=5;
            s.energy=1;


        }
View Full Code Here

TOP

Related Classes of org.jbox2d.common.Vec2

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.