use of org.joml.Matrix4f in project Terasology by MovingBlocks.
the class BulletPhysics method createCollider.
private btPairCachingGhostObject createCollider(Vector3f pos, btCollisionShape shape, short groups, short filters, int collisionFlags) {
Matrix4f startTransform = new Matrix4f().translation(pos);
btPairCachingGhostObject result = new btPairCachingGhostObject();
result.setWorldTransform(startTransform);
result.setCollisionShape(shape);
result.setCollisionFlags(collisionFlags);
discreteDynamicsWorld.addCollisionObject(result, groups, filters);
return result;
}
use of org.joml.Matrix4f in project Terasology by MovingBlocks.
the class BulletPhysics method awakenArea.
@Override
public void awakenArea(Vector3fc pos, float radius) {
btPairCachingGhostObject ghost = new btPairCachingGhostObject();
btSphereShape shape = new btSphereShape(radius);
ghost.setCollisionShape(shape);
ghost.setWorldTransform(new Matrix4f().translationRotateScale(pos, new Quaternionf(), 1.0f));
discreteDynamicsWorld.addCollisionObject(ghost, (short) -1, (short) -1);
for (int i = 0; i < ghost.getNumOverlappingObjects(); ++i) {
btCollisionObject other = ghost.getOverlappingObject(i);
other.activate(true);
}
discreteDynamicsWorld.removeCollisionObject(ghost);
}
use of org.joml.Matrix4f in project Terasology by MovingBlocks.
the class LwjglCanvasRenderer method drawMesh.
@Override
public void drawMesh(Mesh mesh, Material material, Rectanglei drawRegion, Rectanglei cropRegion, Quaternionfc rotation, Vector3fc offset, float scale, float alpha) {
if (!material.isRenderable()) {
return;
}
AABBfc meshAABB = mesh.getAABB();
Vector3f meshExtents = meshAABB.extent(new Vector3f());
float fitScale = 0.35f * Math.min(drawRegion.getSizeX(), drawRegion.getSizeY()) / Math.max(meshExtents.x, Math.max(meshExtents.y, meshExtents.z));
Vector3f centerOffset = meshAABB.center(new Vector3f());
centerOffset.mul(-1.0f);
Matrix4f centerTransform = new Matrix4f().translationRotateScale(centerOffset, new Quaternionf(), 1);
Matrix4f userTransform = new Matrix4f().translationRotateScale(offset, rotation, -fitScale * scale);
Matrix4f translateTransform = new Matrix4f().translationRotateScale(new Vector3f((drawRegion.minX + drawRegion.getSizeX() / 2) * uiScale, (drawRegion.minY + drawRegion.getSizeY() / 2) * uiScale, 0), new Quaternionf(), 1);
userTransform.mul(centerTransform);
translateTransform.mul(userTransform);
Matrix4f finalMat = new Matrix4f().setTranslation(0, 0, -1024f);
finalMat.mul(translateTransform);
material.setFloat4(CROPPING_BOUNDARIES_PARAM, cropRegion.minX * uiScale, cropRegion.maxX * uiScale, cropRegion.minY * uiScale, cropRegion.maxY * uiScale);
glEnable(GL11.GL_DEPTH_TEST);
glClear(GL11.GL_DEPTH_BUFFER_BIT);
modelMatrixStack.pushMatrix();
modelMatrixStack.set(finalMat);
modelMatrixStack.scale(this.uiScale, this.uiScale, this.uiScale);
material.setMatrix4("posMatrix", translateTransform);
material.setMatrix4("projectionMatrix", projMatrix);
material.setMatrix4("modelViewMatrix", modelMatrixStack);
material.setMatrix3("normalMatrix", modelMatrixStack.normal(new Matrix3f()));
material.setFloat("alpha", alpha);
material.bindTextures();
mesh.render();
modelMatrixStack.popMatrix();
glDisable(GL11.GL_DEPTH_TEST);
}
use of org.joml.Matrix4f in project Terasology by MovingBlocks.
the class LwjglCanvasRenderer method preRender.
@Override
public void preRender() {
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// TODO: figure out previous call to viewport scaling is handled
// changing resolution scaling affect viewport of LWJGLCanvas causing strange scaling artifact.
glViewport(0, 0, displayDevice.getWidth(), displayDevice.getHeight());
projMatrix.setOrtho(0, displayDevice.getWidth(), displayDevice.getHeight(), 0, 0, 2048f);
modelMatrixStack.pushMatrix();
modelMatrixStack.set(new Matrix4f().setTranslation(0, 0, -1024));
modelMatrixStack.scale(uiScale, uiScale, uiScale);
requestedCropRegion = new Rectanglei(0, 0, displayDevice.getWidth(), displayDevice.getHeight());
currentTextureCropRegion = requestedCropRegion;
textureMat.setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX, requestedCropRegion.maxX, requestedCropRegion.minY, requestedCropRegion.maxY);
}
use of org.joml.Matrix4f in project Terasology by MovingBlocks.
the class GLTFCommonFormat method loadBones.
protected List<Bone> loadBones(GLTF gltf, GLTFSkin skin, List<byte[]> loadedBuffers) {
List<Bone> bones = new ArrayList<>();
TIntIntMap boneToJoint = new TIntIntHashMap();
List<Matrix4f> inverseMats = loadInverseMats(skin.getInverseBindMatrices(), skin.getJoints().size(), gltf, loadedBuffers);
for (int i = 0; i < skin.getJoints().size(); i++) {
int nodeIndex = skin.getJoints().get(i);
GLTFNode node = gltf.getNodes().get(nodeIndex);
Vector3f position = new Vector3f();
Quaternionf rotation = new Quaternionf();
Vector3f scale = new Vector3f(1, 1, 1);
if (node.getTranslation() != null) {
position.set(node.getTranslation());
}
if (node.getRotation() != null) {
rotation.set(node.getRotation());
}
if (node.getScale() != null) {
scale.set(node.getScale());
}
String boneName = node.getName();
if (Strings.isNullOrEmpty(boneName)) {
boneName = "bone_" + i;
}
Bone bone = new Bone(i, boneName, new Matrix4f().translationRotateScale(position, rotation, scale));
bone.setInverseBindMatrix(inverseMats.get(i));
bones.add(bone);
boneToJoint.put(nodeIndex, i);
}
for (int i = 0; i < skin.getJoints().size(); i++) {
int nodeIndex = skin.getJoints().get(i);
GLTFNode node = gltf.getNodes().get(nodeIndex);
Bone bone = bones.get(i);
TIntIterator iterator = node.getChildren().iterator();
while (iterator.hasNext()) {
bone.addChild(bones.get(boneToJoint.get(iterator.next())));
}
}
return bones;
}
Aggregations