LWJGL 3 Camera issues











up vote
0
down vote

favorite












The problem's I'm experiencing started when I created a 3rd person camera in my project. I've used LWJGL 2 with no issues, so I followed the same path with LWJGL 3 and adjusted for the changes between the versions. The issues I'm experiencing are:




  1. When rotating around my object, the rotation is canted and goes extremely fast. I have to drag my mouse off the screen to rotate the opposite way.

  2. When rotating, my model is not within view of the camera(however the model is still the center point it rotates around).

  3. When I zoom in or out, it zooms continuously. non-stop. (pretty sure I can fix this issue myself with some tweeks).


I think some of these issues are because of the differences in the versions. as an example, in LWJGL 2 I would use Mouse.getDWheel(); , for LWJGL 3 however, I used GLFW's scrollCallback to retrieve the Y scroll value. I noticed that it returns 1.0-5.0(It may go higher, but 5 is the highest I've seen) when scrolling up, and the negative values going down.



The following is my camera class:



package entities;

import org.joml.Vector3f;
import org.lwjgl.glfw.GLFW;

import input.Input;

public class Camera {

private float distanceFromPlayer = 50;
private float angleAroundPlayer = 0;

private Vector3f position = new Vector3f(0,0,0);
private float pitch = 20;
private float yaw;
private float roll;

private Player player;

public Camera(Player player) {

this.player = player;

}

public void move(Input input) {
calculateZoom(input);
calculatePitch(input);
calculateAngleAroundPlayer(input);
float horizontalDistance = calculateHorizontalDistance();
float verticalDistance = calculateVerticalDistance();
calculateCameraPosition(horizontalDistance, verticalDistance);
}

public Vector3f getPosition() {
return position;
}

public float getPitch() {
return pitch;
}

public float getYaw() {
return yaw;
}

public float getRoll() {
return roll;
}

private void calculateCameraPosition(float horizDistance, float verticDistance) {
float theta = player.getRotY() + angleAroundPlayer;
float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
position.x = player.getPosition().x - offsetX;
position.z = player.getPosition().z - offsetZ;
position.y = player.getPosition().y + verticDistance;
this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
}

private float calculateHorizontalDistance() {
return (float) (distanceFromPlayer * Math.cos(Math.toRadians(pitch)));
}

private float calculateVerticalDistance() {
return (float) (distanceFromPlayer * Math.sin(Math.toRadians(pitch)));
}

private void calculateZoom(Input input) {
float zoomLevel = input.getMouseWheelVelocity() * 0.1f;
distanceFromPlayer -= zoomLevel;

}

private void calculatePitch(Input input) {
if(input.isMouseDown(GLFW.GLFW_MOUSE_BUTTON_1)) {
//possible issue
float pitchChange = (float) (input.getMouseY() * 0.01f);
pitch -= pitchChange;
}
}

private void calculateAngleAroundPlayer(Input input) {
if(input.isMouseDown(GLFW.GLFW_MOUSE_BUTTON_2)) {
float angleChange = (float) (input.getMouseX() * 0.01f);
angleAroundPlayer -= angleChange;
}
}
}


This is my input class, where I get my mouse wheel velocity:



package input;

import java.nio.DoubleBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;

import renderEngine.Window;

public class Input {


private long window;
private boolean keys = new boolean[GLFW.GLFW_KEY_LAST];
private boolean mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
private float mouseWheelVelocity = 0;


public Input(Window win) {
super();
this.window = win.getID();
}

public void init() {

GLFW.glfwSetScrollCallback(window, (long win, double dx, double dy) -> {
System.out.println(dy);
setMouseWheelVelocity((float) dy);


});
}


public boolean isKeyDown(int keyCode) {

return GLFW.glfwGetKey(window, keyCode) == 1;

}

public boolean isMouseDown(int mouseButton) {

return GLFW.glfwGetMouseButton(window, mouseButton) == 1;

}

public boolean isKeyPressed(int keyCode) {

return isKeyDown(keyCode) && !keys[keyCode];
}

public boolean isKeyReleased(int keyCode) {

return !isKeyDown(keyCode) && keys[keyCode];

}

public boolean isMousePressed(int mouseButton) {

return isMouseDown(mouseButton) && !mouseButtons[mouseButton];

}

public boolean isMouseReleased(int mouseButton) {

return !isMouseDown(mouseButton) && mouseButtons[mouseButton];

}

public double getMouseX() {
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
GLFW.glfwGetCursorPos(window, buffer, null);
return buffer.get(0);
}

public double getMouseY() {
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
GLFW.glfwGetCursorPos(window, null, buffer);
return buffer.get(0);

}

public float getMouseWheelVelocity() {
return mouseWheelVelocity;
}

public void setMouseWheelVelocity(float mouseWheelVelocity) {
this.mouseWheelVelocity = mouseWheelVelocity;
}

public void updateInput() {
for (int i = 0; i < GLFW.GLFW_KEY_LAST; i++) {
keys[i] = isKeyDown(i);
}
for (int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++) {
mouseButtons[i] = isMouseDown(i);
}
}

public void currentKeyBind() {
if(isKeyPressed(GLFW.GLFW_KEY_Q)) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
}
if(isKeyReleased(GLFW.GLFW_KEY_Q)) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
}
}

}


