use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class GImpactCollisionAlgorithm method gimpact_vs_shape_find_pairs.
protected void gimpact_vs_shape_find_pairs(Transform trans0, Transform trans1, GImpactShapeInterface shape0, CollisionShape shape1, IntArrayList collided_primitives) {
Stack stack = Stack.enter();
AABB boxshape = stack.allocAABB();
if (shape0.hasBoxSet()) {
Transform trans1to0 = stack.allocTransform();
trans1to0.inverse(trans0);
trans1to0.mul(trans1);
shape1.getAabb(trans1to0, boxshape.min, boxshape.max);
shape0.getBoxSet().boxQuery(boxshape, collided_primitives);
} else {
shape1.getAabb(trans1, boxshape.min, boxshape.max);
AABB boxshape0 = stack.allocAABB();
int i = shape0.getNumChildShapes();
while ((i--) != 0) {
shape0.getChildAabb(i, trans0, boxshape0.min, boxshape0.max);
if (boxshape.has_collision(boxshape0)) {
collided_primitives.add(i);
}
}
}
stack.leave();
}
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);
}
Aggregations