use of com.bulletphysics.linearmath.Transform in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method addChildShape.
/**
* adds a child shape at the given local translation
* @param shape the child shape to add
* @param location the local location of the child shape
*/
public void addChildShape(CollisionShape shape, Vector3f location) {
Transform transA = new Transform(Converter.convert(new Matrix3f()));
Converter.convert(location, transA.origin);
children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape));
((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
use of com.bulletphysics.linearmath.Transform in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method addChildShape.
/**
* adds a child shape at the given local translation
* @param shape the child shape to add
* @param location the local location of the child shape
*/
public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) {
if (shape instanceof CompoundCollisionShape) {
throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!");
}
Transform transA = new Transform(Converter.convert(rotation));
Converter.convert(location, transA.origin);
Converter.convert(rotation, transA.basis);
children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape));
((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class CollisionWorld method updateSingleAabb.
// JAVA NOTE: ported from 2.74, missing contact threshold stuff
public void updateSingleAabb(CollisionObject colObj) {
Stack stack = Stack.enter();
Vector3f minAabb = stack.allocVector3f(), maxAabb = stack.allocVector3f();
Vector3f tmp = stack.allocVector3f();
Transform tmpTrans = stack.allocTransform();
colObj.getCollisionShape().getAabb(colObj.getWorldTransform(tmpTrans), minAabb, maxAabb);
// need to increase the aabb for contact thresholds
Vector3f contactThreshold = stack.allocVector3f();
contactThreshold.set(BulletGlobals.getContactBreakingThreshold(), BulletGlobals.getContactBreakingThreshold(), BulletGlobals.getContactBreakingThreshold());
minAabb.sub(contactThreshold);
maxAabb.add(contactThreshold);
BroadphaseInterface bp = broadphasePairCache;
// moving objects should be moderately sized, probably something wrong if not
// TODO: optimize
tmp.sub(maxAabb, minAabb);
if (colObj.isStaticObject() || (tmp.lengthSquared() < 1e12f)) {
bp.setAabb(colObj.getBroadphaseHandle(), minAabb, maxAabb, dispatcher1);
} else {
// something went wrong, investigate
// this assert is unwanted in 3D modelers (danger of loosing work)
colObj.setActivationState(CollisionObject.DISABLE_SIMULATION);
if (updateAabbs_reportMe && debugDrawer != null) {
updateAabbs_reportMe = false;
debugDrawer.reportErrorWarning("Overflow in AABB, object removed from simulation");
debugDrawer.reportErrorWarning("If you can reproduce this, please email bugs@continuousphysics.com\n");
debugDrawer.reportErrorWarning("Please include above information, your Platform, version of OS.\n");
debugDrawer.reportErrorWarning("Thanks.\n");
}
}
stack.leave();
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class CollisionWorld method rayTestSingle.
// TODO
public static void rayTestSingle(Transform rayFromTrans, Transform rayToTrans, CollisionObject collisionObject, CollisionShape collisionShape, Transform colObjWorldTransform, RayResultCallback resultCallback) {
Stack stack = Stack.enter();
SphereShape pointShape = new SphereShape(0f);
pointShape.setMargin(0f);
ConvexShape castShape = pointShape;
if (collisionShape.isConvex()) {
CastResult castResult = new CastResult();
castResult.fraction = resultCallback.closestHitFraction;
ConvexShape convexShape = (ConvexShape) collisionShape;
VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();
//#define USE_SUBSIMPLEX_CONVEX_CAST 1
//#ifdef USE_SUBSIMPLEX_CONVEX_CAST
SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(castShape, convexShape, simplexSolver);
if (convexCaster.calcTimeOfImpact(rayFromTrans, rayToTrans, colObjWorldTransform, colObjWorldTransform, castResult)) {
//add hit
if (castResult.normal.lengthSquared() > 0.0001f) {
if (castResult.fraction < resultCallback.closestHitFraction) {
//#ifdef USE_SUBSIMPLEX_CONVEX_CAST
//rotate normal into worldspace
rayFromTrans.basis.transform(castResult.normal);
//#endif //USE_SUBSIMPLEX_CONVEX_CAST
castResult.normal.normalize();
LocalRayResult localRayResult = new LocalRayResult(collisionObject, null, castResult.normal, castResult.fraction);
boolean normalInWorldSpace = true;
resultCallback.addSingleResult(localRayResult, normalInWorldSpace);
}
}
}
} else {
if (collisionShape.isConcave()) {
if (collisionShape.getShapeType() == BroadphaseNativeType.TRIANGLE_MESH_SHAPE_PROXYTYPE) {
// optimized version for BvhTriangleMeshShape
BvhTriangleMeshShape triangleMesh = (BvhTriangleMeshShape) collisionShape;
Transform worldTocollisionObject = stack.allocTransform();
worldTocollisionObject.inverse(colObjWorldTransform);
Vector3f rayFromLocal = stack.alloc(rayFromTrans.origin);
worldTocollisionObject.transform(rayFromLocal);
Vector3f rayToLocal = stack.alloc(rayToTrans.origin);
worldTocollisionObject.transform(rayToLocal);
BridgeTriangleRaycastCallback rcb = new BridgeTriangleRaycastCallback(rayFromLocal, rayToLocal, resultCallback, collisionObject, triangleMesh);
rcb.hitFraction = resultCallback.closestHitFraction;
triangleMesh.performRaycast(rcb, rayFromLocal, rayToLocal);
} else {
ConcaveShape triangleMesh = (ConcaveShape) collisionShape;
Transform worldTocollisionObject = stack.allocTransform();
worldTocollisionObject.inverse(colObjWorldTransform);
Vector3f rayFromLocal = stack.alloc(rayFromTrans.origin);
worldTocollisionObject.transform(rayFromLocal);
Vector3f rayToLocal = stack.alloc(rayToTrans.origin);
worldTocollisionObject.transform(rayToLocal);
BridgeTriangleRaycastCallback rcb = new BridgeTriangleRaycastCallback(rayFromLocal, rayToLocal, resultCallback, collisionObject, triangleMesh);
rcb.hitFraction = resultCallback.closestHitFraction;
Vector3f rayAabbMinLocal = stack.alloc(rayFromLocal);
VectorUtil.setMin(rayAabbMinLocal, rayToLocal);
Vector3f rayAabbMaxLocal = stack.alloc(rayFromLocal);
VectorUtil.setMax(rayAabbMaxLocal, rayToLocal);
triangleMesh.processAllTriangles(rcb, rayAabbMinLocal, rayAabbMaxLocal);
}
} else {
// todo: use AABB tree or other BVH acceleration structure!
if (collisionShape.isCompound()) {
CompoundShape compoundShape = (CompoundShape) collisionShape;
int i = 0;
Transform childTrans = stack.allocTransform();
for (i = 0; i < compoundShape.getNumChildShapes(); i++) {
compoundShape.getChildTransform(i, childTrans);
CollisionShape childCollisionShape = compoundShape.getChildShape(i);
Transform childWorldTrans = stack.alloc(colObjWorldTransform);
childWorldTrans.mul(childTrans);
// replace collision shape so that callback can determine the triangle
CollisionShape saveCollisionShape = collisionObject.getCollisionShape();
collisionObject.internalSetTemporaryCollisionShape(childCollisionShape);
rayTestSingle(rayFromTrans, rayToTrans, collisionObject, childCollisionShape, childWorldTrans, resultCallback);
// restore
collisionObject.internalSetTemporaryCollisionShape(saveCollisionShape);
}
}
}
}
stack.leave();
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class CollisionWorld method convexSweepTest.
/**
* convexTest performs a swept convex cast on all objects in the {@link CollisionWorld}, and calls the resultCallback
* This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
*/
public void convexSweepTest(ConvexShape castShape, Transform convexFromWorld, Transform convexToWorld, ConvexResultCallback resultCallback) {
Stack stack = Stack.enter();
Transform convexFromTrans = stack.allocTransform();
Transform convexToTrans = stack.allocTransform();
convexFromTrans.set(convexFromWorld);
convexToTrans.set(convexToWorld);
Vector3f castShapeAabbMin = stack.allocVector3f();
Vector3f castShapeAabbMax = stack.allocVector3f();
// Compute AABB that encompasses angular movement
{
Vector3f linVel = stack.allocVector3f();
Vector3f angVel = stack.allocVector3f();
TransformUtil.calculateVelocity(convexFromTrans, convexToTrans, 1f, linVel, angVel);
Transform R = stack.allocTransform();
R.setIdentity();
R.setRotation(convexFromTrans.getRotation(stack.allocQuat4f()));
castShape.calculateTemporalAabb(R, linVel, angVel, 1f, castShapeAabbMin, castShapeAabbMax);
}
Transform tmpTrans = stack.allocTransform();
Vector3f collisionObjectAabbMin = stack.allocVector3f();
Vector3f collisionObjectAabbMax = stack.allocVector3f();
float[] hitLambda = new float[1];
// do a ray-shape query using convexCaster (CCD)
for (int i = 0; i < collisionObjects.size(); i++) {
CollisionObject collisionObject = collisionObjects.getQuick(i);
// only perform raycast if filterMask matches
if (resultCallback.needsCollision(collisionObject.getBroadphaseHandle())) {
//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
collisionObject.getWorldTransform(tmpTrans);
collisionObject.getCollisionShape().getAabb(tmpTrans, collisionObjectAabbMin, collisionObjectAabbMax);
AabbUtil2.aabbExpand(collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
// could use resultCallback.closestHitFraction, but needs testing
hitLambda[0] = 1f;
Vector3f hitNormal = stack.allocVector3f();
if (AabbUtil2.rayAabb(convexFromWorld.origin, convexToWorld.origin, collisionObjectAabbMin, collisionObjectAabbMax, hitLambda, hitNormal)) {
objectQuerySingle(castShape, convexFromTrans, convexToTrans, collisionObject, collisionObject.getCollisionShape(), tmpTrans, resultCallback, getDispatchInfo().allowedCcdPenetration);
}
}
}
stack.leave();
}
Aggregations