use of com.bulletphysics.util.Stack in project bdx by GoranM.
the class BoxShape method getHalfExtentsWithMargin.
public Vector3f getHalfExtentsWithMargin(Vector3f out) {
Stack stack = Stack.enter();
Vector3f halfExtents = getHalfExtentsWithoutMargin(out);
Vector3f margin = stack.allocVector3f();
margin.set(getMargin(), getMargin(), getMargin());
halfExtents.add(margin);
stack.leave();
return out;
}
use of com.bulletphysics.util.Stack in project bdx by GoranM.
the class BoxShape method getPlaneEquation.
public void getPlaneEquation(Vector4f plane, int i) {
Stack stack = Stack.enter();
Vector3f halfExtents = getHalfExtentsWithoutMargin(stack.allocVector3f());
switch(i) {
case 0:
plane.set(1f, 0f, 0f, -halfExtents.x);
break;
case 1:
plane.set(-1f, 0f, 0f, -halfExtents.x);
break;
case 2:
plane.set(0f, 1f, 0f, -halfExtents.y);
break;
case 3:
plane.set(0f, -1f, 0f, -halfExtents.y);
break;
case 4:
plane.set(0f, 0f, 1f, -halfExtents.z);
break;
case 5:
plane.set(0f, 0f, -1f, -halfExtents.z);
break;
default:
assert (false);
}
stack.leave();
}
use of com.bulletphysics.util.Stack in project bdx by GoranM.
the class CapsuleShape method localGetSupportingVertexWithoutMargin.
@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec0, Vector3f out) {
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;
float radius = getRadius();
Vector3f tmp1 = stack.allocVector3f();
Vector3f tmp2 = stack.allocVector3f();
Vector3f pos = stack.allocVector3f();
{
pos.set(0f, 0f, 0f);
VectorUtil.setCoord(pos, getUpAxis(), getHalfHeight());
VectorUtil.mul(tmp1, vec, localScaling);
tmp1.scale(radius);
tmp2.scale(getMargin(), vec);
vtx.add(pos, tmp1);
vtx.sub(tmp2);
newDot = vec.dot(vtx);
if (newDot > maxDot) {
maxDot = newDot;
supVec.set(vtx);
}
}
{
pos.set(0f, 0f, 0f);
VectorUtil.setCoord(pos, getUpAxis(), -getHalfHeight());
VectorUtil.mul(tmp1, vec, localScaling);
tmp1.scale(radius);
tmp2.scale(getMargin(), vec);
vtx.add(pos, tmp1);
vtx.sub(tmp2);
newDot = vec.dot(vtx);
if (newDot > maxDot) {
maxDot = newDot;
supVec.set(vtx);
}
}
stack.leave();
return out;
}
use of com.bulletphysics.util.Stack in project bdx by GoranM.
the class CollisionShape method calculateTemporalAabb.
///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
///result is conservative
public void calculateTemporalAabb(Transform curTrans, Vector3f linvel, Vector3f angvel, float timeStep, Vector3f temporalAabbMin, Vector3f temporalAabbMax) {
//start with static aabb
getAabb(curTrans, temporalAabbMin, temporalAabbMax);
Stack stack = Stack.enter();
float temporalAabbMaxx = temporalAabbMax.x;
float temporalAabbMaxy = temporalAabbMax.y;
float temporalAabbMaxz = temporalAabbMax.z;
float temporalAabbMinx = temporalAabbMin.x;
float temporalAabbMiny = temporalAabbMin.y;
float temporalAabbMinz = temporalAabbMin.z;
// add linear motion
Vector3f linMotion = stack.alloc(linvel);
linMotion.scale(timeStep);
//todo: simd would have a vector max/min operation, instead of per-element access
if (linMotion.x > 0f) {
temporalAabbMaxx += linMotion.x;
} else {
temporalAabbMinx += linMotion.x;
}
if (linMotion.y > 0f) {
temporalAabbMaxy += linMotion.y;
} else {
temporalAabbMiny += linMotion.y;
}
if (linMotion.z > 0f) {
temporalAabbMaxz += linMotion.z;
} else {
temporalAabbMinz += linMotion.z;
}
//add conservative angular motion
float angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
Vector3f angularMotion3d = stack.allocVector3f();
angularMotion3d.set(angularMotion, angularMotion, angularMotion);
temporalAabbMin.set(temporalAabbMinx, temporalAabbMiny, temporalAabbMinz);
temporalAabbMax.set(temporalAabbMaxx, temporalAabbMaxy, temporalAabbMaxz);
temporalAabbMin.sub(angularMotion3d);
temporalAabbMax.add(angularMotion3d);
stack.leave();
}
use of com.bulletphysics.util.Stack in project bdx by GoranM.
the class CollisionShape method getBoundingSphere.
public float getBoundingSphere(Vector3f center) {
Stack stack = Stack.enter();
Vector3f tmp = stack.allocVector3f();
Transform tr = stack.allocTransform();
tr.setIdentity();
Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
getAabb(tr, aabbMin, aabbMax);
tmp.sub(aabbMax, aabbMin);
float radius = tmp.length() * 0.5f;
tmp.add(aabbMin, aabbMax);
center.scale(0.5f, tmp);
stack.leave();
return radius;
}
Aggregations