use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class EngineTest method init.
/*
* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
*/
public void init(GLAutoDrawable drawable) {
engine.init(drawable);
if (osEngine == null) {
osEngine = Engine.createOffScreenInstance(drawable, 512, 512);
//
Light osLight0 = osEngine.getLightAt(0);
osLight0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
osLight0.getDiffuse().set(1.0f, 1.0f, 1.0f, 1.0f);
osLight0.getPosition().set(0.0f, -4f, -4f, 1.0f);
osLight0.getSpotDirection().set(new Vector3(osLight0.getPosition().getArray())).sub(new Vector3(0f, 0f, 0f));
osLight0.setEnabled(true);
// cam
Camera osCam = osEngine.getCamera();
osCam.setZNear(0.10f);
osCam.setZFar(50.00f);
osCam.getLookFrom().set(0f, 4f, -4f);
osCam.getLookAt().set(0f, 0.50f, 0f);
osCam.computeUpVector(osCam.getLookFrom(), osCam.getLookAt(), osCam.getUpVector());
// scene color
osEngine.getSceneColor().set(0.5f, 0.0f, 0.0f, 1.0f);
}
// cam
Camera cam = engine.getCamera();
cam.setZNear(0.10f);
cam.setZFar(50.00f);
cam.getLookFrom().set(0f, 3f, -8f);
cam.getLookAt().set(0f, 0.50f, 0f);
cam.computeUpVector(cam.getLookFrom(), cam.getLookAt(), cam.getUpVector());
// lights
Light light0 = engine.getLightAt(0);
light0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
light0.getDiffuse().set(0.5f, 0.5f, 0.5f, 1f);
light0.getSpecular().set(1f, 1f, 1f, 1f);
light0.getPosition().set(0f, 20000f, 0f, 1f);
light0.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light0.getPosition().getArray()));
light0.setConstantAttenuation(0.5f);
light0.setLinearAttenuation(0f);
light0.setQuadraticAttenuation(0f);
light0.setSpotExponent(0f);
light0.setSpotCutOff(180f);
light0.setEnabled(true);
Light light1 = engine.getLightAt(1);
light1.getDiffuse().set(1.0f, 0.0f, 0.0f, 1.0f);
light1.getPosition().set(-4.0f, 5.0f, -5.0f, 1.0f);
light1.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light1.getPosition().getArray()));
light1.setEnabled(true);
Light light2 = engine.getLightAt(2);
light2.getDiffuse().set(0.0f, 1.0f, 0.0f, 1.0f);
light2.getPosition().set(+4.0f, 5.0f, 0.0f, 1.0f);
light2.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light2.getPosition().getArray()));
light2.setEnabled(true);
// scene
players = new ArrayList<Object3D>();
playersBoundingVolumeModel = new ArrayList<Object3D>();
playerBoundingVolumesTransformed = new ArrayList<BoundingVolume>();
try {
Model _barrel = DAEReader.read("resources/tests/models/barrel", "barrel.dae");
Object3D barrel = new Object3D("barrel", _barrel);
barrelBoundingVolume = new ConvexMesh(new Object3DModel(_barrel));
barrel.getTranslation().set(1.5f, 0.35f, -2f);
barrel.setDynamicShadowingEnabled(true);
barrel.setEnabled(true);
barrel.update();
barrelBoundingVolumeTransformed = barrelBoundingVolume.clone();
barrelBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(barrelBoundingVolume, barrel);
engine.addEntity(barrel);
// wall
Model _farPlane = createWallModel();
Object3D farPlane = new Object3D("wall", _farPlane);
farPlane.bindDiffuseTexture("wall", "wall", osEngine.getFrameBuffer());
engine.addEntity(farPlane);
//
Model _grass = DAEReader.read("resources/tests/models/grass", "grass.dae");
Object3D grass = new Object3D("ground", _grass);
grass.setEnabled(true);
grass.getScale().set(8f, 1f, 8f);
grass.update();
engine.addEntity(grass);
// players
Model _player = DAEReader.read("resources/tests/models/dummy", "testDummy_textured.DAE");
_player.addAnimationSetup("still", 3, 3, true);
_player.addAnimationSetup("walk", 0, 18, true);
// player bounding volume
// playerBoundingVolume = Sphere.createBoundingVolume(new Vector3(0,90f/130f,0), 90f/130f);
playerBoundingVolume = Capsule.createBoundingVolume(new Vector3(0, 30f / 130f, 0), new Vector3(0, 230f / 130f, 0), 25 / 130f);
// playerBoundingVolume = BoundingBox.createBoundingVolume(new Vector3(-25f/130f, 0, -25f/130f), new Vector3(+25f/130f, 180f/130f, +25f/130f));
/*
playerBoundingVolume = OrientedBoundingBox.createBoundingVolume(
new Vector3(0f, 90f/130f, 0f),
new Vector3(1f, 0f, 0f),
new Vector3(0f, 1f, 0f),
new Vector3(0f, 0f, 1f),
new Vector3(25f/130f, 90f/130f, 25f/130f)
);
*/
playerBoundingVolumeModel = PrimitiveModel.createModel(playerBoundingVolume, "player_bv");
// add player 1
// player
Object3D player1 = new Object3D("player1", _player);
player1.getTranslation().add(new Vector3(-1.50f, 0f, 0f));
player1.setAnimation("still");
player1.getRotations().add(new Rotation(0f, new Vector3(0f, 1f, 0f)));
player1.update();
player1.setEnabled(true);
player1.setPickable(true);
player1.setDynamicShadowingEnabled(true);
engine.addEntity(player1);
// bounding volume transformed
BoundingVolume player1BoundingVolumeTransformed = playerBoundingVolume.clone();
player1BoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player1);
playerBoundingVolumesTransformed.add(player1BoundingVolumeTransformed);
// add to engine
players.add(player1);
// bounding volume
Object3D player1BoundingVolume = new Object3D("player1_bv", playerBoundingVolumeModel);
player1BoundingVolume.fromTransformations(player1);
player1BoundingVolume.setEnabled(true);
playersBoundingVolumeModel.add(player1BoundingVolume);
// engine.addEntity(player1BoundingVolume);
// add player 2
// player
Object3D player2 = new Object3D("player2", _player);
player2.getTranslation().add(new Vector3(1.50f, 0f, 0f));
player2.setAnimation("still");
player2.getRotations().add(new Rotation(0f, new Vector3(0f, 1f, 0f)));
player2.update();
player2.setEnabled(true);
player2.setPickable(true);
player2.setDynamicShadowingEnabled(true);
players.add(player2);
// bounding volume transformed
BoundingVolume player2BoundingVolumeTransformed = playerBoundingVolume.clone();
player2BoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player2);
playerBoundingVolumesTransformed.add(player2BoundingVolumeTransformed);
// add to engine
engine.addEntity(player2);
// bounding volume
Object3D player2BoundingVolume = new Object3D("player2_bv", playerBoundingVolumeModel);
player2BoundingVolume.fromTransformations(player2);
player2BoundingVolume.setEnabled(true);
playersBoundingVolumeModel.add(player2BoundingVolume);
// engine.addEntity(player2BoundingVolume);
// add cube
Model _cube = DAEReader.read("resources/tests/models/test", "cube.dae");
cube = new Object3D("cube", _cube);
cube.getTranslation().add(new Vector3(0f, 0f, 0f));
cube.getScale().set(2f, 2f, 2f);
cube.update();
cube.setPickable(true);
cube.setDynamicShadowingEnabled(true);
cube.setEnabled(true);
cubeBoundingVolume = cube.getBoundingBox();
cubeBoundingVolumeTransformed = cubeBoundingVolume.clone();
cubeBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(cubeBoundingVolume, cube);
engine.addEntity(cube);
//
cubeBoundingVolumeModel = PrimitiveModel.createModel(cubeBoundingVolume, "cube_bv");
// bounding volume
Object3D cubeBoundingVolumeObject3D = new Object3D("cube_bv", cubeBoundingVolumeModel);
cubeBoundingVolumeObject3D.fromTransformations(cube);
cubeBoundingVolumeObject3D.setEnabled(true);
engine.addEntity(cubeBoundingVolumeObject3D);
// wall
Model _wall = DAEReader.read("resources/tests/models/wall", "wall.dae");
Object3D wall0 = new Object3D("wall0", _wall);
wall0.getTranslation().add(new Vector3(-1.00f, 0f, 3.00f));
wall0.update();
wall0.setPickable(true);
wall0.setEnabled(true);
engine.addEntity(wall0);
Object3D wall1 = new Object3D("wall1", _wall);
wall1.getTranslation().add(new Vector3(0f, 0f, 3.00f));
wall1.update();
wall1.setPickable(true);
wall1.setEnabled(true);
engine.addEntity(wall1);
// os engine test
Object3D osCube = new Object3D("cube", _cube);
osCube.getTranslation().add(new Vector3(0f, 0f, 0f));
osCube.getScale().set(2f, 2f, 2f);
osCube.update();
osEngine.addEntity(osCube);
//
circleTransformations = new Transformations();
engine.addEntity(new PointsParticleSystemEntity("circle", false, new CircleParticleEmitter(3000, 50, 50, new Vector3(1f, 0f, 0f), new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 0f), 0.4f, 0f, 0f, new Vector3(0f, 0.2f, 0f), new Vector3(0f, 0.2f, 0f), new Color4(1f, 1f, 1f, 0.3f), new Color4(1f, 1f, 1f, 0.3f)), 1000, true));
engine.getEntity("circle").setEnabled(true);
engine.addEntity(new PointsParticleSystemEntity("water", true, new SphereParticleEmitter(4000, 1000, 0, 0.1f, 0.0f, new Sphere(new Vector3(-1f, 1f, 0f), 0.05f), new Vector3(-4f, 0f, 1f), new Vector3(-1f, 0f, 0f), new Color4(0.8f, 0.8f, 1f, 0.25f), new Color4(0.8f, 0.8f, 1f, 0.25f)), 4000, true));
engine.getEntity("water").setEnabled(true);
engine.addEntity(new PointsParticleSystemEntity("snow", false, new BoundingBoxParticleEmitter(15, 15000, 1000, 0, 0, new OrientedBoundingBox(new Vector3(0f, 4f, 0f), new Vector3(1f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(0f, 0f, 1f), new Vector3(4f, 0f, 4f)), new Vector3(0f, -0.5f, 0f), new Vector3(0f, -0.1f, 0f), new Color4(0.8f, 0.8f, 1f, 0.5f), new Color4(0.8f, 0.8f, 1f, 0.5f)), 1024, true));
engine.getEntity("snow").setEnabled(true);
engine.addEntity(new PointsParticleSystemEntity("firebase", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.2f, 0f), 0.2f), new Vector3(0f, 0.1f, 0f), new Vector3(0f, 0.1f, 0f), new Color4(0.0f, 0f, 0f, 0.5f), new Color4(0.4f, 0f, 0f, 0.5f)), 2048, true));
engine.getEntity("firebase").setEnabled(true);
//
engine.addEntity(new PointsParticleSystemEntity("firetop", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.7f, 0f), 0.1f), new Vector3(0f, 0.06f, 0f), new Vector3(0f, 0.12f, 0f), new Color4(0.75f, 0.0f, 0f, 0.5f), new Color4(1f, 1f, 0f, 0.5f)), 2048, true));
engine.getEntity("firetop").setEnabled(true);
//
engine.addEntity(new PointsParticleSystemEntity("firesmoke", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.7f, 0f), 0.1f), new Vector3(0f, 0.2f, 0f), new Vector3(0f, 0.4f, 0f), new Color4(0.8f, 0.8f, 0.8f, 0.1f), new Color4(0.8f, 0.8f, 0.8f, 0.1f)), 2048, true));
engine.getEntity("firesmoke").setEnabled(true);
((ParticleSystemEntity) engine.getEntity("circle")).setPickable(false);
((ParticleSystemEntity) engine.getEntity("snow")).setPickable(false);
((ParticleSystemEntity) engine.getEntity("firebase")).setPickable(true);
((ParticleSystemEntity) engine.getEntity("firetop")).setPickable(true);
((ParticleSystemEntity) engine.getEntity("firesmoke")).setPickable(true);
} catch (Exception exception) {
exception.printStackTrace();
System.out.println("Could not load object: " + exception.getMessage());
}
}
use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class EngineTest method doPlayerControl.
/**
* Do player control
* @param idx
* @param key left
* @param key right
* @param key up
*/
private void doPlayerControl(int idx, boolean keyLeft, boolean keyRight, boolean keyUp) {
float fps = engine.getTiming().getCurrentFPS();
Object3D player = players.get(idx);
BoundingVolume playerBoundingVolumeTransformed = playerBoundingVolumesTransformed.get(idx);
Rotations rotations = player.getRotations();
Rotation r = rotations.get(0);
player.update();
Vector3 movement = new Vector3();
// left, right
if (keyRight)
r.setAngle(r.getAngle() - (135f / fps));
if (keyLeft)
r.setAngle(r.getAngle() + (135f / fps));
if (keyRight || keyLeft) {
player.update();
playerBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player);
}
// forward
if (keyUp) {
// apply movement
r.getQuaternion().multiply(new Vector3(0f, 0f, 1f), movement);
movement.scale(1.50f / fps);
player.getTranslation().add(movement);
player.update();
playerBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player);
// walking animation
if (player.getAnimation().equals("walk") == false) {
player.setAnimation("walk");
}
} else {
// still animation
if (player.getAnimation().equals("walk") == true) {
player.setAnimation("still");
}
}
// check if collides with cube
if (playerBoundingVolumeTransformed.doesCollideWith(cubeBoundingVolumeTransformed, movement, collision) == true && collision.hasPenetration() == true) {
System.out.println("cube: " + collision);
// yep, move object out of collision
player.getTranslation().sub(collision.getNormal().clone().scale(collision.getPenetration()));
player.update();
playerBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player);
}
// check if collides with barrel
if (CollisionDetection.getInstance().doCollide((Capsule) playerBoundingVolumeTransformed, (ConvexMesh) barrelBoundingVolumeTransformed, movement, collision) == true && collision.hasPenetration() == true) {
System.out.println("barrel: " + collision);
// yep, move object out of collision
player.getTranslation().sub(collision.getNormal().clone().scale(collision.getPenetration()));
player.update();
playerBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player);
}
// check if collides with other players
for (int i = 0; i < players.size(); i++) {
// do not check with same player
if (idx == i)
continue;
// do collide?
if (playerBoundingVolumeTransformed.doesCollideWith(playerBoundingVolumesTransformed.get(i), movement, collision) == true && collision.hasPenetration()) {
System.out.println("player: " + collision);
// yep, move object out of collision
player.getTranslation().sub(collision.getNormal().clone().scale(collision.getPenetration()));
player.update();
playerBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player);
}
}
}
use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class PhysicsTest1 method init.
/*
* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
*/
public void init(GLAutoDrawable drawable) {
drawable.getGL().setSwapInterval(0);
engine.init(drawable);
Object3D entity;
// cam
Camera cam = engine.getCamera();
cam.setZNear(0.10f);
cam.setZFar(50.00f);
cam.getLookFrom().set(0f, 4f * 2.5f, -6f * 2.5f);
cam.getLookAt().set(0f, 0.0f, 0f);
cam.computeUpVector(cam.getLookFrom(), cam.getLookAt(), cam.getUpVector());
// lights
Light light0 = engine.getLightAt(0);
light0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
light0.getDiffuse().set(0.5f, 0.5f, 0.5f, 1f);
light0.getSpecular().set(1f, 1f, 1f, 1f);
light0.getPosition().set(0f, 20000f, 0f, 1f);
light0.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light0.getPosition().getArray()));
light0.setConstantAttenuation(0.5f);
light0.setLinearAttenuation(0f);
light0.setQuadraticAttenuation(0f);
light0.setSpotExponent(0f);
light0.setSpotCutOff(180f);
light0.setEnabled(true);
// ground
OrientedBoundingBox ground = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(8f, 1f, 8f));
Model groundModel = PrimitiveModel.createModel(ground, "ground_model");
groundModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.8f, 0.8f, 1f);
groundModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 1f, 1f, 1f);
entity = new Object3D("ground", groundModel);
// entity.getRotations().add(new Rotation(10f, OrientedBoundingBox.AABB_AXIS_Z.clone()));
entity.update();
engine.addEntity(entity);
world.addStaticRigidBody("ground", true, RIGID_TYPEID_STANDARD, entity, ground, 0.5f);
// side
OrientedBoundingBox side = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(1f, 16f, 8f));
Model sideModel = PrimitiveModel.createModel(side, "side_model");
sideModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.8f, 0.8f, 1f);
sideModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 1f, 1f, 1f);
// far
OrientedBoundingBox nearFar = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(8f, 16f, 1f));
Model nearFarModel = PrimitiveModel.createModel(nearFar, "far_model");
nearFarModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.8f, 0.8f, 1f);
nearFarModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 1f, 1f, 1f);
// far
entity = new Object3D("far", nearFarModel);
entity.getTranslation().addZ(+9f);
entity.update();
engine.addEntity(entity);
world.addStaticRigidBody("far", true, RIGID_TYPEID_STANDARD, entity, nearFar, 0.5f);
// near
entity = new Object3D("near", nearFarModel);
entity.getTranslation().addZ(-9f);
entity.getEffectColorMul().set(1f, 1f, 1f, 0f);
entity.update();
engine.addEntity(entity);
world.addStaticRigidBody("near", true, RIGID_TYPEID_STANDARD, entity, nearFar, 0.5f);
// side left
entity = new Object3D("sideright", sideModel);
entity.getTranslation().addX(-9f);
entity.update();
engine.addEntity(entity);
world.addStaticRigidBody("sideright", true, RIGID_TYPEID_STANDARD, entity, side, 0.5f);
// side right
entity = new Object3D("sideleft", sideModel);
entity.getTranslation().addX(9f);
entity.update();
engine.addEntity(entity);
world.addStaticRigidBody("sideleft", true, RIGID_TYPEID_STANDARD, entity, side, 0.5f);
// box
OrientedBoundingBox box = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(0.6f, 0.6f, 0.6f));
Model boxModel = PrimitiveModel.createModel(box, "box_model");
boxModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.5f, 0.5f, 1f);
boxModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 0f, 1f);
// boxes
for (int i = 0; i < BOX_COUNT; i++) {
entity = new Object3D("box" + i, boxModel);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(10f + i * 3.0f);
entity.getTranslation().addX(-2f + i * 0.1f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("box" + i, true, RIGID_TYPEID_STANDARD, entity, box, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(box, 100f, 1f, 1f, 1f));
}
// stack
for (int i = 0; i < BOXSTACK_COUNT; i++) {
entity = new Object3D("box" + (BOX_COUNT + i), boxModel);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(1.6f + (i * 1.2f));
entity.getTranslation().addX(+3f);
entity.getTranslation().addZ(-5f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("box" + (BOX_COUNT + i), true, RIGID_TYPEID_STANDARD, entity, box, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(box, 100f, 1f, 1f, 1f));
}
// sphere
Sphere sphere = new Sphere(new Vector3(0f, 0f, 0f), 0.4f);
Model sphereModel = PrimitiveModel.createModel(sphere, "sphere_model");
sphereModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.5f, 0.8f, 0.8f, 1f);
sphereModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(0f, 1f, 1f, 1f);
// spheres
for (int i = 0; i < SPHERE_COUNT; i++) {
entity = new Object3D("sphere" + i, sphereModel);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(12f + (i * 1f));
entity.getTranslation().addX(0.45f * i - 3f);
entity.getTranslation().addZ(0.1f * i - 3f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("sphere" + i, true, RIGID_TYPEID_STANDARD, entity, sphere, 0.75f, 0.4f, 10f, RigidBody.computeInertiaMatrix(sphere, 10f, 1f, 1f, 1f));
}
// sphere
Capsule capsule = new Capsule(new Vector3(0f, 0.5f, 0f), new Vector3(0f, -0.5f, 0f), 0.25f);
Model capsuleModel = PrimitiveModel.createModel(capsule, "capsule_model");
capsuleModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.0f, 0.8f, 1f);
capsuleModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 1f, 1f);
//
for (int i = 0; i < CAPSULE_COUNT; i++) {
entity = new Object3D("capsule" + i, capsuleModel);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(14f + (i * 2f));
entity.getTranslation().addX((i * 0.5f));
// entity.getPivot().set(capsule.getCenter());
entity.update();
engine.addEntity(entity);
world.addRigidBody("capsule" + i, true, RIGID_TYPEID_STANDARD, entity, capsule, 0.0f, 0.4f, 3f, RigidBody.computeInertiaMatrix(capsule, 3f, 1f, 1f, 1f));
}
// sphere
//Capsule capsuleBig = new Capsule(
// new Vector3(0f,+1f,0f),
// new Vector3(0f,-1f,0f),
// 0.5f
//);
OrientedBoundingBox capsuleBig = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(0.5f, 1f, 0.5f));
Model capsuleBigModel = PrimitiveModel.createModel(capsuleBig, "capsulebig_model");
capsuleBigModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(1f, 0.8f, 0.8f, 1f);
capsuleBigModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 0f, 1f);
System.out.println(capsuleBig.getCenter());
//
entity = new Object3D("capsulebig1", capsuleBigModel);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(5f);
entity.getTranslation().addX(-2f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("capsulebig1", true, RIGID_TYPEID_STANDARD, entity, capsuleBig, 0f, 1f, 80f, RigidBody.getNoRotationInertiaMatrix());
//
entity = new Object3D("capsulebig2", capsuleBigModel);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(5f);
entity.getTranslation().addX(+2f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("capsulebig2", true, RIGID_TYPEID_STANDARD, entity, capsuleBig, 0f, 1f, 100f, RigidBody.getNoRotationInertiaMatrix());
try {
// load barrel, set up bounding volume
Model _barrel = DAEReader.read("resources/tests/models/barrel", "barrel.dae");
// _barrel.getImportTransformationsMatrix().scale(2f);
ConvexMesh barrelBoundingVolume = new ConvexMesh(new Object3DModel(_barrel));
// set up barrel 1 in 3d engine
entity = new Object3D("barrel1", _barrel);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(5f);
entity.getTranslation().addX(+4f);
entity.getScale().set(2f, 2f, 2f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("barrel1", true, RIGID_TYPEID_STANDARD, entity, barrelBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(barrelBoundingVolume, 100f, 1f, 1f, 1f));
// set up barrel 2 in 3d engine
entity = new Object3D("barrel2", _barrel);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(5f);
entity.getTranslation().addX(+6f);
entity.getScale().set(2f, 2f, 2f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("barrel2", true, RIGID_TYPEID_STANDARD, entity, barrelBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(barrelBoundingVolume, 100f, 1f, 1f, 1f));
// load cone, set up bounding volume
Model _cone = DAEReader.read("resources/tests/models/cone", "cone.dae");
// _barrel.getImportTransformationsMatrix().scale(2f);
ConvexMesh coneBoundingVolume = new ConvexMesh(new Object3DModel(_cone));
// set up cone 1 in 3d engine
entity = new Object3D("cone1", _cone);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(5f);
entity.getTranslation().addX(-4f);
entity.getScale().set(3f, 3f, 3f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("cone1", true, RIGID_TYPEID_STANDARD, entity, coneBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(coneBoundingVolume, 100f, 1f, 1f, 1f));
// set up cone 1 in 3d engine
entity = new Object3D("cone2", _cone);
entity.setDynamicShadowingEnabled(true);
entity.getTranslation().addY(5f);
entity.getTranslation().addX(-5f);
entity.getScale().set(3f, 3f, 3f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("cone2", true, RIGID_TYPEID_STANDARD, entity, coneBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(coneBoundingVolume, 100f, 1f, 1f, 1f));
// load cone, set up bounding volume
Model _tire = DAEReader.read("resources/tests/models/tire", "tire.dae");
// _barrel.getImportTransformationsMatrix().scale(2f);
ConvexMesh tireBoundingVolume = new ConvexMesh(new Object3DModel(_tire));
// set up tire 1 in 3d engine
entity = new Object3D("tire1", _tire);
entity.setDynamicShadowingEnabled(true);
entity.getRotations().add(new Rotation(90f, new Vector3(1f, 0f, 0f)));
entity.getTranslation().addY(5f);
entity.getTranslation().addX(-4f);
entity.getTranslation().addZ(-2f);
entity.getScale().set(2f, 2f, 2f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("tire1", true, RIGID_TYPEID_STANDARD, entity, tireBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(tireBoundingVolume, 100f, 1f, 1f, 1f));
// set up tire 1 in 3d engine
entity = new Object3D("tire2", _tire);
entity.setDynamicShadowingEnabled(true);
entity.getRotations().add(new Rotation(90f, new Vector3(1f, 0f, 0f)));
entity.getTranslation().addY(5f);
entity.getTranslation().addX(-6f);
entity.getTranslation().addZ(-2f);
entity.getScale().set(2f, 2f, 2f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("tire2", true, RIGID_TYPEID_STANDARD, entity, tireBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(tireBoundingVolume, 100f, 1f, 1f, 1f));
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class LevelEditorView method updateGrid.
/**
* Update dynamic grid
*/
private void updateGrid() {
// check if to display grid
if (gridEnabled == false)
return;
// TODO: use pool
// check if to move grid
int centerX = (int) gridCenter.getX();
int centerZ = (int) gridCenter.getZ();
int centerLastX = gridCenterLast == null ? centerX : (int) gridCenterLast.getX();
int centerLastZ = gridCenterLast == null ? centerZ : (int) gridCenterLast.getZ();
if (gridCenterLast != null && (centerLastX != centerX || centerLastZ != centerZ) == false) {
return;
}
int gridDimensionLeft = GRID_DIMENSION_X + (centerLastX < centerX ? centerX - centerLastX : 0);
int gridDimensionRight = GRID_DIMENSION_X + (centerLastX > centerX ? centerLastX - centerX : 0);
int gridDimensionNear = GRID_DIMENSION_Y + (centerLastZ < centerZ ? centerZ - centerLastZ : 0);
int gridDimensionFar = GRID_DIMENSION_Y + (centerLastZ > centerZ ? centerLastZ - centerZ : 0);
// create ground plates
int addedCells = 0;
int removedCells = 0;
int reAddedCells = 0;
for (int gridZ = -gridDimensionNear; gridZ < gridDimensionFar; gridZ++) for (int gridX = -gridDimensionLeft; gridX < gridDimensionRight; gridX++) {
String objectId = "leveleditor.ground@" + (centerX + gridX) + "," + (centerZ + gridZ);
Entity _object = engine.getEntity(objectId);
if (gridX < -GRID_DIMENSION_X || gridX >= GRID_DIMENSION_X || gridZ < -GRID_DIMENSION_Y || gridZ >= GRID_DIMENSION_Y) {
if (_object != null) {
engine.removeEntity(objectId);
removedCells++;
}
} else if (_object == null) {
_object = selectedObjectsById.get(objectId);
if (_object != null) {
engine.addEntity(_object);
reAddedCells++;
} else {
_object = new Object3D(objectId, levelEditorGround);
_object.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis0()));
_object.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis1()));
_object.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis2()));
_object.getTranslation().set(centerX + (float) gridX * groundPlateWidth, gridY - 0.05f, centerZ + (float) gridZ * groundPlateDepth);
//_object.setDynamicShadowingEnabled(false); // TODO
_object.setEnabled(true);
_object.setPickable(true);
_object.update();
setStandardObjectColorEffect(_object);
engine.addEntity(_object);
addedCells++;
}
}
}
// System.out.println("readded: " + reAddedCells + ", added: " + addedCells + ", removed: " + removedCells + ", total:" + engine.getEntityCount());
if (gridCenterLast == null)
gridCenterLast = new Vector3();
gridCenterLast.set(gridCenter);
}
use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.
the class LevelEditorView method computeSpotDirection.
/**
* Compute spot direction
* @param i
*/
public void computeSpotDirection(int i, Vector4 position, Vector3 spotTo) {
Vector3 _from = new Vector3(position.getArray());
Vector3 spotDirection = spotTo.clone().sub(_from);
// set up in level light
level.getLightAt(i).getPosition().set(position.getX(), position.getY(), position.getZ(), position.getW());
level.getLightAt(i).getSpotTo().set(spotTo.getX(), spotTo.getY(), spotTo.getZ());
level.getLightAt(i).getSpotDirection().set(spotDirection.getX(), spotDirection.getY(), spotDirection.getZ());
// set up in engine light
engine.getLightAt(i).getPosition().set(position.getX(), position.getY(), position.getZ(), position.getW());
engine.getLightAt(i).getSpotDirection().set(spotDirection.getX(), spotDirection.getY(), spotDirection.getZ());
// set light in controller
levelEditorScreenController.setLight(i, level.getLightAt(i).getAmbient(), level.getLightAt(i).getDiffuse(), level.getLightAt(i).getSpecular(), level.getLightAt(i).getPosition(), level.getLightAt(i).getConstantAttenuation(), level.getLightAt(i).getLinearAttenuation(), level.getLightAt(i).getQuadraticAttenuation(), level.getLightAt(i).getSpotTo(), level.getLightAt(i).getSpotDirection(), level.getLightAt(i).getSpotExponent(), level.getLightAt(i).getSpotCutOff(), level.getLightAt(i).isEnabled());
}
Aggregations