use of javax.vecmath.Vector3f in project bdx by GoranM.
the class DbvtAabbMm method swap.
public static void swap(DbvtAabbMm p1, DbvtAabbMm p2) {
Stack stack = Stack.enter();
Vector3f tmp = stack.allocVector3f();
tmp.set(p1.mi);
p1.mi.set(p2.mi);
p2.mi.set(tmp);
tmp.set(p1.mx);
p1.mx.set(p2.mx);
p2.mx.set(tmp);
stack.leave();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class DbvtAabbMm method Intersect.
public static boolean Intersect(DbvtAabbMm a, DbvtAabbMm b, Transform xform) {
Stack stack = Stack.enter();
Vector3f d0 = stack.allocVector3f();
Vector3f d1 = stack.allocVector3f();
Vector3f tmp = stack.allocVector3f();
// JAVA NOTE: check
b.Center(d0);
xform.transform(d0);
d0.sub(a.Center(tmp));
MatrixUtil.transposeTransform(d1, d0, xform.basis);
float[] s0 = new float[] { 0, 0 };
float[] s1 = new float[2];
s1[0] = xform.origin.dot(d0);
s1[1] = s1[0];
a.AddSpan(d0, s0, 0, s0, 1);
b.AddSpan(d1, s1, 0, s1, 1);
if (s0[0] > (s1[1])) {
stack.leave();
return false;
}
if (s0[1] < (s1[0])) {
stack.leave();
return false;
}
stack.leave();
return true;
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class DbvtAabbMm method Proximity.
public static float Proximity(DbvtAabbMm a, DbvtAabbMm b) {
Stack stack = Stack.enter();
Vector3f d = stack.allocVector3f();
Vector3f tmp = stack.allocVector3f();
d.add(a.mi, a.mx);
tmp.add(b.mi, b.mx);
d.sub(tmp);
float result = Math.abs(d.x) + Math.abs(d.y) + Math.abs(d.z);
stack.leave();
return result;
}
use of javax.vecmath.Vector3f 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 javax.vecmath.Vector3f 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();
}
Aggregations