[gameprogrammer] Re: Rotation, Rotation, Rotation...

  • From: "richard sabbarton" <richard.sabbarton@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Tue, 18 Mar 2008 08:39:35 +0000

Hi Robbert,

I have been looking into this a bit further and I think I can describe
the problem a little better. (maybe)...

OK.  What I want is to be able to rotate my Player view around my
players axis and not the global axis.  So, if my player starts out, as
is default, looking down the Z Axis and then looks down I want my
players Z axis to point down so that a rotation around my players axis
are relative to the player and not the global axis.

Lets say my control keys are up,down,left and right.  If my player
pushes down by 90 deg and then pushes left by 90 deg I want my player
to now be on its side looking 90 deg to the left of its original
position.

Currently, pushing down for 90 deg looks down but then the left action
rotates the view and I am still looking down.

I read the Quaternion Camera tutorial that Vince sent through (Thanks
Vince) but I don't think I really understood it.  It has
copy/paste'able code that I think would do exactly what I want but I
would prefer to do something I understand.  Also, I will need the same
functionality for objects in my world as well and I am not sure, given
the calculations involved, that this is going to run quick enough.

I have been looking into rotation matrices and transforms as well.

One thing has certainly become clear... My Math is letting me down.  I
have a feeling the answer to my problem lies in a trip to the bookshop
for some Math Texts and a large supply of sugary snacks and caffeine
based drinks.

The thing is, there are tons of tutorials out there that explain how
to do this.  The problem is that they all seem to assume a certain
ammount of knowledge on the subject before they begin.  Again, back to
the Math Texts...

Richard


On 17/03/2008, Robbert de Groot <zekaric@xxxxxxxx> wrote:
> I'm not sure I completely understand what you are getting at but...
>
> The first rotation may work because the player is in the beginning
> state.  Matches the coordinate system that you are expecting.
> Subsequent rotations may not work because the player is not in a
> coodinate system that isn't matching the default (left or right
> handed coordinate system.)
>
> You will probably have to keep track of your player's forward, up and
> right/left vectors and use those for your rotation axes.  I'm
> guessing, in your situation, you can't just assume X, Y and Z axes of
> your player will match the world's X, Y and Z axes for rotation.
>
> --- richard sabbarton <richard.sabbarton@xxxxxxxxx> wrote:
>
> > Hi Guys,
> >
> > I have a problem and I am absolutely sure that I have missed
> > something
> > obscenely obvious.  This is C++ with OpenGL/SDL.
> >
> > In a 3D environment my player struct has 3 values for rotation
> > around
> > x,y and z.  I want the player to be able to freely rotate around
> > all 3
> > axis and I always want the mouse/joystick/keypad to operate the x
> > and
> > y axis rotation.  When I initially move the mouse the rotation is
> > correct.  Left/Right and my scene rotates left and right.
> >
> > If I rotate around z and then move the mouse my scene moves up and
> > down instead of left and right.  Now, I thought that all I needed
> > to
> > do was change the order in which I rotated around each axis.  I
> > thought that if I rotated around Z first and then x and y after
> > then
> > the movement of the mouse would always appear correct onscreen.
> > This
> > is what I call:
> >
> > glRotatef(Player.ZRot,0.0f,0.0f,1.0f);  // Rotation around Z axis
> > glRotatef(Player.YRot,1.0f,0.0f,0.0f); // YRot is up and down
> > around X axis
> > glRotatef(Player.XRot,0.0f,1.0f,0.0f); // XRot is left and right
> > around Y axis
> >
> >
> > I thought that after performing the rotation the subsequent
> > rotations
> > would be relative to the previous one.  So, if I rotate 90deg
> > around Z
> > I thought it would then rotate relative to that effectivly
> > switching
> > the x and y axis.  But it doesn't does it...
> >
> > So I guess that is my question...  How do I perform a rotation and
> > then make all subsequent rotations relative to that initial
> > rotation?
> >
> > Regards
> >
> > Richard
> >
> > ---------------------
> > To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> >
> >
> >
>
>
> Robbert de Groot
>
>
>      Connect with friends from any web browser - no download required. Try 
> the new Yahoo! Canada Messenger for the Web BETA at 
> http://ca.messenger.yahoo.com/webmessengerpromo.php
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: