Crystal Space
Welcome, Guest. Please login or register.
April 23, 2014, 07:39:24 am

Login with username, password and session length
Search:     Advanced search
8990 Posts in 2037 Topics by 7616 Members
Latest Member: Tomrenner
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Confused, cant get a camera and mesh to rotate the same way?
« previous next »
Pages: [1] Print
Author Topic: Confused, cant get a camera and mesh to rotate the same way?  (Read 1649 times)
Recon
Newbie
*
Posts: 24


View Profile
« on: September 02, 2006, 03:53:06 am »

Been trying to do this for a while now.
I want to move the camera to the position of a mesh and then rotate the mesh the same as the camera.
For some reason the mesh rotates in the opposite direction to the camera. This worked fine with a normal mesh, don't seem to work with a child mesh.

Here is some code so you can see what i am trying

Code:

void AppSol::ProcessFrame()
{
csVector3 start, end;
   iMovable* movable ;
csReversibleTransform pot;
csMatrix3 rot;

  if (g3d->BeginDraw(engine->GetBeginDrawFlags() | CSDRAW_3DGRAPHICS))
  {
// First get elapsed time from the virtual clock.
csTicks elapsed_time = vc->GetElapsedTicks ();
// Now rotate the camera according to keyboard state
float speed = (elapsed_time / 1000.0) * (0.06 * 20);

iCamera* c = view->GetCamera();

if (kbd->GetKeyState (CSKEY_SHIFT))
  {
    // If the user is holding down shift, the arrow keys will cause
    // the camera to strafe up, down, left or right from it's
    // current position.
    if (kbd->GetKeyState (CSKEY_RIGHT))
      c->Move (CS_VEC_RIGHT * 4 * speed);
    if (kbd->GetKeyState (CSKEY_LEFT))
      c->Move (CS_VEC_LEFT * 4 * speed);
    if (kbd->GetKeyState (CSKEY_UP))
      c->Move (CS_VEC_UP * 4 * speed);
    if (kbd->GetKeyState (CSKEY_DOWN))
      c->Move (CS_VEC_DOWN * 4 * speed);
  }
  else
  {

               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_UP))
c->Move (CS_VEC_FORWARD * 4 * speed);
if (kbd->GetKeyState (CSKEY_DOWN))
c->Move (CS_VEC_BACKWARD * 4 * speed);

if (kbd->GetKeyState (CSKEY_F1)) {
// set camera to position.001
// Set controll to turret
PlayerMeshName = "trader";
PlayerCrewPos = "turret.001";
playermesh = engine->FindMeshObject ( "trader" , 0 );

aChildren = playermesh->QuerySceneNode()->GetChildrenArray ();
playermesh = aChildren->Top()->QueryMesh();
movable = playermesh->GetMovable ();

// get mesh's transform and move camera
pot = movable->GetFullTransform();
c->SetTransform (pot);
                           } //end if select turret
  }// end if key press


                       // It's a turret position, only change the rotation
       // Position our playermesh the same as camera
    movable = playermesh->GetMovable ();
end = movable->GetTransform().GetOrigin (); // want this mesh to say at it's current loc
rot = c->GetTransform().GetT2O();                         
csOrthoTransform pot ( rot, end);
              movable->SetTransform (pot);

// update player mesh in egin world space
movable->UpdateMove ();



// Tell 3D driver we're going to display 3D things.
if (!g3d->BeginDraw (engine->GetBeginDrawFlags () | CSDRAW_3DGRAPHICS))
  return;

// Tell the camera to render into the frame buffer.
view->Draw ();
}
}


I took out some code to make it clearer what i am doing. Seems to me only explanation is that my mesh is upside down in relation to the camera. But I made the transforms the same?

any suggestions as to what i am doing wrong?

thx

« Last Edit: September 02, 2006, 01:02:38 pm by Recon » Logged
Recon
Newbie
*
Posts: 24


View Profile
« Reply #1 on: September 07, 2006, 09:08:37 pm »

well figured out my problem.
The mesh I am tring to rotate the same as the camera is a child mesh. So if i set the child mesh with the rotation of the camera is does not take into account the rotation of the parent mesh.

So I am thinking the smart thing to do is rotate the mesh and make the camera match. Might still have the same problem.
So a question, how do you sum 2 csMatrix3 rotation?


 
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1704


View Profile
« Reply #2 on: September 08, 2006, 07:28:47 am »

well figured out my problem.
The mesh I am tring to rotate the same as the camera is a child mesh. So if i set the child mesh with the rotation of the camera is does not take into account the rotation of the parent mesh.

So I am thinking the smart thing to do is rotate the mesh and make the camera match. Might still have the same problem.
So a question, how do you sum 2 csMatrix3 rotation?


 


If you mean: how do you combine two rotations so that one happens after the other then you just multiply them.

Greetings,
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 5.102 seconds with 15 queries.