use of org.terasology.physics.shapes.CollisionShape in project Terasology by MovingBlocks.
the class BlockShapeTest method testConvexHull.
@Test
public void testConvexHull() {
BlockShape blockShape = assetManager.getAsset("engine:halfSlope", BlockShape.class).get();
CollisionShape shape = blockShape.getCollisionShape(Rotation.rotate(Yaw.CLOCKWISE_90));
Assert.assertEquals(shape instanceof ConvexHullShape, true);
if (shape instanceof ConvexHullShape) {
Vector3f[] test = new Vector3f[] { new Vector3f(0.49999997f, 0.0f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, 0.0f, 0.49999997f) };
BulletConvexHullShape bulletConvexHullShape = (BulletConvexHullShape) shape;
ObjectArrayList<javax.vecmath.Vector3f> points = ((com.bulletphysics.collision.shapes.ConvexHullShape) bulletConvexHullShape.underlyingShape).getPoints();
for (int x = 0; x < points.size(); x++) {
fuzzVectorTest(test[x], VecMath.from(points.get(x)));
}
}
}
use of org.terasology.physics.shapes.CollisionShape in project Terasology by MovingBlocks.
the class BlockShapeImpl method getCollisionShape.
@Override
public CollisionShape getCollisionShape(Rotation rot) {
Rotation simplifiedRot = applySymmetry(rot);
CollisionShape result = collisionShape.get(simplifiedRot);
if (result == null && baseCollisionShape != null) {
result = baseCollisionShape.rotate(simplifiedRot.getQuat4f());
collisionShape.put(simplifiedRot, result);
}
return result;
}
use of org.terasology.physics.shapes.CollisionShape in project Terasology by MovingBlocks.
the class BulletCompoundShape method rotate.
// TODO: Add removeChildShape if needed
@Override
public CollisionShape rotate(Quat4f rot) {
CompoundShape newShape = new CompoundShape();
for (BulletCompoundShapeChild child : childList) {
CollisionShape rotatedChild = child.childShape.rotate(rot);
javax.vecmath.Vector3f offset = com.bulletphysics.linearmath.QuaternionUtil.quatRotate(VecMath.to(rot), child.transform.origin, new javax.vecmath.Vector3f());
newShape.addChildShape(new Transform(new javax.vecmath.Matrix4f(VecMath.to(Rotation.none().getQuat4f()), offset, 1.0f)), ((BulletCollisionShape) rotatedChild).underlyingShape);
}
return new BulletCompoundShape(newShape);
}
Aggregations