本文整理汇总了Java中org.jbox2d.dynamics.BodyType.KINEMATIC属性的典型用法代码示例。如果您正苦于以下问题:Java BodyType.KINEMATIC属性的具体用法?Java BodyType.KINEMATIC怎么用?Java BodyType.KINEMATIC使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jbox2d.dynamics.BodyType
的用法示例。
在下文中一共展示了BodyType.KINEMATIC属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Init
@Override
public synchronized void Init()
{
//System.out.println("init");
Vector2 meters = Coordinates.PixelsToMeters(this.position);
Vector2 meterssize = Coordinates.PixelsToMeters(this.size);
//System.out.println("Metersize: " + meterssize.ToString());
//System.out.println("Metersize to pixels: " + Coordinates.MetersToPixels(meterssize).ToString());
//System.out.println("this.size is " + this.size.ToString());
this.physics = new BoxPhysics(meters.x, meters.y, meterssize.x, meterssize.y, (this.simulatePhysics) ? BodyType.DYNAMIC : BodyType.KINEMATIC, this, this.information);
this.physics.Create();
//this.physics.GetPhysicsBody().setFixedRotation(false);
//this.physics.GetPhysicsBody().setBullet(true);
super.Init();
System.out.println("My name is " + this.name);
//System.out.println("Physics size is " + this.physics.GetPhysicsBody().getToString());
}
示例2: step
/**
* @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.TestbedSettings)
*/
@Override
public void step(TestbedSettings settings) {
super.step(settings);
addTextLine("Keys: (d) dynamic, (s) static, (k) kinematic");
// Drive the kinematic body.
if (m_platform.getType() == BodyType.KINEMATIC) {
Vec2 p = m_platform.getTransform().position;
Vec2 v = m_platform.getLinearVelocity();
if ((p.x < -10.0f && v.x < 0.0f) || (p.x > 10.0f && v.x > 0.0f)) {
v.x = -v.x;
m_platform.setLinearVelocity(v);
}
}
}
示例3: setType
/**
* Sets the simulation type of the physical body. It can be one of the values
* {@link Behavior#STATIC}, {@link Behavior#DYNAMIC}, or {@link Behavior#KINEMATIC}.
*
* @param type The desired simulation type
*
* @see Behavior
*/
public final void setType(Behavior type) {
if (body != null) {
switch (type) {
case DYNAMIC:
body.m_type = BodyType.DYNAMIC;
break;
case STATIC:
body.m_type = BodyType.STATIC;
break;
default:
body.m_type = BodyType.KINEMATIC;
break;
}
} else desc.type = type;
}
示例4: step
@Override
public void step(TestbedSettings settings) {
super.step(settings);
addTextLine("Keys: (d) dynamic, (s) static, (k) kinematic");
// Drive the kinematic body.
if (m_platform.getType() == BodyType.KINEMATIC) {
Vec2 p = m_platform.getTransform().p;
Vec2 v = m_platform.getLinearVelocity();
if ((p.x < -10.0f && v.x < 0.0f) || (p.x > 10.0f && v.x > 0.0f)) {
v.x = -v.x;
m_platform.setLinearVelocity(v);
}
}
}
示例5: step
/**
* @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.ShowcaseSettings)
*/
@Override
public void step(ShowcaseSettings settings) {
super.step(settings);
// Drive the kinematic body.
if (m_platform.getType() == BodyType.KINEMATIC) {
Vec2 p = m_platform.getTransform().position;
Vec2 v = m_platform.getLinearVelocity();
if ((p.x < -10.0f && v.x < 0.0f) || (p.x > 10.0f && v.x > 0.0f)) {
v.x = -v.x;
m_platform.setLinearVelocity(v);
}
}
}
示例6: createSnapshot
public PhysicsComponentSnapshot createSnapshot()
{
PhysicsComponentSnapshot snapshot = new PhysicsComponentSnapshot();
snapshot.position = new Vector2(engineBody.getPosition().x, engineBody.getPosition().y);
snapshot.angle = engineBody.getAngle();
if (engineBody.m_type == BodyType.DYNAMIC)
snapshot.type = PhysicsComponentType.DYNAMIC;
else if (engineBody.m_type == BodyType.KINEMATIC)
snapshot.type = PhysicsComponentType.KINEMATIC;
else if (engineBody.m_type == BodyType.STATIC)
snapshot.type = PhysicsComponentType.STATIC;
List<PhysicsShapeSnapshot> snapshots = new ArrayList<PhysicsShapeSnapshot>();
shapePool.foreach((PhysicsShape shape) -> {
if (shape.isRelevantToClient())
snapshots.addAll(shape.getSnapshots());
});
snapshot.shapes = new PhysicsShapeSnapshot[snapshots.size()];
snapshots.toArray(snapshot.shapes);
return snapshot;
}
示例7: createBody
protected final Body createBody(float x, float y, float rotation) {
BodyDef bd = new BodyDef();
bd.position.set(toBox2dCS(x, y));
bd.angle = (float) Math.toRadians(rotation);
bd.type = isStatic() ? BodyType.STATIC : kinematic ? BodyType.KINEMATIC : BodyType.DYNAMIC;
bd.fixedRotation = isBodyRotationFixed();
Body body = parent.physicsWorld.createBody(bd);
body.setUserData(this);
if( flying ) {
body.setGravityScale(0);
body.setLinearDamping(0);
}
return body;
}
示例8: Init
@Override
public synchronized void Init()
{
Vector2 scaledPosition = Coordinates.PixelsToMeters(this.position);
Vector2 scaledSize = Coordinates.PixelsToMeters(this.size);
this.physics = new EllipsePhysics(scaledPosition.x, scaledPosition.y, scaledSize.y, this.simulatePhysics ? (BodyType.DYNAMIC) : (BodyType.KINEMATIC), this, this.information);
this.physics.GetPhysicsBody().setFixedRotation(false);
super.Init();
}
示例9: SetDefaultBoxPhysics
public void SetDefaultBoxPhysics(Box box, PhysicsInformation information)
{
Vector2 meters = Coordinates.PixelsToMeters(this.position);
Vector2 meterssize = Coordinates.PixelsToMeters(this.size);
this.physics = new BoxPhysics(meters.x, meters.y, meterssize.x, meterssize.y, (this.simulatePhysics) ? BodyType.DYNAMIC : BodyType.KINEMATIC, box, information);
this.physics.GetPhysicsBody().setFixedRotation(false);
}
示例10: SetDefaultEllipsePhysics
public void SetDefaultEllipsePhysics(Ellipse ellipse, PhysicsInformation information)
{
Vector2 meters = Coordinates.PixelsToMeters(this.position);
Vector2 meterssize = Coordinates.PixelsToMeters(this.size);
this.physics = new EllipsePhysics(meters.x, meters.y, meterssize.y, (this.simulatePhysics) ? BodyType.DYNAMIC : BodyType.KINEMATIC, ellipse, information);
this.physics.GetPhysicsBody().setFixedRotation(false);
}
示例11: Init
@Override
public synchronized void Init()
{
Vector2 meters = Coordinates.PixelsToMeters(this.position);
Vector2 meterssize = Coordinates.PixelsToMeters(this.size);
float width = Coordinates.PixelsToMeters(new Vector2(Core.GAME_WIDTH, 0)).x;
this.physics = new GroundPhysics(meters.x, meters.y, meterssize.x, meterssize.y, BodyType.KINEMATIC, this);
this.physics.GetPhysicsBody().setActive(true);
this.physics.GetPhysicsBody().setGravityScale(0);
super.Init();
}
示例12: attach
/**
* Attaches a physical body to the simulator. You do not need to call this method directly if
* you are using physics simulation through a scene.
*
* @param body The new physical body
*
* @see com.annahid.libs.artenus.physics.PhysicalBody
*/
public void attach(PhysicalBody body) {
if (body.body == null) {
final PhysicalBody.Descriptor bodyDesc = body.desc;
final BodyDef def = new BodyDef();
def.allowSleep = true;
def.angularDamping = bodyDesc.angularDamping;
def.angularVelocity = bodyDesc.angularVelocity;
def.bullet = bodyDesc.bullet;
def.fixedRotation = bodyDesc.fixedRotation;
def.linearDamping = bodyDesc.linearDamping;
switch (bodyDesc.type) {
case DYNAMIC:
def.type = BodyType.DYNAMIC;
break;
case STATIC:
def.type = BodyType.STATIC;
break;
default:
def.type = BodyType.KINEMATIC;
break;
}
body.body = world.createBody(def);
body.body.m_userData = body;
body.createFixture();
body.setPosition(bodyDesc.position.x, bodyDesc.position.y);
body.setRotation(bodyDesc.angle);
body.body.setLinearVelocity(new Vec2(bodyDesc.linearVelocity.x, bodyDesc.linearVelocity.y));
body.body.setActive(def.active);
body.desc = null;
for (JointDescriptor joint : body.joints) {
if (joint.jointObject == null && joint.body1.body != null && joint.body2.body != null) {
switch (joint.jointType) {
case RevoluteJointDescriptor.TYPE:
final RevoluteJointDef jointDef = new RevoluteJointDef();
final Point2D anchor = ((RevoluteJointDescriptor) joint).anchorPoint;
jointDef.initialize(joint.body1.body, joint.body2.body, new Vec2(anchor.x / PhysicsSimulator.pixelsPerMeter, anchor.y / PhysicsSimulator.pixelsPerMeter));
joint.jointObject = world.createJoint(jointDef);
break;
default:
break;
}
}
}
}
}
示例13: deserializeBody
public Body deserializeBody(World argWorld, PbBody argBody) {
PbBody b = argBody;
BodyDef bd = new BodyDef();
bd.position.set(pbToVec(b.getPosition()));
bd.angle = b.getAngle();
bd.linearDamping = b.getLinearDamping();
bd.angularDamping = b.getAngularDamping();
bd.gravityScale = b.getGravityScale();
// velocities are populated after fixture addition
bd.bullet = b.getBullet();
bd.allowSleep = b.getAllowSleep();
bd.awake = b.getAwake();
bd.active = b.getActive();
bd.fixedRotation = b.getFixedRotation();
switch (b.getType()) {
case DYNAMIC:
bd.type = BodyType.DYNAMIC;
break;
case KINEMATIC:
bd.type = BodyType.KINEMATIC;
break;
case STATIC:
bd.type = BodyType.STATIC;
break;
default:
UnsupportedObjectException e =
new UnsupportedObjectException("Unknown body type: " + argBody.getType(), Type.BODY);
if (ulistener == null || ulistener.isUnsupported(e)) {
throw e;
}
return null;
}
Body body = argWorld.createBody(bd);
for (int i = 0; i < b.getFixturesCount(); i++) {
deserializeFixture(body, b.getFixtures(i));
}
// adding fixtures can change this, so we put this here and set it directly in the body
body.m_linearVelocity.set(pbToVec(b.getLinearVelocity()));
body.m_angularVelocity = b.getAngularVelocity();
if (listener != null && b.hasTag()) {
listener.processBody(body, b.getTag());
}
return body;
}