Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (580) Games in Android Showcase (162) games submitted by our members Games in WIP (632) 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 2011 times) 0 Members and 1 Guest 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
 « 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
 « 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
 « 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
 « 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

You cannot reply to this message, because it is very, very old.

 Waterwolf (22 views) 2015-05-20 15:01:45 chrislo27 (26 views) 2015-05-20 03:42:21 BurntPizza (60 views) 2015-05-10 15:53:18 FrozenShade (46 views) 2015-05-07 09:11:21 TheLopais (209 views) 2015-05-06 13:36:48 TheLopais (193 views) 2015-05-06 13:35:14 TheLopais (200 views) 2015-05-06 13:33:39 TheLopais (217 views) 2015-05-06 13:32:48 TheLopais (215 views) 2015-05-06 13:31:28 ClaasJG (237 views) 2015-04-30 20:33:25
 Spasi 31x BurntPizza 16x theagentd 13x DavidBVal 13x ra4king 12x EgonOlsen 11x Husk 10x KevinWorkman 9x princec 8x scanevaro 8x opiop65 7x KaiHH 7x revers 6x Riven 6x MrPork 5x SauronWatchesYou 5x
 List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00
 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