Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cubeTest;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.input.Mouse;
- import org.lwjgl.util.vector.Vector3f;
- public class Camera {
- public Vector3f pos = new Vector3f(50, 50, -50);
- public float pitch, yaw, roll;
- private float speed = 0.3f;
- private final float MAX_UP = 85;
- private final float MAX_DOWN = -85;
- private float RANGE = 10;
- private boolean m;
- public void tick() {
- if (Keyboard.isKeyDown(Keyboard.KEY_F))
- Mouse.setGrabbed(false);
- if (Mouse.isGrabbed()) {
- float dx = Mouse.getDX() * 0.1f * 2;
- float dy = Mouse.getDY() * 0.1f * 2;
- pitch -= dy;
- // if(pitch < 0) pitch = 360;
- // if(pitch > 360) pitch = 360;
- yaw += dx;
- if (pitch >= MAX_UP)
- pitch = MAX_UP;
- if (pitch <= MAX_DOWN)
- pitch = MAX_DOWN;
- // toggle block spawn
- if (Mouse.isButtonDown(0) && m) {
- m = false;
- // x,y,z range
- float xr = RANGE * (float) Math.sin(Math.toRadians(-yaw));
- float zr = RANGE * (float) Math.cos(Math.toRadians(-yaw));
- float yr = RANGE * (float) Math.tan(Math.toRadians(pitch));
- // float xr = (float) (RANGE * Math.cos(Math.toRadians(yaw)) * Math.sin(pitch));
- // float yr = (float) (RANGE * Math.sin(Math.toRadians(yaw)) * Math.sin(pitch));
- // float zr = (float) (RANGE * Math.cos(pitch));
- CubeGame.addCube(new Vector3f(pos.x - xr, pos.y - yr, pos.z
- - zr), 1);
- System.out.println("");
- System.out.println("pitch: " + pitch);
- System.out.println("y-range: " + yr);
- System.out.println("z-range: " + zr);
- System.out.println("x-range: " + xr);
- } else if (!Mouse.isButtonDown(0)) {
- }
- m = true;
- if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
- pos.x += speed * (float) Math.sin(Math.toRadians(yaw));
- pos.z -= speed * (float) Math.cos(Math.toRadians(yaw));
- }
- if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
- pos.x -= speed * (float) Math.sin(Math.toRadians(yaw));
- pos.z += speed * (float) Math.cos(Math.toRadians(yaw));
- }
- if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
- pos.x += speed * (float) Math.sin(Math.toRadians(yaw - 90));
- pos.z -= speed * (float) Math.cos(Math.toRadians(yaw - 90));
- }
- if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
- pos.x += speed * (float) Math.sin(Math.toRadians(yaw + 90));
- pos.z -= speed * (float) Math.cos(Math.toRadians(yaw + 90));
- }
- if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
- pos.y += speed;
- }
- if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
- pos.y -= speed;
- }
- } else if (Mouse.isButtonDown(0)) {
- Mouse.setGrabbed(true);
- }
- }
- public Vector3f getPos() {
- return pos;
- }
- public float getPitch() {
- return pitch;
- }
- public float getYaw() {
- return yaw;
- }
- public float getRoll() {
- return roll;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment