本文整理匯總了Java中org.jbox2d.dynamics.Body類的典型用法代碼示例。如果您正苦於以下問題:Java Body類的具體用法?Java Body怎麽用?Java Body使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Body類屬於org.jbox2d.dynamics包,在下文中一共展示了Body類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getJointTranslation
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
public float getJointTranslation() {
Body b1 = m_bodyA;
Body b2 = m_bodyB;
Vec2 p1 = pool.popVec2();
Vec2 p2 = pool.popVec2();
Vec2 axis = pool.popVec2();
b1.getWorldPointToOut(m_localAnchorA, p1);
b2.getWorldPointToOut(m_localAnchorA, p2);
p2.subLocal(p1);
b1.getWorldVectorToOut(m_localXAxisA, axis);
float translation = Vec2.dot(p2, axis);
pool.pushVec2(3);
return translation;
}
示例2: testNewWorld
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
@Test
public void testNewWorld() {
World world = new World(new Vec2(0, -9.8f));
BodyDef axisDef = new BodyDef();
axisDef.type = BodyType.STATIC;
axisDef.position = new Vec2(3, 3);
Body axis = world.createBody(axisDef);
CircleShape axisShape = new CircleShape();
axisShape.setRadius(0.02f);
axisShape.m_p.set(0, 0);
//FixtureDef axisFixture = new FixtureDef();
//axisFixture.shape = axisShape;
//axis.createFixture(axisFixture);
}
示例3: addBodies
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
public void addBodies(){
if (m_count < MAX_NUM) {
float x = random(-0.7f, 0.7f);
float y = random(-0.7f, 0.7f);
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(x, y);
Body body = world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.18f, 0.18f);
Fixture fixture = body.createFixture(shape, 0.01f);
fixture.m_friction = 0.1f;
fixture.m_restitution = 0.5f;
++m_count;
colorMode(HSB, 360, 100, 100);
float hue = (360 * m_count /(float)MAX_NUM) % 360;
world.bodies.add(body, true, color(hue, 100, 100), true, color(hue, 100, 50), 1f);
colorMode(RGB, 255, 255, 255);
}
}
示例4: updateSensor
import org.jbox2d.dynamics.Body; //導入依賴的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);
}
}
}
示例5: initScene
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
public void initScene() {
Body ground = null;
{
BodyDef bd = new BodyDef();
bd.position.set(0.0f, 20.0f);
ground = world.createBody(bd);
}
float a = 0.5f;
Vec2 h = new Vec2(0.0f, a);
colorMode(HSB, 1f);
Body root = AddNode(ground, new Vec2(), 0, 3.0f, a);
colorMode(RGB, 255);
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.bodyA = ground;
jointDef.bodyB = root;
jointDef.localAnchorA.setZero();
jointDef.localAnchorB = h;
world.createJoint(jointDef);
world.bodies.addAll();
}
示例6: display
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
static public void display(PGraphics pg, Body body){
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
display(pg, fixture);
// if (body.isActive() == false) {
// display(pg, fixture);
// } else if (body.getType() == BodyType.STATIC) {
// display(pg, fixture);
// } else if (body.getType() == BodyType.KINEMATIC) {
// display(pg, fixture);
// } else if (body.isAwake() == false) {
// display(pg, fixture);
// } else {
// display(pg, fixture);
// }
}
}
示例7: addAll
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
/**
*
* Add/create shapes for all bodies/joints that have not attached shapes.<br>
*
*/
public void addAll(boolean create_bodies, boolean create_joints){
if(create_bodies){
for (Body body = world.getBodyList(); body != null; body = body.getNext()) {
DwBody dwbody = DwWorld.getShape(body);
if(dwbody == null){
add(body);
}
}
}
if(create_joints){
for (Joint joint = world.getJointList(); joint != null; joint = joint.getNext()) {
DwJoint dwjoint = DwWorld.getShape(joint);
if(dwjoint == null){
add(joint);
}
}
}
}
示例8: DwBody
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
public DwBody(DwBodyGroup parent, Body body){
this.parent = parent;
this.body = body;
// create PShape
this.shape = parent.papplet.createShape(PConstants.GROUP);
// link PShapes
parent.shape.addChild(shape);
body.setUserData(this);
// create children
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
add(fixture);
}
}
示例9: updateBodies
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
public void updateBodies(){
for (Body body = super.getBodyList(); body != null; body = body.getNext()) {
Transform xf = body.getTransform();
DwBody dwbody = getShape(body);
if(dwbody != null){
dwbody.shape.resetMatrix();
dwbody.shape.rotate(xf.q.getAngle());
dwbody.shape.translate(xf.p.x, xf.p.y);
}
// for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
// PShape shp_fixture = DwBodyRenderP5.getShape(fixture);
// if(shp_fixture != null){
// shp_fixture.resetMatrix();
// shp_fixture.rotate(xf.q.getAngle());
// shp_fixture.translate(xf.p.x, xf.p.y);
// }
// }
}
}
示例10: reportFixture
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
@Override
public boolean reportFixture(Fixture argFixture) {
Body body = argFixture.getBody();
// static bodies can be moved too, but need to set to dynamic for the
// mouse-joint to work.
BodyType type = body.getType();
if (BodyType.DYNAMIC == type || enable_static_drag) {
if (argFixture.testPoint(point)) {
body_type_cpy = type;
fixture = argFixture;
body.setType(BodyType.DYNAMIC);
return false;
}
}
return true;
}
示例11: solveVelocityConstraints
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
/**
* @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;
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);
}
示例12: getJointTranslation
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
public float getJointTranslation() {
Body b1 = m_bodyA;
Body b2 = m_bodyB;
Vec2 p1 = pool.popVec2();
Vec2 p2 = pool.popVec2();
Vec2 axis = pool.popVec2();
b1.getWorldPointToOut(m_localAnchor1, p1);
b2.getWorldPointToOut(m_localAnchor2, p2);
p2.subLocal(p1);
b1.getWorldVectorToOut(m_localXAxis1, axis);
float translation = Vec2.dot(p2, axis);
pool.pushVec2(3);
return translation;
}
示例13: getJointTranslation
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
public float getJointTranslation() {
Body b1 = m_bodyA;
Body b2 = m_bodyB;
Vec2 p1 = pool.popVec2();
Vec2 p2 = pool.popVec2();
Vec2 axis = pool.popVec2();
b1.getWorldPointToOut(m_localAnchor1, p1);
b2.getWorldPointToOut(m_localAnchor1, p2);
p2.subLocal(p1);
b1.getWorldVectorToOut(m_localXAxis1, axis);
float translation = Vec2.dot(p2, axis);
pool.pushVec2(3);
return translation;
}
示例14: initialize
import org.jbox2d.dynamics.Body; //導入依賴的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);
float C = lengthA + ratio * lengthB;
maxLengthA = C - ratio * PulleyJoint.MIN_PULLEY_LENGTH;
maxLengthB = (C - PulleyJoint.MIN_PULLEY_LENGTH) / ratio;
}
示例15: createCircle
import org.jbox2d.dynamics.Body; //導入依賴的package包/類
public void createCircle()
{
float radius = 2.0f;
CircleShape shape = new CircleShape();
shape.m_p.setZero();
shape.m_radius = radius;
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.0f;
Vec2 p = new Vec2((float)Math.random(), 3.0f + (float)Math.random());
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position = p;
//bd.allowSleep = false;
Body body = m_world.createBody(bd);
body.createFixture(fd);
}