• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

3D 3D Camera Yaw, Pitch, Roll

J

jtmx

Guest
Hello all,

I'm trying to create a 3D Camera in GMS2 that has Yaw, Pitch and Roll. I managed to get the Yaw and Pitch working however I can't seem to get the Roll working properly. Any help with this would be greatly appreciated.

Code:
Code:
if keyboard_check(ord("A"))
cam_yaw -= 10;
if keyboard_check(ord("D"))
cam_yaw += 10;
if keyboard_check(ord("W"))
cam_pitch -= 10;
if keyboard_check(ord("S"))
cam_pitch += 10;
if keyboard_check(ord("Q"))
cam_roll -= 10;
if keyboard_check(ord("E"))
cam_roll += 10;

cam_xto = dcos(cam_yaw) * dcos(cam_pitch);
cam_yto = dsin(cam_yaw) * dcos(cam_pitch);
cam_zto = dsin(cam_pitch);
cam_xup = dsin(cam_roll);
cam_yup = dcos(cam_roll);
cam_zup = dcos(cam_pitch);

matrix_build_lookat(x,y,z,x + cam_xto,y + cam_yto,z + cam_zto,cam_xup,cam_yup,cam_zup);
 
L

Lonewolff

Guest
I normally handle all of this using the matrix_* functions. I've never tried it the way you are going about it.
 

GMWolf

aka fel666
You have to rotate around the local forward axis to get roll working correctly.

To do that, I get the previous frame matrix and get the Nth column. That will be the axis to rotate around.
N depends on your axis system.
If x is forward, then use the 0th column.
If y Is forward, then use the 1rst column.
If z is forward, the. Use the 2nd column.

I would do that for all 3 axis, not just roll.
 
Kind of depends on what you are trying to do.

If you are just trying to implement Z*Y*X rotation order, then:

assuming 0 rotation puts +x forward, and +z up.

camera's look vector is:
cz*cy
-sz*cy
sy

and camera's up vector is:
-cz*sy*cx + sz*sx
sz*sy*cx + cz*sx
cy*cx

"c" = cosine, "s" = sine, "x,y,z" = roll, pitch, yaw.

This will produce clockwise rotations with positive angles when looking toward the origin from negative direction along axis of rotation in a left-handed coordinate sytsem, and anti-clockwise when doing the same in a right-handed coordinate system.
 
Last edited:
Top