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


Java Vec2.sub方法代碼示例

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


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

示例3: 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

示例4: 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

示例5: 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

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