Re: [osg-users] moving object along rotated vector

2010-07-02 Thread J.P. Delport

Hi,

as you've seen, q*f in OSG is shorthand for (qc * fq * q). It's the 
opposite of what one might expect. There are some inconsistencies... go 
here:


http://article.gmane.org/gmane.comp.graphics.openscenegraph.user/43425

Also, like you said, rotations can be visualised either from the 
coordinate system's point of view or the object's. See also here:


http://article.gmane.org/gmane.comp.graphics.openscenegraph.user/37721

cheers
jp


On 01/07/10 17:43, Tom Pearce wrote:

The various methods we're talking about for figuring out a forward vector are 
rotating in different directions - here's a bit of test code to confirm.


Code:
FILE* fp = fopen(printout.txt, w);
osg::Vec3 f(0., 1., 0.);
osg::Quat fq(0., 1., 0., 0.);
osg::Quat q(osg::DegreesToRadians(45.0), osg::Vec3(0., 0., 1.));
osg::Quat qc = q.conj();
osg::Vec3 r1 = q*f;
osg::Vec3 r2 = (q * fq * qc).asVec3();
osg::Vec3 r3 = q.inverse() * f;
fprintf(fp, quat *  vec: %f %f %f\n, r1.x(), r1.y(), r1.z());
fprintf(fp, q * fq * qc: %f %f %f\n, r2.x(), r2.y(), r2.z());
fprintf(fp, q.inverse*f: %f %f %f\n, r3.x(), r3.y(), r3.z());
fclose(fp);



Results:
quat *  vec: -0.707107 0.707107 0.00
q * fq  * qc: 0.707107 0.707107 0.00
q.inverse*f: 0.707107 0.707107 0.00

Since the test rotation you've been using is close to pi/2, it looks like the 
axis is switched... but really, it's just rotated in the opposite direction 
than you expect.

When you get a rotation quat out of of a PAT or MatrixTransform, (I guess) it's 
giving you the coordinate system transform.  When you transform a coordinate 
system in one direction, it's equivalent to rotating vectors in the opposite 
direction.  So if you try and rotate a vector directly by this transform, ie by 
doing quat*vec, your forward vector will be rotated an equal amount but in the 
opposite direction from how the model appears on the screen.

By doing quat * vec * quat.conj(), or by doing quat.inverse() * vec, you're 
applying the coordinate system transform to your vector, and everything works 
out such that your forward vector and your on-screen model have rotated 
together.

I'm still quite new to these maths, so please, an expert should pitch in!  I am 
basing this all on my own experiences with moving objects around in osg.

Cheers,
Tom[/code]

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





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



--
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] moving object along rotated vector

2010-07-02 Thread Tom Pearce
Hi,


 q*f in OSG is shorthand for (qc * fq * q). It's the 
 opposite of what one might expect. There are some inconsistencies...


My approach is always to try it the way I think it should work, and when it 
doesn't, start playing with the multiplication order - eventually something 
works.  It does mess with my head a bit when I try and understand the math, but 
in the end as long as  my code does what I want, I'm don't worry much.

Just out of curiosity, does anyone know why quat*vec3 was implemented the way 
it was?  Everything I've read (outside of osg) about using quats to rotate 
points (ie vectors) says q*fq*qc is the way to do it.

Cheers,
Tom

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





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


Re: [osg-users] moving object along rotated vector

2010-07-02 Thread J.P. Delport

Hi,

On 02/07/10 17:36, Tom Pearce wrote:

Hi,



q*f in OSG is shorthand for (qc * fq * q). It's the opposite of
what one might expect. There are some inconsistencies...



My approach is always to try it the way I think it should work, and
when it doesn't, start playing with the multiplication order -
eventually something works.  It does mess with my head a bit when I
try and understand the math, but in the end as long as  my code does
what I want, I'm don't worry much.

Just out of curiosity, does anyone know why quat*vec3 was implemented
the way it was?  Everything I've read (outside of osg) about using
quats to rotate points (ie vectors) says q*fq*qc is the way to do
it.


I think it's merely a convenient overload of * that matches 
matrix*vec... If you go look at the math in the Quat function, it does 
qc*vq*q.


jp



Cheers, Tom

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





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



--
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] moving object along rotated vector

2010-07-01 Thread J.P. Delport

Hi,

you'll have to give me more details on your coordinate system. If your 
object default to pointing in +X, to move it backward you will need to 
use Q*-X. How are you rotating the object? About which axis?


jp

On 01/07/10 01:22, Sanat Talmaki wrote:

Hi jp,

Thanks for those suggestions. I implemented them but I am probably still doing 
something wrong as the behavior is not as expected.

