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());
}
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;
}
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;
}
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);
}
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);
}
Aggregations