use of net.drewke.tdme.engine.physics.RigidBody in project tdme by andreasdr.
the class PhysicsTest3 method display.
/**
* Display
*/
public void display(GLAutoDrawable drawable) {
// apply some manual damping on boxes on x and z axis
for (int i = 0; i < BOX_COUNT; i++) {
RigidBody body = world.getRigidBody("box" + i);
body.getLinearVelocity().setX(body.getLinearVelocity().getX() * (1f - 1f / 10f));
body.getLinearVelocity().setZ(body.getLinearVelocity().getZ() * (1f - 1f / 10f));
}
for (int i = 0; i < BOXSTACK_COUNT; i++) {
RigidBody body = world.getRigidBody("box" + (BOX_COUNT + i));
body.getLinearVelocity().setX(body.getLinearVelocity().getX() * (1f - 1f / 10f));
body.getLinearVelocity().setZ(body.getLinearVelocity().getZ() * (1f - 1f / 10f));
}
RigidBody capsuleBig1 = world.getRigidBody("capsulebig1");
if (keyLeft)
capsuleBig1.getLinearVelocity().setX(8f);
else if (keyRight)
capsuleBig1.getLinearVelocity().setX(-8f);
else
capsuleBig1.getLinearVelocity().setX(0f);
if (keyUp)
capsuleBig1.getLinearVelocity().setZ(8f);
else if (keyDown)
capsuleBig1.getLinearVelocity().setZ(-8f);
else
capsuleBig1.getLinearVelocity().setZ(0f);
RigidBody capsuleBig2 = world.getRigidBody("capsulebig2");
if (keyA)
capsuleBig2.getLinearVelocity().setX(6f);
else if (keyD)
capsuleBig2.getLinearVelocity().setX(-6f);
else
capsuleBig2.getLinearVelocity().setX(0f);
if (keyW)
capsuleBig2.getLinearVelocity().setZ(6f);
else if (keyS)
capsuleBig2.getLinearVelocity().setZ(-6f);
else
capsuleBig2.getLinearVelocity().setZ(0f);
long start = System.currentTimeMillis();
// animator.getLastFPS();
float fps = 60f;
world.update(1f / fps);
world.synch(engine);
engine.display(drawable);
long end = System.currentTimeMillis();
System.out.println("PhysicsTest::display::" + (end - start) + "ms");
}
use of net.drewke.tdme.engine.physics.RigidBody in project tdme by andreasdr.
the class Level method addLevel.
/**
* Add level to physics world
* @param world
* @param level
* @param rigid bodies (will be filled by logic)
* @param translation
*/
public static void addLevel(World world, LevelEditorLevel level, ArrayList<RigidBody> rigidBodies, Vector3 translation) {
// load level objects
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject object = level.getObjectAt(i);
// skip on empties or trigger
if (object.getEntity().getType() == EntityType.EMPTY)
continue;
if (object.getEntity().getType() == EntityType.TRIGGER)
continue;
if (object.getEntity().getType() == EntityType.PARTICLESYSTEM)
continue;
//
for (int j = 0; j < object.getEntity().getBoundingVolumeCount(); j++) {
LevelEditorEntityBoundingVolume entityBv = object.getEntity().getBoundingVolumeAt(j);
// keep track of world ids
String worldId = object.getId() + ".bv." + j;
// TODO: apply transformations
Transformations transformations = new Transformations();
// apply transformations
transformations.fromTransformations(object.getTransformations());
// apply translation
if (translation != null) {
transformations.getTranslation().add(translation);
transformations.update();
}
// add to physics world
RigidBody rigidBody = world.addStaticRigidBody(worldId, true, RIGIDBODY_TYPEID_STATIC, transformations, entityBv.getBoundingVolume(), 1.0f);
rigidBody.setCollisionTypeIds(RIGIDBODY_TYPEID_STATIC | RIGIDBODY_TYPEID_PLAYER);
// add to rigid bodies
rigidBodies.add(rigidBody);
}
}
}
use of net.drewke.tdme.engine.physics.RigidBody in project tdme by andreasdr.
the class PhysicsTest1 method display.
/*
* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#display(com.jogamp.opengl.GLAutoDrawable)
*/
public void display(GLAutoDrawable drawable) {
// apply some manual damping on boxes on x and z axis
for (int i = 0; i < BOX_COUNT; i++) {
RigidBody body = world.getRigidBody("box" + i);
body.getLinearVelocity().setX(body.getLinearVelocity().getX() * (1f - 1f / 10f));
body.getLinearVelocity().setZ(body.getLinearVelocity().getZ() * (1f - 1f / 10f));
}
for (int i = 0; i < BOXSTACK_COUNT; i++) {
RigidBody body = world.getRigidBody("box" + (BOX_COUNT + i));
body.getLinearVelocity().setX(body.getLinearVelocity().getX() * (1f - 1f / 10f));
body.getLinearVelocity().setZ(body.getLinearVelocity().getZ() * (1f - 1f / 10f));
}
RigidBody capsuleBig1 = world.getRigidBody("capsulebig1");
if (keyLeft)
capsuleBig1.getLinearVelocity().setX(8f);
else if (keyRight)
capsuleBig1.getLinearVelocity().setX(-8f);
else
capsuleBig1.getLinearVelocity().setX(0f);
if (keyUp)
capsuleBig1.getLinearVelocity().setZ(8f);
else if (keyDown)
capsuleBig1.getLinearVelocity().setZ(-8f);
else
capsuleBig1.getLinearVelocity().setZ(0f);
RigidBody capsuleBig2 = world.getRigidBody("capsulebig2");
if (keyA)
capsuleBig2.getLinearVelocity().setX(6f);
else if (keyD)
capsuleBig2.getLinearVelocity().setX(-6f);
else
capsuleBig2.getLinearVelocity().setX(0f);
if (keyW)
capsuleBig2.getLinearVelocity().setZ(6f);
else if (keyS)
capsuleBig2.getLinearVelocity().setZ(-6f);
else
capsuleBig2.getLinearVelocity().setZ(0f);
long start = System.currentTimeMillis();
// animator.getLastFPS();
float fps = 60f;
world.update(1f / fps);
world.synch(engine);
engine.display(drawable);
long end = System.currentTimeMillis();
System.out.println("PhysicsTest::display::" + (end - start) + "ms");
}
use of net.drewke.tdme.engine.physics.RigidBody in project tdme by andreasdr.
the class Level method enableLevel.
/**
* Enable disabled level in physics world
* @param world
* @param level
* @param rigid bodies
* @param translation
*/
public static void enableLevel(World world, LevelEditorLevel level, ArrayList<RigidBody> rigidBodies, Vector3 translation) {
// load level objects
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject object = level.getObjectAt(i);
// TODO: this is nearly O(N^3), fix this
for (int j = 0; j < object.getEntity().getBoundingVolumeCount(); j++) {
for (int k = 0; k < rigidBodies.size(); k++) {
// world id
RigidBody rigidBody = rigidBodies.get(k);
// check if world id belong to current object
compareMutableString.set(object.getId());
compareMutableString.append(".bv.");
compareMutableString.append(j);
if (compareMutableString.equals(rigidBody.getId()) == false)
continue;
// set new transformations
transformations.fromTransformations(object.getTransformations());
// apply translations
if (translation != null) {
transformations.getTranslation().add(translation);
transformations.update();
}
rigidBody.synch(transformations);
// enable
rigidBody.setEnabled(true);
}
}
}
}
Aggregations