use of com.bulletphysics.util.Stack in project bdx by GoranM.
the class CompoundShape method addChildShape.
public void addChildShape(Transform localTransform, CollisionShape shape) {
//m_childTransforms.push_back(localTransform);
//m_childShapes.push_back(shape);
CompoundShapeChild child = new CompoundShapeChild();
child.transform.set(localTransform);
child.childShape = shape;
child.childShapeType = shape.getShapeType();
child.childMargin = shape.getMargin();
children.add(child);
Stack stack = Stack.enter();
// extend the local aabbMin/aabbMax
Vector3f _localAabbMin = stack.allocVector3f(), _localAabbMax = stack.allocVector3f();
shape.getAabb(localTransform, _localAabbMin, _localAabbMax);
// JAVA NOTE: rewritten
// for (int i=0;i<3;i++)
// {
// if (this.localAabbMin[i] > _localAabbMin[i])
// {
// this.localAabbMin[i] = _localAabbMin[i];
// }
// if (this.localAabbMax[i] < _localAabbMax[i])
// {
// this.localAabbMax[i] = _localAabbMax[i];
// }
// }
VectorUtil.setMin(this.localAabbMin, _localAabbMin);
VectorUtil.setMax(this.localAabbMax, _localAabbMax);
stack.leave();
}
use of com.bulletphysics.util.Stack in project bdx by GoranM.
the class ConeShape method localGetSupportingVertex.
@Override
public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
Vector3f supVertex = coneLocalSupport(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 supVertex;
}
use of com.bulletphysics.util.Stack 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 com.bulletphysics.util.Stack 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 com.bulletphysics.util.Stack 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;
}
Aggregations