Search in sources :

Example 96 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class AABBRenderer method prepare.

private void prepare() {
    defaultMaterial.enable();
    Matrix4f modelView = new Matrix4f();
    Camera camera = worldRenderer.getActiveCamera();
    Vector3f center = aabb.center(new Vector3f());
    Vector3f cameraPosition = CoreRegistry.get(LocalPlayer.class).getViewPosition(new Vector3f());
    modelView.set(camera.getViewMatrix()).mul(new Matrix4f().setTranslation(center.x() - cameraPosition.x, center.y() - cameraPosition.y, center.z() - cameraPosition.z));
    defaultMaterial.setMatrix4("modelViewMatrix", modelView);
    defaultMaterial.setMatrix4("projectionMatrix", camera.getProjectionMatrix());
}
Also used : Matrix4f(org.joml.Matrix4f) LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) Vector3f(org.joml.Vector3f) Camera(org.terasology.engine.rendering.cameras.Camera)

Example 97 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class BulletSweepCallback method calculateAverageSlope.

@Override
public float calculateAverageSlope(float originalSlope, float checkingOffset) {
    Vector3f contactPoint = this.getHitPointWorld();
    float slope = 1f;
    boolean foundSlope = false;
    Vector3f fromWorld = new Vector3f(contactPoint);
    fromWorld.y += 0.2f;
    Vector3f toWorld = new Vector3f(contactPoint);
    toWorld.y -= 0.2f;
    ClosestRayResultCallback resultCallback = new ClosestRayResultCallback(fromWorld, toWorld);
    Matrix4f from = new Matrix4f().setTranslation(fromWorld);
    Matrix4f to = new Matrix4f().setTranslation(toWorld);
    Matrix4f targetTransform = this.getHitCollisionObject().getWorldTransform();
    btDiscreteDynamicsWorld.rayTestSingle(from, to, this.getHitCollisionObject(), this.getHitCollisionObject().getCollisionShape(), targetTransform, resultCallback);
    if (resultCallback.hasHit()) {
        foundSlope = true;
        Vector3f result = new Vector3f();
        resultCallback.getHitNormalWorld(result);
        slope = Math.min(slope, result.dot(0, 1, 0));
    }
    Vector3f secondTraceOffset = new Vector3f();
    this.getHitNormalWorld(secondTraceOffset);
    secondTraceOffset.y = 0;
    secondTraceOffset.normalize();
    secondTraceOffset.mul(checkingOffset);
    fromWorld.add(secondTraceOffset);
    toWorld.add(secondTraceOffset);
    resultCallback = new ClosestRayResultCallback(fromWorld, toWorld);
    from = new Matrix4f().setTranslation(fromWorld);
    to = new Matrix4f().setTranslation(toWorld);
    targetTransform = this.getHitCollisionObject().getWorldTransform();
    btDiscreteDynamicsWorld.rayTestSingle(from, to, this.getHitCollisionObject(), this.getHitCollisionObject().getCollisionShape(), targetTransform, resultCallback);
    if (resultCallback.hasHit()) {
        foundSlope = true;
        Vector3f hitNormal = new Vector3f();
        resultCallback.getHitNormalWorld(hitNormal);
        slope = Math.min(slope, hitNormal.dot(0, 1, 0));
    }
    if (!foundSlope) {
        slope = originalSlope;
    }
    resultCallback.dispose();
    return slope;
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) ClosestRayResultCallback(com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback)

Example 98 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class BulletSweepCallback method checkForStep.

@Override
public boolean checkForStep(Vector3f direction, float stepHeight, float slopeFactor, float checkForwardDistance) {
    boolean moveUpStep;
    boolean hitStep = false;
    float stepSlope = 1f;
    Vector3f lookAheadOffset = new Vector3f(direction.x, direction.y, direction.z);
    lookAheadOffset.y = 0;
    lookAheadOffset.normalize();
    lookAheadOffset.mul(checkForwardDistance);
    Vector3f fromWorld = new Vector3f();
    this.getHitPointWorld(fromWorld);
    fromWorld.y += stepHeight + 0.05f;
    fromWorld.add(lookAheadOffset);
    Vector3f toWorld = new Vector3f();
    this.getHitPointWorld(toWorld);
    toWorld.y -= 0.05f;
    toWorld.add(lookAheadOffset);
    ClosestRayResultCallback rayResult = new ClosestRayResultCallback(fromWorld, toWorld);
    Matrix4f transformFrom = new Matrix4f().setTranslation(fromWorld);
    Matrix4f transformTo = new Matrix4f().setTranslation(toWorld);
    Matrix4f targetTransform = this.getHitCollisionObject().getWorldTransform();
    btDiscreteDynamicsWorld.rayTestSingle(transformFrom, transformTo, this.getHitCollisionObject(), this.getHitCollisionObject().getCollisionShape(), targetTransform, rayResult);
    if (rayResult.hasHit()) {
        hitStep = true;
        Vector3f hitNormal = new Vector3f();
        rayResult.getHitNormalWorld(hitNormal);
        stepSlope = hitNormal.dot(0, 1, 0);
    }
    fromWorld.add(lookAheadOffset);
    toWorld.add(lookAheadOffset);
    rayResult = new ClosestRayResultCallback(fromWorld, toWorld);
    transformFrom = new Matrix4f().setTranslation(fromWorld);
    transformTo = new Matrix4f().setTranslation(toWorld);
    targetTransform = this.getHitCollisionObject().getWorldTransform();
    btDiscreteDynamicsWorld.rayTestSingle(transformFrom, transformTo, this.getHitCollisionObject(), this.getHitCollisionObject().getCollisionShape(), targetTransform, rayResult);
    if (rayResult.hasHit()) {
        hitStep = true;
        Vector3f hitNormal = new Vector3f();
        rayResult.getHitNormalWorld(hitNormal);
        stepSlope = Math.min(stepSlope, hitNormal.dot(0, 1, 0));
    }
    moveUpStep = hitStep && stepSlope >= slopeFactor;
    return moveUpStep;
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) ClosestRayResultCallback(com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback)

Example 99 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class LocationComponentTest method testParentRotatesWorldLocation.

@Test
public void testParentRotatesWorldLocation() {
    LocationComponent parent = giveParent();
    loc.setLocalPosition(pos1);
    parent.setLocalRotation(yawRotation);
    assertEquals(new Vector3f(pos1.z, pos1.y, -pos1.x), loc.getWorldPosition(new Vector3f()), 0.00001f);
}
Also used : Vector3f(org.joml.Vector3f) Test(org.junit.jupiter.api.Test)

Example 100 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class LocationComponentTest method testScaleRotateAndOffsetCombineCorrectlyForWorldPosition.

@Test
public void testScaleRotateAndOffsetCombineCorrectlyForWorldPosition() {
    LocationComponent parent = giveParent();
    loc.setLocalPosition(pos1);
    parent.setLocalScale(2.0f);
    parent.setLocalPosition(pos2);
    parent.setLocalRotation(yawRotation);
    assertEquals(new Vector3f(8, 7, 2), loc.getWorldPosition(new Vector3f()), 0.00001f);
}
Also used : Vector3f(org.joml.Vector3f) Test(org.junit.jupiter.api.Test)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8