use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class GImpactCollisionAlgorithm method gimpact_vs_compoundshape.
public void gimpact_vs_compoundshape(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, CompoundShape shape1, boolean swapped) {
Stack stack = Stack.enter();
Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
Transform childtrans1 = stack.allocTransform();
Transform tmpTrans = stack.allocTransform();
int i = shape1.getNumChildShapes();
while ((i--) != 0) {
CollisionShape colshape1 = shape1.getChildShape(i);
childtrans1.mul(orgtrans1, shape1.getChildTransform(i, tmpTrans));
body1.setWorldTransform(childtrans1);
// collide child shape
gimpact_vs_shape(body0, body1, shape0, colshape1, swapped);
// restore transforms
body1.setWorldTransform(orgtrans1);
}
stack.leave();
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class GImpactCollisionAlgorithm method collide_sat_triangles.
/*
protected void collide_gjk_triangles(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, GImpactMeshShapePart shape1, IntArrayList pairs, int pair_count) {
}
*/
void collide_sat_triangles(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, GImpactMeshShapePart shape1, PairSet pairs, int pair_count) {
Stack stack = Stack.enter();
Vector3f tmp = stack.allocVector3f();
Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
PrimitiveTriangle ptri0 = stack.allocPrimitiveTriangle();
PrimitiveTriangle ptri1 = stack.allocPrimitiveTriangle();
TriangleContact contact_data = stack.allocTriangleContact();
shape0.lockChildShapes();
shape1.lockChildShapes();
int pair_pointer = 0;
while ((pair_count--) != 0) {
//triface0 = pairs.get(pair_pointer);
//triface1 = pairs.get(pair_pointer + 1);
//pair_pointer += 2;
Pair pair = pairs.get(pair_pointer++);
triface0 = pair.index1;
triface1 = pair.index2;
shape0.getPrimitiveTriangle(triface0, ptri0);
shape1.getPrimitiveTriangle(triface1, ptri1);
//#ifdef TRI_COLLISION_PROFILING
//bt_begin_gim02_tri_time();
//#endif
ptri0.applyTransform(orgtrans0);
ptri1.applyTransform(orgtrans1);
// build planes
ptri0.buildTriPlane();
ptri1.buildTriPlane();
// test conservative
if (ptri0.overlap_test_conservative(ptri1)) {
if (ptri0.find_triangle_collision_clip_method(ptri1, contact_data)) {
int j = contact_data.point_count;
while ((j--) != 0) {
tmp.x = contact_data.separating_normal.x;
tmp.y = contact_data.separating_normal.y;
tmp.z = contact_data.separating_normal.z;
addContactPoint(body0, body1, contact_data.points[j], tmp, -contact_data.penetration_depth);
}
}
}
//#ifdef TRI_COLLISION_PROFILING
//bt_end_gim02_tri_time();
//#endif
}
shape0.unlockChildShapes();
shape1.unlockChildShapes();
stack.leave();
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class GameObject method updateBody.
public void updateBody(Mesh mesh) {
GameObject compParent = parent != null && parent.body.getCollisionShape().isCompound() ? parent : null;
boolean isCompChild = compParent != null && !(currBodyType == BodyType.NO_COLLISION || currBodyType == BodyType.SENSOR);
if (isCompChild) {
parent(null);
}
Matrix4f transform = transform();
Vector3f scale = scale();
CollisionShape shape = body.getCollisionShape();
body.setCollisionShape(Bullet.makeShape(mesh.model.meshes.first(), currBoundsType, shape.getMargin(), shape.isCompound()));
Transform startTransform = new Transform();
body.getMotionState().getWorldTransform(startTransform);
Matrix4f originMatrix = new Matrix4f();
originMatrix.set(origin);
Transform centerOfMassTransform = new Transform();
centerOfMassTransform.set(originMatrix);
centerOfMassTransform.mul(startTransform);
body.setCenterOfMassTransform(centerOfMassTransform);
transform(transform);
scale(scale);
if (body.isInWorld()) {
scene.world.updateSingleAabb(body);
} else {
// update Aabb hack for when not in world
scene.world.addRigidBody(body);
scene.world.updateSingleAabb(body);
scene.world.removeRigidBody(body);
}
if (isCompChild) {
parent(compParent);
}
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class GameObject method position.
public Vector3f position() {
Transform t = new Transform();
body.getWorldTransform(t);
return new Vector3f(t.origin);
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class GameObject method parent.
public void parent(GameObject p, boolean compound) {
CompoundShape compShapeOld = null;
if (parent != null) {
parent.children.remove(this);
if (compound) {
compShapeOld = parent.compoundShape();
if (compShapeOld != null) {
scene.world.removeRigidBody(parent.body);
compShapeOld.removeChildShape(body.getCollisionShape());
scene.world.addRigidBody(parent.body);
}
}
} else if (p == null) {
return;
}
parent = p;
if (parent != null) {
parent.children.add(this);
updateLocalTransform();
updateLocalScale();
if (compound) {
CompoundShape compShape = parent.compoundShape();
if (compShape != null) {
scene.world.removeRigidBody(body);
compShape.addChildShape(new Transform(localTransform), body.getCollisionShape());
}
} else {
dynamics(false);
}
} else if (currBodyType == BodyType.STATIC || currBodyType == BodyType.SENSOR) {
if (compound && compShapeOld != null)
scene.world.addRigidBody(body);
} else {
dynamics(true);
}
}
Aggregations