use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class BVHAnimation method transformBlenderBVHExportToChunkStoriesWorldSpace.
public static Matrix4f transformBlenderBVHExportToChunkStoriesWorldSpace(Matrix4f matrix) {
// Swaps Y and Z axises arround
Matrix4f blender2ingame = new Matrix4f();
blender2ingame.m11(0.0f);
blender2ingame.m22(0.0f);
blender2ingame.m12(1.0f);
blender2ingame.m21(1.0f);
// Rotate the matrix first to apply the transformation in blender space
blender2ingame.mul(matrix, matrix);
// Mirror it
Matrix4f mirror = new Matrix4f();
mirror.m22(-1.0f);
mirror.mul(matrix, matrix);
// Rotate again after so it's back the correct way arround
matrix.mul(blender2ingame, matrix);
matrix.mul(mirror, matrix);
return matrix;
}
use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class BVHAnimation method getBoneHierarchyTransformationMatrixWithOffset.
public Matrix4f getBoneHierarchyTransformationMatrixWithOffset(String boneName, double animationTime) {
Matrix4f matrix = null;
if (frames == 0) {
System.out.println("Invalid bone : " + boneName + "in animation" + this);
return new Matrix4f();
}
// Get the normal bone transformation
matrix = getBoneHierarchyTransformationMatrix(boneName, animationTime);
// Apply the offset matrix
matrix.mul(getOffsetMatrix(boneName));
return matrix;
}
use of org.joml.Matrix4f in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onTargetChanged.
@ReceiveEvent
public void onTargetChanged(PlayerTargetChangedEvent event, EntityRef entity) {
EntityRef target = event.getNewTarget();
hasTarget = target.exists();
if (hasTarget) {
LocationComponent location = target.getComponent(LocationComponent.class);
if (location != null) {
BlockComponent blockComp = target.getComponent(BlockComponent.class);
BlockRegionComponent blockRegion = target.getComponent(BlockRegionComponent.class);
if (blockComp != null || blockRegion != null) {
Vector3f blockPos = location.getWorldPosition(new Vector3f());
Block block = worldProvider.getBlock(blockPos);
aabb.set(block.getBounds(blockPos));
} else {
MeshComponent mesh = target.getComponent(MeshComponent.class);
if (mesh != null && mesh.mesh != null) {
aabb.set(mesh.mesh.getAABB());
aabb.transform(new Matrix4f().translationRotateScale(location.getWorldPosition(new Vector3f()), location.getWorldRotation(new Quaternionf()), location.getWorldScale()));
}
}
}
}
}
use of org.joml.Matrix4f in project Terasology by MovingBlocks.
the class SpriteParticleRenderer method renderAlphaBlend.
@Override
public void renderAlphaBlend() {
if (!opengl33) {
return;
}
PerspectiveCamera camera = (PerspectiveCamera) worldRenderer.getActiveCamera();
Vector3f cameraPosition = camera.getPosition();
Matrix4f viewProjection = new Matrix4f(camera.getViewProjectionMatrix()).translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z);
Material material = Assets.getMaterial(PARTICLE_MATERIAL_URI).get();
material.enable();
material.setFloat3("camera_position", cameraPosition.x, cameraPosition.y, cameraPosition.z);
material.setMatrix4("view_projection", viewProjection.get(matrixBuffer));
particleSystemManager.getParticleEmittersByDataComponent(ParticleDataSpriteComponent.class).forEach(particleSystem -> drawParticles(material, particleSystem));
}
use of org.joml.Matrix4f 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;
}
Aggregations