Hello, I am new to OSG and having trouble with modifying the camera.
I have added my own event handler to process keyboard inputs to change the
camera view.
This handler holds references to 5 camera manipulators, and upon a KEYDOWN, it
switches to the correct camera manipulator as such:
Code:
......
if (key == '1' && m_topCamera.valid())
{
m_scene->setCameraManipulator(m_topCamera, false);
m_topCamera->update();
return true;
}
if (key == '2' && m_sideCamera.valid())
{
m_scene->setCameraManipulator(m_sideCamera, false);
m_sideCamera->update();
return true;
}
if (key == '4' && m_userCamera.valid())
{
m_scene->setCameraManipulator(m_userCamera, false);
m_userCamera->update();
return true;
}
.....
m_topCamera is an OrthoCamera derived from StandardManipulator
m_userCamera is a UserCamera derived from FirstPersonManipulator
each has a _camera member that points to the same instance
Code:
void OrthoCamera::update()
{
double aR,l,r,b,t,n,f, fov;
if (_camera->getProjectionMatrixAsOrtho(l,r,b,t,n,f))
{
aR = fabs(r-l)/fabs(t-b);
_camera->setProjectionMatrixAsOrtho2D(-_zoom*aR, _zoom*aR, -_zoom,
_zoom);
}
else
{
_camera->getProjectionMatrixAsPerspective(fov,aR,n,f);
_camera->setProjectionMatrixAsOrtho2D(-_zoom*aR, _zoom*aR, -_zoom,
_zoom);
}
}
Code:
void UserCamera::update()
{
double aR,l,r,b,t,n,f, fov;
if (_camera->getProjectionMatrixAsOrtho(l,r,b,t,n,f))
{
aR = fabs(r-l)/fabs(t-b);
_camera->setProjectionMatrixAsPerspective(54.0, aR, n, f);
}
else
{
_camera->getProjectionMatrixAsPerspective(fov,aR,n,f);
_camera->setProjectionMatrixAsPerspective(fov, aR, n, f);
}
}
The problem:
When switching back and forth from top camera to user camera, everything works
great.
However, when switching from side camera to user camera, all the normals appear
to be inverted... all the lighting is messed up and I am seeing the inside of
objects. It also seems to draw objects in front of objects that should be
hidden. This problem is fixed when I go back to top camera then back to user
camera.
Am I needing to do some type of invalidating to get things refreshed? Sorry,
very new to OSG and unaware of all the functions.
Thanks,
Jason
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=47827#47827
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org