Just some input on what could be wrong, and a direction I should head to fix it would be great.
I've looked around at tutorials and the documentation for glfw and LWJGL for answers, I can't seem to find one without completely rebuilding most of my project.










share|improve this question




















  • 1




    The problem is very likely where you already noted //possible issue. You are constantly adding the current mouse coordinate to your angles, everytime calculatePitch and calculateAngleAroundPlayer is called. So if the mouse x coordinate is, say, 1600 you constantly decrement angleAroundPlayer by 16.0. What you likely wanted to do (if you used Mouse.getDX/DY() before in LWJGL 2) is to store the old mouse coordinates and compute the delta between old and new.
    – httpdigest
    Nov 19 at 9:26








  • 1




    As soon as I read your comment, I knew you were right. Thank you!
    – Lane will
    Nov 20 at 5:10















up vote
0
down vote

favorite












The problem's I'm experiencing started when I created a 3rd person camera in my project. I've used LWJGL 2 with no issues, so I followed the same path with LWJGL 3 and adjusted for the changes between the versions. The issues I'm experiencing are:




  1. When rotating around my object, the rotation is canted and goes extremely fast. I have to drag my mouse off the screen to rotate the opposite way.

  2. When rotating, my model is not within view of the camera(however the model is still the center point it rotates around).

  3. When I zoom in or out, it zooms continuously. non-stop. (pretty sure I can fix this issue myself with some tweeks).


I think some of these issues are because of the differences in the versions. as an example, in LWJGL 2 I would use Mouse.getDWheel(); , for LWJGL 3 however, I used GLFW's scrollCallback to retrieve the Y scroll value. I noticed that it returns 1.0-5.0(It may go higher, but 5 is the highest I've seen) when scrolling up, and the negative values going down.



The following is my camera class:



package entities;

import org.joml.Vector3f;
import org.lwjgl.glfw.GLFW;

import input.Input;

public class Camera {

private float distanceFromPlayer = 50;
private float angleAroundPlayer = 0;

private Vector3f position = new Vector3f(0,0,0);
private float pitch = 20;
private float yaw;
private float roll;

private Player player;

public Camera(Player player) {

this.player = player;

}

public void move(Input input) {
calculateZoom(input);
calculatePitch(input);
calculateAngleAroundPlayer(input);
float horizontalDistance = calculateHorizontalDistance();
float verticalDistance = calculateVerticalDistance();
calculateCameraPosition(horizontalDistance, verticalDistance);
}

public Vector3f getPosition() {
return position;
}

public float getPitch() {
return pitch;
}

public float getYaw() {
return yaw;
}

public float getRoll() {
return roll;
}

private void calculateCameraPosition(float horizDistance, float verticDistance) {
float theta = player.getRotY() + angleAroundPlayer;
float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
position.x = player.getPosition().x - offsetX;
position.z = player.getPosition().z - offsetZ;
position.y = player.getPosition().y + verticDistance;
this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
}

private float calculateHorizontalDistance() {
return (float) (distanceFromPlayer * Math.cos(Math.toRadians(pitch)));
}

private float calculateVerticalDistance() {
return (float) (distanceFromPlayer * Math.sin(Math.toRadians(pitch)));
}

private void calculateZoom(Input input) {
float zoomLevel = input.getMouseWheelVelocity() * 0.1f;
distanceFromPlayer -= zoomLevel;

}

private void calculatePitch(Input input) {
if(input.isMouseDown(GLFW.GLFW_MOUSE_BUTTON_1)) {
//possible issue
float pitchChange = (float) (input.getMouseY() * 0.01f);
pitch -= pitchChange;
}
}

private void calculateAngleAroundPlayer(Input input) {
if(input.isMouseDown(GLFW.GLFW_MOUSE_BUTTON_2)) {
float angleChange = (float) (input.getMouseX() * 0.01f);
angleAroundPlayer -= angleChange;
}
}
}


