Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Subtract rotation?

2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
01-27-2010 10:56
Hi,

I am trying have one object rez another and am having trouble with rotation.

The object doing the rezzing has a base roation of (270,0,0) (this is in euler), meaning, that the object is oriented correctly when it rotated this way.

A user can rotate the rezzing object in any direction and I want to have the object it rezzes rotated the same way. The problem is that the base rotation of the object that's being rezzed is <0,0,0>. I am trying to find the rotation I need to use in the call to llRezObject.

I tried various approaches to get the rotations to work out. I tried setting the X and Y components to zero, but that only works in a few cases; I also tried llRotBetween, but I don't think that's the right way to go.

Thanks -2fast
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
01-27-2010 11:26
rotation x_rot = < llSin( angle/2 ), 0, 0, llCos( angle/2 )>; // rotate angle around x-axis
with angle=3*PI/2 you get:
rotation x_rot = < 0.7071068, 0.0, 0.0, -0.7071068>; // rotate 270 degrees around x-axis

Use x_rot to rotate the rezzed object relative to the rezzing object:
llGetRot()*x_rot; to 'add' the rotation
llGetRot()/x_rot; to 'subtract' the rotation.
Which you want is not clear to me from your text, I hope it is clear to you:)

You will probably need to rotate the relative position by the same amount, as well
_____________________
From Studio Dora
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-27-2010 12:07
you might want to try my rotation help page, it contains formulas for rez offset rotations, and such... and is a little simpler than Dora's example
https://wiki.secondlife.com/wiki/User:Void_Singer/Rotations
_____________________
|
| . "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...
| -
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
01-27-2010 12:16
From: Dora Gustafson
Use x_rot to rotate the rezzed object relative to the rezzing object:
llGetRot()*x_rot; to 'add' the rotation
llGetRot()/x_rot; to 'subtract' the rotation.


Hi Dora - thanks for your reply but I am getting results like the ones I was getting before.

Maybe this will clarify...

The rezzing object A is rotated at <270,0,0>. What I'd like to have happen is that the rezzed object B rezzes, facing the same way as object A through a call to llRezObject. So, the values I am looking for are something like this:

* A = <270,0,0> then B=<0,0,0>
* A = <270,45,0> then B = <270,45,0>
* A= <0,90,270 then B = <0,0,270>

I got these results by rotating my objects together in-world and then noting the values. I thought of a lookup table, but that's not practical since the user can rotate the object A in any direction.

It gets more involved when I want something like this:

* A = <0,45,270> then B=<0,315,270> or...
* A = <35.25,30,215.25> then B=<324.75,330,215.25>

Cases in the first group are far more likely than the second examples, but I think there might be some way get the right values in all cases - I have no idea where to start.

Thanks -2fast
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
01-27-2010 12:29
From: Void Singer
you might want to try my rotation help page...
[/img]

Hi Void,

I looked there and tried this:

CODE

rotation x2 = llEuler2Rot(<270,0,0>*DEG_TO_RAD);
rotation x3=x2*llGetRot();


...it's almost exactly what I need - except that the rezzed prim is backwards. I can't login now, but maybe it is just a matter of changing the X value or using one of your formulas to reverse the rotation.

Regards -2fast
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-27-2010 15:14
If I've properly understood the situation, you've got a set-up that looks right with the rezzer rotated at whatever llEuler2Rot( < 270.0,0.0,0.0 > *DEG_TO_RAD) is and rezzed object rotated at ZERO_ROTATION.

If that's the case, try something like this
CODE


vector offset = < 5.0, 2.0, 1.0 > ; //or whatever it is

rotation rezzer_rot;// you could read the rotation by script, enter it here and comment out the next line
vector rezzer_rot_window = <270.00,0.00,00.00>; // the numbers in the rotation box in the edit window

rotation child_rot;// you could read the rotation by script, enter it here and comment out the next line
vector child_rot_window =<0.00,0.00,0. 00>;// the numbers in the rotation box in the edit window


default
{
state_entry()
{

rezzer_rot = llEuler2Rot(rezzer_rot_window*DEG_TO_RAD);

child_rot = llEuler2Rot(child_rot_window*DEG_TO_RAD);
offset = offset/rezzer_rot;
}

touch_start(integer total_number)
{
llRezAtRoot( // fixed typo
llGetInventoryName(INVENTORY_OBJECT,0), // fixed typo
llGetPos()+offset*llGetRot(),
ZERO_VECTOR,
(child_rot/rezzer_rot)*llGetRot(),
99);
}
}
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
01-28-2010 11:06
From: Innula Zenovka
If I've properly understood the situation, you've got a set-up that looks right with the rezzer...
[/php]

Outstanding - that works perfectly!

So it looks like there are two things at work here - thinking in terms of the rotations you want and this: (child_rot/rezzer_rot)*llGetRot();

I adapted this to reverse a dynamic rotation too - worked perfectly!

{ By the way - not sure if the forum ate it...the line in the touch_start event is missing 'llRezObject(' and the first L of llGetInventoryName }

-2fast
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-28-2010 13:18
From: 2fast4u Nabob
Outstanding - that works perfectly!

So it looks like there are two things at work here - thinking in terms of the rotations you want and this: (child_rot/rezzer_rot)*llGetRot();

I adapted this to reverse a dynamic rotation too - worked perfectly!

{ By the way - not sure if the forum ate it...the line in the touch_start event is missing 'llRezObject(' and the first L of llGetInventoryName }

-2fast
Fixed typos.. thanks for pointing them out. Glad it helped.

What the divisions there do is discount the local rotation when first you calculated the offset and rotations and set them to what they would have been had the rezzer prim been oriented at ZERO_ROTATION (i.e. makes them sim rotations, which is what llGetPos() and llGetRot() return) and the rezzed prim positioned and rotated correctly in relation to that. Then the *llGetRot() at run-time translates them to whatever the rezzer's local rotation happens to be when you use it.