use of javax.vecmath.Vector4f in project bdx by GoranM.
the class GImpactCollisionAlgorithm method gimpacttrimeshpart_vs_plane_collision.
protected void gimpacttrimeshpart_vs_plane_collision(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
Stack stack = Stack.enter();
Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
StaticPlaneShape planeshape = shape1;
Vector4f plane = stack.allocVector4f();
PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
// test box against plane
AABB tribox = stack.allocAABB();
shape0.getAabb(orgtrans0, tribox.min, tribox.max);
tribox.increment_margin(planeshape.getMargin());
if (tribox.plane_classify(plane) != PlaneIntersectionType.COLLIDE_PLANE) {
return;
}
shape0.lockChildShapes();
float margin = shape0.getMargin() + planeshape.getMargin();
Vector3f vertex = stack.allocVector3f();
Vector3f tmp = stack.allocVector3f();
int vi = shape0.getVertexCount();
while ((vi--) != 0) {
shape0.getVertex(vi, vertex);
orgtrans0.transform(vertex);
float distance = VectorUtil.dot3(vertex, plane) - plane.w - margin;
if (//add contact
distance < 0f) {
if (swapped) {
tmp.set(-plane.x, -plane.y, -plane.z);
addContactPoint(body1, body0, vertex, tmp, distance);
} else {
tmp.set(plane.x, plane.y, plane.z);
addContactPoint(body0, body1, vertex, tmp, distance);
}
}
}
shape0.unlockChildShapes();
stack.leave();
}
use of javax.vecmath.Vector4f in project bdx by GoranM.
the class GeometryUtil method getPlaneEquationsFromVertices.
public static void getPlaneEquationsFromVertices(ObjectArrayList<Vector3f> vertices, ObjectArrayList<Vector4f> planeEquationsOut) {
Stack stack = Stack.enter();
Vector4f planeEquation = stack.allocVector4f();
Vector3f edge0 = stack.allocVector3f(), edge1 = stack.allocVector3f();
Vector3f tmp = stack.allocVector3f();
int numvertices = vertices.size();
// brute force:
for (int i = 0; i < numvertices; i++) {
Vector3f N1 = vertices.getQuick(i);
for (int j = i + 1; j < numvertices; j++) {
Vector3f N2 = vertices.getQuick(j);
for (int k = j + 1; k < numvertices; k++) {
Vector3f N3 = vertices.getQuick(k);
edge0.sub(N2, N1);
edge1.sub(N3, N1);
float normalSign = 1f;
for (int ww = 0; ww < 2; ww++) {
tmp.cross(edge0, edge1);
planeEquation.x = normalSign * tmp.x;
planeEquation.y = normalSign * tmp.y;
planeEquation.z = normalSign * tmp.z;
if (VectorUtil.lengthSquared3(planeEquation) > 0.0001f) {
VectorUtil.normalize3(planeEquation);
if (notExist(planeEquation, planeEquationsOut)) {
planeEquation.w = -VectorUtil.dot3(planeEquation, N1);
// check if inside, and replace supportingVertexOut if needed
if (areVerticesBehindPlane(planeEquation, vertices, 0.01f)) {
planeEquationsOut.add(new Vector4f(planeEquation));
}
}
}
normalSign = -1f;
}
}
}
}
stack.leave();
}
use of javax.vecmath.Vector4f in project bdx by GoranM.
the class GeometryUtil method isPointInsidePlanes.
public static boolean isPointInsidePlanes(ObjectArrayList<Vector4f> planeEquations, Vector3f point, float margin) {
int numbrushes = planeEquations.size();
for (int i = 0; i < numbrushes; i++) {
Vector4f N1 = planeEquations.getQuick(i);
float dist = VectorUtil.dot3(N1, point) + N1.w - margin;
if (dist > 0f) {
return false;
}
}
return true;
}
use of javax.vecmath.Vector4f in project bdx by GoranM.
the class GeometryUtil method getVerticesFromPlaneEquations.
public static void getVerticesFromPlaneEquations(ObjectArrayList<Vector4f> planeEquations, ObjectArrayList<Vector3f> verticesOut) {
Stack stack = Stack.enter();
Vector3f n2n3 = stack.allocVector3f();
Vector3f n3n1 = stack.allocVector3f();
Vector3f n1n2 = stack.allocVector3f();
Vector3f potentialVertex = stack.allocVector3f();
int numbrushes = planeEquations.size();
// brute force:
for (int i = 0; i < numbrushes; i++) {
Vector4f N1 = planeEquations.getQuick(i);
for (int j = i + 1; j < numbrushes; j++) {
Vector4f N2 = planeEquations.getQuick(j);
for (int k = j + 1; k < numbrushes; k++) {
Vector4f N3 = planeEquations.getQuick(k);
VectorUtil.cross3(n2n3, N2, N3);
VectorUtil.cross3(n3n1, N3, N1);
VectorUtil.cross3(n1n2, N1, N2);
if ((n2n3.lengthSquared() > 0.0001f) && (n3n1.lengthSquared() > 0.0001f) && (n1n2.lengthSquared() > 0.0001f)) {
// point P out of 3 plane equations:
// d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 )
// P = -------------------------------------------------------------------------
// N1 . ( N2 * N3 )
float quotient = VectorUtil.dot3(N1, n2n3);
if (Math.abs(quotient) > 0.000001f) {
quotient = -1f / quotient;
n2n3.scale(N1.w);
n3n1.scale(N2.w);
n1n2.scale(N3.w);
potentialVertex.set(n2n3);
potentialVertex.add(n3n1);
potentialVertex.add(n1n2);
potentialVertex.scale(quotient);
// check if inside, and replace supportingVertexOut if needed
if (isPointInsidePlanes(planeEquations, potentialVertex, 0.01f)) {
verticesOut.add(new Vector3f(potentialVertex));
}
}
}
}
}
}
stack.leave();
}
use of javax.vecmath.Vector4f in project bdx by GoranM.
the class VectorUtil method closestAxis4.
public static int closestAxis4(Vector4f vec) {
Vector4f tmp = new Vector4f(vec);
tmp.absolute();
return maxAxis4(tmp);
}
Aggregations