This is my input class, where I get my mouse wheel velocity:



package input;

import java.nio.DoubleBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;

import renderEngine.Window;

public class Input {


private long window;
private boolean keys = new boolean[GLFW.GLFW_KEY_LAST];
private boolean mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
private float mouseWheelVelocity = 0;


public Input(Window win) {
super();
this.window = win.getID();
}

public void init() {

GLFW.glfwSetScrollCallback(window, (long win, double dx, double dy) -> {
System.out.println(dy);
setMouseWheelVelocity((float) dy);


});
}


public boolean isKeyDown(int keyCode) {

return GLFW.glfwGetKey(window, keyCode) == 1;

}

public boolean isMouseDown(int mouseButton) {

return GLFW.glfwGetMouseButton(window, mouseButton) == 1;

}

public boolean isKeyPressed(int keyCode) {

return isKeyDown(keyCode) && !keys[keyCode];
}

public boolean isKeyReleased(int keyCode) {

return !isKeyDown(keyCode) && keys[keyCode];

}

public boolean isMousePressed(int mouseButton) {

return isMouseDown(mouseButton) && !mouseButtons[mouseButton];

}

public boolean isMouseReleased(int mouseButton) {

return !isMouseDown(mouseButton) && mouseButtons[mouseButton];

}

public double getMouseX() {
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
GLFW.glfwGetCursorPos(window, buffer, null);
return buffer.get(0);
}

public double getMouseY() {
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
GLFW.glfwGetCursorPos(window, null, buffer);
return buffer.get(0);

}

public float getMouseWheelVelocity() {
return mouseWheelVelocity;
}

public void setMouseWheelVelocity(float mouseWheelVelocity) {
this.mouseWheelVelocity = mouseWheelVelocity;
}

public void updateInput() {
for (int i = 0; i < GLFW.GLFW_KEY_LAST; i++) {
keys[i] = isKeyDown(i);
}
for (int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++) {
mouseButtons[i] = isMouseDown(i);
}
}

public void currentKeyBind() {
if(isKeyPressed(GLFW.GLFW_KEY_Q)) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
}
if(isKeyReleased(GLFW.GLFW_KEY_Q)) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
}
}

}


Just some input on what could be wrong, and a direction I should head to fix it would be great.
I've looked around at tutorials and the documentation for glfw and LWJGL for answers, I can't seem to find one without completely rebuilding most of my project.










share|improve this question




















  • 1




    The problem is very likely where you already noted //possible issue. You are constantly adding the current mouse coordinate to your angles, everytime calculatePitch and calculateAngleAroundPlayer is called. So if the mouse x coordinate is, say, 1600 you constantly decrement angleAroundPlayer by 16.0. What you likely wanted to do (if you used Mouse.getDX/DY() before in LWJGL 2) is to store the old mouse coordinates and compute the delta between old and new.
    – httpdigest
    Nov 19 at 9:26








  • 1




    As soon as I read your comment, I knew you were right. Thank you!
    – Lane will
    Nov 20 at 5:10













up vote
0
down vote

favorite









up vote
0
down vote

favorite











The problem's I'm experiencing started when I created a 3rd person camera in my project. I've used LWJGL 2 with no issues, so I followed the same path with LWJGL 3 and adjusted for the changes between the versions. The issues I'm experiencing are:




  1. When rotating around my object, the rotation is canted and goes extremely fast. I have to drag my mouse off the screen to rotate the opposite way.

  2. When rotating, my model is not within view of the camera(however the model is still the center point it rotates around).

  3. When I zoom in or out, it zooms continuously. non-stop. (pretty sure I can fix this issue myself with some tweeks).


