use of javax.vecmath.Vector3f 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 javax.vecmath.Vector3f 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 javax.vecmath.Vector3f 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;
}
use of javax.vecmath.Vector3f 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 javax.vecmath.Vector3f 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;
}
Aggregations