Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Setting an Objects Heading

Nur Ophuls
Registered User
Join date: 12 Jan 2007
Posts: 4
11-02-2007 17:26
I have a multi prim object with a head and a body, where the body is the primary linked object.

The object has an arbitrary location and rotation when dropped in world but visually it has an obvious heading - to where the head is pointing.

I would like to align the object with the closest compass direction (North, West, etc.).

I have used Linked messages to get the Head prim location communicated back to the body on a touch and then used llArcTan2 (using the y and x position values of the Head and the body) to get the angle that a line from the body position to the head position makes with the world.

I then compare the angle returned by llArcTan2 to find the closest compass direction and use the difference to rotate the object to the compass heading.

Is there an easier way? Seems awfully complicated and there are small rounding/LSL errors creeping in.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-02-2007 19:46
//-- assumes root prim is aligned zero rotation in the build
vector vVecCurrentFacing = llRot2Euler( llGetRot() ) * RAD_TO_DEG;
integer vIntCardinalDirection = llRound( vVecCurrentFacing.z / 90.0 );
llSetRot( llEuler2Rot( <.0, .0, vIntCardinalDirection * 90 * DEG_TO_RAD> );


that should work
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Nur Ophuls
Registered User
Join date: 12 Jan 2007
Posts: 4
11-03-2007 06:41
That assumption, unfortunately, is not the case. The actual object I'm trying to set the heading for is complex with many linked prims. The primary prim is an elongated egg shape that has been rotated in Z and X

But thanks for the suggestion and I will try that on the simple test case object.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-03-2007 09:08
From: Nur Ophuls
That assumption, unfortunately, is not the case. The actual object I'm trying to set the heading for is complex with many linked prims. The primary prim is an elongated egg shape that has been rotated in Z and X

But thanks for the suggestion and I will try that on the simple test case object.

if you calculate the roots rotation beforehand hard code and invert it, you should be ablle to correct for that..

somthing like set the object up at facing north, thendrop a new script in with
baseRot = llGetRot();
baseRot.s *= -1;
llOwnerSay( (string)baseRot );

delete that after, then in the code use

vector vVecCurrentFacing = baseRot * llRot2Euler( llGetRot() ) * RAD_TO_DEG; //-- cancel the roots rotation to get the object facing
integer vIntCardinalDirection = llRound( vVecCurrentFacing.z / 90.0 );
llSetRot( llEuler2Rot( <.0, .0, vIntCardinalDirection * 90 * DEG_TO_RAD> ) * baseRot); //-- offset the cardinal direction to align the facing with the roots rotation


pretty sure that's right, can't test atm, but it gives you an idea of how it might work... I may have the local and global rotations backwards, or even the inversion in spots... but those 2 factors should be the only thing off

or you could choose and unrotated root? =)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Nur Ophuls
Registered User
Join date: 12 Jan 2007
Posts: 4
11-03-2007 11:27
Being the lazy blonde that I am, I re-aligned the body - so your first suggestion works a treat.

I'm sure I could make the second one work after a while - but I need to study rotations more.

Thanks ever so much!!!