Please, forgive me, but I need help and I've been stuck on this for a few weeks now, I'm making no progress and everywhere I go and I see a different answer, everything I try doesn't work. I've had enough tips and advice, now I really just need someone to give me the answer for me to work backwards from because I can't understand this.
What has made this subject most confusing is the way everyone uses a different set of conventions or rules, and their answers are based on their own conventions without defining what they are.
So here is the set of conventions I've formed based on what seems to be most common and logical:
- Right Hand Rule for axis.
- Positive Y is up, Positive Z is towards the viewer, Positive X is to the right.
- Row Major matrixes, transposed when sent to shaders.
- Pitch: rotation about the X axis
- Yaw: rotation about the y axis
- Roll: rotation about the z axis
- Rotation order: Roll, Pitch, Yaw (is this correct? can someone check me on this?)
- Positive rotation values, looking down from positive end of an axis, results in clockwise rotation.
- Default direction for 0 rotation across all axis is a vector pointing down to negative Y.
.. given those conventions (by all means correct me if they are wrong!), how does one:
- Write a LookAt function? (lookAt(vector position, vector eyefocus, vector up))
- Calculate a rotation matrix. (rotation(x, y, z))
I've tried answering these two questions myself at least over the past 3 weeks, I've re-written my LookAt & Rotation Matrix function at least 30 times, I've tested dozens of methods and read through material I've seen on hundreds of websites and read many answered questions, copied other people's code, and nothing I've made so far has worked, everything has produced the wrong result. Some of which have produced some hilariously bizarre outputs not even close to correct rotation.
I've been working on this every night with the exception of last night because I was getting so frustrated with the repeated failure that I had to stop and take a break.
Please, just show me what the correct method is so I can work backwards from that and figure out how it works, I'm just not getting the correct answer and this is driving me a little crazy!
I'm writing in Java but I'll take code written in any language, most of my 3D rendering code is actually working quite brilliantly, it's just the maths I can't understand.
UPDATE: SOLVED
Thankyou for your help! I now have a working LookAt function that I actually understand and I couldn't be happier (if anyone would like to see it by all means ask).
I did try again at creating a rotation matrix based off pitch/yaw/roll variables and it again seemed to fail, but I've decided to dump attempting to use euler angles for the freelook camera as it seems to be ill-suited for the role, instead I'm going to create a quaternion class, might have better luck going down that path, otherwise I'll resort to using the pitch/yaw as spherical coordinates and rely on the new working LookAt function for rotation.
If anyone else is facing a similar problem and wants to ask me questions, feel free to.
At least I'm not stuck anymore, thanks for the help!