Well I decided about a week ago to try (again) to learn LWJGL, and it’s actually a very easy library now that I have more experience. It’s a lot of fun to use. Once deciding to move onto 3D, which I’m more used to, I started following SHC’s tutorials. They’re very nice, thanks for them if you see this.
After following his tutorial for a camera class, I decided to add in a few of my own things primarily pitch, roll, and yaw in order to make a first person ‘flying’ type camera for the fun of it. I have almost everything working perfectly, but for some reason my pitch isn’t being applied to my movement correctly. If I look up at a slight angle I fly up at that angle perfectly fine, however if I look almost straight up, it just flies at what seems to be a 45 degree angle.
However, funnily enough when I go down while looking straight up, it works perfectly. The video below will show that as well.
Here’s what I’m doing to calculate the movement:
public void move(float amount, float direction) {
position.z += amount * Math.sin(Math.toRadians(rotation.y + 90 * direction + yaw));
position.x += amount * Math.cos(Math.toRadians(rotation.y + 90 * direction + yaw));
position.y += amount * Math.sin(Math.toRadians(pitch));
}
The Y part is the part where I’m pretty much guessing, so that’s most likely what’s wrong.
As well as my rotations:
public void apply() {
view.setIdentity();
Matrix4f.rotate((float) Math.toRadians(rotation.x + pitch), xAxis, view, view);
Matrix4f.rotate((float) Math.toRadians(rotation.y + yaw), yAxis, view, view);
Matrix4f.rotate((float) Math.toRadians(rotation.z), zAxis, view, view);
Matrix4f.translate(position, view, view);
}
I’m a little shaky on matrix math, so excuse me if it’s an elementary problem.
Also, here’s a video demonstrating the problem, note that when I do go straight up and down, I am pressing the Spacebar (up) and Control (down) buttons. I’m using WASD for movement.
BTJ9chsecoM