I used the debugger to check the values of the vectors but the numbers dont 
make sense to me. Thus is the case of Down arroy key and thus I used (0, -1, 0) 
as my default forward pointing vector. But what I observed is the object moving 
forward and its y-value increasing instead of decreasing.

Initial position = positionArray = (132.86, 78.277, 18.48)
Initial attitude= quat = (0, 0, 0.719, 0.695)

vector = quat*(0,-1,0) = (0.99, 0.035, 0.00)
vector*2  = (1.998, 0.069, 0)

PositionArray = PositionArray + vector*2 = (134.86, 78.34, 18.48)
---

code:

Code:
positionArray = PATCurrent-getPosition();
quat = PATCurrent-getAttitude();
vector = quat.operator *(osg::Vec3(0, 1.0, 0.0));
vector.operator *=(2);
positionArray = positionArray.operator +(vector);
PATCurrent-setPosition(positionArray);




Best,
Sanat

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





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



--
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] moving object along rotated vector

2010-07-01 Thread Roberts, Gareth (UK)
I have bought some models of motor vehicles and found that some have the
X axis as forwards and some the Y axis, which can cause confusion when
you are tryiong to orient and move a model.
If you load up a model on its own in osgviewer you will see the rear of
the model if the Y axis is forwards, the side if X is forwards. 
The Quat returned by getAttitude is the rotation from the default
orientation.
The four components represent a vector and an angle - but let the OSG
code worry about that.

Try something like this:

osg::Quat Qmodel = osg::Quat(0.0, osg::Vec3(0.0,1.0,0.0));
osg::Quat Qturn = osg::Quat(0.1, osg::Vec3(0.0,0.0,1.0));
osg::Vec3 pos, vel;


//initialise pos, vel

//loop
  Qmodel = Qmodel*Qturn;
  vel = Qturn*vel;
  pos = pos + vel;
  model-setAttitude (Qmodel);
  model-setPosition(pos);
//end loop

Your model should go round in circles, moving the way it's facing.


-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Sanat
Talmaki
Sent: 01 July 2010 00:28
To: osg-users@lists.openscenegraph.org
Subject: Re: [osg-users] moving object along rotated vector


   *** WARNING ***

This mail has originated outside your organization, either from an
external partner or the Global Internet. 
 Keep this in mind if you answer this message. 

Hi Tom,

Could you tell me where you read up the quaternion parts that helped you
figure out the code you posted. I went through some stuff on the wiki
and another pdf on quaternions that I found. But in both those cases,
they refer to a quat as something causing rotation from vector v1 to v2.


So in this case when we call PAT-getAttitude() and get a quat, what
exactly are we getting, which 2 vectors are we rotating between ?
Secondly, I'm also a little confused as to what the 4 values in a quat
object represent  

Thanks!

Sanat

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





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


This email and any attachments are confidential to the intended recipient and 
may also be privileged. If you are not the intended recipient please delete it 
from your system and notify the sender. You should not copy it or use it for 
any purpose nor disclose or distribute its contents to any other person. 

MBDA UK Limited, a company registered in England and Wales, registration number 
3144919 whose registered office is at Six Hills Way, Stevenage, Hertfordshire, 
SG1 2DA, England.


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] moving object along rotated vector

2010-07-01 Thread Sanat Talmaki
Hi,

I tried a slightly different approach from using Quaternions and so far its 
working. After using the debugger in visual studio and checking the angle 
returned by the function-
PAT- getAttitude().getRotate(angle, vector);
angleDegrees = osg::RadiansToDegrees(angle);

The angle always pointed in the direction of the vector I wanted my object to 
move along. This gave me the idea to simply use cos and sin of that angle and 
increment current x and y position from PAT by the vlaue of cos(angle) and 
sin(angle) respectively.

So I did:
y = sin(angle);
x = cos(angle);
positionArray.y() -= y;  //or + for up key
positionArray.x() -= x;
//set PAT to new position array.

And because with sin and cos of angle 90 giving +ve and -ve values just from 
the function, it takes care of forward backward movement even when facing the 
wrong way eg- if i've rotated enough to be facing backwards and then hit 
forward, the x, y values from the angle between 180 to 270 give -ve values and 
so it moves the object back keeping the UP key logic intact.

Hope I was able to explain what I tried to do. 

Thanks for the help though, I will try and figure out how to do this using Quat.

Best,
Sanat

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





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


Re: [osg-users] moving object along rotated vector

2010-07-01 Thread Sanat Talmaki
Hi Rob,

