本文整理汇总了Java中com.badlogic.gdx.physics.box2d.Body.setTransform方法的典型用法代码示例。如果您正苦于以下问题:Java Body.setTransform方法的具体用法?Java Body.setTransform怎么用?Java Body.setTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.physics.box2d.Body
的用法示例。
在下文中一共展示了Body.setTransform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWall
import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
/**
* Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax),
* and rotating the box counterclockwise through the given angle, with specified restitution.
*/
public static Body createWall(World world, float xmin, float ymin, float xmax, float ymax,
float angle, float restitution) {
float cx = (xmin + xmax) / 2;
float cy = (ymin + ymax) / 2;
float hx = Math.abs((xmax - xmin) / 2);
float hy = Math.abs((ymax - ymin) / 2);
PolygonShape wallshape = new PolygonShape();
// Don't set the angle here; instead call setTransform on the body below. This allows future
// calls to setTransform to adjust the rotation as expected.
wallshape.setAsBox(hx, hy, new Vector2(0f, 0f), 0f);
FixtureDef fdef = new FixtureDef();
fdef.shape = wallshape;
fdef.density = 1.0f;
if (restitution>0) fdef.restitution = restitution;
BodyDef bd = new BodyDef();
bd.position.set(cx, cy);
Body wall = world.createBody(bd);
wall.createFixture(fdef);
wall.setType(BodyDef.BodyType.StaticBody);
wall.setTransform(cx, cy, angle);
return wall;
}
示例2: applyRotation
import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
public void applyRotation(Field field, double dt) {
currentAngle += dt*rotationSpeed;
if (currentAngle>TAU) currentAngle -= TAU;
if (currentAngle<0) currentAngle += TAU;
for(int i=0; i<elementIDs.length; i++) {
double angle = currentAngle + angleIncrement*i;
FieldElement element = field.getFieldElementById(elementIDs[i]);
Body body = element.getBodies().get(0);
double x = centerX + radius*Math.cos(angle);
double y = centerY + radius*Math.sin(angle);
body.setTransform((float)x, (float)y, body.getAngle());
}
}