/** Get the angle in radians. * @return the current world rotation angle in radians. */ public float getAngle () { return body.getAngle(); }
/** * Initialize the bodies, anchors, and reference angle using a world anchor point. * * @param bA * @param bB * @param anchor */ public void initialize(Body bA, Body bB, Vec2 anchor) { bodyA = bA; bodyB = bB; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, and reference angle using the world anchor. * * @param b1 * @param b2 * @param anchor */ public void initialize(final Body b1, final Body b2, final Vec2 anchor) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world * axis. */ public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); bodyA.getLocalVectorToOut(axis, localAxisA); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, and reference angle using a world anchor point. * * @param bA * @param bB * @param anchor */ public void initialize(Body bA, Body bB, Vec2 anchor) { bodyA = bA; bodyB = bB; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, and reference angle using the world anchor. * * @param b1 * @param b2 * @param anchor */ public void initialize(final Body b1, final Body b2, final Vec2 anchor) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world * axis. */ public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); bodyA.getLocalVectorToOut(axis, localAxisA); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
context.save(); context.translate(center.x, center.y); context.rotate(body.getAngle()); for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) { Shape shape = fixture.getShape();
private float getViewRotation(View view) { Body body = (Body) view.getTag(R.id.wd_view_body_tag); if (null != body) { float angle = body.getAngle(); //注意换算 return (angle / 3.14f * 180f) % 360; } return 0; }
@Override public boolean onAreaTouched( final TouchEvent pSceneTouchEvent, final ITouchArea pTouchArea,final float pTouchAreaLocalX, final float pTouchAreaLocalY) { if(pSceneTouchEvent.isActionMove()) { final AnimatedSprite face = (AnimatedSprite) pTouchArea; final Body faceBody = (Body)face.getUserData(); faceBody.setTransform(pSceneTouchEvent.getX() / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, pSceneTouchEvent.getY() / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, faceBody.getAngle()); return true; } return false; }
/** * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world * axis. */ public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); bodyA.getLocalVectorToOut(axis, localAxisA); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, axis, and reference angle using the world * anchor and world axis. */ public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis){ bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); bodyA.getLocalVectorToOut(axis, localAxisA); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
void Break() { // Create two bodies from one. Body body1 = m_piece1.getBody(); Vec2 center = body1.getWorldCenter(); body1.destroyFixture(m_piece2); m_piece2 = null; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position = body1.getPosition(); bd.angle = body1.getAngle(); Body body2 = getWorld().createBody(bd); m_piece2 = body2.createFixture(m_shape2, 1.0f); // Compute consistent velocities for new bodies based on // cached velocity. Vec2 center1 = body1.getWorldCenter(); Vec2 center2 = body2.getWorldCenter(); Vec2 velocity1 = m_velocity.add(Vec2.cross(m_angularVelocity, center1.sub(center))); Vec2 velocity2 = m_velocity.add(Vec2.cross(m_angularVelocity, center2.sub(center))); body1.setAngularVelocity(m_angularVelocity); body1.setLinearVelocity(velocity1); body2.setAngularVelocity(m_angularVelocity); body2.setLinearVelocity(velocity2); }
public void drawSpriteForBody(Body body, Sprite sprite, SpriteBatch spriteBatch) { Vector2 offset = new Vector2(sprite.getWidth() / 2f, sprite.getHeight() / 2f); Vector2 position = body.getPosition().cpy().scl(Constants.PIXELS_PER_METER).sub(offset); float rotation = body.getAngle() * MathUtils.radiansToDegrees; sprite.setRotation(rotation); sprite.setPosition(position.x, position.y); sprite.draw(spriteBatch); }
builder.setAngle(argBody.getAngle()); builder.setLinearVelocity(vecToPb(argBody.getLinearVelocity())); builder.setAngularVelocity(argBody.getAngularVelocity());
void display() { Vec2 pos = box2d.getBodyPixelCoord(body); float a = body.getAngle(); rectMode(CENTER); pushMatrix(); translate(pos.x, pos.y); rotate(-a); fill(175); stroke(0); rect(0, 0, w, h); popMatrix(); }