Search in sources :

Example 1 with CollisionShape

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)));
        }
    }
}
Also used : CollisionShape(org.terasology.physics.shapes.CollisionShape) BlockShape(org.terasology.world.block.shapes.BlockShape) Vector3f(org.terasology.math.geom.Vector3f) BulletConvexHullShape(org.terasology.physics.bullet.shapes.BulletConvexHullShape) ConvexHullShape(org.terasology.physics.shapes.ConvexHullShape) BulletConvexHullShape(org.terasology.physics.bullet.shapes.BulletConvexHullShape) Test(org.junit.Test)

Example 2 with CollisionShape

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;
}
Also used : CollisionShape(org.terasology.physics.shapes.CollisionShape) Rotation(org.terasology.math.Rotation)

Example 3 with CollisionShape

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);
}
Also used : CollisionShape(org.terasology.physics.shapes.CollisionShape) CompoundShape(com.bulletphysics.collision.shapes.CompoundShape) Transform(com.bulletphysics.linearmath.Transform)

Aggregations

CollisionShape (org.terasology.physics.shapes.CollisionShape)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)1 Transform (com.bulletphysics.linearmath.Transform)1 Test (org.junit.Test)1 Rotation (org.terasology.math.Rotation)1 Vector3f (org.terasology.math.geom.Vector3f)1 BulletConvexHullShape (org.terasology.physics.bullet.shapes.BulletConvexHullShape)1 ConvexHullShape (org.terasology.physics.shapes.ConvexHullShape)1 BlockShape (org.terasology.world.block.shapes.BlockShape)1