use of javax.vecmath.Vector3f in project bdx by GoranM.
the class ConeShape method calculateLocalInertia.
@Override
public void calculateLocalInertia(float mass, Vector3f inertia) {
Stack stack = Stack.enter();
Transform identity = stack.allocTransform();
identity.setIdentity();
Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
getAabb(identity, aabbMin, aabbMax);
Vector3f halfExtents = stack.allocVector3f();
halfExtents.sub(aabbMax, aabbMin);
halfExtents.scale(0.5f);
float margin = getMargin();
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);
//inertia.x() = scaledmass * (y2+z2);
//inertia.y() = scaledmass * (x2+z2);
//inertia.z() = scaledmass * (x2+y2);
stack.leave();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class ConvexHullShape method addPoint.
public void addPoint(Vector3f point) {
points.add(new Vector3f(point));
recalcLocalAabb();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class ConvexHullShape method localGetSupportingVertex.
@Override
public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
Vector3f supVertex = localGetSupportingVertexWithoutMargin(vec, out);
if (getMargin() != 0f) {
Stack stack = Stack.enter();
Vector3f vecnorm = stack.alloc(vec);
if (vecnorm.lengthSquared() < (BulletGlobals.FLT_EPSILON * BulletGlobals.FLT_EPSILON)) {
vecnorm.set(-1f, -1f, -1f);
}
vecnorm.normalize();
supVertex.scaleAdd(getMargin(), vecnorm, supVertex);
stack.leave();
}
return out;
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class ConvexHullShape method localGetSupportingVertexWithoutMargin.
@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec0, Vector3f out) {
Vector3f supVec = out;
supVec.set(0f, 0f, 0f);
float newDot, maxDot = -1e30f;
Stack stack = Stack.enter();
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();
for (int i = 0; i < points.size(); i++) {
VectorUtil.mul(vtx, points.getQuick(i), localScaling);
newDot = vec.dot(vtx);
if (newDot > maxDot) {
maxDot = newDot;
supVec.set(vtx);
}
}
stack.leave();
return out;
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class ConvexInternalShape method getAabbSlow.
@Override
public void getAabbSlow(Transform trans, Vector3f minAabb, Vector3f maxAabb) {
Stack stack = Stack.enter();
float margin = getMargin();
Vector3f vec = stack.allocVector3f();
Vector3f tmp1 = stack.allocVector3f();
Vector3f tmp2 = stack.allocVector3f();
for (int i = 0; i < 3; i++) {
vec.set(0f, 0f, 0f);
VectorUtil.setCoord(vec, i, 1f);
MatrixUtil.transposeTransform(tmp1, vec, trans.basis);
localGetSupportingVertex(tmp1, tmp2);
trans.transform(tmp2);
VectorUtil.setCoord(maxAabb, i, VectorUtil.getCoord(tmp2, i) + margin);
VectorUtil.setCoord(vec, i, -1f);
MatrixUtil.transposeTransform(tmp1, vec, trans.basis);
localGetSupportingVertex(tmp1, tmp2);
trans.transform(tmp2);
VectorUtil.setCoord(minAabb, i, VectorUtil.getCoord(tmp2, i) - margin);
}
stack.leave();
}
Aggregations