use of com.bulletphysics.collision.shapes.SphereShape in project bdx by GoranM.
the class DiscreteDynamicsWorld method debugDrawObject.
public void debugDrawObject(Transform worldTransform, CollisionShape shape, Vector3f color) {
Stack stack = Stack.enter();
Vector3f tmp = stack.allocVector3f();
Vector3f tmp2 = stack.allocVector3f();
// Draw a small simplex at the center of the object
{
Vector3f start = stack.alloc(worldTransform.origin);
tmp.set(1f, 0f, 0f);
worldTransform.basis.transform(tmp);
tmp.add(start);
tmp2.set(1f, 0f, 0f);
getDebugDrawer().drawLine(start, tmp, tmp2);
tmp.set(0f, 1f, 0f);
worldTransform.basis.transform(tmp);
tmp.add(start);
tmp2.set(0f, 1f, 0f);
getDebugDrawer().drawLine(start, tmp, tmp2);
tmp.set(0f, 0f, 1f);
worldTransform.basis.transform(tmp);
tmp.add(start);
tmp2.set(0f, 0f, 1f);
getDebugDrawer().drawLine(start, tmp, tmp2);
}
if (shape.getShapeType() == BroadphaseNativeType.COMPOUND_SHAPE_PROXYTYPE) {
CompoundShape compoundShape = (CompoundShape) shape;
for (int i = compoundShape.getNumChildShapes() - 1; i >= 0; i--) {
Transform childTrans = new Transform();
compoundShape.getChildTransform(i, childTrans);
CollisionShape colShape = compoundShape.getChildShape(i);
Transform res = new Transform();
res.mul(worldTransform, childTrans);
debugDrawObject(res, colShape, color);
}
} else {
switch(shape.getShapeType()) {
case SPHERE_SHAPE_PROXYTYPE:
{
SphereShape sphereShape = (SphereShape) shape;
//radius doesn't include the margin, so draw with margin
float radius = sphereShape.getMargin();
debugDrawSphere(radius, worldTransform, color);
break;
}
//}
case CAPSULE_SHAPE_PROXYTYPE:
{
CapsuleShape capsuleShape = (CapsuleShape) shape;
float radius = capsuleShape.getRadius();
float halfHeight = capsuleShape.getHalfHeight();
// Draw the ends
{
Transform childTransform = new Transform(worldTransform);
childTransform.origin.set(0, 0, halfHeight);
worldTransform.transform(childTransform.origin);
debugDrawSphere(radius, childTransform, color);
}
{
Transform childTransform = new Transform(worldTransform);
childTransform.origin.set(0, 0, -halfHeight);
worldTransform.transform(childTransform.origin);
debugDrawSphere(radius, childTransform, color);
}
// Draw some additional lines
Vector3f from = stack.allocVector3f();
Vector3f a = stack.allocVector3f();
Vector3f to = stack.allocVector3f();
Vector3f b = stack.allocVector3f();
from.set(worldTransform.origin);
a.set(-radius, 0, halfHeight);
worldTransform.basis.transform(a);
from.add(a);
to.set(worldTransform.origin);
b.set(-radius, 0, -halfHeight);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
from.set(worldTransform.origin);
a.set(radius, 0, halfHeight);
worldTransform.basis.transform(a);
from.add(a);
to.set(worldTransform.origin);
b.set(radius, 0, -halfHeight);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
from.set(worldTransform.origin);
a.set(0, -radius, halfHeight);
worldTransform.basis.transform(a);
from.add(a);
to.set(worldTransform.origin);
b.set(0, -radius, -halfHeight);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
from.set(worldTransform.origin);
a.set(0, radius, halfHeight);
worldTransform.basis.transform(a);
from.add(a);
to.set(worldTransform.origin);
b.set(0, radius, -halfHeight);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
break;
}
case CONE_SHAPE_PROXYTYPE:
{
ConeShape coneShape = (ConeShape) shape;
//+coneShape.getMargin();
float radius = coneShape.getRadius();
//+coneShape.getMargin();
float height = coneShape.getHeight();
int upAxis = coneShape.getConeUpIndex();
float[] tmpv = new float[] { 0, 0, 0 };
Vector3f offsetHeight = new Vector3f();
offsetHeight.get(tmpv);
tmpv[upAxis] = height * 0.5f;
offsetHeight.set(tmpv);
Vector3f offsetRadius = new Vector3f();
offsetRadius.get(tmpv);
tmpv[(upAxis + 1) % 3] = radius;
offsetRadius.set(tmpv);
Vector3f offset2Radius = new Vector3f();
offset2Radius.get(tmpv);
tmpv[(upAxis + 2) % 3] = radius;
offset2Radius.set(tmpv);
Vector3f from = stack.allocVector3f();
Vector3f a = stack.allocVector3f();
Vector3f to = stack.allocVector3f();
Vector3f b = stack.allocVector3f();
from.set(worldTransform.origin);
a.set(offsetHeight);
worldTransform.basis.transform(a);
from.add(a);
to.set(worldTransform.origin);
b.set(offsetHeight);
b.negate();
b.add(offsetRadius);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
to.set(worldTransform.origin);
b.set(offsetHeight);
b.negate();
b.sub(offsetRadius);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
to.set(worldTransform.origin);
b.set(offsetHeight);
b.negate();
b.add(offset2Radius);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
to.set(worldTransform.origin);
b.set(offsetHeight);
b.negate();
b.sub(offset2Radius);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
break;
}
case CYLINDER_SHAPE_PROXYTYPE:
{
CylinderShape cylinder = (CylinderShape) shape;
int upAxis = cylinder.getUpAxis();
float radius = cylinder.getRadius();
float[] tmpv = new float[] { 0, 0, 0 };
Vector3f halfExtents = new Vector3f();
cylinder.getHalfExtentsWithMargin(halfExtents);
halfExtents.get(tmpv);
float halfHeight = tmpv[upAxis];
Vector3f offsetHeight = new Vector3f();
offsetHeight.get(tmpv);
tmpv[upAxis] = halfHeight;
offsetHeight.set(tmpv);
Vector3f offsetRadius = new Vector3f();
offsetRadius.get(tmpv);
tmpv[(upAxis + 1) % 3] = radius;
offsetRadius.set(tmpv);
Vector3f from = stack.allocVector3f();
Vector3f a = stack.allocVector3f();
Vector3f to = stack.allocVector3f();
Vector3f b = stack.allocVector3f();
from.set(worldTransform.origin);
a.set(offsetHeight);
a.add(offsetRadius);
worldTransform.basis.transform(a);
from.add(a);
to.set(worldTransform.origin);
b.set(offsetHeight);
b.negate();
b.add(offsetRadius);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
from.set(worldTransform.origin);
a.set(offsetHeight);
a.sub(offsetRadius);
worldTransform.basis.transform(a);
from.add(a);
to.set(worldTransform.origin);
b.set(offsetHeight);
b.negate();
b.sub(offsetRadius);
worldTransform.basis.transform(b);
to.add(b);
getDebugDrawer().drawLine(from, to, color);
break;
}
default:
{
if (shape.isConcave()) {
//btConcaveShape* concaveMesh = (btConcaveShape*) shape;
////todo pass camera, for some culling
//btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
//btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
//DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
//concaveMesh.processAllTriangles(&drawCallback,aabbMin,aabbMax);
ConcaveShape concaveMesh = (ConcaveShape) shape;
//todo: pass camera for some culling
Vector3f aabbMax = stack.allocVector3f();
Vector3f aabbMin = stack.allocVector3f();
aabbMax.set(1e30f, 1e30f, 1e30f);
aabbMin.set(-1e30f, -1e30f, -1e30f);
//DebugDrawcallback drawCallback;
DebugDrawcallback drawCallback = new DebugDrawcallback(getDebugDrawer(), worldTransform, color);
concaveMesh.processAllTriangles(drawCallback, aabbMin, aabbMax);
}
/// for polyhedral shapes
if (shape.isPolyhedral()) {
PolyhedralConvexShape polyshape = (PolyhedralConvexShape) shape;
Vector3f a = stack.allocVector3f();
Vector3f b = stack.allocVector3f();
int i;
for (i = 0; i < polyshape.getNumEdges(); i++) {
polyshape.getEdge(i, a, b);
worldTransform.transform(a);
worldTransform.transform(b);
getDebugDrawer().drawLine(a, b, color);
}
}
}
}
}
stack.leave();
}
Aggregations