use of net.drewke.tdme.engine.primitives.OrientedBoundingBox in project tdme by andreasdr.
the class LevelEditorEntityBoundingVolume method setupObb.
/**
* Setup bounding volume oriented bounding box
* @param center
* @param axis 0
* @param axis 1
* @param axis 2
* @param half extension
*/
public void setupObb(Vector3 center, Vector3 axis0, Vector3 axis1, Vector3 axis2, Vector3 halfExtension) {
boundingVolume = new OrientedBoundingBox(center, axis0, axis1, axis2, halfExtension);
model = PrimitiveModel.createModel(boundingVolume, (levelEditorEntity.getModel() != null ? levelEditorEntity.getModel().getId() : levelEditorEntity.getId()) + "_model_bv." + id + "." + (staticIdx++));
modelMeshFile = null;
updateLevelEditorEntity();
}
use of net.drewke.tdme.engine.primitives.OrientedBoundingBox in project tdme by andreasdr.
the class EntityBoundingVolumeView method resetBoundingVolume.
/**
* Reset bounding volume
* @param entity
* @param idx
*/
public void resetBoundingVolume(LevelEditorEntity entity, int idx) {
// determine AABB
BoundingBox aabb = null;
// if we have a model we also have a AABB
if (entity.getModel() != null) {
aabb = entity.getModel().getBoundingBox();
} else {
// otherwise just create one for now
// this applies currently for particle systems
// TODO: check if particle system
aabb = new BoundingBox(new Vector3(-0.5f, 0f, -0.5f), new Vector3(0.5f, 3f, 0.5f));
}
// set up oriented bounding box
OrientedBoundingBox obb = new OrientedBoundingBox(aabb);
// set up sphere
modelViewerScreenController.setupSphere(idx, obb.getCenter(), obb.getHalfExtension().computeLength());
// set up capsule
{
Vector3 a = new Vector3();
Vector3 b = new Vector3();
float radius = 0.0f;
float[] halfExtensionXYZ = obb.getHalfExtension().getArray();
// determine a, b
if (halfExtensionXYZ[0] > halfExtensionXYZ[1] && halfExtensionXYZ[0] > halfExtensionXYZ[2]) {
radius = (float) Math.sqrt(halfExtensionXYZ[1] * halfExtensionXYZ[1] + halfExtensionXYZ[2] * halfExtensionXYZ[2]);
a.set(obb.getAxes()[0]);
a.scale(-(halfExtensionXYZ[0] - radius));
a.add(obb.getCenter());
b.set(obb.getAxes()[0]);
b.scale(+(halfExtensionXYZ[0] - radius));
b.add(obb.getCenter());
} else if (halfExtensionXYZ[1] > halfExtensionXYZ[0] && halfExtensionXYZ[1] > halfExtensionXYZ[2]) {
radius = (float) Math.sqrt(halfExtensionXYZ[0] * halfExtensionXYZ[0] + halfExtensionXYZ[2] * halfExtensionXYZ[2]);
a.set(obb.getAxes()[1]);
a.scale(-(halfExtensionXYZ[1] - radius));
a.add(obb.getCenter());
b.set(obb.getAxes()[1]);
b.scale(+(halfExtensionXYZ[1] - radius));
b.add(obb.getCenter());
} else {
radius = (float) Math.sqrt(halfExtensionXYZ[0] * halfExtensionXYZ[0] + halfExtensionXYZ[1] * halfExtensionXYZ[1]);
a.set(obb.getAxes()[2]);
a.scale(-(halfExtensionXYZ[2] - radius));
a.add(obb.getCenter());
b.set(obb.getAxes()[2]);
b.scale(+(halfExtensionXYZ[2] - radius));
b.add(obb.getCenter());
}
// setup capsule
modelViewerScreenController.setupCapsule(idx, a, b, radius);
}
// set up AABB bounding box
modelViewerScreenController.setupBoundingBox(idx, aabb.getMin(), aabb.getMax());
// set up oriented bounding box
modelViewerScreenController.setupOrientedBoundingBox(idx, obb.getCenter(), obb.getAxes()[0], obb.getAxes()[1], obb.getAxes()[2], obb.getHalfExtension());
//
modelViewerScreenController.selectBoundingVolume(idx, EntityBoundingVolumeSubScreenController.BoundingVolumeType.NONE);
}
use of net.drewke.tdme.engine.primitives.OrientedBoundingBox in project tdme by andreasdr.
the class PhysicsTest2 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();
// Test scenario serg
cam.setZNear(0.1f);
cam.setZFar(100.00f);
cam.getLookFrom().set(0f, 30f, 30f);
cam.getLookAt().set(0f, 0f, 0f);
// 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(30f, 1f, 30f));
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.getTranslation().setY(-1f);
entity.update();
engine.addEntity(entity);
world.addStaticRigidBody("ground", true, RIGID_TYPEID_STANDARD, entity, ground, 0.5f);
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(1f, 1f, 1f));
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(i * 2f + 1f);
//entity.getTranslation().addX(i * 50f);
entity.update();
engine.addEntity(entity);
world.addRigidBody("box" + i, true, RIGID_TYPEID_STANDARD, entity, box, 0f, 0.8f, 100f, RigidBody.computeInertiaMatrix(box, 100f, 1f, 1f, 1f));
}
}
use of net.drewke.tdme.engine.primitives.OrientedBoundingBox in project tdme by andreasdr.
the class PhysicsTest3 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);
// 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 {
Model _terrainModel = DAEReader.read("resources/tests/environment/terrain_test", "terrain_test.dae");
_terrainModel.getImportTransformationsMatrix().scale(1.5f);
entity = new Object3D("terrain", _terrainModel);
entity.getTranslation().setY(-4f);
entity.update();
engine.addEntity(entity);
ArrayList<ConvexMesh> groundConvexMeshes = new ArrayList<ConvexMesh>();
ConvexMesh.createTerrainConvexMeshes(new Object3DModel(_terrainModel), groundConvexMeshes);
for (int i = 0; i < groundConvexMeshes.size(); i++) {
world.addStaticRigidBody("ground" + i, true, RIGID_TYPEID_STANDARD, entity, groundConvexMeshes.get(i), 0.5f);
}
// 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();
}
}
Aggregations