Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

direction between two positions?

Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
02-24-2007 11:42
I need a rotation that corresponds to the direction between to positions, and rez an object with that orientation. Assume for now that the object is already "luckily" oriented, that is, if it needs to point <1,0,0> then the euler rotation <1,0,0> is the correct orientation.

Is this correct:

CODE

rotation orientation(vector p1, vector p2)
{
return (llEuler2Rot(llVecNorm(p2 - p1)));
}


This doesn't seem to work. Is my concept wrong, or should I look elsewhere for the problem?

Thanks!
Jeff
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
02-24-2007 11:55
From: Learjeff Innis
I need a rotation that corresponds to the direction between to positions, and rez an object with that orientation. Assume for now that the object is already "luckily" oriented, that is, if it needs to point <1,0,0> then the euler rotation <1,0,0> is the correct orientation.

Is this correct:

CODE

rotation orientation(vector p1, vector p2)
{
return (llEuler2Rot(llVecNorm(p2 - p1)));
}


This doesn't seem to work. Is my concept wrong, or should I look elsewhere for the problem?

Thanks!
Jeff


From what I'm seeing here, you are converting a rotational vecotor (p2 - p1) to a rotational vector (llEuler2Rot() ).

Just try:
{
return (llVecNorm(p2 - p1);)
}

you dont have Euler representations, you're already inputing rotational vectors, which llVecNorm() already expects. if you are working with eular, do this...

vector eul = <0, 0, 45>; //45 degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians rotation
rotation quat = llEuler2Rot( eul ); //convert to quaternion

hope that helps
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
02-24-2007 13:02
I don't think <1,0,0> is an Euler rotation. It is a vector pointing ahead one unit on the x-axis, right? (If not, ignore me forever.) An Euler is 3 angles, in radians.
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
02-24-2007 14:09
From: Lee Ponzu
I don't think <1,0,0> is an Euler rotation. It is a vector pointing ahead one unit on the x-axis, right? (If not, ignore me forever.) An Euler is 3 angles, in radians.


Vectors are just 3 floats, grouped together.

Whether they're used for "position" or "velocity" or "impuse" or "force" or "Euler rotation" is up to how the numbers are used.
_____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
02-24-2007 14:33
From: Ged Larsen
Vectors are just 3 floats, grouped together.

Whether they're used for "position" or "velocity" or "impuse" or "force" or "Euler rotation" is up to how the numbers are used.


Not necessarily... When converting an Euler vector to a rotation, if you want the rotation to be equivalent, then you need to pass an Euler rotation.

If you are just passing a direction vector, you will not get the results you expect.

And since llRezObject() expects a quaternion, the OP is asking how to turn a direction vector into a quaternion.
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
02-24-2007 14:42
From: RobbyRacoon Olmstead
Not necessarily... When converting an Euler vector to a rotation, if you want the rotation to be equivalent, then you need to pass an Euler rotation.

If you are just passing a direction vector, you will not get the results you expect.


Agreed. I was just making the rather silly point that vectors can be used to hold any arbitrary 3 floats. I frequently use them just to simplify passing a couple of values as a sort-of-array/list-of-3.

<1,0,0> _could_ be used as an EulerRotation, but it's probably not the one the OP wanted -- one that rotates about the X axis by 1 radian =~ 57.3 degrees.

But I was just being a dork. Ignore me now.
_____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
02-24-2007 15:01
OK, I've learned that a normalized vector is not the same thing as a Euler rotation. (Thanks Lee!)

But what's answer to my question? How do I convert two positions into a rotation?

I have positions p1 and p2. What I need is the rotation so that rezzing an object at p1 causes it to point to p2. What's the trick?

Thanks!
Jeff
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
02-24-2007 15:05
From: Learjeff Innis
But what's answer to my question? How do I convert two positions into a rotation?

No idea.. Rotations and quatrathingies always makes my head hurt. The example code on this page might be able to help you, tho..
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
02-24-2007 15:19
wow, thanks Meade!

I saw that function entry and dismissed it since it's not what I need at all. But the getRotToPointAxisAt() function looks like may have a clue for me. Thanks!

I'll let y'all know if it works out.

Cheers
Jeff