Having trouble with 3rd person camera setup

I’m working on making a 3rd person camera (in lwjgl) and I simply cannot get the math concepts straight in my head. I’ve worked through the positioning stuff in the arcsynthesis tutorials but I’m still having some trouble thinking in quaternions. I really don’t like Euler angles (yaw, pitch, roll) so I’d like to stay away from them.

Right now I have a player class that has its own camera object as well as player position and camera target vectors and an orientation quaternion. I can update the player’s orientation with a quat but I’m having trouble figuring out how to move the camera’s target and position properly.

Should that be done with quats/position vectors as in the left half of my pic? Would it be better to do it with a pair of spherical position vectors like in the right? And if so, isn’t that subject to gimbal lock?

I’m using an offset target point so as to avoid the irritating player-always-in-the-way effect like in minecraft.

https://sphotos-a.xx.fbcdn.net/hphotos-prn2/8568_576037255774651_205518275_n.jpg

Please and Thank you for the help

This might be useful:

http://rel.phatcode.net/junk.php?id=43

I calculated the orthovectors via vector arithmetic, converted that to quats, do the transforms via quats, converted it to matrix then plug that matrix to opengl.

Your forward vector can be calculated by a simple vector subtraction ang the other 2 could be converted by a simple cross product.

I appreciate the advice, and I’m playing with that file, but I think I’m going to need some more explicit 'here you go bonehead" type help. :-\

You can always view a rotation in 3D as taking 3 orthogonal unit vectors and performing a parallel projection (dot product) of the point into them to form the rotation. So if you have a lookat direction, you already have one. Having a rough desired ‘up’ direction gives you a way to generate the other 2. It looks like you’re asking for the classic lookat formulation. It’s degenerate as lookat approaches either straight up or down but it a reasonable starting point.

Actually I have the lookat formula but I wanted to do the same thing with quats because they don’t degenerate. I roughly understand the lookat formula but I can’t figure how to properly position the camera and target point relative to the player while working with quats. I appreciate the note about dot product though, it’s been a few years since I did calc or trig. :slight_smile:

Using quaternions is fine, but you still need to decide how you want to parametrize the orientation. You have to figure out how you want camera ‘up’ (or right or left) to behave. Quaternions will help for smoothly transitioning from the current camera orientation toward your new target orientation but don’t seem useful for making the target. You effectively have an axis-of-rotation embedded in the quat and you still need to figure out what it is.

Perhaps a little more useful than my last comment would be to look at: arcball and similar.

Ok that helps a lot! The arcball thing makes sense now, my final problem is that I can’t imaging how to make the camera rotate about the player (as in the dark circle in my pic) but look at another point without screwing up the arcball. Mathematically how can I account for rotating around a center that is not my camera target?

Ok, here’s what I’m thinking, (I’m at work so I’ll test it later if I can) I should have two orientation quats, one pointing the camera at the player (center of arcball) and one pointing it at the target point. I use the first one while rotating the camera around the player (ie camToPlayerQuat.tomatrix ()) then set the cameras orientation to camToTargetQuat before rendering. Does that make sense to anyone?

Make your player position your target?

I’m trying to avoid that. Think of how irritating that is in minecraft, your target location is always obscured by the player. :-/ Many games with a quality feel have this system. Think of dead space.

Seeing as I haven’t played those, I don’t think I’d be too helpful.

Try:

Make your target your player.
Rotate your camera position about 30 degrees up.

Two different issues. Rotation about the player defines the local coordinate frame of the camera…we’re more talking about how the camera is oriented in that frame.