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
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