Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Fri Apr 18, 2014 11:15 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: That ***** camera!
PostPosted: Thu Aug 15, 2013 3:58 am 
Postronaut

Joined: Sun Mar 10, 2013 3:32 pm
Posts: 45
Ok, I want to know the basic on good camera control!
First each camera can do

x,y,z
and
rotation x,y,z

but cant figure out the best way to set up controls.
I have two views First person and Third person views


What i would like is "W" ,"A","S","D" to control the view in first person with "Z" and "C" for zooming in / out..

Currently i can do that, but once the camera is rotated the up becomes left or if rotated 180 up becomes down..
As for third person? What is a normal camera view / control... I hope this makes sense?

So lets start with 1st person..
W should take you forward (walking straight in front of you no matter the angle)
S should take you backward (walking straight behind you no matter the angle)
A and D should rotate you.
Z and C zoom in/out

so how do you set up the x,y,z and angle x,y,z? not worried about code wise but logic wise..


Now third person.. should do the same only difference is now the camera is pointing down on the map instead of the "first person view"

any help would be great!
Thanks
Squills
should do the same


Top
 Profile  
 
 Post subject: Re: That ***** camera!
PostPosted: Thu Aug 15, 2013 5:49 am 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 7004
Location: Wilts, Englandshire
Sounds like you're suffering from Gimbal Lock. This can be solved using Quaterions but I've never managed it.

In my OpenGL stuff, I maintained a vector for the camera direction, limited the camera rotations (no roll component) and used gluLookAt to set the view.

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
 Post subject: Re: That ***** camera!
PostPosted: Thu Aug 15, 2013 10:09 am 
Postronaut

Joined: Sun Mar 10, 2013 3:32 pm
Posts: 45
Quaternion-based Camera ? ... looks like fun... ill give it a shot.. that link seems like it will help with 1st person at least..


Top
 Profile  
 
 Post subject: Re: That ***** camera!
PostPosted: Mon Aug 19, 2013 3:18 am 
Postronaut

Joined: Sun Mar 10, 2013 3:32 pm
Posts: 45
well one issue i have ran into , opengl uses something like gllook(position,position,position,view,view,view,up,up,up) 9 values, where delphi camera only has 6
position x,y,z and rotate x,y,z if i remember right glscene use to do the same thing...so maybe i can find something with glscene?


Top
 Profile  
 
 Post subject: Re: That ***** camera!
PostPosted: Mon Aug 19, 2013 2:47 pm 
Fish Doggy

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1738
Location: burrowed
glLookAt() is only a function to set up a matrix. since you use that i assume you're working with an opengl version < 3, or if, using deprecated code.

In any case, I think Quaternions are anything but necessary for your sample. Are you familiar with vector math?

Usually what you'd do is you have a Position for your camera, and a forward unit vector, pointing in the direction you're looking at. That plus the up-vector (pretty much a unit vector pointing in the up direction, be it Z or Y) will be enough to do all your movement and rotations.
To move your camera you'd go

Code:
if(moveforward)
  Camera.position += Forward * speed;


If you want to rotate your view/forward direction you'd rotate the forward vector around the Z/Y Axis (or up-vector).

You didn't mention you'd need it, but for strafing you need to create an additional vector that is at a right angle to the forward vector. The cross-product of forward and up will give you that, thus:

Code:
if(moveright)
  Camera.position += crossproduct(Forward, Up) * speed;
if(moveleft)
  Camera.position -= crossproduct(Forward, Up) * speed;


I never encountered a gimbal lock using this method, even for axis unlocked rotations (3d free roaming movement) and it is still my favored way to go about these things.

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
 Post subject: Re: That ***** camera!
PostPosted: Thu Aug 22, 2013 10:45 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2221
Location: England
weezl wrote:
I never encountered a gimbal lock using this method, even for axis unlocked rotations (3d free roaming movement) and it is still my favored way to go about these things.


Gimbal lock is only an issue with parameterised orientations, like euler angles. eg,
assume forward vector is (0,0,1) and up vector is (0,1,0), then you can define any orientation with three successive transforms, parameterised by three angles:
set camera roll/banking angle - rotate about vector (0,0,1)
set camera pitch/elevation angle - rotate about vector (1,0,0)
set camera bearing/azimuthal angle - rotate about vector (0,1,0)

But if elevation angle were at 90 degrees, then the bearing and roll transformations become identical. So in effect, you lose one of your three parameters when elevation=90. That is gimbal lock.

The system you are using weezl is relatively stable, although if the up and forward vectors are rotated, you have to make sure they (i) remain unit vectors, and (ii) remain orthogonal, otherwise they are liable to drift over time. This can be achieved with a combination of dot and cross products.

The only other thing to watch out for is getting a zero vector at some point in your transformations (which could destroy your whole orientation frame if you later cross product it again with your axes).

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group