Re: [osg-users] Trackball and view question

2007-10-03 Thread David Spilling
Question 1) : You are trying to retrieve the Euler angles (i.e. rotation
about X,Y,Z in some order) from a matrix. You can google for Euler and
Matrix; alternatively start here:

http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/index.htm

Question 2) : As mentioned in previous replies, the translation retrieved
will incorporate the lookDistance of the camera; hence you need to store and
control the lookDistance of the camera - this is a bit similar to the idea
of zoom on the trackball.

For what it's worth, I do this with a combination of distance =
(eye-centre).length(),  trackball-setDistance(distance), and also retrieve
the matrix with
trackball-getInverseMatrix().getLookAt(eye,look,up,distance).

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


Re: [osg-users] Trackball and view question

2007-10-02 Thread Poirier, Guillaume

Hello,

I am still stuck on this problem... :( Here is some concrete code so that maybe 
someone
can help me figure it out and for those who understand code better than english 
:) 

First we are given a camera position (in world coordinate
system) and an orientation. The orientation is the yaw / pitch / roll to 
transform the
vector (0,0,1) to the desired camera view direction.

  osg::Vec3 camTrans(0.1443978698344,
0.0204530392050 ,
0.0124436690688 );

osg::Vec3 camRot(5.4461109291   , 
-4.7768289550   ,
90.9259008041   );

To set the view in the viewer I do:

/*
setView() method

Set view in viewer given camera
translation and rotation.
*/
osg::Vec4 vsCtr(0.0, 0.0, 1.0, 1.0);
osg::Vec4 vsUp(0.0, 1.0, 0.0, 0.0);
osg::Vec4 vsEye(0.0, 0.0, 0.0, 1.0);
osg::Vec4 newCtr, newUp, newEye;

osg::Matrix rotX, rotY, rotZ, transXYZ;
rotX.makeRotate(Deg2Rad(camRot.x()), osg::Vec3(1,0,0));
rotY.makeRotate(Deg2Rad(camRot.y()), osg::Vec3(0,1,0));
rotZ.makeRotate(Deg2Rad(camRot.z()), osg::Vec3(0,0,1));
transXYZ.makeTranslate(camTrans);

newCtr  = vsCtr * rotZ * rotY * rotX * transXYZ;
newEye  = vsEye * rotZ * rotY * rotX * transXYZ;
newUp   = vsUp * rotZ * rotY * rotX * transXYZ;

osg::Vec3 v3Eye(newEye.x(), newEye.y(), newEye.z()); 
osg::Vec3 v3Ctr(newCtr.x(), newCtr.y(), newCtr.z()); 
osg::Vec3 v3Up(newUp.x(), newUp.y(), newUp.z());

pMainCam-setViewMatrixAsLookAt(v3Eye, v3Ctr, v3Up);  

This works well. Now I want to be able to have 
a function that gives the translation / orientation
from the current view matrix:

/*
getView() method

Find position and orientation parameters from view matrix
*/

osg::Matrix viewMat = pMainCam-getViewMatrix();
osg::Matrix invViewMat;
invViewMat.invert(viewMat);
osg::Vec3 translate = invViewMat.getTrans();

With this code I can recuperate the initial translation 
(0.1443978698344, 0.0204530392050, 0.0124436690688).

Question 1:

How can I recuperate the initial rotation ?
(5.4461109291, -4.7768289550, 90.9259008041);

Question 2:

I'd like to add a trackball manipulator to my viewer.
I want to then position the view manually similar to what I 
do in my setView() method. When I read back the translation,
the value is very different from (0.1443978698344, 0.0204530392050, 
0.0124436690688).
How can I adapt my getView() to handle the trackball and give me
the value that I want ?

Any help / suggestion would be highly appreciated as I am struggling
with this.


best regards,


bill



-Original Message-
From: [EMAIL PROTECTED] on behalf of J.P. Delport
Sent: Fri 9/28/2007 2:36 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Trackball and view question
 
Hi,

I am attaching an old email below that I think addressed some of the 
same issues you are having.

Also attached is a code snippet of a modified manipulator base class I use.

regards
jp

Code:
---8--
/** get by distance, rotation, center. */
virtual void getDRC(double distance, osg::Quat rotation, osg::Vec3d 
center) {
distance = _distance;
rotation = _rotation;
center = _center;
}

/** set by distance, rotation, center. This keeps the focus point 
correct. */
virtual void setByDRC(double distance, osg::Quat rotation, osg::Vec3d 
center) {
_distance = distance;
_rotation = rotation;
_center = center;
_thrown = false;
flushMouseEventStack();
}

Old email:
---8--
Hi Morne,

I've done something like this, though not exactly the same. One gotcha I
found was that getting the matrix from the Trackball was not enough to
reset it later. Internally the trackball works with a distance, rotation
and center, (thats a scalar, quat and vec3) and all this info is not
encoded in the final matrix used for drawing. I added getDRC and
setByDRC to the cameras I have.

You can prob find the code for these in the list archives. If you don't,
let me know.

regards
jp

ps. are you in South Africa by any chance?

Morné Pistorius wrote:
   Hi,
  
   I have a scene with various models loaded.  I want to be able to double
   click on a model and have the camera move and position itself in front
   of the model, and afterwards return to the default trackball 
manipulator.
  
   I looked at the osgcamera and osganimation examples and I'm trying to
   come up with a way of doing this.  These are my thoughts:
  
   1. Somehow get the current camera position and attitude from the
   trackball manipulator.
   2. Compute an animation path from this point to a point in front of the
   model.
   3. Replace the trackball manipulator with an AnimationPathManipulator
   and set the animation
   4. Once it is done, replace it with with the original trackball
   manipulator and set its home position to the current camera position.
  
   Does this sound like the right way to go forward?  I would appreciate
   any feedback on this, pointers or gothcas from people with more
   experience than I have.  Also

Re: [osg-users] Trackball and view question

2007-09-30 Thread Robert Osfield
Hi Bill,

The camera manipulators role is to modifying the view matrix so I'm a
bit perplexed that you are suprised by this.

Also please considering move from SimpleViewer up to osgViewer::Viewer
working as an embedded viewer in 2.x rather than using SimpleViewer as
it only existed for a short while and has been totally superseded.

Robert.

On 9/18/07, Poirier, Guillaume [EMAIL PROTECTED] wrote:




 Hello everyone,

  I am using a SimpleViewer. I set up a post draw callback on its main
 camera. In it
  I read the camera eye, center, and up vectors. Initially, this give me (0,
 0, 0),
  (0, 0, -1), and (0, 1, 0) respectively. This is what I expect and it gives
 me a
  particular view of my scene.

  Now I add a trackball manipulator to the main camera and set up the view
 similar
  to what I had previously. When I read back the data it is quite different.
 I would have
  expected the same camera position / orientation than before since what I
 see is
  similar. Unless the trackball affects the model position / orientation and
 not just
  the view ? How can I use a trackball and read back in the post draw
 callback the
  values I want ?


  sincerely,


  Bill
 ___
 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


Re: [osg-users] Trackball and view question

2007-09-28 Thread J.P. Delport
Hi,

I am attaching an old email below that I think addressed some of the 
same issues you are having.

Also attached is a code snippet of a modified manipulator base class I use.

regards
jp

Code:
---8--
/** get by distance, rotation, center. */
virtual void getDRC(double distance, osg::Quat rotation, osg::Vec3d 
center) {
distance = _distance;
rotation = _rotation;
center = _center;
}

/** set by distance, rotation, center. This keeps the focus point 
correct. */
virtual void setByDRC(double distance, osg::Quat rotation, osg::Vec3d 
center) {
_distance = distance;
_rotation = rotation;
_center = center;
_thrown = false;
flushMouseEventStack();
}

Old email:
---8--
Hi Morne,

I've done something like this, though not exactly the same. One gotcha I
found was that getting the matrix from the Trackball was not enough to
reset it later. Internally the trackball works with a distance, rotation
and center, (thats a scalar, quat and vec3) and all this info is not
encoded in the final matrix used for drawing. I added getDRC and
setByDRC to the cameras I have.

You can prob find the code for these in the list archives. If you don't,
let me know.

regards
jp

ps. are you in South Africa by any chance?

Morné Pistorius wrote:
   Hi,
  
   I have a scene with various models loaded.  I want to be able to double
   click on a model and have the camera move and position itself in front
   of the model, and afterwards return to the default trackball 
manipulator.
  
   I looked at the osgcamera and osganimation examples and I'm trying to
   come up with a way of doing this.  These are my thoughts:
  
   1. Somehow get the current camera position and attitude from the
   trackball manipulator.
   2. Compute an animation path from this point to a point in front of the
   model.
   3. Replace the trackball manipulator with an AnimationPathManipulator
   and set the animation
   4. Once it is done, replace it with with the original trackball
   manipulator and set its home position to the current camera position.
  
   Does this sound like the right way to go forward?  I would appreciate
   any feedback on this, pointers or gothcas from people with more
   experience than I have.  Also, if there are any examples that 
better fit
   what I am trying to do, I would be much obliged.
  
   Thank you kindly,
   Morne
  


---8--


Poirier, Guillaume wrote:
 Well this is what I was trying, using 
 viewer.getCamera()-getViewMatrixAsLookAt(osg::Vec3 eye, osg::Vec3 
 center, osg::Vec3 up, float lookDistance=1.0f). In step 2 (with trackball 
 manipulator) I read back the 
 eye, center, and up values in the camera post draw callback. When the pose is 
 almost identical as in the 
 first step, I read the values and they look quite different than what I was 
 setting in the first step. I am still 
 unclear whether this is normal or not. So my question is, if it's normal, 
 is there a transformation 
 I can do to recuperate the step 1 values ? Or do I need to implement a custom 
 view manipulator to achieve
 what I am looking for ?
 
 regards,
 
 
 bill
 
 -Original Message-
 From: [EMAIL PROTECTED] on behalf of Alberto Luaces
 Sent: Thu 9/27/2007 4:38 AM
 To: OpenSceneGraph Users
 Subject: Re: [osg-users] Trackball and view question
  
 Hi Robert et al.
 
 Let me explain what I want to do accomplish an example:
 
 I load a model with no camera manipulator. I know the camera parameters
 (eye, ctr, up)
 that yield a desired pose. I set the viewer camera with those parameters and
 obtain the
 desired pose.
 
 Now I want to assume that I don't know those parameters. A user loads a
 model with a trackball
 manipulator. He / she can manipulate the model until the desired pose is
 obtained and
 recuperate the camera parameters (eye, ctr, up), which should be what I used
 in the previous
 step...
 
 Is that more clear ? How would I achieve this ?
 
 regards,
 
 
 Bill
 
 
 What about osg::Camera::getViewMatrixAsLookAt (osg::Vec3 eye, osg::Vec3 
 center, osg::Vec3 up, float lookDistance=1.0f) ?
 
 Alberto

-- 
This message is subject to the CSIR's copyright terms and conditions, e-mail 
legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at 
http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their 
support.

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


Re: [osg-users] Trackball and view question

2007-09-26 Thread Poirier, Guillaume

Hi Robert et al.

Let me explain what I want to do accomplish an example:

I load a model with no camera manipulator. I know the camera parameters (eye, 
ctr, up)
that yield a desired pose. I set the viewer camera with those parameters and 
obtain the
desired pose.

Now I want to assume that I don't know those parameters. A user loads a model 
with a trackball 
manipulator. He / she can manipulate the model until the desired pose is 
obtained and
recuperate the camera parameters (eye, ctr, up), which should be what I used in 
the previous
step...

Is that more clear ? How would I achieve this ?

regards,


Bill


-Original Message-
From: [EMAIL PROTECTED] on behalf of Robert Osfield
Sent: Tue 9/18/2007 11:28 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Trackball and view question
 
Hi Bill,

The camera manipulators role is to modifying the view matrix so I'm a
bit perplexed that you are suprised by this.

Also please considering move from SimpleViewer up to osgViewer::Viewer
working as an embedded viewer in 2.x rather than using SimpleViewer as
it only existed for a short while and has been totally superseded.

Robert.

On 9/18/07, Poirier, Guillaume [EMAIL PROTECTED] wrote:




 Hello everyone,

  I am using a SimpleViewer. I set up a post draw callback on its main
 camera. In it
  I read the camera eye, center, and up vectors. Initially, this give me (0,
 0, 0),
  (0, 0, -1), and (0, 1, 0) respectively. This is what I expect and it gives
 me a
  particular view of my scene.

  Now I add a trackball manipulator to the main camera and set up the view
 similar
  to what I had previously. When I read back the data it is quite different.
 I would have
  expected the same camera position / orientation than before since what I
 see is
  similar. Unless the trackball affects the model position / orientation and
 not just
  the view ? How can I use a trackball and read back in the post draw
 callback the
  values I want ?


  sincerely,


  Bill
 ___
 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

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


[osg-users] Trackball and view question

2007-09-18 Thread Poirier, Guillaume

Hello everyone,
 
I am using a SimpleViewer. I set up a post draw callback on its main camera. In 
it 
I read the camera eye, center, and up vectors. Initially, this give me (0, 0, 
0),
(0, 0, -1), and (0, 1, 0) respectively. This is what I expect and it gives me a 
particular view of my scene.

Now I add a trackball manipulator to the main camera and set up the view similar
to what I had previously. When I read back the data it is quite different. I 
would have
expected the same camera position / orientation than before since what I see is 
similar. Unless the trackball affects the model position / orientation and not 
just
the view ? How can I use a trackball and read back in the post draw callback the
values I want ?


sincerely,


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


Re: [osg-users] Trackball and view question

2007-09-18 Thread Christophe Medard
Trackball and view questionHi,

The trackballManipulator recomputes the home position (should be called home 
positions in fact since there are three of them) when the scene is set on the 
osgViewer if you don't call 
TrackballManipulator::setAutoComputeHomePosition(false).

The View Matrix you'll get the first time is highly dependent of the 
TrackballManipulator::_homeCenter value (among others).
Since it's a lookAt Matrix that is computed, you can have the impression your 
point of view is the same when looking your window even if you get different 
values in your code (if the direction of sight is the same, unnormalized, for 
example).
Hope it helps,

-- 
Christophe Médard
Société OKTAL (http://www.oktal.fr)
2 impasse Boudeville
31100 Toulouse (France)
Tél. : (+33) 5 62 11 50 10
Fax : (+33) 5 62 11 50 29


- Original Message - 
From: Poirier, Guillaume 
To: osg-users@lists.openscenegraph.org 
Sent: Tuesday, September 18, 2007 4:19 PM
Subject: [osg-users] Trackball and view question




Hello everyone,

I am using a SimpleViewer. I set up a post draw callback on its main camera. In 
it
I read the camera eye, center, and up vectors. Initially, this give me (0, 0, 
0),
(0, 0, -1), and (0, 1, 0) respectively. This is what I expect and it gives me a
particular view of my scene.

Now I add a trackball manipulator to the main camera and set up the view similar
to what I had previously. When I read back the data it is quite different. I 
would have
expected the same camera position / orientation than before since what I see is
similar. Unless the trackball affects the model position / orientation and not 
just
the view ? How can I use a trackball and read back in the post draw callback the
values I want ?


sincerely,


Bill 



___
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