I think some of these issues are because of the differences in the versions. as an example, in LWJGL 2 I would use Mouse.getDWheel(); , for LWJGL 3 however, I used GLFW's scrollCallback to retrieve the Y scroll value. I noticed that it returns 1.0-5.0(It may go higher, but 5 is the highest I've seen) when scrolling up, and the negative values going down.



The following is my camera class:



package entities;

import org.joml.Vector3f;
import org.lwjgl.glfw.GLFW;

import input.Input;

public class Camera {

private float distanceFromPlayer = 50;
private float angleAroundPlayer = 0;

private Vector3f position = new Vector3f(0,0,0);
private float pitch = 20;
private float yaw;
private float roll;

private Player player;

public Camera(Player player) {

this.player = player;

}

public void move(Input input) {
calculateZoom(input);
calculatePitch(input);
calculateAngleAroundPlayer(input);
float horizontalDistance = calculateHorizontalDistance();
float verticalDistance = calculateVerticalDistance();
calculateCameraPosition(horizontalDistance, verticalDistance);
}

public Vector3f getPosition() {
return position;
}

public float getPitch() {
return pitch;
}

public float getYaw() {
return yaw;
}

public float getRoll() {
return roll;
}

private void calculateCameraPosition(float horizDistance, float verticDistance) {
float theta = player.getRotY() + angleAroundPlayer;
float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
position.x = player.getPosition().x - offsetX;
position.z = player.getPosition().z - offsetZ;
position.y = player.getPosition().y + verticDistance;
this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
}

private float calculateHorizontalDistance() {
return (float) (distanceFromPlayer * Math.cos(Math.toRadians(pitch)));
}

private float calculateVerticalDistance() {
return (float) (distanceFromPlayer * Math.sin(Math.toRadians(pitch)));
}

private void calculateZoom(Input input) {
float zoomLevel = input.getMouseWheelVelocity() * 0.1f;
distanceFromPlayer -= zoomLevel;

}

private void calculatePitch(Input input) {
if(input.isMouseDown(GLFW.GLFW_MOUSE_BUTTON_1)) {
//possible issue
float pitchChange = (float) (input.getMouseY() * 0.01f);
pitch -= pitchChange;
}
}

private void calculateAngleAroundPlayer(Input input) {
if(input.isMouseDown(GLFW.GLFW_MOUSE_BUTTON_2)) {
float angleChange = (float) (input.getMouseX() * 0.01f);
angleAroundPlayer -= angleChange;
}
}
}


This is my input class, where I get my mouse wheel velocity:



package input;

import java.nio.DoubleBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;

import renderEngine.Window;

public class Input {


private long window;
private boolean keys = new boolean[GLFW.GLFW_KEY_LAST];
private boolean mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
private float mouseWheelVelocity = 0;


public Input(Window win) {
super();
this.window = win.getID();
}

public void init() {

GLFW.glfwSetScrollCallback(window, (long win, double dx, double dy) -> {
System.out.println(dy);
setMouseWheelVelocity((float) dy);


});
}


public boolean isKeyDown(int keyCode) {

return GLFW.glfwGetKey(window, keyCode) == 1;

}

public boolean isMouseDown(int mouseButton) {

return GLFW.glfwGetMouseButton(window, mouseButton) == 1;

}

public boolean isKeyPressed(int keyCode) {

return isKeyDown(keyCode) && !keys[keyCode];
}

public boolean isKeyReleased(int keyCode) {

return !isKeyDown(keyCode) && keys[keyCode];

}

public boolean isMousePressed(int mouseButton) {

return isMouseDown(mouseButton) && !mouseButtons[mouseButton];

}

public boolean isMouseReleased(int mouseButton) {

return !isMouseDown(mouseButton) && mouseButtons[mouseButton];

}

public double getMouseX() {
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
GLFW.glfwGetCursorPos(window, buffer, null);
return buffer.get(0);
}

public double getMouseY() {
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
GLFW.glfwGetCursorPos(window, null, buffer);
return buffer.get(0);

}

public float getMouseWheelVelocity() {
return mouseWheelVelocity;
}

public void setMouseWheelVelocity(float mouseWheelVelocity) {
this.mouseWheelVelocity = mouseWheelVelocity;
}

public void updateInput() {
for (int i = 0; i < GLFW.GLFW_KEY_LAST; i++) {
keys[i] = isKeyDown(i);
}
for (int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++) {
mouseButtons[i] = isMouseDown(i);
}
}

public void currentKeyBind() {
if(isKeyPressed(GLFW.GLFW_KEY_Q)) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
}
if(isKeyReleased(GLFW.GLFW_KEY_Q)) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
}
}

}


