Package org.jbox2d.dynamics

Examples of org.jbox2d.dynamics.Body


 
  @Override
  public void update(){
   
    if(!contactShapes.isEmpty()){
      Body body;
      Vec2 imp;
      for(Physical ps:contactShapes){
        if(!ps.isDestroyed()){
          body=ps.getBody();
          imp=body.getLinearVelocity().clone();
         
          imp.mulLocal(IMPULSE_MAGNITUDE);
          body.applyLinearImpulse(imp, body.getWorldCenter());
        }
      }
      contactShapes.clear();
     
    }
View Full Code Here


    return Collections.unmodifiableCollection(ground);
  }
 
  public void addObject(WorldObject wo, boolean fastObject) {
    BodyDef def = wo.getBodyDef();
    Body body = jbox2dWorld.createDynamicBody(def);
    body.setBullet(fastObject);
    Vector2d vel = wo.getVelocity();
    body.setLinearVelocity(new Vec2((float) vel.getX(), (float) vel.getY()));
    for (ShapeDef sd : wo.getShapeDefs()) {
      body.createShape(sd);
    }
    // TODO Use body.setMassFromShapes() for more realism
    wo.setBody(body);
    objects.add(wo);
  }
View Full Code Here

    objects.add(wo);
  }

  public void removeObject(WorldObject wo) {
    objects.remove(wo);
    Body body = wo.getBody();
    wo.setBody(null);

    // TODO : REMOVE/ADJUST MAKE CORRECT - just for test... shall never ask to remove object already removed...
    // Remove below lines when test code from Engine is gone...
    if(body == null){
View Full Code Here

    jbox2dWorld.destroyBody(body);
  }

  public void addGround(Shape shape, double elasticity) {
    ground.add(shape);
    Body body = jbox2dWorld.getGroundBody();
    ShapeDef def = AbstractWorldObject.translateShape(shape, elasticity);
    body.createShape(def);
  }
View Full Code Here

    return m_dampingRatio;
  }

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

    float mass = b.getMass();

    // Frequency
    float omega = 2.0f * MathUtils.PI * m_frequencyHz;

    // Damping coefficient
    float d = 2.0f * mass * m_dampingRatio * omega;

    // Spring stiffness
    float k = mass * (omega * omega);

    // magic formulas
    // gamma has units of inverse mass.
    // beta has units of inverse time.
    assert(d + step.dt * k > Settings.EPSILON);
    m_gamma = step.dt * (d + step.dt * k);
    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;
View Full Code Here

    return true;
  }

  @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);
View Full Code Here

  /**
   * @see org.jbox2d.dynamics.joints.Joint#initVelocityConstraints(org.jbox2d.dynamics.TimeStep)
   */
  @Override
  public void initVelocityConstraints(TimeStep step) {
    Body g1 = m_ground1;
    Body g2 = m_ground2;
    Body b1 = m_bodyA;
    Body b2 = m_bodyB;
   
    float K = 0.0f;
    m_J.setZero();
   
    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);
     
 
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;
   
    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;
View Full Code Here

   */
  @Override
  public boolean solvePositionConstraints(float baumgarte) {
    float linearError = 0.0f;
   
    Body b1 = m_bodyA;
    Body b2 = m_bodyB;
   
    float coordinate1, coordinate2;
    if (m_revolute1 != null) {
      coordinate1 = m_revolute1.getJointAngle();
    }
    else {
      coordinate1 = m_prismatic1.getJointTranslation();
    }
   
    if (m_revolute2 != null) {
      coordinate2 = m_revolute2.getJointAngle();
    }
    else {
      coordinate2 = m_prismatic2.getJointTranslation();
    }
   
    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();
   
    pool.pushVec2(1);
    // TODO_ERIN not implemented
    return linearError < Settings.linearSlop;
  }
View Full Code Here

  */
    public void addElement(Element e) {

        e.level = this;
        e.setBodyDef(e.bodydef);
        Body b = world.createBody(e.bodydef);
        e.body=b;
        e.setBody(b);
        n++;
        e.id=n;

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.