fixing update cameras
This commit is contained in:
@@ -25,7 +25,7 @@ public class FirstPersonCamera extends Camera {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public void update () throws Exception {
|
||||
public void standardKeybindUpdate () throws Exception {
|
||||
|
||||
newMouseX = i.getMouseX();
|
||||
newMouseY = i.getMouseY();
|
||||
@@ -48,13 +48,49 @@ public class FirstPersonCamera extends Camera {
|
||||
if (i.isKeyDown(GLFW.GLFW_KEY_S)) movePosition(0, 0, moveSpeed);
|
||||
if (i.isKeyDown(GLFW.GLFW_KEY_SPACE)) movePosition(0, moveSpeed, 0);
|
||||
if (i.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)) movePosition(0, -moveSpeed, 0);
|
||||
if (i.keyPress(GLFW.GLFW_KEY_R)) moveSpeed = 4*moveSpeed;
|
||||
if (i.keyReleased(GLFW.GLFW_KEY_R)) moveSpeed = moveSpeed / 4;
|
||||
if (i.keyPress(GLFW.GLFW_KEY_R)) moveSpeed = 3*moveSpeed;
|
||||
if (i.keyReleased(GLFW.GLFW_KEY_R)) moveSpeed = moveSpeed / 3;
|
||||
|
||||
setRotation(cameraRot);
|
||||
setPosition(cameraPos);
|
||||
|
||||
i.reset();
|
||||
}
|
||||
|
||||
public void moveForward() {
|
||||
movePosition(0, 0, -moveSpeed);
|
||||
}
|
||||
public void moveBackward() {
|
||||
movePosition(0, 0, moveSpeed);
|
||||
}
|
||||
public void moveLeft() {
|
||||
movePosition(-moveSpeed, 0, 0);
|
||||
}
|
||||
public void moveRight() {
|
||||
movePosition(moveSpeed, 0, 0);
|
||||
}
|
||||
public void moveUp() {
|
||||
movePosition(0, moveSpeed, 0);
|
||||
}
|
||||
public void moveDown() {
|
||||
movePosition(0, -moveSpeed, 0);
|
||||
}
|
||||
|
||||
public float getMoveSpeed() {
|
||||
return moveSpeed;
|
||||
}
|
||||
|
||||
public void setMoveSpeed(float moveSpeed) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
}
|
||||
|
||||
public void rotateCamera(float dx, float dy) throws Exception {
|
||||
|
||||
Vector3f cameraRot = getRotation();
|
||||
cameraRot = Vector3f.add(cameraRot, new Vector3f(dy*sensitivity, dx*sensitivity, 0));
|
||||
|
||||
|
||||
setRotation(cameraRot);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package org.hl.engine.objects;
|
||||
|
||||
import org.hl.engine.graphics.Material;
|
||||
import org.hl.engine.graphics.Mesh;
|
||||
import org.hl.engine.graphics.Texture;
|
||||
import org.hl.engine.graphics.Vertex;
|
||||
import org.hl.engine.graphics.*;
|
||||
import org.hl.engine.math.lalg.Vector2f;
|
||||
import org.hl.engine.math.lalg.Vector3f;
|
||||
import org.hl.engine.objects.yloaders.YMesh;
|
||||
@@ -32,10 +29,10 @@ public class GameObject {
|
||||
Yaml yaml = new Yaml();
|
||||
FileInputStream inputStream = new FileInputStream(meshFileName);
|
||||
YMesh yMesh = yaml.loadAs(inputStream, YMesh.class);
|
||||
Integer[] cull = yMesh.getCull().toArray(new Integer[yMesh.getCull().size()]);
|
||||
Integer[] cull = yMesh.getCull().toArray(new Integer[0]);
|
||||
String type = yMesh.getType();
|
||||
String texture = yMesh.getTexture();
|
||||
YPoint[] vertices = yMesh.getVertices().toArray(new YPoint[yMesh.getVertices().size()]);
|
||||
YPoint[] vertices = yMesh.getVertices().toArray(new YPoint[0]);
|
||||
Vertex[] meshFormat = new Vertex[vertices.length];
|
||||
|
||||
for (YPoint vertex : vertices) {
|
||||
@@ -69,6 +66,12 @@ public class GameObject {
|
||||
this.rotation = rotation;
|
||||
|
||||
}
|
||||
public GameObject(String meshFileName, String texturePath, Vector3f position, Vector3f rotation, Vector3f scale) throws Exception {
|
||||
this.mesh = ModelLoader.loadModel(meshFileName, texturePath);
|
||||
this.position = position;
|
||||
this.scale = scale;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
|
||||
public void create() {
|
||||
|
||||
@@ -43,9 +43,7 @@ public class ThirdPersonCamera extends Camera {
|
||||
}
|
||||
|
||||
|
||||
public void update() throws Exception {
|
||||
|
||||
near = 0.1f;
|
||||
public void standardKeybindUpdate() throws Exception {
|
||||
|
||||
newMouseX = i.getMouseX();
|
||||
newMouseY = i.getMouseY();
|
||||
@@ -63,9 +61,13 @@ public class ThirdPersonCamera extends Camera {
|
||||
if (i.isButtonDown(GLFW.GLFW_MOUSE_BUTTON_RIGHT) && zoomEnabled) {
|
||||
if (distance > 0) {
|
||||
distance += dy * sensitivity;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
distance = near;
|
||||
}
|
||||
if (distance > far) {
|
||||
distance = far;
|
||||
}
|
||||
}
|
||||
} else if (clickToMove) {
|
||||
|
||||
@@ -79,6 +81,9 @@ public class ThirdPersonCamera extends Camera {
|
||||
} else {
|
||||
distance = near;
|
||||
}
|
||||
if (distance > far) {
|
||||
distance = far;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (clickToZoom) {
|
||||
@@ -92,6 +97,9 @@ public class ThirdPersonCamera extends Camera {
|
||||
} else {
|
||||
distance = near;
|
||||
}
|
||||
if (distance > far) {
|
||||
distance = far;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -104,6 +112,9 @@ public class ThirdPersonCamera extends Camera {
|
||||
} else {
|
||||
distance = near;
|
||||
}
|
||||
if (distance > far) {
|
||||
distance = far;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -123,6 +134,40 @@ public class ThirdPersonCamera extends Camera {
|
||||
|
||||
i.reset();
|
||||
|
||||
}
|
||||
public void movePosition (float dy, float dx) throws Exception {
|
||||
vertAngle -= dy * sensitivity;
|
||||
horizAngle += dx * sensitivity;
|
||||
|
||||
float horizDistance = (float) (distance * Math.cos(Math.toRadians(vertAngle)));
|
||||
float vertDistance = (float) (distance * Math.sin(Math.toRadians(vertAngle)));
|
||||
|
||||
float xOffset = (float) (horizDistance * Math.sin(Math.toRadians(-horizAngle)));
|
||||
float zOffset = (float) (horizDistance * Math.cos(Math.toRadians(-horizAngle)));
|
||||
|
||||
setPosition(new Vector3f(object.getPosition().getX() + xOffset, object.getPosition().getY() - vertDistance, object.getPosition().getZ() + zOffset));
|
||||
setRotation(new Vector3f(-vertAngle, horizAngle,0));
|
||||
}
|
||||
public void zoom (float dy) throws Exception {
|
||||
if (zoomEnabled) {
|
||||
if (distance > 0) {
|
||||
distance += dy * sensitivity;
|
||||
} else {
|
||||
distance = near;
|
||||
}
|
||||
if (distance > far) {
|
||||
distance = far;
|
||||
}
|
||||
}
|
||||
|
||||
float horizDistance = (float) (distance * Math.cos(Math.toRadians(vertAngle)));
|
||||
float vertDistance = (float) (distance * Math.sin(Math.toRadians(vertAngle)));
|
||||
|
||||
float xOffset = (float) (horizDistance * Math.sin(Math.toRadians(-horizAngle)));
|
||||
float zOffset = (float) (horizDistance * Math.cos(Math.toRadians(-horizAngle)));
|
||||
|
||||
setPosition(new Vector3f(object.getPosition().getX() + xOffset, object.getPosition().getY() - vertDistance, object.getPosition().getZ() + zOffset));
|
||||
setRotation(new Vector3f(-vertAngle, horizAngle,0));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user