Just some input on what could be wrong, and a direction I should head to fix it would be great.
I've looked around at tutorials and the documentation for glfw and LWJGL for answers, I can't seem to find one without completely rebuilding most of my project.










share|improve this question















The problem's I'm experiencing started when I created a 3rd person camera in my project. I've used LWJGL 2 with no issues, so I followed the same path with LWJGL 3 and adjusted for the changes between the versions. The issues I'm experiencing are:




  1. When rotating around my object, the rotation is canted and goes extremely fast. I have to drag my mouse off the screen to rotate the opposite way.

  2. When rotating, my model is not within view of the camera(however the model is still the center point it rotates around).

  3. When I zoom in or out, it zooms continuously. non-stop. (pretty sure I can fix this issue myself with some tweeks).


I think some of these issues are because of the differences in the versions. as an example, in LWJGL 2 I would use Mouse.getDWheel(); , for LWJGL 3 however, I used GLFW's scrollCallback to retrieve the Y scroll value. I noticed that it returns 1.0-5.0(It may go higher, but 5 is the highest I've seen) when scrolling up, and the negative values going down.



The following is my camera class:



package entities;

import org.joml.Vector3f;
import org.lwjgl.glfw.GLFW;

import input.Input;

public class Camera {

private float distanceFromPlayer = 50;
private float angleAroundPlayer = 0;

private Vector3f position = new Vector3f(0,0,0);
private float pitch = 20;
private float yaw;
private float roll;

private Player player;

public Camera(Player player) {

this.player = player;

}

public void move(Input input) {
calculateZoom(input);
calculatePitch(input);
calculateAngleAroundPlayer(input);
float horizontalDistance = calculateHorizontalDistance();
float verticalDistance = calculateVerticalDistance();
calculateCameraPosition(horizontalDistance, verticalDistance);
}

public Vector3f getPosition() {
return position;
}

public float getPitch() {
return pitch;
}

public float getYaw() {
return yaw;
}

public float getRoll() {
return roll;
}

private void calculateCameraPosition(float horizDistance, float verticDistance) {
float theta = player.getRotY() + angleAroundPlayer;
float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
position.x = player.getPosition().x - offsetX;
position.z = player.getPosition().z - offsetZ;
position.y = player.getPosition().y + verticDistance;
this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
}

private float calculateHorizontalDistance() {
return (float) (distanceFromPlayer * Math.cos(Math.toRadians(pitch)));
}

private float calculateVerticalDistance() {
return (float) (distanceFromPlayer * Math.sin(Math.toRadians(pitch)));
}

private void calculateZoom(Input input) {
float zoomLevel = input.getMouseWheelVelocity() * 0.1f;
distanceFromPlayer -= zoomLevel;

}

private void calculatePitch(Input input) {
if(input.isMouseDown(GLFW.GLFW_MOUSE_BUTTON_1)) {
//possible issue
float pitchChange = (float) (input.getMouseY() * 0.01f);
pitch -= pitchChange;
}
}

private void calculateAngleAroundPlayer(Input input) {
if(input.isMouseDown(GLFW.GLFW_MOUSE_BUTTON_2)) {
float angleChange = (float) (input.getMouseX() * 0.01f);
angleAroundPlayer -= angleChange;
}
}
}


This is my input class, where I get my mouse wheel velocity:



package input;

import java.nio.DoubleBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;

import renderEngine.Window;

