Update camera matrices

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
bob
Posts: 57
Joined: Fri Jun 08, 2007 4:17 am
Location: Jacksonville, Fl (USA)
Contact:

Update camera matrices

Post by bob »

It seems after moving my camera, getScreenCoordinatesFrom3DPosition() and getRayFromScreenCoordinates() still use the previous camera positions.

Stepping into the code, I think I need to call CCameraSceneNode::recalculateProjectionMatrix() and/or CCameraSceneNode::recalculateViewArea().

These functions aren't available through ICameraSceneNode however, so is there another way to update these matrices after the camera is moved?

Code: Select all

BOOL screenToWorld( sqirr::CSiVector2d &ptScreen, sqirr::CSiVector &ptWorld, float fDist )
{
    // Get mouse line
    irr::core::line3df ml = 
        m_pSm->getSceneCollisionManager()->
                    getRayFromScreenCoordinates( irr::core::position2di( ptScreen.c_v().X, ptScreen.c_v().Y ), 
                                                 GetCamera().AsCamera() );

    // Calculate position
    ptWorld = ml.start + ( ml.getVector().normalize() * fDist );

    return TRUE;
}
sqirr::CSiVector2d getScreenPos( sqirr::CSiVector &v )
{
    irr::core::position2di pos2d = 
        m_pSm->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition( v.c_v(), GetCamera().AsCamera() );

    return sqirr::CSiVector2d( pos2d.X, pos2d.Y );
}
death_au
Posts: 38
Joined: Tue Apr 17, 2007 9:48 am
Location: Australia

Post by death_au »

I'm not sure that it will work, but you could try calling updateAbsolutePosition() on the camera. That may do all the recalculations you need....
Image
bob
Posts: 57
Joined: Fri Jun 08, 2007 4:17 am
Location: Jacksonville, Fl (USA)
Contact:

Post by bob »

*edit* - Nevermind, calling ICameraSceneNode::OnRegisterSceneNode() also fixes the problem.

*edit* - Thanks death_au, but updateAbsolutePositoin() doesn't do it.

:!: Warning! Stupid idea below, read no further!

I added recalculateViewArea() to ICameraSceneNode and call it before using getRayFromScreenCoordinates() and getScreenCoordinatesFrom3DPosition().

This fixes my problem.

Perhaps this should be added to SVN?

As mentioned, the problem only occurs after moving the camera but before the next render.
Post Reply