Search in sources :

Example 1 with CollisionShape

use of org.terasology.engine.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));
    assertTrue(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;
    // TODO: Test fails because native library is not loaded
    for (int x = 0; x < ((btConvexHullShape) bulletConvexHullShape.underlyingShape).getNumPoints(); x++) {
        fuzzVectorTest(test[x], ((btConvexHullShape) bulletConvexHullShape.underlyingShape).getScaledPoint(x));
    }
}
Also used : CollisionShape(org.terasology.engine.physics.shapes.CollisionShape) BlockShape(org.terasology.engine.world.block.shapes.BlockShape) Vector3f(org.joml.Vector3f) ConvexHullShape(org.terasology.engine.physics.shapes.ConvexHullShape) com.badlogic.gdx.physics.bullet.collision.btConvexHullShape(com.badlogic.gdx.physics.bullet.collision.btConvexHullShape) BulletConvexHullShape(org.terasology.engine.physics.bullet.shapes.BulletConvexHullShape) BulletConvexHullShape(org.terasology.engine.physics.bullet.shapes.BulletConvexHullShape) Test(org.junit.jupiter.api.Test)

Example 2 with CollisionShape

use of org.terasology.engine.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(new Quaternionf(simplifiedRot.orientation()));
        collisionShape.put(simplifiedRot, result);
    }
    return result;
}
Also used : CollisionShape(org.terasology.engine.physics.shapes.CollisionShape) Quaternionf(org.joml.Quaternionf) Rotation(org.terasology.engine.math.Rotation)

Aggregations

CollisionShape (org.terasology.engine.physics.shapes.CollisionShape)2 com.badlogic.gdx.physics.bullet.collision.btConvexHullShape (com.badlogic.gdx.physics.bullet.collision.btConvexHullShape)1 Quaternionf (org.joml.Quaternionf)1 Vector3f (org.joml.Vector3f)1 Test (org.junit.jupiter.api.Test)1 Rotation (org.terasology.engine.math.Rotation)1 BulletConvexHullShape (org.terasology.engine.physics.bullet.shapes.BulletConvexHullShape)1 ConvexHullShape (org.terasology.engine.physics.shapes.ConvexHullShape)1 BlockShape (org.terasology.engine.world.block.shapes.BlockShape)1