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


Java Vec2.mulLocal方法代碼示例

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


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

示例1: updateSensor

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public void updateSensor(){
  
  Body bsensor = m_sensor.getBody();
  CircleShape circle = (CircleShape) m_sensor.getShape();
  Vec2 sensor_pos = bsensor.getWorldPoint(circle.m_p);

  // iterate through all contacts and apply a force on shapes that overlap the sensor.
  for(Contact contact = world.getContactList(); contact != null; contact = contact.m_next){

    Fixture fixtureA = contact.getFixtureA();
    Fixture fixtureB = contact.getFixtureB();
    
    Body body = null;
         if(fixtureA == m_sensor) body = fixtureB.getBody();
    else if(fixtureB == m_sensor) body = fixtureA.getBody();
    else continue;

    Vec2 body_pos = body.getPosition();
    Vec2 dist = sensor_pos.sub(body_pos);
    if (dist.lengthSquared() > Settings.EPSILON * Settings.EPSILON) {
      dist.normalize();
      Vec2 force = dist.mulLocal(200f);
      body.applyForce(force, body_pos);
    }
  }
}
 
開發者ID:diwi,項目名稱:LiquidFunProcessing,代碼行數:27,代碼來源:box2d_Collisions_SensorTest.java

示例2: computeCentroidToOut

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public final void computeCentroidToOut(final Vec2[] vs, final int count, final Vec2 out) {
  assert (count >= 3);

  out.set(0.0f, 0.0f);
  float area = 0.0f;

  // pRef is the reference point for forming triangles.
  // It's location doesn't change the result (except for rounding error).
  final Vec2 pRef = pool1;
  pRef.setZero();

  final Vec2 e1 = pool2;
  final Vec2 e2 = pool3;

  final float inv3 = 1.0f / 3.0f;

  for (int i = 0; i < count; ++i) {
    // Triangle vertices.
    final Vec2 p1 = pRef;
    final Vec2 p2 = vs[i];
    final Vec2 p3 = i + 1 < count ? vs[i + 1] : vs[0];

    e1.set(p2).subLocal(p1);
    e2.set(p3).subLocal(p1);

    final float D = Vec2.cross(e1, e2);

    final float triangleArea = 0.5f * D;
    area += triangleArea;

    // Area weighted centroid
    e1.set(p1).addLocal(p2).addLocal(p3).mulLocal(triangleArea * inv3);
    out.addLocal(e1);
  }

  // Centroid
  assert (area > Settings.EPSILON);
  out.mulLocal(1.0f / area);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:40,代碼來源:PolygonShape.java

示例3: getCenter

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
/**
 * Get the center of the AABB
 * 
 * @return
 */
public final Vec2 getCenter() {
  final Vec2 center = new Vec2(lowerBound);
  center.addLocal(upperBound);
  center.mulLocal(.5f);
  return center;
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:12,代碼來源:AABB.java

示例4: getExtents

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
/**
 * Get the extents of the AABB (half-widths).
 * 
 * @return
 */
public final Vec2 getExtents() {
  final Vec2 center = new Vec2(upperBound);
  center.subLocal(lowerBound);
  center.mulLocal(.5f);
  return center;
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:12,代碼來源:AABB.java

示例5: updateSensor

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public void updateSensor() {
  
  Body bsensor = m_sensor.getBody();
  CircleShape circle = (CircleShape) m_sensor.getShape();
  Vec2 sensor_pos = bsensor.getWorldPoint(circle.m_p);
  
  // Traverse the bodies. Apply a force on shapes that overlap the sensor.
  for (Body body = world.getBodyList(); body != null; body = body.getNext()) {
    if(body == bsensor){
      continue;
    }
    
    boolean is_touching = false;
    DwBody dwbody = DwWorld.getShape(body);
    if(dwbody != null){
      if(dwbody.m_userData instanceof Boolean){
        is_touching = (Boolean) dwbody.m_userData;
      }
    }
    
    
    if (is_touching) {
      Vec2 body_pos = body.getPosition();

      Vec2 dist = sensor_pos.sub(body_pos);
      if (dist.lengthSquared() > Settings.EPSILON * Settings.EPSILON) {
        dist.normalize();
        Vec2 force = dist.mulLocal(200f);
        body.applyForce(force, body_pos);
      }
    }
  }
}
 
開發者ID:diwi,項目名稱:LiquidFunProcessing,代碼行數:34,代碼來源:box2d_Collisions_SensorTestCallback.java

示例6: getReactionForce

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
@Override
public void getReactionForce(float inv_dt, Vec2 argOut) {
  argOut.set(m_JvAC).mulLocal(m_impulse);
  argOut.mulLocal(inv_dt);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:6,代碼來源:GearJoint.java

示例7: getReactionForce

import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
@Override
public void getReactionForce(float inv_dt, Vec2 argOut) {
  argOut.set(m_impulse.x, m_impulse.y);
  argOut.mulLocal(inv_dt);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:6,代碼來源:WeldJoint.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


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