本文整理匯總了Java中org.jbox2d.common.Vec2.add方法的典型用法代碼示例。如果您正苦於以下問題:Java Vec2.add方法的具體用法?Java Vec2.add怎麽用?Java Vec2.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jbox2d.common.Vec2
的用法示例。
在下文中一共展示了Vec2.add方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: step
import org.jbox2d.common.Vec2; //導入方法依賴的package包/類
public void step(){
m_angle += 0.25f * PI / 180.0f;
float radius = 25.0f;
Vec2 point1 = new Vec2(0.0f, 10.0f);
Vec2 p1p2 = new Vec2(radius * cos(m_angle), -radius * abs(sin(m_angle)));
Vec2 point2 = point1.add(p1p2);
callback.m_fixture = null;
world.raycast(callback, point1, point2);
if (callback.m_fixture != null) {
world.debug_draw.drawPoint(callback.m_point, 5.0f/world.transform.screen_scale, new Color3f(0.4f, 0.9f, 0.4f));
world.debug_draw.drawSegment(point1, callback.m_point, new Color3f(0.8f, 0.8f, 0.8f));
Vec2 head = callback.m_normal.mul(.5f).addLocal(callback.m_point);
world.debug_draw.drawSegment(callback.m_point, head, new Color3f(0.9f, 0.9f, 0.4f));
} else {
world.debug_draw.drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f));
}
}
示例2: 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;
}
}