本文整理了Java中org.lwjglb.engine.graph.Transformation
类的一些代码示例,展示了Transformation
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transformation
类的具体详情如下:
包路径:org.lwjglb.engine.graph.Transformation
类名称:Transformation
暂无
代码示例来源:origin: lwjglgamedev/lwjglbook
public Renderer() {
transformation = new Transformation();
specularPower = 10f;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public Matrix4f buildModelLightViewMatrix(GameItem gameItem, Matrix4f lightViewMatrix) {
return buildModelViewMatrix(buildModelMatrix(gameItem), lightViewMatrix);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void updateLightViewMatrix(Vector3f lightDirection, Vector3f lightPosition) {
float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z));
float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x));
float lightAngleZ = 0;
Transformation.updateGenericViewMatrix(lightPosition, new Vector3f(lightAngleX, lightAngleY, lightAngleZ), lightViewMatrix);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f orthoProjMatrix = transformation.getOrthoProjectionMatrix();
sceneShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Matrix4f lightViewMatrix = transformation.getLightViewMatrix();
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
sceneShaderProgram.setUniform("shadowMap", 2);
// 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());
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, shadowMap.getDepthMapTexture().getId());
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix);
sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(gameItem, lightViewMatrix);
sceneShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix);
}
);
}
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderSkyBox(Window window, Camera camera, Scene scene) {
skyBoxShaderProgram.bind();
skyBoxShaderProgram.setUniform("texture_sampler", 0);
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
skyBoxShaderProgram.setUniform("projectionMatrix", projectionMatrix);
SkyBox skyBox = scene.getSkyBox();
Matrix4f viewMatrix = transformation.getViewMatrix();
viewMatrix.m30(0);
viewMatrix.m31(0);
viewMatrix.m32(0);
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(skyBox, viewMatrix);
skyBoxShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
skyBoxShaderProgram.setUniform("ambientLight", scene.getSceneLight().getSkyBoxLight());
scene.getSkyBox().getMesh().render();
skyBoxShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f orthoProjMatrix = transformation.getOrthoProjectionMatrix();
sceneShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Matrix4f lightViewMatrix = transformation.getLightViewMatrix();
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
sceneShaderProgram.setUniform("shadowMap", 2);
sceneShaderProgram.setUniform("renderShadow", scene.isRenderShadows() ? 1 : 0);
renderNonInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
renderInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
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(MATRIX_SIZE_FLOATS * i, modelViewBuffer);
}
Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(modelMatrix, lightViewMatrix);
modelLightViewMatrix.get(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);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void render(Window window, Camera camera, Scene scene, IHud hud) {
clear();
// Render depth map before view ports has been set up
renderDepthMap(window, camera, scene);
glViewport(0, 0, window.getWidth(), window.getHeight());
// Update projection and view atrices once per render cycle
transformation.updateProjectionMatrix(FOV, window.getWidth(), window.getHeight(), Z_NEAR, Z_FAR);
transformation.updateViewMatrix(camera);
renderScene(window, camera, scene);
renderSkyBox(window, camera, scene);
renderHud(window, hud);
//renderAxes(camera);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f orthoProjMatrix = transformation.getOrthoProjectionMatrix();
sceneShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Matrix4f lightViewMatrix = transformation.getLightViewMatrix();
Matrix4f viewMatrix = camera.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
sceneShaderProgram.setUniform("shadowMap", 2);
sceneShaderProgram.setUniform("renderShadow", scene.isRenderShadows() ? 1 : 0);
renderNonInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
renderInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderDepthMap(Window window, Camera camera, Scene scene) {
if (scene.isRenderShadows()) {
// Setup view port to match the texture size
glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO());
glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT);
glClear(GL_DEPTH_BUFFER_BIT);
depthShaderProgram.bind();
DirectionalLight light = scene.getSceneLight().getDirectionalLight();
Vector3f lightDirection = light.getDirection();
float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z));
float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x));
float lightAngleZ = 0;
Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ));
DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords();
Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far);
depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix);
renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix);
// Unbind
depthShaderProgram.unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderSkyBox(Window window, Camera camera, Scene scene) {
skyBoxShaderProgram.bind();
skyBoxShaderProgram.setUniform("texture_sampler", 0);
// Update projection Matrix
Matrix4f projectionMatrix = transformation.getProjectionMatrix(FOV, window.getWidth(), window.getHeight(), Z_NEAR, Z_FAR);
skyBoxShaderProgram.setUniform("projectionMatrix", projectionMatrix);
SkyBox skyBox = scene.getSkyBox();
Matrix4f viewMatrix = transformation.getViewMatrix(camera);
viewMatrix.m30(0);
viewMatrix.m31(0);
viewMatrix.m32(0);
Matrix4f modelViewMatrix = transformation.getModelViewMatrix(skyBox, viewMatrix);
skyBoxShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
skyBoxShaderProgram.setUniform("ambientLight", scene.getSceneLight().getAmbientLight());
scene.getSkyBox().getMesh().render();
skyBoxShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderHud(Window window, IHud hud) {
hudShaderProgram.bind();
Matrix4f ortho = transformation.getOrthoProjectionMatrix(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();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = window.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f orthoProjMatrix = transformation.getOrthoProjectionMatrix();
sceneShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Matrix4f lightViewMatrix = transformation.getLightViewMatrix();
Matrix4f viewMatrix = camera.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
sceneShaderProgram.setUniform("shadowMap", 2);
sceneShaderProgram.setUniform("renderShadow", scene.isRenderShadows() ? 1 : 0);
renderNonInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
renderInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderDepthMap(Window window, Camera camera, Scene scene) {
// Setup view port to match the texture size
glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO());
glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT);
glClear(GL_DEPTH_BUFFER_BIT);
depthShaderProgram.bind();
DirectionalLight light = scene.getSceneLight().getDirectionalLight();
Vector3f lightDirection = light.getDirection();
float lightAngleX = (float)Math.toDegrees(Math.acos(lightDirection.z));
float lightAngleY = (float)Math.toDegrees(Math.asin(lightDirection.x));
float lightAngleZ = 0;
Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ));
DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords();
Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far);
depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelLightViewMatrix = transformation.buildModelViewMatrix(gameItem, lightViewMatrix);
depthShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix);
}
);
}
// Unbind
depthShaderProgram.unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderHud(Window window, IHud hud) {
hudShaderProgram.bind();
Matrix4f ortho = transformation.getOrthoProjectionMatrix(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.getOrtoProjModelMatrix(gameItem, ortho);
hudShaderProgram.setUniform("projModelMatrix", projModelMatrix);
hudShaderProgram.setUniform("colour", gameItem.getMesh().getMaterial().getAmbientColour());
// Render the mesh for this HUD item
mesh.render();
}
hudShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public Matrix4f buildModelViewMatrix(GameItem gameItem, Matrix4f viewMatrix) {
Vector3f rotation = gameItem.getRotation();
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());
return buildModelViewMatrix(modelMatrix, viewMatrix);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f orthoProjMatrix = transformation.getOrthoProjectionMatrix();
sceneShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Matrix4f lightViewMatrix = transformation.getLightViewMatrix();
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
sceneShaderProgram.setUniform("shadowMap", 2);
// 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());
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, shadowMap.getDepthMapTexture().getId());
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix);
sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(gameItem, lightViewMatrix);
sceneShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix);
}
);
}
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderSkyBox(Window window, Camera camera, Scene scene) {
skyBoxShaderProgram.bind();
skyBoxShaderProgram.setUniform("texture_sampler", 0);
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
skyBoxShaderProgram.setUniform("projectionMatrix", projectionMatrix);
SkyBox skyBox = scene.getSkyBox();
Matrix4f viewMatrix = transformation.getViewMatrix();
viewMatrix.m30(0);
viewMatrix.m31(0);
viewMatrix.m32(0);
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(skyBox, viewMatrix);
skyBoxShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
skyBoxShaderProgram.setUniform("ambientLight", scene.getSceneLight().getAmbientLight());
scene.getSkyBox().getMesh().render();
skyBoxShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f orthoProjMatrix = transformation.getOrthoProjectionMatrix();
sceneShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Matrix4f lightViewMatrix = transformation.getLightViewMatrix();
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
sceneShaderProgram.setUniform("shadowMap", 2);
sceneShaderProgram.setUniform("renderShadow", scene.isRenderShadows() ? 1 : 0);
renderNonInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
renderInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
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());
}
}
);
}
}
内容来源于网络,如有侵权,请联系作者删除!