Hi C.L,

There are number of different ways to control the camera, and to
compute the view matrix required to track objects in the scene.  As
you've found out placing a camera in the scene and assume that it'll
somehow track the world by placing it beneath it - as this creates a
circular reference.  There are times when you place a camera in the
scene, but this isn't one of them - placing a camera in the scene is
useful for things like RTT and other effects, but not viewing of the
scene.

So what you are after is controlling the a Viewer's Camera's view
matrix such that the view matrix is the inverse of the world matrix of
the object you are following.  You will also typically want some
offset from this so you aren't viewing from inside the object.  You
could compute this view matrix yourself and set it in the viewers
frame loop, or reuse something like a NodeTrackerManipulator which
does the view matrix computation for you.  Please review the
implementation to see how it works.

Robert.

On Dec 4, 2007 3:27 PM, LOREK Christophe <[EMAIL PROTECTED]> wrote:
> hi,
>
> As anyone already tried to have a camera track a mobile object ?
> How is it supposed to be done using OSGViewer ?
> if someone has some sample code, it would be welcome.
>
> here is what I have tried, so far :
>
> I'm using the OSGViewer, and I'm trying to have a camera follow a mobile
> object.
> First, I had tried to attach the camera to the scenegraph where my
> object was. But after looking thoroughly through the OSGViewer source
> code, I realised that the rendering is done by linking the scenegraph to
> the active camera and perform an inverse transform of the desired camera
> position to the scenegraph. This means that adding the camera to the
> scenegraph create a cycle loop in the scenegraph, causing the OSGViewer
> to enter an infinite loop, ending in a stack overflow. So this seemed
> not to be the good way.
>
> So, I realised that I had no escape but use a CameraManipulator to
> position my camera in the scenegraph.
>
> Then I tried to move my object in the scene, in a kind of brute force
> way, by forcing the parent MatrixTransform of my mobile object with an
> updated matrix according to the movement I desired. This didn't work, as
> it seems that the scenegraph is either locked by the OSGViewer, or
> simply managed in a separate thread that prevents users to temper with
> the Scenegraph directly.
>
> So I just resigned in using a NodeTrackerManipulator to set and schedule
> the movement I wanted.
>
> Now, the problem is, I would like my camera to act as if it were linked
> to the moving object. I tried using the setNode method of my
> CameraManipulator, but it will only work for static objects. But
> whenever my object is moved by a NodeTrackerManipulator, the camera will
> be positionned to a default Home Position.
> I tried to use the same animationPath for the mobile object and the
> camera, but there seems to be no way of handling an animationPath with a
> CameraManipulator, as it can be done with a NodeTrackerManipulator (it
> seems not possible to assign an updateCallback for the Camera, as can be
> done for a Node). So I can't set the speed along the path for the
> camera, and, even if I could, anyway, my camera will not actually follow
> the mobile object, but only follow the same path as my mobile object
> (and would seem to follow the mobile object only if I would synchronise
> the start of the movement for both camera and mobile object, which is
> not what I want, as I would like to switch to a follow mode at anytime
> of the movement)
>
> thanks for your help
>
> C.L
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to