@Override public void render () { if (m_platform.getType() == BodyType.KinematicBody) { Vector2 p = m_platform.getTransform().getPosition(); Vector2 v = m_platform.getLinearVelocity(); if ((p.x < -10 && v.x < 0) || (p.x > 10 && v.x > 0)) { v.x = -v.x; m_platform.setLinearVelocity(v); } } super.render(); // if (renderer.batch != null) { // renderer.batch.begin(); // // renderer.batch.drawText(renderer.font, "Keys: (d) dynamic, (s) static, (k) kinematic", 0, Gdx.app.getGraphics() // // .getHeight(), Color.WHITE); // renderer.batch.end(); // } } }
private void drawJoint (Joint joint) { Body bodyA = joint.getBodyA(); Body bodyB = joint.getBodyB(); Transform xf1 = bodyA.getTransform(); Transform xf2 = bodyB.getTransform(); Vector2 x1 = xf1.getPosition(); Vector2 x2 = xf2.getPosition(); Vector2 p1 = joint.getAnchorA(); Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { drawSegment(p1, p2, JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { PulleyJoint pulley = (PulleyJoint)joint; Vector2 s1 = pulley.getGroundAnchorA(); Vector2 s2 = pulley.getGroundAnchorB(); drawSegment(s1, p1, JOINT_COLOR); drawSegment(s2, p2, JOINT_COLOR); drawSegment(s1, s2, JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR); } else { drawSegment(x1, p1, JOINT_COLOR); drawSegment(p1, p2, JOINT_COLOR); drawSegment(x2, p2, JOINT_COLOR); } }
private void drawJoint (Joint joint) { Body bodyA = joint.getBodyA(); Body bodyB = joint.getBodyB(); Transform xf1 = bodyA.getTransform(); Transform xf2 = bodyB.getTransform(); Vector2 x1 = xf1.getPosition(); Vector2 x2 = xf2.getPosition(); Vector2 p1 = joint.getAnchorA(); Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { drawSegment(p1, p2, JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { PulleyJoint pulley = (PulleyJoint)joint; Vector2 s1 = pulley.getGroundAnchorA(); Vector2 s2 = pulley.getGroundAnchorB(); drawSegment(s1, p1, JOINT_COLOR); drawSegment(s2, p2, JOINT_COLOR); drawSegment(s1, s2, JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR); } else { drawSegment(x1, p1, JOINT_COLOR); drawSegment(p1, p2, JOINT_COLOR); drawSegment(x2, p2, JOINT_COLOR); } }
public void interpolate(float alpha) { for (Box box : activeBoxes) { Body body = box.getBody(); if(body.isActive()) { Transform transform = body.getTransform(); Vector2 bodyPosition = transform.getPosition(); float bodyAngle = transform.getRotation(); box.x = bodyPosition.x * alpha + box.x * (1.0f - alpha); box.y = bodyPosition.y * alpha + box.y * (1.0f - alpha); box.angle = bodyAngle * alpha + box.angle * (1.0f - alpha); } } }
private void drawJoint (Joint joint) { Body bodyA = joint.getBodyA(); Body bodyB = joint.getBodyB(); Transform xf1 = bodyA.getTransform(); Transform xf2 = bodyB.getTransform(); Vector2 x1 = xf1.getPosition(); Vector2 x2 = xf2.getPosition(); Vector2 p1 = joint.getAnchorA(); Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { drawSegment(p1, p2, JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { PulleyJoint pulley = (PulleyJoint)joint; Vector2 s1 = pulley.getGroundAnchorA(); Vector2 s2 = pulley.getGroundAnchorB(); drawSegment(s1, p1, JOINT_COLOR); drawSegment(s2, p2, JOINT_COLOR); drawSegment(s1, s2, JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR); } else { drawSegment(x1, p1, JOINT_COLOR); drawSegment(p1, p2, JOINT_COLOR); drawSegment(x2, p2, JOINT_COLOR); } }
Vector2 bodyPosition = bodyTransform.getPosition(); box.x = bodyPosition.x; box.y = bodyPosition.y;