Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Having trouble with 3rd person camera setup  (Read 1457 times)
0 Members and 1 Guest are viewing this topic.
Offline BrassApparatus

Junior Duke





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

Junior Duke





« 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.  Undecided
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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.
Offline BrassApparatus

Junior Duke





« 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. Smiley
Offline 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.
Offline 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.
Offline BrassApparatus

Junior Duke





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

Junior Duke





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

Make your player position your target?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline BrassApparatus

Junior Duke





« 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.
Offline 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:

Make your target your player.
Rotate your camera position about 30 degrees up.
Offline 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (34 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (54 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!