Yes I have faced that situation that you're talking about. Infact I had to 
rotate my model by 90 in the initial PAT while placing my model in the scene. 
Else the front of my model was facing the +ve x-axis in osg.

I understood the pos vector which I'll get from my PAT but wasn't clear about 
what you initialized the vel vector. Is it just (1,1,1) ? (assuming I want to 
move forward/back by 1 unit on each keyboard hit)

Thanks

Sanat.

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





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


Re: [osg-users] moving object along rotated vector

2010-07-01 Thread Roberts, Gareth (UK)
No, it will be (1,0,0) if the X axis is forwards, (0,1,0) if the Y axis
is forwards. 

-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Sanat
Talmaki
Sent: 01 July 2010 13:46
To: osg-users@lists.openscenegraph.org
Subject: Re: [osg-users] moving object along rotated vector


   *** WARNING ***

This mail has originated outside your organization, either from an
external partner or the Global Internet. 
 Keep this in mind if you answer this message. 

Hi Rob,

Yes I have faced that situation that you're talking about. Infact I had
to rotate my model by 90 in the initial PAT while placing my model in
the scene. Else the front of my model was facing the +ve x-axis in osg.

I understood the pos vector which I'll get from my PAT but wasn't clear
about what you initialized the vel vector. Is it just (1,1,1) ?
(assuming I want to move forward/back by 1 unit on each keyboard hit)

Thanks

Sanat.

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





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


This email and any attachments are confidential to the intended recipient and 
may also be privileged. If you are not the intended recipient please delete it 
from your system and notify the sender. You should not copy it or use it for 
any purpose nor disclose or distribute its contents to any other person. 

MBDA UK Limited, a company registered in England and Wales, registration number 
3144919 whose registered office is at Six Hills Way, Stevenage, Hertfordshire, 
SG1 2DA, England.


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] moving object along rotated vector

2010-07-01 Thread Sanat Talmaki
Hi jp,

I missed your earlier post. But here's what I'm doing:

The coordinate system for my object is pointing to the +ve Y-Axis (into the 
screen). When I hit the UP key I increment Y value by 1 and DOWN decrement by 
1. 
I use the LEFT and RIGHT keys to rotate about (0,0,1).

I am able to get the object to move the way I want without using quat and using 
only the angle from the getAttitude().getRotate(angle, vector) function. But I 
believe I'll need to use quat for something in future so wanted to know how to 
do this using quat. 

Thanks,
Sanat

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





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


Re: [osg-users] moving object along rotated vector

2010-07-01 Thread Tom Pearce
The various methods we're talking about for figuring out a forward vector are 
rotating in different directions - here's a bit of test code to confirm.


Code:
FILE* fp = fopen(printout.txt, w);
osg::Vec3 f(0., 1., 0.);
osg::Quat fq(0., 1., 0., 0.);
osg::Quat q(osg::DegreesToRadians(45.0), osg::Vec3(0., 0., 1.));
osg::Quat qc = q.conj();
osg::Vec3 r1 = q*f;
osg::Vec3 r2 = (q * fq * qc).asVec3();
osg::Vec3 r3 = q.inverse() * f;
fprintf(fp, quat *  vec: %f %f %f\n, r1.x(), r1.y(), r1.z());
fprintf(fp, q * fq * qc: %f %f %f\n, r2.x(), r2.y(), r2.z());
fprintf(fp, q.inverse*f: %f %f %f\n, r3.x(), r3.y(), r3.z());
fclose(fp);



Results:
quat *  vec: -0.707107 0.707107 0.00
q * fq  * qc: 0.707107 0.707107 0.00
q.inverse*f: 0.707107 0.707107 0.00

Since the test rotation you've been using is close to pi/2, it looks like the 
axis is switched... but really, it's just rotated in the opposite direction 
than you expect.

When you get a rotation quat out of of a PAT or MatrixTransform, (I guess) it's 
giving you the coordinate system transform.  When you transform a coordinate 
system in one direction, it's equivalent to rotating vectors in the opposite 
direction.  So if you try and rotate a vector directly by this transform, ie by 
doing quat*vec, your forward vector will be rotated an equal amount but in the 
opposite direction from how the model appears on the screen.

By doing quat * vec * quat.conj(), or by doing quat.inverse() * vec, you're 
applying the coordinate system transform to your vector, and everything works 
out such that your forward vector and your on-screen model have rotated 
together.

I'm still quite new to these maths, so please, an expert should pitch in!  I am 
basing this all on my own experiences with moving objects around in osg.

Cheers,
Tom[/code]

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





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


Re: [osg-users] moving object along rotated vector

2010-06-30 Thread J.P. Delport

Hi,

