public DummyGame() { renderer = new Renderer(); camera = new Camera(); cameraInc = new Vector3f(0.0f, 0.0f, 0.0f); angleInc = 0; lightAngle = 45; }
@Override public void update(float interval, MouseInput mouseInput) { // Update camera based on mouse if (mouseInput.isRightButtonPressed()) { Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); } // Update camera position Vector3f prevPos = new Vector3f(camera.getPosition()); camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); // Check if there has been a collision. If true, set the y position to // the maximum height float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE; if (camera.getPosition().y <= height) { camera.setPosition(prevPos.x, prevPos.y, prevPos.z); } // Update directional light direction, intensity and colour SceneLight sceneLight = scene.getSceneLight(); DirectionalLight directionalLight = sceneLight.getDirectionalLight(); double angRad = Math.toRadians(lightAngle); directionalLight.getDirection().x = (float) Math.sin(angRad); directionalLight.getDirection().y = (float) Math.cos(angRad); }
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; }
@Override public void update(float interval, MouseInput mouseInput) { // Update camera position camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); // Update camera based on mouse if (mouseInput.isRightButtonPressed()) { Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); } }
public void selectGameItem(GameItem[] gameItems, Camera camera) { dir = camera.getViewMatrix().positiveZ(dir).negate(); selectGameItem(gameItems, camera.getPosition(), dir); }
@Override public void update(float interval, MouseInput mouseInput, Window window) { if (mouseInput.isRightButtonPressed()) { // Update camera based on mouse Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); sceneChanged = true; } // Update camera position camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); lightAngle += angleInc; if (lightAngle < 0) { lightAngle = 0; } else if (lightAngle > 180) { lightAngle = 180; } float zValue = (float) Math.cos(Math.toRadians(lightAngle)); float yValue = (float) Math.sin(Math.toRadians(lightAngle)); Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection(); lightDirection.x = 0; lightDirection.y = yValue; lightDirection.z = zValue; lightDirection.normalize(); // Update view matrix camera.updateViewMatrix(); }
public void render(Window window, Camera camera, Scene scene) { clear(); frustumFilter.updateFrustum(window.getProjectionMatrix(), camera.getViewMatrix()); frustumFilter.filter(scene.getGameMeshes()); frustumFilter.filter(scene.getGameInstancedMeshes()); // Render depth map before view ports has been set up renderDepthMap(window, camera, scene); glViewport(0, 0, window.getWidth(), window.getHeight()); // Update projection matrix once per render cycle window.updateProjectionMatrix(); renderScene(window, camera, scene); renderSkyBox(window, camera, scene); renderParticles(window, camera, scene); //renderAxes(camera); renderCrossHair(window); }
public void selectGameItem(GameItem[] gameItems, Camera camera) { dir = camera.getViewMatrix().positiveZ(dir).negate(); selectGameItem(gameItems, camera.getPosition(), dir); }
@Override public void update(float interval, MouseInput mouseInput, Window window) { if (mouseInput.isRightButtonPressed()) { // Update camera based on mouse Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); sceneChanged = true; } // Update camera position camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); lightAngle += angleInc; if (lightAngle < 0) { lightAngle = 0; } else if (lightAngle > 180) { lightAngle = 180; } float zValue = (float) Math.cos(Math.toRadians(lightAngle)); float yValue = (float) Math.sin(Math.toRadians(lightAngle)); Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection(); lightDirection.x = 0; lightDirection.y = yValue; lightDirection.z = zValue; lightDirection.normalize(); // Update view matrix camera.updateViewMatrix(); }
@Override public void update(float interval, MouseInput mouseInput) { // Update camera position camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); // Update camera based on mouse if (mouseInput.isRightButtonPressed()) { Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); } }
public void render(Window window, Camera camera, Scene scene) { clear(); if (window.getOptions().frustumCulling) { frustumFilter.updateFrustum(window.getProjectionMatrix(), camera.getViewMatrix()); frustumFilter.filter(scene.getGameMeshes()); frustumFilter.filter(scene.getGameInstancedMeshes()); } // Render depth map before view ports has been set up renderDepthMap(window, camera, scene); glViewport(0, 0, window.getWidth(), window.getHeight()); // Update projection matrix once per render cycle window.updateProjectionMatrix(); renderScene(window, camera, scene); renderSkyBox(window, camera, scene); renderParticles(window, camera, scene); //renderAxes(camera); renderCrossHair(window); }
@Override public void update(float interval, MouseInput mouseInput) { // Update camera based on mouse if (mouseInput.isRightButtonPressed()) { Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); } // Update camera position Vector3f prevPos = new Vector3f(camera.getPosition()); camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); // Check if there has been a collision. If true, set the y position to // the maximum height float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE; if (camera.getPosition().y <= height) { camera.setPosition(prevPos.x, prevPos.y, prevPos.z); } lightAngle += angleInc; if (lightAngle < 0) { lightAngle = 0; } else if (lightAngle > 180) { lightAngle = 180; } float zValue = (float) Math.cos(Math.toRadians(lightAngle)); float yValue = (float) Math.sin(Math.toRadians(lightAngle)); Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection(); lightDirection.x = 0; lightDirection.y = yValue; lightDirection.z = zValue; lightDirection.normalize(); }
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; }
public DummyGame() { renderer = new Renderer(); camera = new Camera(); cameraInc = new Vector3f(0.0f, 0.0f, 0.0f); angleInc = 0; lightAngle = 45; }
public void selectGameItem(GameItem[] gameItems, Camera camera) { dir = camera.getViewMatrix().positiveZ(dir).negate(); selectGameItem(gameItems, camera.getPosition(), dir); }
@Override public void update(float interval, MouseInput mouseInput, Window window) { if (mouseInput.isRightButtonPressed()) { // Update camera based on mouse Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); sceneChanged = true; } // Update camera position camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); lightAngle += angleInc; if (lightAngle < 0) { lightAngle = 0; } else if (lightAngle > 180) { lightAngle = 180; } float zValue = (float) Math.cos(Math.toRadians(lightAngle)); float yValue = (float) Math.sin(Math.toRadians(lightAngle)); Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection(); lightDirection.x = 0; lightDirection.y = yValue; lightDirection.z = zValue; lightDirection.normalize(); // Update view matrix camera.updateViewMatrix(); }
@Override public void update(float interval, MouseInput mouseInput) { // Update camera position camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); // Update camera based on mouse if (mouseInput.isRightButtonPressed()) { Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); } }
public void render(Window window, Camera camera, Scene scene, boolean sceneChanged) { clear(); if (window.getOptions().frustumCulling) { frustumFilter.updateFrustum(window.getProjectionMatrix(), camera.getViewMatrix()); frustumFilter.filter(scene.getGameMeshes()); frustumFilter.filter(scene.getGameInstancedMeshes()); } // Render depth map before view ports has been set up if (scene.isRenderShadows() && sceneChanged) { shadowRenderer.render(window, scene, camera, transformation, this); } glViewport(0, 0, window.getWidth(), window.getHeight()); // Update projection matrix once per render cycle window.updateProjectionMatrix(); renderScene(window, camera, scene); renderSkyBox(window, camera, scene); renderParticles(window, camera, scene); //renderAxes(camera); //renderCrossHair(window); }
@Override public void update(float interval, MouseInput mouseInput) { // Update camera based on mouse if (mouseInput.isRightButtonPressed()) { Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); } // Update camera position Vector3f prevPos = new Vector3f(camera.getPosition()); camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); // Check if there has been a collision. If true, set the y position to // the maximum height float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE; if (camera.getPosition().y <= height) { camera.setPosition(prevPos.x, prevPos.y, prevPos.z); } lightAngle += angleInc; if (lightAngle < 0) { lightAngle = 0; } else if (lightAngle > 180) { lightAngle = 180; } float zValue = (float) Math.cos(Math.toRadians(lightAngle)); float yValue = (float) Math.sin(Math.toRadians(lightAngle)); Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection(); lightDirection.x = 0; lightDirection.y = yValue; lightDirection.z = zValue; lightDirection.normalize(); }
public Matrix4f updateViewMatrix(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; }