本文整理了Java中com.badlogic.gdx.physics.box2d.Body.getTransform()
方法的一些代码示例,展示了Body.getTransform()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.getTransform()
方法的具体详情如下:
包路径:com.badlogic.gdx.physics.box2d.Body
类名称:Body
方法名:getTransform
[英]Get the body transform for the body's origin.
[中]获取实体原点的实体变换。
代码示例来源:origin: libgdx/libgdx
@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();
// }
}
}
代码示例来源:origin: libgdx/libgdx
protected void renderBody (Body body) {
Transform transform = body.getTransform();
for (Fixture fixture : body.getFixtureList()) {
if (drawBodies) {
drawShape(fixture, transform, getColorByBody(body));
if (drawVelocities) {
Vector2 position = body.getPosition();
drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
}
}
if (drawAABBs) {
drawAABB(fixture, transform);
}
}
}
代码示例来源:origin: libgdx/libgdx
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);
}
}
代码示例来源:origin: libgdx/libgdx
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);
}
}
代码示例来源:origin: libgdx/libgdx
protected void renderBody (Body body) {
Transform transform = body.getTransform();
int len = body.getFixtureList().size;
Array<Fixture> fixtures = body.getFixtureList();
for (int i = 0; i < len; i++) {
Fixture fixture = fixtures.get(i);
if (drawBodies) {
if (body.isActive() == false && drawInactiveBodies)
drawShape(fixture, transform, SHAPE_NOT_ACTIVE);
else if (body.getType() == BodyType.StaticBody)
drawShape(fixture, transform, SHAPE_STATIC);
else if (body.getType() == BodyType.KinematicBody)
drawShape(fixture, transform, SHAPE_KINEMATIC);
else if (body.isAwake() == false)
drawShape(fixture, transform, SHAPE_NOT_AWAKE);
else
drawShape(fixture, transform, SHAPE_AWAKE);
}
if (drawAABBs) {
drawAABB(fixture, transform);
}
}
}
代码示例来源:origin: dsaltares/libgdx-cookbook
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);
}
}
}
代码示例来源:origin: com.badlogicgames.gdx/gdx-box2d
protected void renderBody (Body body) {
Transform transform = body.getTransform();
for (Fixture fixture : body.getFixtureList()) {
if (drawBodies) {
drawShape(fixture, transform, getColorByBody(body));
if (drawVelocities) {
Vector2 position = body.getPosition();
drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
}
}
if (drawAABBs) {
drawAABB(fixture, transform);
}
}
}
代码示例来源:origin: com.badlogicgames.gdx/gdx-box2d
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);
}
}
代码示例来源:origin: dsaltares/libgdx-cookbook
Transform bodyTransform = box.getBody().getTransform();
Vector2 bodyPosition = bodyTransform.getPosition();
box.x = bodyPosition.x;
内容来源于网络,如有侵权,请联系作者删除!