本文整理匯總了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());
}
}