|
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
|
03-23-2009 07:55
How can I calculate the rotation of a line connecting two known points?
_____________________
Visit ChereeMotion - Life's Best Pinup Poses http://slurl.com/secondlife/Wild%20Rice/38/230/51
|
|
Te Tenjin
Registered User
Join date: 1 Aug 2007
Posts: 4
|
03-23-2009 08:47
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
03-23-2009 10:58
From: Cheree Bury How can I calculate the rotation of a line connecting two known points? Tell me more! rotate? around one end or the middle or the global zero? Or do you want to rotate an object with the line as an axis? Mind reading isn't my best 
_____________________
From Studio Dora
|
|
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
|
03-23-2009 19:46
From: Dora Gustafson Tell me more! rotate? around one end or the middle or the global zero? Or do you want to rotate an object with the line as an axis? Mind reading isn't my best  From the other thread that you answered: From: Cheree Bury As I follow along a defined path, when I change directions, I want to place a prim at that spot and rotate it to split the angle of the change of direction. I rotation slerp( rotation a, rotation b, float t ) { return llAxisAngle2Rot( llRot2Axis(b /= a), t * llRot2Angle(b)) * a; }//Written collectively, Taken from http://forums.secondlife.com/showthread.php?p=536622
I'm still trying to figure this out. So, if I make a 90 degree turn, I want to place a prim rotated at 45 degrees to each line. A 60 degree turn would yield a 30 degree rotation, and so forth all the way up to (but not including) 360 degrees.) I am now using the slerp function and llRotBetween mentioned earlier but cannot get the rotations right to pass to it.
_____________________
Visit ChereeMotion - Life's Best Pinup Poses http://slurl.com/secondlife/Wild%20Rice/38/230/51
|
|
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
|
Sample code
03-23-2009 20:30
I have pared my code down to this so maybe someone can see what I am doing wrong:
rotation slerp( rotation a, rotation b, float t ) { return llAxisAngle2Rot( llRot2Axis(b /= a), t * llRot2Angle(b)) * a; }//Written collectively, Taken from http://forums.secondlife.com/showthread.php?p=536622
rotation RotBetween(vector start, vector end) //adjusts quaternion magnitude so (start * return == end) {//Authors note: I have never had a use for this but it's good to know how to do it if I did. rotation rot = llRotBetween(start, end); llSay(0, (string)start); llSay(0, (string)end); if(start) { if(end) { float d = llSqrt(llVecMag(end) / llVecMag(start)); return <rot.x * d, rot.y * d, rot.z * d, rot.s * d>; } } return rot; }//Strife
default { state_entry() { }
touch_start(integer total_number) { vector pos1 = <0.0, 2.0, 1.0>; //beginning vector pos2 = <0.0, 1.0, 1.0>; //middle vector pos3 = <0.0, 1.0, 2.0>; //end rotation rot1 = RotBetween(pos1, pos2); //first line rotation rot2 = RotBetween(pos2, pos3); //second line rotation rot3 = slerp(rot1, rot2, 0.5); //split the difference in the rotations llSay(0, "rot1 = " + (string)llRot2Euler(rot1)); llSay(0, "rot2 = " + (string)llRot2Euler(rot2));
vector EulerRot = llRot2Euler(rot3); llSay(0, "rot3 = " + (string)EulerRot); //this is the rotation I want to set my prim to llSay(0, "degrees = <" + (string)(EulerRot.x * RAD_TO_DEG) + ", " + (string)(EulerRot.y * RAD_TO_DEG) + ", " + (string)(EulerRot.z * RAD_TO_DEG) + ">"); } }
With these numbers, I would expect the output to be 45 degrees, but I never get that.
_____________________
Visit ChereeMotion - Life's Best Pinup Poses http://slurl.com/secondlife/Wild%20Rice/38/230/51
|
|
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
|
03-24-2009 09:29
Hello, is this mic on? 
_____________________
Visit ChereeMotion - Life's Best Pinup Poses http://slurl.com/secondlife/Wild%20Rice/38/230/51
|