How to set camera node's target after I setProjectionMatrix?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Tonytonytang
Posts: 7
Joined: Tue May 31, 2016 9:01 am

How to set camera node's target after I setProjectionMatrix?

Post by Tonytonytang »

Hi, I am new to irrlicht and new to 3D programming, recently I'm doing a vr project, I set the camera's projection matrix from the vr glasses' result, and now I need to set the 'right' target to 'fit' the new projection matrix, for which I mean is the target-posistion vector is at the center of the screen. And for my few days experiences I assume that every time after setting the camera target irrlicht would change the camera's projection matrix, by default irrlicht would match them (target-position vector and projection matrix) and make the target-position vector at the center of screen, so how do I set target after I set a new camera projection matrix and make it like default. Thanks.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: How to set camera node's target after I setProjectionMat

Post by hendu »

Setting the target only changes the view matrix, as expected. What is the issue? The projection matrix does not affect the target.
Tonytonytang
Posts: 7
Joined: Tue May 31, 2016 9:01 am

Re: How to set camera node's target after I setProjectionMat

Post by Tonytonytang »

hendu wrote:Setting the target only changes the view matrix, as expected. What is the issue? The projection matrix does not affect the target.

Code: Select all

 
if(mpHmd)
    {
        ovrHmd_BeginFrame(mpHmd, 0);
 
        //Get eye poses, feeding in correct IPD offset
        ovrVector3f ViewOffset[2] = {mpVrData->EyeRenderDesc[0].HmdToEyeViewOffset,mpVrData->EyeRenderDesc[1].HmdToEyeViewOffset};
        ovrPosef EyeRenderPose[2];
        ovrHmd_GetEyePoses(mpHmd, 0, ViewOffset, EyeRenderPose, NULL);
 
        scene::ICameraSceneNode* camNow = mpDevice->getSceneManager()->getActiveCamera();
 
        for (int i = 0; i < 2; i++)
        {
            mpDevice->getVideoDriver()->setRenderTarget(mTargets[i], true, true, video::SColor(0,0,0,0));
 
            SetAffect(i, EyeRenderPose, camNow);
 
            mpDevice->getSceneManager()->drawAll();
            mpDevice->getGUIEnvironment()->drawAll();
            pGame->Render();
 
            mpDevice->getVideoDriver()->setRenderTarget(0, true, true, 0);
 
            ovrFovPort fov;
            fov = mpHmd->DefaultEyeFov[i];
            fov.LeftTan *= 0.7f;
            fov.RightTan *= 0.7f;
            fov.UpTan *= 0.7f;
            fov.DownTan *= 0.7f;
 
            ovrMatrix4f proj = ovrMatrix4f_Projection(fov, camNow->getNearValue(), camNow->getFarValue(), ovrProjection_None);
            camNow->setProjectionMatrix(CConvertUseful::MatOvrToIrr(proj));  /*this is the place of applying the VR glasses matrix to the camera*/
        }
        ovrHmd_EndFrame(mpHmd, EyeRenderPose, &mpVrData->eyeTex[0].Texture);
 
 
        //camNow->setViewMatrixAffector(tmp2);
    }
Disregard of functions with 'ovr_' prefix, those are the VR SDK functions, now the result is just like I'm sitting in a bus, the bus turning directions have nothing to do with my looking at directions, I want to change the bus turning direction the same as my looking at direction. By the way, thanks hendu, maybe I should try using a viewMatrix to set camera by matrix4::buildCameraLookAtMatrixLH() :)
Post Reply