use of com.bulletphysics.collision.shapes.StaticPlaneShape in project bdx by GoranM.
the class ConvexPlaneCollisionAlgorithm method processCollision.
@Override
public void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
if (manifoldPtr == null) {
return;
}
Stack stack = Stack.enter();
Transform tmpTrans = stack.allocTransform();
CollisionObject convexObj = isSwapped ? body1 : body0;
CollisionObject planeObj = isSwapped ? body0 : body1;
ConvexShape convexShape = (ConvexShape) convexObj.getCollisionShape();
StaticPlaneShape planeShape = (StaticPlaneShape) planeObj.getCollisionShape();
boolean hasCollision = false;
Vector3f planeNormal = planeShape.getPlaneNormal(stack.allocVector3f());
float planeConstant = planeShape.getPlaneConstant();
Transform planeInConvex = stack.allocTransform();
convexObj.getWorldTransform(planeInConvex);
planeInConvex.inverse();
planeInConvex.mul(planeObj.getWorldTransform(tmpTrans));
Transform convexInPlaneTrans = stack.allocTransform();
convexInPlaneTrans.inverse(planeObj.getWorldTransform(tmpTrans));
convexInPlaneTrans.mul(convexObj.getWorldTransform(tmpTrans));
Vector3f tmp = stack.allocVector3f();
tmp.negate(planeNormal);
planeInConvex.basis.transform(tmp);
Vector3f vtx = convexShape.localGetSupportingVertex(tmp, stack.allocVector3f());
Vector3f vtxInPlane = stack.alloc(vtx);
convexInPlaneTrans.transform(vtxInPlane);
float distance = (planeNormal.dot(vtxInPlane) - planeConstant);
Vector3f vtxInPlaneProjected = stack.allocVector3f();
tmp.scale(distance, planeNormal);
vtxInPlaneProjected.sub(vtxInPlane, tmp);
Vector3f vtxInPlaneWorld = stack.alloc(vtxInPlaneProjected);
planeObj.getWorldTransform(tmpTrans).transform(vtxInPlaneWorld);
hasCollision = distance < manifoldPtr.getContactBreakingThreshold();
resultOut.setPersistentManifold(manifoldPtr);
if (hasCollision) {
// report a contact. internally this will be kept persistent, and contact reduction is done
Vector3f normalOnSurfaceB = stack.alloc(planeNormal);
planeObj.getWorldTransform(tmpTrans).basis.transform(normalOnSurfaceB);
Vector3f pOnB = stack.alloc(vtxInPlaneWorld);
resultOut.addContactPoint(normalOnSurfaceB, pOnB, distance);
}
if (ownManifold) {
if (manifoldPtr.getNumContacts() != 0) {
resultOut.refreshContactPoints();
}
}
stack.leave();
}
use of com.bulletphysics.collision.shapes.StaticPlaneShape in project bdx by GoranM.
the class GImpactCollisionAlgorithm method gimpacttrimeshpart_vs_plane_collision.
protected void gimpacttrimeshpart_vs_plane_collision(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
Stack stack = Stack.enter();
Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
StaticPlaneShape planeshape = shape1;
Vector4f plane = stack.allocVector4f();
PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
// test box against plane
AABB tribox = stack.allocAABB();
shape0.getAabb(orgtrans0, tribox.min, tribox.max);
tribox.increment_margin(planeshape.getMargin());
if (tribox.plane_classify(plane) != PlaneIntersectionType.COLLIDE_PLANE) {
return;
}
shape0.lockChildShapes();
float margin = shape0.getMargin() + planeshape.getMargin();
Vector3f vertex = stack.allocVector3f();
Vector3f tmp = stack.allocVector3f();
int vi = shape0.getVertexCount();
while ((vi--) != 0) {
shape0.getVertex(vi, vertex);
orgtrans0.transform(vertex);
float distance = VectorUtil.dot3(vertex, plane) - plane.w - margin;
if (//add contact
distance < 0f) {
if (swapped) {
tmp.set(-plane.x, -plane.y, -plane.z);
addContactPoint(body1, body0, vertex, tmp, distance);
} else {
tmp.set(plane.x, plane.y, plane.z);
addContactPoint(body0, body1, vertex, tmp, distance);
}
}
}
shape0.unlockChildShapes();
stack.leave();
}
use of com.bulletphysics.collision.shapes.StaticPlaneShape in project bdx by GoranM.
the class GImpactCollisionAlgorithm method gimpact_vs_shape.
public void gimpact_vs_shape(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, CollisionShape shape1, boolean swapped) {
if (shape0.getGImpactShapeType() == ShapeType.TRIMESH_SHAPE) {
GImpactMeshShape meshshape0 = (GImpactMeshShape) shape0;
part0 = meshshape0.getMeshPartCount();
while ((part0--) != 0) {
gimpact_vs_shape(body0, body1, meshshape0.getMeshPart(part0), shape1, swapped);
}
return;
}
//#ifdef GIMPACT_VS_PLANE_COLLISION
if (shape0.getGImpactShapeType() == ShapeType.TRIMESH_SHAPE_PART && shape1.getShapeType() == BroadphaseNativeType.STATIC_PLANE_PROXYTYPE) {
GImpactMeshShapePart shapepart = (GImpactMeshShapePart) shape0;
StaticPlaneShape planeshape = (StaticPlaneShape) shape1;
gimpacttrimeshpart_vs_plane_collision(body0, body1, shapepart, planeshape, swapped);
return;
}
if (shape1.isCompound()) {
CompoundShape compoundshape = (CompoundShape) shape1;
gimpact_vs_compoundshape(body0, body1, shape0, compoundshape, swapped);
return;
} else if (shape1.isConcave()) {
ConcaveShape concaveshape = (ConcaveShape) shape1;
gimpact_vs_concave(body0, body1, shape0, concaveshape, swapped);
return;
}
Stack stack = Stack.enter();
Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
IntArrayList collided_results = new IntArrayList();
gimpact_vs_shape_find_pairs(orgtrans0, orgtrans1, shape0, shape1, collided_results);
if (collided_results.size() == 0) {
return;
}
shape0.lockChildShapes();
GIM_ShapeRetriever retriever0 = new GIM_ShapeRetriever(shape0);
boolean child_has_transform0 = shape0.childrenHasTransform();
Transform tmpTrans = stack.allocTransform();
int i = collided_results.size();
while ((i--) != 0) {
int child_index = collided_results.get(i);
if (swapped) {
triface1 = child_index;
} else {
triface0 = child_index;
}
CollisionShape colshape0 = retriever0.getChildShape(child_index);
if (child_has_transform0) {
tmpTrans.mul(orgtrans0, shape0.getChildTransform(child_index));
body0.setWorldTransform(tmpTrans);
}
// collide two shapes
if (swapped) {
shape_vs_shape_collision(body1, body0, shape1, colshape0);
} else {
shape_vs_shape_collision(body0, body1, colshape0, shape1);
}
// restore transforms
if (child_has_transform0) {
body0.setWorldTransform(orgtrans0);
}
}
shape0.unlockChildShapes();
stack.leave();
}
use of com.bulletphysics.collision.shapes.StaticPlaneShape in project jmonkeyengine by jMonkeyEngine.
the class PlaneCollisionShape method createShape.
protected void createShape() {
cShape = new StaticPlaneShape(Converter.convert(plane.getNormal()), plane.getConstant());
cShape.setLocalScaling(Converter.convert(getScale()));
cShape.setMargin(margin);
}
Aggregations