to get a vector to where the object is pointing, just multiply the 
default point-to-front vector, I assume (1,0,0) in your case, with the 
quaternion you have for the rotation. Then add this vector multiplied by 
some amplitude to the current position.


jp

On 30/06/10 00:16, Sanat Talmaki wrote:

Hi,

I am attaching a screenshot of what I am trying to do. In the screenshot you 
can see 2 objects placed on a terrain. The lower one is rotated about Z axis 
and I use the keyboard UP and DOWN keys to move the object along the Y-axis in 
the terrain.

However even after I have rotated the object, I am not able to figure out how 
to get the new vector along which the object is now pointing.

I figured I would find the angle I have rotated the object by using Quat and 
then depending on angle value 0-90, 90-180, 180-270 or 270-360, find the 
tangent of the angle and move it that way. But I'm sure im complicating things 
here.

The code I'm using to move the object and rotate is pasted below: (i've only 
copied the cases for Up and rotate right as down and left are identical)

else if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Up)
 {
std::cout  textBox-getText()  std::endl;   
 
positionArray = PATCurrent-getPosition();
//vector = PATCurrent-getAttitude().asVec3();
PATCurrent-getAttitude().getRotate(angle,vector);
angleDegrees = osg::RadiansToDegrees(angle);
y = positionArray.y();
x = positionArray.x();
x += vector.x();
y += 1;
positionArray.y()=y;
positionArray.x()=x;
PATCurrent-setPosition(positionArray);
return true;
}
else if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Right)
 {
//use key right to rotate the object to the right
quat = PATCurrent-getAttitude();
quat.getRotate(angle, vector);
angleDegrees = osg::RadiansToDegrees(angle);
//if angle is 0 make it 360
if(angleDegrees= 1)
{
  angleDegrees = 360;
}
angleDegrees -= 1;

quat.makeRotate(osg::DegreesToRadians(angleDegrees),vector);
PATCurrent-setAttitude(quat);
//PATCurrent-setPosition(vector);
}

If you can tell me what I am missing out here I'd be very thankful.

Also, if there is some literature out there that deals with this, I'd be more 
than happy to study it.

Thanks,

Sincerely,

Sanat

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




Attachments:
http://forum.openscenegraph.org//files/test_sc1_368.jpg


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



--
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] moving object along rotated vector

2010-06-30 Thread Sanat Talmaki
Hi jp,

I'm not sure if I've entirely followed what you were saying but here's what I 
thought I you meant-

positionArray = PATCurrent-getPosition();
vector = PATCurrent-getAttitude().asVec3()*(osg::Vec3 (1, 0, 0));
xTemp = vector.x();
yTemp = vector.y();
zTemp = vector.z();

xTemp *= 1;
yTemp *= 1;
zTemp *= 1;


x = PositionArray.x() + xTemp;
y = PositionArray.y() + yTemp;
z = PositionArray.z() + zTemp;

//then set current position using x,y,z and set as new PAT position.

Correct me if I'm wrong..

Thanks!

Sanat

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





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


Re: [osg-users] moving object along rotated vector

2010-06-30 Thread J.P. Delport

Hi,

On 30/06/10 17:05, Sanat Talmaki wrote:

Hi jp,

I'm not sure if I've entirely followed what you were saying but here's what I 
thought I you meant-

positionArray = PATCurrent-getPosition();
vector = PATCurrent-getAttitude().asVec3()*(osg::Vec3 (1, 0, 0));


skip the asVec3, you want to multiply by the orientation Quat. IOW you 
want to rotate your object's default front vector to where it is 
pointing in space.


Quat = PATCurrent-getAttitude();
vector = Quat * osg::Vec3 (1, 0, 0)

now vector would point to where your object is pointing.


xTemp = vector.x();
yTemp = vector.y();
zTemp = vector.z();

xTemp *= 1;
yTemp *= 1;
zTemp *= 1;


you should be able to scale the unit direction vector by a single 
multipy (see the Vec headers). Instead of *1, you should multiply by 
some scale that makes sense for you.





x = PositionArray.x() + xTemp;
y = PositionArray.y() + yTemp;
z = PositionArray.z() + zTemp;


same here, you can just add two vectors, you don't need to add component 
wise manually.




//then set current position using x,y,z and set as new PAT position.

Correct me if I'm wrong..


hope it works...

jp



Thanks!

Sanat

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





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


--
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] moving object along rotated vector

2010-06-30 Thread Tom Pearce
Hi,

I've been doing it this way, works like a charm:

Say your forward vector is (0, 1, 0), pointing along the y axis, make an  
with from this by adding a real coordinate (4th coordinate) of zero - (0, 1, 0, 
0).

