use of javax.vecmath.Vector3f in project bdx by GoranM.
the class ShapeHull method buildHull.
public boolean buildHull(float margin) {
Stack stack = Stack.enter();
Vector3f norm = stack.allocVector3f();
int numSampleDirections = NUM_UNITSPHERE_POINTS;
{
int numPDA = shape.getNumPreferredPenetrationDirections();
if (numPDA != 0) {
for (int i = 0; i < numPDA; i++) {
shape.getPreferredPenetrationDirection(i, norm);
unitSpherePoints.getQuick(numSampleDirections).set(norm);
numSampleDirections++;
}
}
}
ObjectArrayList<Vector3f> supportPoints = new ObjectArrayList<Vector3f>();
MiscUtil.resize(supportPoints, NUM_UNITSPHERE_POINTS + ConvexShape.MAX_PREFERRED_PENETRATION_DIRECTIONS * 2, Suppliers.NEW_VECTOR3F_SUPPLIER);
for (int i = 0; i < numSampleDirections; i++) {
shape.localGetSupportingVertex(unitSpherePoints.getQuick(i), supportPoints.getQuick(i));
}
HullDesc hd = new HullDesc();
hd.flags = HullFlags.TRIANGLES;
hd.vcount = numSampleDirections;
//#ifdef BT_USE_DOUBLE_PRECISION
//hd.mVertices = &supportPoints[0];
//hd.mVertexStride = sizeof(btVector3);
//#else
hd.vertices = supportPoints;
//hd.vertexStride = 3 * 4;
//#endif
HullLibrary hl = new HullLibrary();
HullResult hr = new HullResult();
if (!hl.createConvexHull(hd, hr)) {
stack.leave();
return false;
}
MiscUtil.resize(vertices, hr.numOutputVertices, Suppliers.NEW_VECTOR3F_SUPPLIER);
for (int i = 0; i < hr.numOutputVertices; i++) {
vertices.getQuick(i).set(hr.outputVertices.getQuick(i));
}
numIndices = hr.numIndices;
MiscUtil.resize(indices, numIndices, 0);
for (int i = 0; i < numIndices; i++) {
indices.set(i, hr.indices.get(i));
}
// free temporary hull result that we just copied
hl.releaseResult(hr);
stack.leave();
return true;
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class StaticPlaneShape method processAllTriangles.
@Override
public void processAllTriangles(TriangleCallback callback, Vector3f aabbMin, Vector3f aabbMax) {
Stack stack = Stack.enter();
Vector3f tmp = stack.allocVector3f();
Vector3f tmp1 = stack.allocVector3f();
Vector3f tmp2 = stack.allocVector3f();
Vector3f halfExtents = stack.allocVector3f();
halfExtents.sub(aabbMax, aabbMin);
halfExtents.scale(0.5f);
float radius = halfExtents.length();
Vector3f center = stack.allocVector3f();
center.add(aabbMax, aabbMin);
center.scale(0.5f);
// this is where the triangles are generated, given AABB and plane equation (normal/constant)
Vector3f tangentDir0 = stack.allocVector3f(), tangentDir1 = stack.allocVector3f();
// tangentDir0/tangentDir1 can be precalculated
TransformUtil.planeSpace1(planeNormal, tangentDir0, tangentDir1);
Vector3f supVertex0 = stack.allocVector3f(), supVertex1 = stack.allocVector3f();
Vector3f projectedCenter = stack.allocVector3f();
tmp.scale(planeNormal.dot(center) - planeConstant, planeNormal);
projectedCenter.sub(center, tmp);
Vector3f[] triangle = new Vector3f[] { stack.allocVector3f(), stack.allocVector3f(), stack.allocVector3f() };
tmp1.scale(radius, tangentDir0);
tmp2.scale(radius, tangentDir1);
VectorUtil.add(triangle[0], projectedCenter, tmp1, tmp2);
tmp1.scale(radius, tangentDir0);
tmp2.scale(radius, tangentDir1);
tmp.sub(tmp1, tmp2);
VectorUtil.add(triangle[1], projectedCenter, tmp);
tmp1.scale(radius, tangentDir0);
tmp2.scale(radius, tangentDir1);
tmp.sub(tmp1, tmp2);
triangle[2].sub(projectedCenter, tmp);
callback.processTriangle(triangle, 0, 0);
tmp1.scale(radius, tangentDir0);
tmp2.scale(radius, tangentDir1);
tmp.sub(tmp1, tmp2);
triangle[0].sub(projectedCenter, tmp);
tmp1.scale(radius, tangentDir0);
tmp2.scale(radius, tangentDir1);
tmp.add(tmp1, tmp2);
triangle[1].sub(projectedCenter, tmp);
tmp1.scale(radius, tangentDir0);
tmp2.scale(radius, tangentDir1);
VectorUtil.add(triangle[2], projectedCenter, tmp1, tmp2);
callback.processTriangle(triangle, 0, 1);
stack.leave();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class StridingMeshInterface method internalProcessAllTriangles.
public void internalProcessAllTriangles(InternalTriangleIndexCallback callback, Vector3f aabbMin, Vector3f aabbMax) {
Stack stack = Stack.enter();
int graphicssubparts = getNumSubParts();
Vector3f[] triangle = /*[3]*/
new Vector3f[] { stack.allocVector3f(), stack.allocVector3f(), stack.allocVector3f() };
Vector3f meshScaling = getScaling(stack.allocVector3f());
for (int part = 0; part < graphicssubparts; part++) {
VertexData data = getLockedReadOnlyVertexIndexBase(part);
for (int i = 0, cnt = data.getIndexCount() / 3; i < cnt; i++) {
data.getTriangle(i * 3, meshScaling, triangle);
callback.internalProcessTriangleIndex(triangle, part, i);
}
unLockReadOnlyVertexBase(part);
}
stack.leave();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class TriangleMeshShape method localGetSupportingVertex.
public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
Stack stack = Stack.enter();
Vector3f tmp = stack.allocVector3f();
Vector3f supportVertex = out;
Transform ident = stack.allocTransform();
ident.setIdentity();
SupportVertexCallback supportCallback = new SupportVertexCallback(vec, ident);
Vector3f aabbMax = stack.allocVector3f();
aabbMax.set(1e30f, 1e30f, 1e30f);
tmp.negate(aabbMax);
processAllTriangles(supportCallback, tmp, aabbMax);
supportCallback.getSupportVertexLocal(supportVertex);
stack.leave();
return out;
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class DiscreteDynamicsWorld method updateActivationState.
protected void updateActivationState(float timeStep) {
BulletStats.pushProfile("updateActivationState");
Stack stack = Stack.enter();
int sp = stack.getSp();
try {
Vector3f tmp = stack.allocVector3f();
for (int i = 0; i < collisionObjects.size(); i++) {
CollisionObject colObj = collisionObjects.getQuick(i);
RigidBody body = RigidBody.upcast(colObj);
if (body != null) {
body.updateDeactivation(timeStep);
if (body.wantsSleeping()) {
if (body.isStaticOrKinematicObject()) {
body.setActivationState(CollisionObject.ISLAND_SLEEPING);
} else {
if (body.getActivationState() == CollisionObject.ACTIVE_TAG) {
body.setActivationState(CollisionObject.WANTS_DEACTIVATION);
}
if (body.getActivationState() == CollisionObject.ISLAND_SLEEPING) {
tmp.set(0f, 0f, 0f);
body.setAngularVelocity(tmp);
body.setLinearVelocity(tmp);
}
}
} else {
if (body.getActivationState() != CollisionObject.DISABLE_DEACTIVATION) {
body.setActivationState(CollisionObject.ACTIVE_TAG);
}
}
}
}
} finally {
stack.leave(sp);
BulletStats.popProfile();
}
}
Aggregations