use of spacegraph.util.math.Quat4f in project narchy by automenta.
the class SpaceWidget method render.
static void render(GL2 gl, SimpleSpatial src, float twist, Iterable<? extends EDraw> ee) {
Quat4f tmpQ = new Quat4f();
ee.forEach(e -> {
float width = e.width;
float thresh = 0.1f;
if (width <= thresh) {
float aa = e.a * (width / thresh);
if (aa < 1 / 256f)
return;
gl.glColor4f(e.r, e.g, e.b, aa);
Draw.renderLineEdge(gl, src, e.tgt(), width);
} else {
Draw.renderHalfTriEdge(gl, src, e, width, twist, tmpQ);
}
});
}
use of spacegraph.util.math.Quat4f in project narchy by automenta.
the class Collisions method convexSweepTest.
/**
* convexTest performs a swept convex cast on all objects in the {@link Collisions}, and calls the resultCallback
* This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
*/
public void convexSweepTest(ConvexShape castShape, Transform convexFromWorld, Transform convexToWorld, ConvexResultCallback resultCallback) {
Transform convexFromTrans = new Transform();
Transform convexToTrans = new Transform();
convexFromTrans.set(convexFromWorld);
convexToTrans.set(convexToWorld);
v3 castShapeAabbMin = new v3();
v3 castShapeAabbMax = new v3();
// Compute AABB that encompasses angular movement
v3 linVel = new v3();
v3 angVel = new v3();
TransformUtil.calculateVelocity(convexFromTrans, convexToTrans, 1f, linVel, angVel);
{
Transform R = new Transform();
R.setIdentity();
R.setRotation(convexFromTrans.getRotation(new Quat4f()));
castShape.calculateTemporalAabb(R, linVel, angVel, 1f, castShapeAabbMin, castShapeAabbMax);
}
// Transform R = new Transform();
v3 collisionObjectAabbMin = new v3();
v3 collisionObjectAabbMax = new v3();
float[] hitLambda = new float[1];
// go over all objects, and if the ray intersects their aabb + cast shape aabb,
// do a ray-shape query using convexCaster (CCD)
v3 hitNormal = new v3();
List<Collidable> collidables = collidables();
for (int i = 0, collidablesSize = collidables.size(); i < collidablesSize; i++) {
Collidable collidable = collidables.get(i);
// only perform raycast if filterMask matches
if (resultCallback.needsCollision(collidable.broadphase)) {
// RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
Transform S = collidable.transform;
CollisionShape shape = collidable.shape();
shape.getAabb(S, collisionObjectAabbMin, collisionObjectAabbMax);
AabbUtil2.aabbExpand(collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
// could use resultCallback.closestHitFraction, but needs testing
hitLambda[0] = 1f;
// may not be necessary
hitNormal.zero();
if (AabbUtil2.rayAabb(convexFromWorld, convexToWorld, collisionObjectAabbMin, collisionObjectAabbMax, hitLambda, hitNormal)) {
objectQuerySingle(castShape, convexFromTrans, convexToTrans, collidable, shape, S, resultCallback, dispatchInfo.allowedCcdPenetration);
}
}
}
}
Aggregations