Camera Opengl to OSG or with MatrixTransfrom

34 views
Skip to first unread message

Daoudou Souffou

unread,
Jan 17, 2023, 9:24:01 AM1/17/23
to osg-...@googlegroups.com
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

Robert Osfield

unread,
Jan 21, 2023, 9:42:08 AM1/21/23
to OpenSceneGraph Users
Could you post your question on the new github forum as this is new official place for support.

Daoudou Souffou

unread,
Jan 24, 2023, 1:47:54 PM1/24/23
to osg-...@googlegroups.com
Hello 

Okay thanks 


--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/730dba22-191e-4c5e-a4d7-44c3d6adcddbn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages