Re: [osg-users] Arcball Camera without unexpecting 'roll' of the camera

2016-05-17 Thread Jan Ciger
On Tue, May 17, 2016 at 2:35 PM, Daniel Neos  wrote:

> Unfortunalety there is no feature "throw" feature. My class inherits from
> osgGA::GUIEventHandler and there is no setAllowThrow implemented, as far as
> I know.
>
>
And if I am zooming in, sometimes the effect gets worse and the camera is
> hardly to control. Maybe there is an error in my rotation setup?
>


That sounds like a classic case of gimbal lock to me. You are rotating
using 2 Euler angles rotations, so it is easy to align the axes in exactly
"the wrong way" and trigger the singularity when approaching +- 90 degrees.

You may want to look at this code:
https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Arcball

J.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Arcball Camera without unexpecting 'roll' of the camera

2016-05-17 Thread Daniel Neos
Unfortunalety there is no feature "throw" feature. My class inherits from 
osgGA::GUIEventHandler and there is no setAllowThrow implemented, as far as I 
know.

Here is (part of) my actual mouse dragging code:


Code:


bool CameraHandler::handle(const osgGA::GUIEventAdapter & ea, 
osgGA::GUIActionAdapter & us)
{
osgViewer::View* viewer = dynamic_cast(&us);
osg::Matrixd viewMatrix = viewer->getCamera()->getViewMatrix();
osg::Vec3d translation = viewMatrix.getTrans();

osg::Matrixd rotationX = osg::Matrix::rotate(deltaX  * 0.5, 
osg::Y_AXIS);
osg::Matrixd rotationY = osg::Matrix::rotate(-deltaY * 0.5, 
osg::X_AXIS);
osg::Matrixd preTrans = osg::Matrix::identity();
osg::Matrixd postTrans = osg::Matrix::identity();

osg::Vec3d bsCenter = osg::Vec3d(137.69, 284.17, 3305.0); // 
scene is (almost) static
m_rotationPoint = osg::Vec3(0.0, 0.0 , 0.0); // good rotation 
point for 

m_rotationPoint = translation - bsCenter; // good rotation 
point for 

preTrans.setTrans(-m_rotationPoint);
postTrans.setTrans(m_rotationPoint);

viewMatrix = viewMatrix * (preTrans * rotationX * rotationY * 
postTrans);
viewer->getCamera()->setViewMatrix(viewMatrix);

// ensure fixed point to look at
osg::Vec3d eye, center, up;
viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
if (focusPointFlag)
{
viewer->getCamera()->setViewMatrixAsLookAt(eye, bsCenter , 
up);
}

return true;
}





And if I am zooming in, sometimes the effect gets worse and the camera is 
hardly to control. Maybe there is an error in my rotation setup?

Thank you!

Cheers
Daniel Neos


cbuchner1 wrote:
> Could it be that the "throw" feature of the camera manipulator is responsible 
> for the roll?
> 
> If so, try disabling it.
> 
> 
> Also, post source code if you want specific help with a specific issue in 
> your implementation.
> 
> 
> Christian
> 
> 
> 
> 



Code:




--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67128#67128





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Arcball Camera without unexpecting 'roll' of the camera

2016-05-17 Thread Christian Buchner
Could it be that the "throw" feature of the camera manipulator is
responsible for the roll?
If so, try disabling it.

Also, post source code if you want specific help with a specific issue in
your implementation.

Christian


2016-05-16 14:59 GMT+02:00 Daniel Neos :

> Hi everyone,
>
> I have implemented a Cameramanipulator by myself, because I need more
> individually control over the camera in the scene, like rotating around a
> specific axis.
>
> I let osg compute the Boundingsphere of my scene and set the rotationpoint
> and the lookat-point or center-point at the center of the Boundingsphere.
>
> My rotation works like this
>
> 1.) Translate the camera to the center of the Boundingsphere
> (Multiplicated from the right side of the viewmatrix of the camera fist)
>
> 2.) Rotate the viewmatrix by the OSG::x_axis and OSG::y_axis (depending on
> the mousemovement)
>
> 3.) Translate the camera back with the vector from step 1.
>
> 4.) Now with the last step I ensure, that the camera stays focused at the
> samepoint by getting the eye, center and up vector and reseting the center
> vector, while eye and up remains the same.
>
> This usually works fine and it is easy to navigate through the scene with
> the mouse, but as I reach some regions the camera unexpectedly seem to
> rotate around its own z-axis which results in to a 'roll'.
>
> How can I prevent this behaviour? Sample code with arcball camera would be
> appreciated too :)
>
> Thank you!
>
> Cheers,
> Daniel
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=67113#67113
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Arcball Camera without unexpecting 'roll' of the camera

2016-05-16 Thread Daniel Neos
Hi everyone,

I have implemented a Cameramanipulator by myself, because I need more 
individually control over the camera in the scene, like rotating around a 
specific axis.

I let osg compute the Boundingsphere of my scene and set the rotationpoint and 
the lookat-point or center-point at the center of the Boundingsphere.

My rotation works like this

1.) Translate the camera to the center of the Boundingsphere (Multiplicated 
from the right side of the viewmatrix of the camera fist)

2.) Rotate the viewmatrix by the OSG::x_axis and OSG::y_axis (depending on the 
mousemovement)

3.) Translate the camera back with the vector from step 1.

4.) Now with the last step I ensure, that the camera stays focused at the 
samepoint by getting the eye, center and up vector and reseting the center 
vector, while eye and up remains the same.

This usually works fine and it is easy to navigate through the scene with the 
mouse, but as I reach some regions the camera unexpectedly seem to rotate 
around its own z-axis which results in to a 'roll'.

How can I prevent this behaviour? Sample code with arcball camera would be 
appreciated too :)

Thank you!

Cheers,
Daniel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67113#67113





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org