You also have a rotation quat q, and take it's conjugate to get q_prime.
Then multiply as below to get the new forward quat, then get the vector from 
that.

q_prime = q.conj();
osg::Quat forward_quat(0., 1., 0. 0.);
osg::Quat rotated_foward = q * forward_quat * q_prime;

osg::Vec3 new_forward_vec = rotated_forward.asVec3();


I'm no expert so take this with a grain of salt, but when I tried the method JP 
outlined (which was my first shot at doing it) the rotated vector wasn't 
correct (or at least not what I expected).  Looking up quaterion rotation 
online, wikipedia for example, I found the method I described above.

Of course, JP's method works spot on for what to do with your object when 
you're moving it along your newly rotated forward vector by however far you 
want to move it.


Cheers,
Tom

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





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


Re: [osg-users] moving object along rotated vector

2010-06-30 Thread Sanat Talmaki
Hi jp,

Thanks for those suggestions. I implemented them but I am probably still doing 
something wrong as the behavior is not as expected. 

I used the debugger to check the values of the vectors but the numbers dont 
make sense to me. Thus is the case of Down arroy key and thus I used (0, -1, 0) 
as my default forward pointing vector. But what I observed is the object moving 
forward and its y-value increasing instead of decreasing. 

Initial position = positionArray = (132.86, 78.277, 18.48)
Initial attitude= quat = (0, 0, 0.719, 0.695)

vector = quat*(0,-1,0) = (0.99, 0.035, 0.00)
vector*2  = (1.998, 0.069, 0)

PositionArray = PositionArray + vector*2 = (134.86, 78.34, 18.48)
---

code:

Code:
positionArray = PATCurrent-getPosition();
quat = PATCurrent-getAttitude();
vector = quat.operator *(osg::Vec3(0, 1.0, 0.0));
vector.operator *=(2);
positionArray = positionArray.operator +(vector);
PATCurrent-setPosition(positionArray);




Best,
Sanat

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





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


Re: [osg-users] moving object along rotated vector

2010-06-30 Thread Sanat Talmaki
Hi Tom,

Could you tell me where you read up the quaternion parts that helped you figure 
out the code you posted. I went through some stuff on the wiki and another pdf 
on quaternions that I found. But in both those cases, they refer to a quat as 
something causing rotation from vector v1 to v2. 

So in this case when we call PAT-getAttitude() and get a quat, what exactly 
are we getting, which 2 vectors are we rotating between ?
Secondly, I'm also a little confused as to what the 4 values in a quat object 
represent  

Thanks!

Sanat

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





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


[osg-users] moving object along rotated vector

2010-06-29 Thread Sanat Talmaki
Hi,

I am attaching a screenshot of what I am trying to do. In the screenshot you 
can see 2 objects placed on a terrain. The lower one is rotated about Z axis 
and I use the keyboard UP and DOWN keys to move the object along the Y-axis in 
the terrain.

However even after I have rotated the object, I am not able to figure out how 
to get the new vector along which the object is now pointing. 

I figured I would find the angle I have rotated the object by using Quat and 
then depending on angle value 0-90, 90-180, 180-270 or 270-360, find the 
tangent of the angle and move it that way. But I'm sure im complicating things 
here.

The code I'm using to move the object and rotate is pasted below: (i've only 
copied the cases for Up and rotate right as down and left are identical)

else if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Up)
{
std::cout  textBox-getText()  std::endl;   

positionArray = PATCurrent-getPosition();
//vector = PATCurrent-getAttitude().asVec3();
PATCurrent-getAttitude().getRotate(angle,vector);
angleDegrees = osg::RadiansToDegrees(angle);
y = positionArray.y();
x = positionArray.x();
x += vector.x();
y += 1;
positionArray.y()=y;
positionArray.x()=x;
PATCurrent-setPosition(positionArray);
return true;
} 
else if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Right)
{
//use key right to rotate the object to the right
quat = PATCurrent-getAttitude();
quat.getRotate(angle, vector);
angleDegrees = osg::RadiansToDegrees(angle);
//if angle is 0 make it 360
if(angleDegrees = 1)
{
  angleDegrees = 360;
}
angleDegrees -= 1;

quat.makeRotate(osg::DegreesToRadians(angleDegrees),vector);
PATCurrent-setAttitude(quat);
//PATCurrent-setPosition(vector);
}

If you can tell me what I am missing out here I'd be very thankful.

Also, if there is some literature out there that deals with this, I'd be more 
than happy to study it.

Thanks,

Sincerely,

Sanat

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




Attachments: 
http://forum.openscenegraph.org//files/test_sc1_368.jpg


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