/** Initialize the bodies, anchors, and reference angle using a world anchor point. */ public void initialize (Body bodyA, Body bodyB, Vector2 anchor) { this.bodyA = bodyA; this.bodyB = bodyB; localAnchorA.set(bodyA.getLocalPoint(anchor)); localAnchorB.set(bodyB.getLocalPoint(anchor)); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); }
/** Initialize the bodies, anchors, and reference angle using a world anchor point. */ public void initialize (Body body1, Body body2, Vector2 anchor) { this.bodyA = body1; this.bodyB = body2; this.localAnchorA.set(body1.getLocalPoint(anchor)); this.localAnchorB.set(body2.getLocalPoint(anchor)); referenceAngle = body2.getAngle() - body1.getAngle(); }
/** Initialize the bodies, anchors, and reference angle using a world anchor point. */ public void initialize (Body bodyA, Body bodyB, Vector2 anchor) { this.bodyA = bodyA; this.bodyB = bodyB; localAnchorA.set(bodyA.getLocalPoint(anchor)); localAnchorB.set(bodyB.getLocalPoint(anchor)); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); }
/** Initialize the bodies, anchors, axis, and reference angle using the world anchor and world axis. */ public void initialize (Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis) { this.bodyA = bodyA; this.bodyB = bodyB; localAnchorA.set(bodyA.getLocalPoint(anchor)); localAnchorB.set(bodyB.getLocalPoint(anchor)); localAxisA.set(bodyA.getLocalVector(axis)); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); }
/** Initialize the bodies, anchors, axis, and reference angle using the world anchor and world axis. */ public void initialize (Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis) { this.bodyA = bodyA; this.bodyB = bodyB; localAnchorA.set(bodyA.getLocalPoint(anchor)); localAnchorB.set(bodyB.getLocalPoint(anchor)); localAxisA.set(bodyA.getLocalVector(axis)); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); }
private void renderBox (Body body, float halfWidth, float halfHeight) { // get the bodies center and angle in world coordinates Vector2 pos = body.getWorldCenter(); float angle = body.getAngle(); // set the translation and rotation matrix transform.setToTranslation(pos.x, pos.y, 0); transform.rotate(0, 0, 1, (float)Math.toDegrees(angle)); // render the box renderer.begin(ShapeType.Line); renderer.setTransformMatrix(transform); renderer.setColor(1, 1, 1, 1); renderer.rect(-halfWidth, -halfHeight, halfWidth * 2, halfHeight * 2); renderer.end(); }
public void create () { cam = new OrthographicCamera(48, 32); cam.position.set(0, 15, 0); renderer = new Box2DDebugRenderer(); world = new World(new Vector2(0, -10), true); Body body = world.createBody(new BodyDef()); CircleShape shape = new CircleShape(); shape.setRadius(1f); MassData mass = new MassData(); mass.mass = 1f; body.setMassData(mass); body.setFixedRotation(true); body.setType(BodyType.KinematicBody); body.createFixture(shape, 1); body.setBullet(true); body.setTransform(new Vector2(0, 0), body.getAngle()); body.setLinearVelocity(new Vector2(50f, 0)); }
Body box = boxes.get(i); float angle = MathUtils.radiansToDegrees * box.getAngle(); // the rotation angle around the center batch.draw(textureRegion, position.x - 1, position.y - 1, // the bottom left corner of the box, unrotated 1f, 1f, // the rotation center relative to the bottom left corner of the box
public Box(float x, float y, float box_width, float box_height, Texture texture) { BOX_WIDTH = box_width; BOX_HEIGHT = box_height; boxTex = texture; boxBody = createPolygon(BodyType.DynamicBody, x, y, 1f, 0.2f, 0.8f, box_width * 0.5f, box_height * 0.5f); this.x = x - (BOX_WIDTH*.5f); this.y = y - (BOX_HEIGHT*.5f); this.angle = boxBody.getAngle(); }
@Override public void saveStateTo (EntityRenderState state) { state.position.set(body.getPosition()); state.orientation = body.getAngle(); }
/** Initialize the bodies, anchors, and reference angle using a world anchor point. */ public void initialize (Body body1, Body body2, Vector2 anchor) { this.bodyA = body1; this.bodyB = body2; this.localAnchorA.set(body1.getLocalPoint(anchor)); this.localAnchorB.set(body2.getLocalPoint(anchor)); referenceAngle = body2.getAngle() - body1.getAngle(); }
/** Initialize the bodies, anchors, axis, and reference angle using the world anchor and world axis. */ public void initialize (Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis) { this.bodyA = bodyA; this.bodyB = bodyB; localAnchorA.set(bodyA.getLocalPoint(anchor)); localAnchorB.set(bodyB.getLocalPoint(anchor)); localAxisA.set(bodyA.getLocalVector(axis)); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); }
@Override public boolean mouseMoved(int screenX, int screenY) { viewport.getCamera().unproject(point.set(screenX, screenY, 0)); pointerBody.setTransform(point.x, point.y, pointerBody.getAngle() + 5 * MathUtils.degreesToRadians); return true; }
protected void updateBody() { if (body == null || staticLight) return; final Vector2 vec = body.getPosition(); float angle = body.getAngle(); final float cos = MathUtils.cos(angle); final float sin = MathUtils.sin(angle); final float dX = bodyOffsetX * cos - bodyOffsetY * sin; final float dY = bodyOffsetX * sin + bodyOffsetY * cos; start.x = vec.x + dX; start.y = vec.y + dY; setDirection(bodyAngleOffset + angle * MathUtils.radiansToDegrees); }
protected void updateBody() { if (body == null || staticLight) return; final Vector2 vec = body.getPosition(); float angle = body.getAngle(); final float cos = MathUtils.cos(angle); final float sin = MathUtils.sin(angle); final float dX = bodyOffsetX * cos - bodyOffsetY * sin; final float dY = bodyOffsetX * sin + bodyOffsetY * cos; start.x = vec.x + dX; start.y = vec.y + dY; setDirection(bodyAngleOffset + angle * MathUtils.radiansToDegrees); }
/** * set the position use the camera's viewPort . the zero-zero is on the left bottom */ public void setPosition(final float x,final float y){ super.setPosition(x, y); model.body.setTransform(new Vector2(x,y).add(model.drawableOffsetX,model.drawableOffsetY).scl(1/RADIO), model.body.getAngle()); }