Crystal Space
Welcome, Guest. Please login or register.
August 23, 2014, 04:50:47 am

Login with username, password and session length
Search:     Advanced search
9005 Posts in 2043 Topics by 8334 Members
Latest Member: Jacobrosa
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  General Crystal Space Discussion
| | |-+  3D Camera Rotation
« previous next »
Pages: [1] Print
Author Topic: 3D Camera Rotation  (Read 2747 times)
Lumooja
Newbie
*
Posts: 3


View Profile
« on: March 18, 2006, 07:55:00 pm »

I can't get the camera to rotate around itself.

The X-axis rotation works fine.
The Y-axis rotation does not rotate around the camera, but around the world's Y-axis?
Also, when I rotate around the Z-axis, it seems to rotate also around something else than the camera's Z-axis.

I added Z-axis rotation to simple1.cpp like this:
Quote
// We now assign a new rotation transformation to the camera.  You
  // can think of the rotation this way: starting from the zero
  // position, you first rotate "rotY" radians on your Y axis to get
  // the first rotation.  From there you rotate "rotX" radians on the
  // your X axis to get the final rotation.  We multiply the
  // individual rotations on each axis together to get a single
  // rotation matrix.  The rotations are applied in right to left
  // order .
  csMatrix3 rot = csXRotMatrix3 (rotX) * csYRotMatrix3 (rotY) * csZRotMatrix3 (rotZ);
  csOrthoTransform ot (rot, c->GetTransform().GetOrigin ());
  c->SetTransform (ot);
« Last Edit: March 18, 2006, 07:58:53 pm by Lumooja » Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: March 19, 2006, 11:01:52 am »

Try inverting the rotation matrices.

Greetings,
Logged
Lumooja
Newbie
*
Posts: 3


View Profile
« Reply #2 on: March 19, 2006, 01:23:00 pm »

Thanks, that was new to me.

I tried the following:
Quote
  csMatrix3 rot = csXRotMatrix3 (rotX).GetInverse() * csYRotMatrix3 (rotY).GetInverse() * csZRotMatrix3 (rotZ).GetInverse();
  csOrthoTransform ot (rot.GetInverse(), c->GetTransform().GetOrigin ());

It seems to fix the Y-axis rotation (cursor left/right) when X-axis is turned, however when I rotate around the Z-axis, the X and Y axis are now rotating around the world's X/Y-axises always.

Don't I need to set the UpVector each time the camera is turned (and how would I calculate this), or can this be done somehow with this inversing matrices trick?

Hmm, now the iCamera class doesn't seem to have .SetUp() and .SetLookAt() methods.

Ahh, iModelDataCamera has .SetUpVector() and .SetFrontVector() (sounds like this could be the same as .SetLookAt() in other engines) methods, but <mdldata.h> which has iModelCamera is missing now.
« Last Edit: March 20, 2006, 09:58:11 pm by Lumooja » Logged
Lumooja
Newbie
*
Posts: 3


View Profile
« Reply #3 on: March 20, 2006, 11:29:25 pm »

Yes! I found it!

No need for any matrix operations at all. I watched the Cassini Division movie and those guys had a web site at the end of the movie, there I found cassini.cpp and this simple code to rotate the camera in real 3D manner (I added Z-axis rotation though):

   // handle keyboard input... asynchronously, I guess
   if(kbd->GetKeyState(CSKEY_RIGHT))   c->GetTransform().RotateThis(CS_VEC_ROT_RIGHT, speed);
   if(kbd->GetKeyState(CSKEY_LEFT))   c->GetTransform().RotateThis(CS_VEC_ROT_LEFT, speed);
   if(kbd->GetKeyState(CSKEY_PGUP))   c->GetTransform().RotateThis(CS_VEC_TILT_UP, speed);
   if(kbd->GetKeyState(CSKEY_PGDN))   c->GetTransform().RotateThis(CS_VEC_TILT_DOWN, speed);
   if(kbd->GetKeyState(CSKEY_DEL))      c->GetTransform().RotateThis(CS_VEC_TILT_LEFT, speed);
   if(kbd->GetKeyState(CSKEY_END))      c->GetTransform().RotateThis(CS_VEC_TILT_RIGHT, speed);
   if(kbd->GetKeyState(CSKEY_UP))      c->Move(CS_VEC_FORWARD * 4 * speed);
   if(kbd->GetKeyState(CSKEY_DOWN))   c->Move(CS_VEC_BACKWARD * 4 * speed);

Now my modified appsimple1.cpp works perfectly, and I can focus on the next steps with Crystal Space.
These original lines were totally useless for my needs, and so I commented them out:

// csMatrix3 rot = csXRotMatrix3 (rotX) * csYRotMatrix3 (rotY) * csZRotMatrix3 (rotZ);
// csTransform ot (rot, c->GetTransform().GetOrigin());

Btw, The Cassini Division is an awesome game - I love the realistic thruster sounds! Beats any commercial space game Smiley
« Last Edit: March 20, 2006, 11:39:37 pm by Lumooja » Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 6.199 seconds with 15 queries.