Ok, here is the code that we use when we move the camera. The moveBorder is set when you move the camera too the side of the screen.
void CameraView::draw(csTicks elapsed_time)
{
if(moveBorder.right)
{
//CameraIsoLookat(views[current_view]);
if(moveBorder.up)
{
//Move forward & right
camera->MoveWorld (CS_VEC_FORWARD * CAMERA_SPEED * elapsed_time, false);
camera->MoveWorld (CS_VEC_RIGHT * CAMERA_SPEED * elapsed_time, false);
}
else if(moveBorder.down)
{
//Move backward & right
camera->MoveWorld (CS_VEC_BACKWARD * CAMERA_SPEED * elapsed_time, false);
camera->MoveWorld (CS_VEC_RIGHT * CAMERA_SPEED * elapsed_time, false);
}
else
{
//Move right
camera->MoveWorld (CS_VEC_RIGHT * CAMERA_SPEED * elapsed_time, false);
}
}
else if(moveBorder.left)
{
if(moveBorder.up)
{
//Move forward & left
camera->MoveWorld (CS_VEC_FORWARD * CAMERA_SPEED * elapsed_time, false);
camera->MoveWorld (CS_VEC_LEFT * CAMERA_SPEED * elapsed_time, false);
}
else if(moveBorder.down)
{
//Move backward & left
camera->MoveWorld (CS_VEC_BACKWARD * CAMERA_SPEED * elapsed_time, false);
camera->MoveWorld (CS_VEC_LEFT * CAMERA_SPEED * elapsed_time, false);
}
else{
//Move left
camera->MoveWorld (CS_VEC_LEFT * CAMERA_SPEED * elapsed_time, false);
}
}
else if(moveBorder.up)
{
//Move forward
camera->MoveWorld (CS_VEC_FORWARD * CAMERA_SPEED * elapsed_time, false);
//camera->Move(CS_VEC_DOWN, false);
}
else if(moveBorder.down){
//Move backward
camera->MoveWorld (CS_VEC_BACKWARD * CAMERA_SPEED * elapsed_time, false);
//camera->Move(CS_VEC_DOWN, false);
//camera->Move(CS_VEC_UP, false);
}
// due to moving the camera so far away, depth buffer accuracy is
// impaired, repair that by using smaller coordinate system
view->Draw();
}
This is the method that we use too determine what point of the world you clicked on.
csVector3 CameraView::getWorldPoint(double x, double y)
{
//The mouse (0,0) starts in upperleft corner while the g2d (0,0) starts in lowerleft corner
//fix the y position
csVector2 v2d(x, (float)(view->GetContext()->GetHeight() - y));
csVector3 v3d;
// First translate the mouse position to a 3d vector, aiming away from the camera origin.
camera->InvPerspective(v2d, DEFAULT_Z_VALUE, v3d);
//transform the camera 3d vector to a world vector
clickedPoint = camera->GetTransform().This2OtherRelative(v3d);
//Get the sector
iSector* sector = view->GetCamera()->GetSector();
//Get the origin of the camera in world position
csVector3 origin = view->GetCamera()->GetTransform().GetOrigin();
csVector3 isect;
int sel;
//Calculates the first position where a beam between origin and clickedPoint intersects the world.
iMeshWrapper* mesh = sector->HitBeamPortals(origin, clickedPoint, isect, &sel);
return isect;
}
Thanks for the help
