use of javax.vecmath.Vector3f in project bdx by GoranM.
the class OptimizedBvh method setQuantizationValues.
public void setQuantizationValues(Vector3f aabbMin, Vector3f aabbMax, float quantizationMargin) {
// enlarge the AABB to avoid division by zero when initializing the quantization values
Stack stack = Stack.enter();
Vector3f clampValue = stack.allocVector3f();
clampValue.set(quantizationMargin, quantizationMargin, quantizationMargin);
bvhAabbMin.sub(aabbMin, clampValue);
bvhAabbMax.add(aabbMax, clampValue);
Vector3f aabbSize = stack.allocVector3f();
aabbSize.sub(bvhAabbMax, bvhAabbMin);
bvhQuantization.set(65535f, 65535f, 65535f);
VectorUtil.div(bvhQuantization, bvhQuantization, aabbSize);
stack.leave();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class OptimizedBvh method getAabbMax.
public Vector3f getAabbMax(int nodeIndex) {
if (useQuantization) {
Vector3f tmp = new Vector3f();
unQuantize(tmp, quantizedLeafNodes.getQuantizedAabbMax(nodeIndex));
return tmp;
}
// non-quantized
return leafNodes.getQuick(nodeIndex).aabbMaxOrg;
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class OptimizedBvh method refit.
public void refit(StridingMeshInterface meshInterface) {
if (useQuantization) {
// calculate new aabb
Stack stack = Stack.enter();
Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
meshInterface.calculateAabbBruteForce(aabbMin, aabbMax);
setQuantizationValues(aabbMin, aabbMax);
updateBvhNodes(meshInterface, 0, curNodeIndex, 0);
// now update all subtree headers
int i;
for (i = 0; i < SubtreeHeaders.size(); i++) {
BvhSubtreeInfo subtree = SubtreeHeaders.getQuick(i);
subtree.setAabbFromQuantizeNode(quantizedContiguousNodes, subtree.rootNodeIndex);
}
stack.leave();
} else {
// JAVA NOTE: added for testing, it's too slow for practical use
build(meshInterface, false, null, null);
}
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class PolyhedralConvexShape method calculateLocalInertia.
@Override
public void calculateLocalInertia(float mass, Vector3f inertia) {
// not yet, return box inertia
Stack stack = Stack.enter();
float margin = getMargin();
Transform ident = stack.allocTransform();
ident.setIdentity();
Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
getAabb(ident, aabbMin, aabbMax);
Vector3f halfExtents = stack.allocVector3f();
halfExtents.sub(aabbMax, aabbMin);
halfExtents.scale(0.5f);
float lx = 2f * (halfExtents.x + margin);
float ly = 2f * (halfExtents.y + margin);
float lz = 2f * (halfExtents.z + margin);
float x2 = lx * lx;
float y2 = ly * ly;
float z2 = lz * lz;
float scaledmass = mass * 0.08333333f;
inertia.set(y2 + z2, x2 + z2, x2 + y2);
inertia.scale(scaledmass);
stack.leave();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class PolyhedralConvexShape method localGetSupportingVertexWithoutMargin.
// /** optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp */
// public Hull optionalHull = null;
@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec0, Vector3f out) {
int i;
Stack stack = Stack.enter();
Vector3f supVec = out;
supVec.set(0f, 0f, 0f);
float maxDot = -1e30f;
Vector3f vec = stack.alloc(vec0);
float lenSqr = vec.lengthSquared();
if (lenSqr < 0.0001f) {
vec.set(1f, 0f, 0f);
} else {
float rlen = 1f / (float) Math.sqrt(lenSqr);
vec.scale(rlen);
}
Vector3f vtx = stack.allocVector3f();
float newDot;
for (i = 0; i < getNumVertices(); i++) {
getVertex(i, vtx);
newDot = vec.dot(vtx);
if (newDot > maxDot) {
maxDot = newDot;
supVec = vtx;
}
}
stack.leave();
return out;
}
Aggregations