org.joml.Matrix4f Java Examples
The following examples show how to use
org.joml.Matrix4f.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Matrix4fTest.java From JOML with MIT License | 6 votes |
public static void testFrustumRay() { Vector3f dir = new Vector3f(); Matrix4f m = new Matrix4f() .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f) .rotateY((float) Math.toRadians(90)); Vector3f expectedDir; m.frustumRayDir(0, 0, dir); expectedDir = new Vector3f(1, -1, -1).normalize(); TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(1, 0, dir); expectedDir = new Vector3f(1, -1, 1).normalize(); TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(0, 1, dir); expectedDir = new Vector3f(1, 1, -1).normalize(); TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(1, 1, dir); expectedDir = new Vector3f(1, 1, 1).normalize(); TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f); }
Example #2
Source File: AnimMeshesLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
private static void buildTransFormationMatrices(AINodeAnim aiNodeAnim, Node node) { int numFrames = aiNodeAnim.mNumPositionKeys(); AIVectorKey.Buffer positionKeys = aiNodeAnim.mPositionKeys(); AIVectorKey.Buffer scalingKeys = aiNodeAnim.mScalingKeys(); AIQuatKey.Buffer rotationKeys = aiNodeAnim.mRotationKeys(); for (int i = 0; i < numFrames; i++) { AIVectorKey aiVecKey = positionKeys.get(i); AIVector3D vec = aiVecKey.mValue(); Matrix4f transfMat = new Matrix4f().translate(vec.x(), vec.y(), vec.z()); AIQuatKey quatKey = rotationKeys.get(i); AIQuaternion aiQuat = quatKey.mValue(); Quaternionf quat = new Quaternionf(aiQuat.x(), aiQuat.y(), aiQuat.z(), aiQuat.w()); transfMat.rotate(quat); if (i < aiNodeAnim.mNumScalingKeys()) { aiVecKey = scalingKeys.get(i); vec = aiVecKey.mValue(); transfMat.scale(vec.x(), vec.y(), vec.z()); } node.addTransformation(transfMat); } }
Example #3
Source File: Matrix4fTest.java From JOML with MIT License | 6 votes |
public static void testOrthoCropWithPerspective() { Matrix4f lightView = new Matrix4f() .lookAt(0, 5, 0, 0, 0, 0, 0, 0, -1); Matrix4f crop = new Matrix4f(); Matrix4f fin = new Matrix4f(); new Matrix4f().perspective((float) Math.toRadians(90), 1.0f, 5, 10).invertPerspective().orthoCrop(lightView, crop).mulOrthoAffine(lightView, fin); Vector3f p = new Vector3f(); fin.transformProject(p.set(0, 0, -5)); assertEquals(+0.0f, p.x, 1E-6f); assertEquals(-1.0f, p.y, 1E-6f); assertEquals(+0.0f, p.z, 1E-6f); fin.transformProject(p.set(0, 0, -10)); assertEquals(+0.0f, p.x, 1E-6f); assertEquals(+1.0f, p.y, 1E-6f); assertEquals(+0.0f, p.z, 1E-6f); fin.transformProject(p.set(-10, 10, -10)); assertEquals(-1.0f, p.x, 1E-6f); assertEquals(+1.0f, p.y, 1E-6f); assertEquals(-1.0f, p.z, 1E-6f); }
Example #4
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 6 votes |
private void renderInstancedMeshes(Scene scene, ShaderProgram shader, Matrix4f viewMatrix, Matrix4f lightViewMatrix) { shader.setUniform("isInstanced", 1); // Render each mesh with the associated game Items Map<InstancedMesh, List<GameItem>> mapMeshes = scene.getGameInstancedMeshes(); for (InstancedMesh mesh : mapMeshes.keySet()) { Texture text = mesh.getMaterial().getTexture(); if (text != null) { sceneShaderProgram.setUniform("numCols", text.getNumCols()); sceneShaderProgram.setUniform("numRows", text.getNumRows()); } if (viewMatrix != null) { shader.setUniform("material", mesh.getMaterial()); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, shadowMap.getDepthMapTexture().getId()); } mesh.renderListInstanced(mapMeshes.get(mesh), transformation, viewMatrix, lightViewMatrix); } }
Example #5
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 6 votes |
private void renderHud(Window window, IHud hud) { if (hud != null) { hudShaderProgram.bind(); Matrix4f ortho = transformation.getOrtho2DProjectionMatrix(0, window.getWidth(), window.getHeight(), 0); for (GameItem gameItem : hud.getGameItems()) { Mesh mesh = gameItem.getMesh(); // Set ortohtaphic and model matrix for this HUD item Matrix4f projModelMatrix = transformation.buildOrtoProjModelMatrix(gameItem, ortho); hudShaderProgram.setUniform("projModelMatrix", projModelMatrix); hudShaderProgram.setUniform("colour", gameItem.getMesh().getMaterial().getAmbientColour()); hudShaderProgram.setUniform("hasTexture", gameItem.getMesh().getMaterial().isTextured() ? 1 : 0); // Render the mesh for this HUD item mesh.render(); } hudShaderProgram.unbind(); } }
Example #6
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 6 votes |
public void renderScene(Window window, Camera camera, Scene scene) { sceneShaderProgram.bind(); Matrix4f projectionMatrix = transformation.getProjectionMatrix(); sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix); Matrix4f viewMatrix = transformation.getViewMatrix(); SceneLight sceneLight = scene.getSceneLight(); renderLights(viewMatrix, sceneLight); sceneShaderProgram.setUniform("texture_sampler", 0); sceneShaderProgram.setUniform("fog", scene.getFog()); // Render each mesh with the associated game Items Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes(); for (Mesh mesh : mapMeshes.keySet()) { sceneShaderProgram.setUniform("material", mesh.getMaterial()); mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> { Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix); sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix); } ); } sceneShaderProgram.unbind(); }
Example #7
Source File: MD5Loader.java From lwjglbook with Apache License 2.0 | 6 votes |
/** * Constructs and AnimGameItem instace based on a MD5 Model an MD5 Animation * * @param md5Model The MD5 Model * @param animModel The MD5 Animation * @param defaultColour Default colour to use if there are no textures * @return * @throws Exception */ public static AnimGameItem process(MD5Model md5Model, MD5AnimModel animModel, Vector4f defaultColour) throws Exception { List<Matrix4f> invJointMatrices = calcInJointMatrices(md5Model); List<AnimatedFrame> animatedFrames = processAnimationFrames(md5Model, animModel, invJointMatrices); List<Mesh> list = new ArrayList<>(); for (MD5Mesh md5Mesh : md5Model.getMeshes()) { Mesh mesh = generateMesh(md5Model, md5Mesh); handleTexture(mesh, md5Mesh, defaultColour); list.add(mesh); } Mesh[] meshes = new Mesh[list.size()]; meshes = list.toArray(meshes); AnimGameItem result = new AnimGameItem(meshes, animatedFrames, invJointMatrices); return result; }
Example #8
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 6 votes |
public void renderScene(Window window, Camera camera, Scene scene) { sceneShaderProgram.bind(); Matrix4f projectionMatrix = transformation.getProjectionMatrix(); sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix); Matrix4f viewMatrix = transformation.getViewMatrix(); SceneLight sceneLight = scene.getSceneLight(); renderLights(viewMatrix, sceneLight); sceneShaderProgram.setUniform("texture_sampler", 0); // Render each mesh with the associated game Items Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes(); for (Mesh mesh : mapMeshes.keySet()) { sceneShaderProgram.setUniform("material", mesh.getMaterial()); mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> { Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix); sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix); } ); } sceneShaderProgram.unbind(); }
Example #9
Source File: ShadowCascade.java From lwjglbook with Apache License 2.0 | 5 votes |
public ShadowCascade(float zNear, float zFar) { this.zNear = zNear; this.zFar = zFar; this.projViewMatrix = new Matrix4f(); this.orthoProjMatrix = new Matrix4f(); this.centroid = new Vector3f(); this.lightViewMatrix = new Matrix4f(); this.frustumCorners = new Vector3f[FRUSTUM_CORNERS]; for (int i = 0; i < FRUSTUM_CORNERS; i++) { frustumCorners[i] = new Vector3f(); } tmpVec = new Vector4f(); }
Example #10
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 5 votes |
private void renderNonInstancedMeshes(Scene scene) { sceneShaderProgram.setUniform("isInstanced", 0); // Render each mesh with the associated game Items Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes(); for (Mesh mesh : mapMeshes.keySet()) { sceneShaderProgram.setUniform("material", mesh.getMaterial()); Texture text = mesh.getMaterial().getTexture(); if (text != null) { sceneShaderProgram.setUniform("numCols", text.getNumCols()); sceneShaderProgram.setUniform("numRows", text.getNumRows()); } shadowRenderer.bindTextures(GL_TEXTURE2); mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> { sceneShaderProgram.setUniform("selectedNonInstanced", gameItem.isSelected() ? 1.0f : 0.0f); Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem); sceneShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix); if (gameItem instanceof AnimGameItem) { AnimGameItem animGameItem = (AnimGameItem) gameItem; AnimatedFrame frame = animGameItem.getCurrentFrame(); sceneShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices()); } } ); } }
Example #11
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 5 votes |
private void renderParticles(Window window, Camera camera, Scene scene) { particlesShaderProgram.bind(); particlesShaderProgram.setUniform("texture_sampler", 0); Matrix4f projectionMatrix = transformation.getProjectionMatrix(); particlesShaderProgram.setUniform("projectionMatrix", projectionMatrix); Matrix4f viewMatrix = transformation.getViewMatrix(); IParticleEmitter[] emitters = scene.getParticleEmitters(); int numEmitters = emitters != null ? emitters.length : 0; glDepthMask(false); glBlendFunc(GL_SRC_ALPHA, GL_ONE); for (int i = 0; i < numEmitters; i++) { IParticleEmitter emitter = emitters[i]; InstancedMesh mesh = (InstancedMesh)emitter.getBaseParticle().getMesh(); Texture text = mesh.getMaterial().getTexture(); particlesShaderProgram.setUniform("numCols", text.getNumCols()); particlesShaderProgram.setUniform("numRows", text.getNumRows()); mesh.renderListInstanced(emitter.getParticles(), true, transformation, viewMatrix, null); } glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthMask(true); particlesShaderProgram.unbind(); }
Example #12
Source File: Mesh.java From cineast with MIT License | 5 votes |
/** * Scales the Mesh by the provided factor. This will reset the surfaceArea and bounding-box property. * * @param factor Factor by which the Mesh should be scaled. Values < 1.0 will cause the Mesh to shrink. */ @Override public synchronized final void scale(float factor) { Matrix4f scaling = new Matrix4f().scale(factor); for (Mesh.Vertex v : this.vertices) { v.position.mulPosition(scaling); } /* Reset surface-area and bounding box, which are not invariant under scaling. */ this.surfaceArea = null; this.boundingbox = null; }
Example #13
Source File: ShaderProgram.java From lwjglbook with Apache License 2.0 | 5 votes |
public void setUniform(String uniformName, Matrix4f value) { // Dump the matrix into a float buffer try (MemoryStack stack = MemoryStack.stackPush()) { glUniformMatrix4fv(uniforms.get(uniformName), false, value.get(stack.mallocFloat(16))); } }
Example #14
Source File: ShaderProgram.java From lwjglbook with Apache License 2.0 | 5 votes |
public void setUniform(String uniformName, Matrix4f value) { // Dump the matrix into a float buffer try (MemoryStack stack = MemoryStack.stackPush()) { glUniformMatrix4fv(uniforms.get(uniformName), false, value.get(stack.mallocFloat(16))); } }
Example #15
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getViewMatrix(Camera camera) { Vector3f cameraPos = camera.getPosition(); Vector3f rotation = camera.getRotation(); viewMatrix.identity(); // First do the rotation so camera rotates over its position viewMatrix.rotate((float)Math.toRadians(rotation.x), new Vector3f(1, 0, 0)) .rotate((float)Math.toRadians(rotation.y), new Vector3f(0, 1, 0)); // Then do the translation viewMatrix.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z); return viewMatrix; }
Example #16
Source File: InstancedMesh.java From lwjglbook with Apache License 2.0 | 5 votes |
public void renderListInstanced(List<GameItem> gameItems, boolean billBoard, Transformation transformation, Matrix4f viewMatrix, Matrix4f lightViewMatrix) { initRender(); int chunkSize = numInstances; int length = gameItems.size(); for (int i = 0; i < length; i += chunkSize) { int end = Math.min(length, i + chunkSize); List<GameItem> subList = gameItems.subList(i, end); renderChunkInstanced(subList, billBoard, transformation, viewMatrix, lightViewMatrix); } endRender(); }
Example #17
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 5 votes |
private void renderParticles(Window window, Camera camera, Scene scene) { // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); particlesShaderProgram.bind(); Matrix4f viewMatrix = camera.getViewMatrix(); particlesShaderProgram.setUniform("viewMatrix", viewMatrix); particlesShaderProgram.setUniform("texture_sampler", 0); Matrix4f projectionMatrix = window.getProjectionMatrix(); particlesShaderProgram.setUniform("projectionMatrix", projectionMatrix); IParticleEmitter[] emitters = scene.getParticleEmitters(); int numEmitters = emitters != null ? emitters.length : 0; glDepthMask(false); glBlendFunc(GL_SRC_ALPHA, GL_ONE); for (int i = 0; i < numEmitters; i++) { IParticleEmitter emitter = emitters[i]; InstancedMesh mesh = (InstancedMesh) emitter.getBaseParticle().getMesh(); Texture text = mesh.getMaterial().getTexture(); particlesShaderProgram.setUniform("numCols", text.getNumCols()); particlesShaderProgram.setUniform("numRows", text.getNumRows()); mesh.renderListInstanced(emitter.getParticles(), true, transformation, viewMatrix); } glDisable(GL_BLEND); glDepthMask(true); particlesShaderProgram.unbind(); }
Example #18
Source File: Transform3D.java From WraithEngine with Apache License 2.0 | 5 votes |
/** * Calculates the full matrix for this transform and stores it in the output * matrix parameter. A full transform is considered: * <p> * <code>out = parent * local</code> * <p> * for the given transforms. If this transform does not have a parent, then this * method returns the local transformation matrix. * * @param out * - The matrix to store the output into. */ public void getFullMatrix(Matrix4f out) { if (parent == null) { getLocalMatrix(out); return; } parent.getFullMatrix(matrixBuffer); out.set(matrixBuffer); getLocalMatrix(matrixBuffer); out.mul(matrixBuffer); }
Example #19
Source File: ShaderProgram.java From lwjglbook with Apache License 2.0 | 5 votes |
public void setUniform(String uniformName, Matrix4f value) { // Dump the matrix into a float buffer try (MemoryStack stack = MemoryStack.stackPush()) { glUniformMatrix4fv(uniforms.get(uniformName), false, value.get(stack.mallocFloat(16))); } }
Example #20
Source File: CameraTest.java From WraithEngine with Apache License 2.0 | 5 votes |
@Test public void getProjectionMatrix() { Screen screen = mock(Screen.class); when(screen.getAspect()).thenReturn(4f / 3f); Camera camera = new Camera(screen); Matrix4f mat = new Matrix4f(); mat.perspective((float) Math.PI / 2f, 4f / 3f, 0.1f, 1000f); assertTrue(mat.equals(camera.getProjectionMatrix(), 0.0001f)); }
Example #21
Source File: ShaderProgram.java From lwjglbook with Apache License 2.0 | 5 votes |
public void setUniform(String uniformName, Matrix4f value) { // Dump the matrix into a float buffer try (MemoryStack stack = MemoryStack.stackPush()) { glUniformMatrix4fv(uniforms.get(uniformName), false, value.get(stack.mallocFloat(16))); } }
Example #22
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getOrtoProjModelMatrix(GameItem gameItem, Matrix4f orthoMatrix) { Vector3f rotation = gameItem.getRotation(); Matrix4f modelMatrix = new Matrix4f(); modelMatrix.identity().translate(gameItem.getPosition()). rotateX((float) Math.toRadians(-rotation.x)). rotateY((float) Math.toRadians(-rotation.y)). rotateZ((float) Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f orthoMatrixCurr = new Matrix4f(orthoMatrix); orthoMatrixCurr.mul(modelMatrix); return orthoMatrixCurr; }
Example #23
Source File: Matrix4fTest.java From JOML with MIT License | 5 votes |
public static void testFrustumCornerIdentity() { Matrix4f m = new Matrix4f(); Vector3f corner = new Vector3f(); m.frustumCorner(Matrix4fc.CORNER_NXNYNZ, corner); // left, bottom, near TestUtil.assertVector3fEquals(new Vector3f(-1, -1, -1), corner, 1E-6f); m.frustumCorner(Matrix4fc.CORNER_PXNYNZ, corner); // right, bottom, near TestUtil.assertVector3fEquals(new Vector3f(1, -1, -1), corner, 1E-6f); m.frustumCorner(Matrix4fc.CORNER_PXNYPZ, corner); // right, bottom, far TestUtil.assertVector3fEquals(new Vector3f(1, -1, 1), corner, 1E-6f); m.frustumCorner(Matrix4fc.CORNER_NXPYPZ, corner); // left, top, far TestUtil.assertVector3fEquals(new Vector3f(-1, 1, 1), corner, 1E-6f); }
Example #24
Source File: InstancedMesh.java From lwjglbook with Apache License 2.0 | 5 votes |
private void renderChunkInstanced(List<GameItem> gameItems, boolean depthMap, Transformation transformation, Matrix4f viewMatrix, Matrix4f lightViewMatrix) { this.modelViewBuffer.clear(); this.modelLightViewBuffer.clear(); int i = 0; for (GameItem gameItem : gameItems) { Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem); if (!depthMap) { Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(modelMatrix, viewMatrix); modelViewMatrix.get(InstancedMesh.MATRIX_SIZE_FLOATS * i, modelViewBuffer); } Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(modelMatrix, lightViewMatrix); modelLightViewMatrix.get(InstancedMesh.MATRIX_SIZE_FLOATS * i, this.modelLightViewBuffer); i++; } glBindBuffer(GL_ARRAY_BUFFER, modelViewVBO); glBufferData(GL_ARRAY_BUFFER, modelViewBuffer, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, modelLightViewVBO); glBufferData(GL_ARRAY_BUFFER, modelLightViewBuffer, GL_DYNAMIC_DRAW); glDrawElementsInstanced( GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0, gameItems.size()); glBindBuffer(GL_ARRAY_BUFFER, 0); }
Example #25
Source File: ShaderProgram.java From lwjglbook with Apache License 2.0 | 5 votes |
public void setUniform(String uniformName, Matrix4f value) { // Dump the matrix into a float buffer try (MemoryStack stack = MemoryStack.stackPush()) { glUniformMatrix4fv(uniforms.get(uniformName), false, value.get(stack.mallocFloat(16))); } }
Example #26
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 5 votes |
public void renderScene(Window window, Camera camera, Scene scene) { sceneShaderProgram.bind(); Matrix4f viewMatrix = camera.getViewMatrix(); Matrix4f projectionMatrix = window.getProjectionMatrix(); sceneShaderProgram.setUniform("viewMatrix", viewMatrix); sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix); List<ShadowCascade> shadowCascades = shadowRenderer.getShadowCascades(); for (int i = 0; i < ShadowRenderer.NUM_CASCADES; i++) { ShadowCascade shadowCascade = shadowCascades.get(i); sceneShaderProgram.setUniform("orthoProjectionMatrix", shadowCascade.getOrthoProjMatrix(), i); sceneShaderProgram.setUniform("cascadeFarPlanes", ShadowRenderer.CASCADE_SPLITS[i], i); sceneShaderProgram.setUniform("lightViewMatrix", shadowCascade.getLightViewMatrix(), i); } SceneLight sceneLight = scene.getSceneLight(); renderLights(viewMatrix, sceneLight); sceneShaderProgram.setUniform("fog", scene.getFog()); sceneShaderProgram.setUniform("texture_sampler", 0); sceneShaderProgram.setUniform("normalMap", 1); int start = 2; for (int i = 0; i < ShadowRenderer.NUM_CASCADES; i++) { sceneShaderProgram.setUniform("shadowMap_" + i, start + i); } sceneShaderProgram.setUniform("renderShadow", scene.isRenderShadows() ? 1 : 0); renderNonInstancedMeshes(scene); renderInstancedMeshes(scene, viewMatrix); sceneShaderProgram.unbind(); }
Example #27
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getModelViewMatrix(GameItem gameItem, Matrix4f viewMatrix) { Vector3f rotation = gameItem.getRotation(); modelViewMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f viewCurr = new Matrix4f(viewMatrix); return viewCurr.mul(modelViewMatrix); }
Example #28
Source File: ShaderProgram.java From lwjglbook with Apache License 2.0 | 5 votes |
public void setUniform(String uniformName, Matrix4f value) { // Dump the matrix into a float buffer try (MemoryStack stack = MemoryStack.stackPush()) { glUniformMatrix4fv(uniforms.get(uniformName), false, value.get(stack.mallocFloat(16))); } }
Example #29
Source File: ShaderProgram.java From lwjglbook with Apache License 2.0 | 5 votes |
public void setUniform(String uniformName, Matrix4f value) { // Dump the matrix into a float buffer try (MemoryStack stack = MemoryStack.stackPush()) { glUniformMatrix4fv(uniforms.get(uniformName), false, value.get(stack.mallocFloat(16))); } }
Example #30
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 5 votes |
private void renderNonInstancedMeshes(Scene scene, boolean depthMap, ShaderProgram shader, Matrix4f viewMatrix, Matrix4f lightViewMatrix) { sceneShaderProgram.setUniform("isInstanced", 0); // Render each mesh with the associated game Items Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes(); for (Mesh mesh : mapMeshes.keySet()) { if (!depthMap) { shader.setUniform("material", mesh.getMaterial()); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, shadowMap.getDepthMapTexture().getId()); } mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> { Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem); if (!depthMap) { Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(modelMatrix, viewMatrix); sceneShaderProgram.setUniform("modelViewNonInstancedMatrix", modelViewMatrix); } Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(modelMatrix, lightViewMatrix); sceneShaderProgram.setUniform("modelLightViewNonInstancedMatrix", modelLightViewMatrix); if (gameItem instanceof AnimGameItem) { AnimGameItem animGameItem = (AnimGameItem) gameItem; AnimatedFrame frame = animGameItem.getCurrentFrame(); shader.setUniform("jointsMatrix", frame.getJointMatrices()); } } ); } }