Hello all
I have some questions.
I want to transmit the camera of my opengl scene to my OSG scene, to do this I retrieve the view of my camera as well as the point it is looking at with the following code:
{
GLdouble camera_pos[3];
double rationZoom = m_pModel->GetView()->m_graphEnv.GetZoomRatio();
int* iViewport = m_pModel->GetView()->m_graphEnv.GetViewport();
double* projetMatrix = m_pModel->GetView()->m_graphEnv.GetProjMatrix();
double* modelMatrix = m_pModel->GetView()->m_graphEnv.GetModelMatrix();
double screenCenterX = m_pModel->GetView()->m_graphEnv.GetScreenCenterX();
double screenCenterY = m_pModel->GetView()->m_graphEnv.GetScreenCenterY();
double rotateX = m_pModel->GetView()->m_graphEnv.GetRotationCenterX();
double rotateY = m_pModel->GetView()->m_graphEnv.GetRotationCenterY();
double rotateZ = m_pModel->GetView()->m_graphEnv.GetRotationCenterZ();
// I retrieve the camera and the center of the screen (for the point it is looking)
gluUnProject((iViewport[2] - iViewport[0]) / 2, (iViewport[3] - iViewport[1]) / 2,
0.0, modelMatrix, projetMatrix, iViewport, &camera_pos[0], &camera_pos[1], &camera_pos[2]);
// rotCenter it's the center point looking
osg::Vec3f rotCenter = osg::Vec3f(screenCenterX,
screenCenterY,
rationZoom * (-1.0));
double X = (camera_pos[0] / 2) / rationZoom;
double Y = (camera_pos[1] / 2) / rationZoom;
double Z = (camera_pos[2] / 2) / rationZoom;
osg::Vec3 updateCameraPosition(X, Y,Z);
osg::Vec3f eye(updateCameraPosition);
osg::Vec3f up(0, 0, 1);
osg::Vec3f centre = osg::Vec3f(rotCenter.x(), rotCenter.y(), rotCenter.z());
nodeCamera->setViewMatrixAsLookAt(eye, centre, up);
}
but i don't know why, i have wrong values with osg eye Y axis. Does anyone have any ideas ??
If I'm not mistaken the OpenGL coordinate system is : Y up, X right, Z forward but I don't have this configuration on my OSG scene. Maybe this is the problem ?
Or I have to use Matrix Transform and rotate the matrix to have the same coordinate system of my OpenGL scène ?? So can I set matrixtransform with my camera and set it to my viewer ??
Thanks in advance
Souffou