use of javax.vecmath.Matrix3f in project bdx by GoranM.
the class Mesh method vertTransformUV.
public void vertTransformUV(int materialSlot, Matrix3f matrix) {
Matrix3f m = matrix;
float[] vals = { m.m00, m.m10, m.m20, m.m01, m.m11, m.m21, m.m02, m.m12, m.m22 };
float[] verts = new float[getVertexCount() * Bdx.VERT_STRIDE];
model.meshes.first().getVertices(verts);
MeshPart mp = model.meshParts.get(materialSlot);
com.badlogic.gdx.graphics.Mesh.transformUV(new Matrix3(vals), verts, Bdx.VERT_STRIDE, 6, mp.offset, mp.size);
model.meshes.first().setVertices(verts);
}
use of javax.vecmath.Matrix3f in project bdx by GoranM.
the class CapsuleShape method getAabb.
@Override
public void getAabb(Transform t, Vector3f aabbMin, Vector3f aabbMax) {
Stack stack = Stack.enter();
Vector3f tmp = stack.allocVector3f();
Vector3f halfExtents = stack.allocVector3f();
halfExtents.set(getRadius(), getRadius(), getRadius());
VectorUtil.setCoord(halfExtents, upAxis, getRadius() + getHalfHeight());
halfExtents.x += getMargin();
halfExtents.y += getMargin();
halfExtents.z += getMargin();
Matrix3f abs_b = stack.allocMatrix3f();
abs_b.set(t.basis);
MatrixUtil.absolute(abs_b);
Vector3f center = t.origin;
Vector3f extent = stack.allocVector3f();
abs_b.getRow(0, tmp);
extent.x = tmp.dot(halfExtents);
abs_b.getRow(1, tmp);
extent.y = tmp.dot(halfExtents);
abs_b.getRow(2, tmp);
extent.z = tmp.dot(halfExtents);
aabbMin.sub(center, extent);
aabbMax.add(center, extent);
stack.leave();
}
use of javax.vecmath.Matrix3f in project bdx by GoranM.
the class CompoundShape method calculatePrincipalAxisTransform.
/**
* Computes the exact moment of inertia and the transform from the coordinate
* system defined by the principal axes of the moment of inertia and the center
* of mass to the current coordinate system. "masses" points to an array
* of masses of the children. The resulting transform "principal" has to be
* applied inversely to all children transforms in order for the local coordinate
* system of the compound shape to be centered at the center of mass and to coincide
* with the principal axes. This also necessitates a correction of the world transform
* of the collision object by the principal transform.
*/
public void calculatePrincipalAxisTransform(float[] masses, Transform principal, Vector3f inertia) {
int n = children.size();
Stack stack = Stack.enter();
float totalMass = 0;
Vector3f center = stack.allocVector3f();
center.set(0, 0, 0);
for (int k = 0; k < n; k++) {
center.scaleAdd(masses[k], children.getQuick(k).transform.origin, center);
totalMass += masses[k];
}
center.scale(1f / totalMass);
principal.origin.set(center);
Matrix3f tensor = stack.allocMatrix3f();
tensor.setZero();
for (int k = 0; k < n; k++) {
Vector3f i = stack.allocVector3f();
children.getQuick(k).childShape.calculateLocalInertia(masses[k], i);
Transform t = children.getQuick(k).transform;
Vector3f o = stack.allocVector3f();
o.sub(t.origin, center);
// compute inertia tensor in coordinate system of compound shape
Matrix3f j = stack.allocMatrix3f();
j.transpose(t.basis);
j.m00 *= i.x;
j.m01 *= i.x;
j.m02 *= i.x;
j.m10 *= i.y;
j.m11 *= i.y;
j.m12 *= i.y;
j.m20 *= i.z;
j.m21 *= i.z;
j.m22 *= i.z;
j.mul(t.basis, j);
// add inertia tensor
tensor.add(j);
// compute inertia tensor of pointmass at o
float o2 = o.lengthSquared();
j.setRow(0, o2, 0, 0);
j.setRow(1, 0, o2, 0);
j.setRow(2, 0, 0, o2);
j.m00 += o.x * -o.x;
j.m01 += o.y * -o.x;
j.m02 += o.z * -o.x;
j.m10 += o.x * -o.y;
j.m11 += o.y * -o.y;
j.m12 += o.z * -o.y;
j.m20 += o.x * -o.z;
j.m21 += o.y * -o.z;
j.m22 += o.z * -o.z;
// add inertia tensor of pointmass
tensor.m00 += masses[k] * j.m00;
tensor.m01 += masses[k] * j.m01;
tensor.m02 += masses[k] * j.m02;
tensor.m10 += masses[k] * j.m10;
tensor.m11 += masses[k] * j.m11;
tensor.m12 += masses[k] * j.m12;
tensor.m20 += masses[k] * j.m20;
tensor.m21 += masses[k] * j.m21;
tensor.m22 += masses[k] * j.m22;
}
MatrixUtil.diagonalize(tensor, principal.basis, 0.00001f, 20);
inertia.set(tensor.m00, tensor.m11, tensor.m22);
stack.leave();
}
use of javax.vecmath.Matrix3f in project bdx by GoranM.
the class CompoundShape method getAabb.
/**
* getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version.
*/
@Override
public void getAabb(Transform trans, Vector3f aabbMin, Vector3f aabbMax) {
Stack stack = Stack.enter();
Vector3f localHalfExtents = stack.allocVector3f();
localHalfExtents.sub(localAabbMax, localAabbMin);
localHalfExtents.scale(0.5f);
localHalfExtents.x += getMargin();
localHalfExtents.y += getMargin();
localHalfExtents.z += getMargin();
Vector3f localCenter = stack.allocVector3f();
localCenter.add(localAabbMax, localAabbMin);
localCenter.scale(0.5f);
Matrix3f abs_b = stack.alloc(trans.basis);
MatrixUtil.absolute(abs_b);
Vector3f center = stack.alloc(localCenter);
trans.transform(center);
Vector3f tmp = stack.allocVector3f();
Vector3f extent = stack.allocVector3f();
abs_b.getRow(0, tmp);
extent.x = tmp.dot(localHalfExtents);
abs_b.getRow(1, tmp);
extent.y = tmp.dot(localHalfExtents);
abs_b.getRow(2, tmp);
extent.z = tmp.dot(localHalfExtents);
aabbMin.sub(center, extent);
aabbMax.add(center, extent);
stack.leave();
}
use of javax.vecmath.Matrix3f in project bdx by GoranM.
the class ScaledBvhTriangleMeshShape method getAabb.
@Override
public void getAabb(Transform trans, Vector3f aabbMin, Vector3f aabbMax) {
Stack stack = Stack.enter();
Vector3f localAabbMin = bvhTriMeshShape.getLocalAabbMin(stack.allocVector3f());
Vector3f localAabbMax = bvhTriMeshShape.getLocalAabbMax(stack.allocVector3f());
Vector3f tmpLocalAabbMin = stack.allocVector3f();
Vector3f tmpLocalAabbMax = stack.allocVector3f();
VectorUtil.mul(tmpLocalAabbMin, localAabbMin, localScaling);
VectorUtil.mul(tmpLocalAabbMax, localAabbMax, localScaling);
localAabbMin.x = (localScaling.x >= 0f) ? tmpLocalAabbMin.x : tmpLocalAabbMax.x;
localAabbMin.y = (localScaling.y >= 0f) ? tmpLocalAabbMin.y : tmpLocalAabbMax.y;
localAabbMin.z = (localScaling.z >= 0f) ? tmpLocalAabbMin.z : tmpLocalAabbMax.z;
localAabbMax.x = (localScaling.x <= 0f) ? tmpLocalAabbMin.x : tmpLocalAabbMax.x;
localAabbMax.y = (localScaling.y <= 0f) ? tmpLocalAabbMin.y : tmpLocalAabbMax.y;
localAabbMax.z = (localScaling.z <= 0f) ? tmpLocalAabbMin.z : tmpLocalAabbMax.z;
Vector3f localHalfExtents = stack.allocVector3f();
localHalfExtents.sub(localAabbMax, localAabbMin);
localHalfExtents.scale(0.5f);
float margin = bvhTriMeshShape.getMargin();
localHalfExtents.x += margin;
localHalfExtents.y += margin;
localHalfExtents.z += margin;
Vector3f localCenter = stack.allocVector3f();
localCenter.add(localAabbMax, localAabbMin);
localCenter.scale(0.5f);
Matrix3f abs_b = stack.alloc(trans.basis);
MatrixUtil.absolute(abs_b);
Vector3f center = stack.alloc(localCenter);
trans.transform(center);
Vector3f extent = stack.allocVector3f();
Vector3f tmp = stack.allocVector3f();
abs_b.getRow(0, tmp);
extent.x = tmp.dot(localHalfExtents);
abs_b.getRow(1, tmp);
extent.y = tmp.dot(localHalfExtents);
abs_b.getRow(2, tmp);
extent.z = tmp.dot(localHalfExtents);
aabbMin.sub(center, extent);
aabbMax.add(center, extent);
stack.leave();
}
Aggregations