I am posting links to two pictures that will (hopefully) explain what movement I want to achieve. (links are to my google drive because the site keeps saying “wrong file” if I try to upload them here)
https://drive.google.com/open?id=0B4Ygnk4SnEMVbXR5bkJ0WWZ2VXc
https://drive.google.com/open?id=0B4Ygnk4SnEMVQ3ZrNmt5UmxSR0E
So basically I want the ship (orange) to orbit the solid body (grey) in a circle which lies in the yz-plane. Holding down the left/right arrow should make the ship continuously orbit the body following the circular trajectory. Pressing the up/down arrow should rotate the circle so it is no longer in the yz-plane but is “tilted”; the ship should move on that now-tilted circle.
This way, you control two coordinates but are still sort of able to cover a 3D volume since you move on a fixed-radius sphere.
I cannot get it to work as I’m out of ideas. I tried:
- two successive rotations (an x- and a y-rotation)
- moving the ship in spherical coordinate system
- rotate about y-axis first, then rotate about the rotated x-axis (as a result of the rotation about the y-axis) - see code below
but these approaches don’t work.
Below is my code so far. User input is received via float hor (left/right arrows) and float vert (up/down arrows).
mat4 shipMatrix = identity();
rotate(&shipMatrix, test, sinf(hor), 0, cosf(hor));
rotate(&shipMatrix, vert, 0, 1, 0);
//stable, prepare ship for user input
scale(&shipMatrix, 0.5, 0.5, 0.5);
translate(&shipMatrix, 0, 0, 3);
rotate(&shipMatrix, 3.14159265, 0, 1, 0);
glUniformMatrix4fv(modelMatrixLoc, 1, GL_FALSE, &shipMatrix.m[0]);
I feel this might be more math than OpenGL but hopefully some OpenGL expert has encountered this problem before and knows of a solution.