Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Having trouble with 3rd person camera setup  (Read 5541 times) 0 Members and 2 Guests are viewing this topic.
BrassApparatus

Junior Devvie

 « Posted 2013-06-13 23:27:41 »

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.

Please and Thank you for the help
relminator
 « Reply #1 - Posted 2013-06-14 01:51:26 »

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.
BrassApparatus

Junior Devvie

 « Reply #2 - Posted 2013-06-14 05:29:13 »

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.
Roquen

JGO Kernel

Medals: 517

 « Reply #3 - Posted 2013-06-14 09:09:51 »

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.
BrassApparatus

Junior Devvie

 « Reply #4 - Posted 2013-06-14 10:06:02 »

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.
Roquen

JGO Kernel

Medals: 517

 « Reply #5 - Posted 2013-06-14 11:58:04 »

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.
Roquen

JGO Kernel

Medals: 517

 « Reply #6 - Posted 2013-06-14 15:09:32 »

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

Junior Devvie

 « Reply #7 - Posted 2013-06-14 20:59:20 »

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?
BrassApparatus

Junior Devvie

 « Reply #8 - Posted 2013-06-15 02:27:51 »

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?
relminator
 « Reply #9 - Posted 2013-06-15 02:44:15 »

BrassApparatus

Junior Devvie

 « Reply #10 - Posted 2013-06-15 03:30:36 »

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.
relminator
 « Reply #11 - Posted 2013-06-15 03:45:19 »

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

Try:

Roquen

JGO Kernel

Medals: 517

 « Reply #12 - Posted 2013-06-15 11:24:40 »

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?

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.
Pages: [1]
 ignore  |  Print

 nelsongames (19 views) 2018-04-24 18:15:36 nelsongames (17 views) 2018-04-24 18:14:32 ivj94 (607 views) 2018-03-24 14:47:39 ivj94 (51 views) 2018-03-24 14:46:31 ivj94 (400 views) 2018-03-24 14:43:53 Solater (65 views) 2018-03-17 05:04:08 nelsongames (110 views) 2018-03-05 17:56:34 Gornova (175 views) 2018-03-02 22:15:33 buddyBro (746 views) 2018-02-28 16:59:18 buddyBro (93 views) 2018-02-28 16:45:17
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org