public class Input {


private long window;
private boolean keys = new boolean[GLFW.GLFW_KEY_LAST];
private boolean mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
private float mouseWheelVelocity = 0;


public Input(Window win) {
super();
this.window = win.getID();
}

public void init() {

GLFW.glfwSetScrollCallback(window, (long win, double dx, double dy) -> {
System.out.println(dy);
setMouseWheelVelocity((float) dy);


});
}


public boolean isKeyDown(int keyCode) {

return GLFW.glfwGetKey(window, keyCode) == 1;

}

public boolean isMouseDown(int mouseButton) {

return GLFW.glfwGetMouseButton(window, mouseButton) == 1;

}

public boolean isKeyPressed(int keyCode) {

return isKeyDown(keyCode) && !keys[keyCode];
}

public boolean isKeyReleased(int keyCode) {

return !isKeyDown(keyCode) && keys[keyCode];

}

public boolean isMousePressed(int mouseButton) {

return isMouseDown(mouseButton) && !mouseButtons[mouseButton];

}

public boolean isMouseReleased(int mouseButton) {

return !isMouseDown(mouseButton) && mouseButtons[mouseButton];

}

public double getMouseX() {
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
GLFW.glfwGetCursorPos(window, buffer, null);
return buffer.get(0);
}

public double getMouseY() {
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
GLFW.glfwGetCursorPos(window, null, buffer);
return buffer.get(0);

}

public float getMouseWheelVelocity() {
return mouseWheelVelocity;
}

public void setMouseWheelVelocity(float mouseWheelVelocity) {
this.mouseWheelVelocity = mouseWheelVelocity;
}

public void updateInput() {
for (int i = 0; i < GLFW.GLFW_KEY_LAST; i++) {
keys[i] = isKeyDown(i);
}
for (int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++) {
mouseButtons[i] = isMouseDown(i);
}
}

public void currentKeyBind() {
if(isKeyPressed(GLFW.GLFW_KEY_Q)) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
}
if(isKeyReleased(GLFW.GLFW_KEY_Q)) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
}
}

}


Just some input on what could be wrong, and a direction I should head to fix it would be great.
I've looked around at tutorials and the documentation for glfw and LWJGL for answers, I can't seem to find one without completely rebuilding most of my project.







java lwjgl glfw






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 7:25

























asked Nov 19 at 7:14









Lane will

337




337








  • 1




    The problem is very likely where you already noted //possible issue. You are constantly adding the current mouse coordinate to your angles, everytime calculatePitch and calculateAngleAroundPlayer is called. So if the mouse x coordinate is, say, 1600 you constantly decrement angleAroundPlayer by 16.0. What you likely wanted to do (if you used Mouse.getDX/DY() before in LWJGL 2) is to store the old mouse coordinates and compute the delta between old and new.
    – httpdigest
    Nov 19 at 9:26








  • 1




    As soon as I read your comment, I knew you were right. Thank you!
    – Lane will
    Nov 20 at 5:10














  • 1




    The problem is very likely where you already noted //possible issue. You are constantly adding the current mouse coordinate to your angles, everytime calculatePitch and calculateAngleAroundPlayer is called. So if the mouse x coordinate is, say, 1600 you constantly decrement angleAroundPlayer by 16.0. What you likely wanted to do (if you used Mouse.getDX/DY() before in LWJGL 2) is to store the old mouse coordinates and compute the delta between old and new.
    – httpdigest
    Nov 19 at 9:26








  • 1




    As soon as I read your comment, I knew you were right. Thank you!
    – Lane will
    Nov 20 at 5:10








1




1




The problem is very likely where you already noted //possible issue. You are constantly adding the current mouse coordinate to your angles, everytime calculatePitch and calculateAngleAroundPlayer is called. So if the mouse x coordinate is, say, 1600 you constantly decrement angleAroundPlayer by 16.0. What you likely wanted to do (if you used Mouse.getDX/DY() before in LWJGL 2) is to store the old mouse coordinates and compute the delta between old and new.
– httpdigest
Nov 19 at 9:26






The problem is very likely where you already noted //possible issue. You are constantly adding the current mouse coordinate to your angles, everytime calculatePitch and calculateAngleAroundPlayer is called. So if the mouse x coordinate is, say, 1600 you constantly decrement angleAroundPlayer by 16.0. What you likely wanted to do (if you used Mouse.getDX/DY() before in LWJGL 2) is to store the old mouse coordinates and compute the delta between old and new.
– httpdigest
Nov 19 at 9:26






1




1




As soon as I read your comment, I knew you were right. Thank you!
– Lane will
Nov 20 at 5:10




As soon as I read your comment, I knew you were right. Thank you!
– Lane will
Nov 20 at 5:10

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369890%2flwjgl-3-camera-issues%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369890%2flwjgl-3-camera-issues%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga