SetLocalRot in SetPrimitiveParams
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
09-07-2008 07:55
I am trying to both move a child prim and rotate it relative to the root prim at the same time. I have the correct individual llSetPos and llSetLocalPos working but the time delay is visually disturbing. I wanted to use llSetPrimitiveParams but cant work out the method. The information in the Wiki is confusing to say the least. So much text about quaternions and such. Why isn't there an option within llSetPrinitiveParams to do it? No scrub that question can't expect miracles from LSL. I've attached the best effort I have so far which works as long as the root prim is still unrotated globally. But when rotated about its Y axis the script goes wrong as I expected but can't see how to cure.
|
|
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
|
09-07-2008 08:41
I think this is the 'trick' you're looking for:
llSetPrimitiveParams([PRIM_ROTATION, rot / llGetRootRotation()]);
..where rot is the local rotation you're trying to achieve.
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-07-2008 09:33
What you want is extremely hard to do if you don't know how  it took me a month or two to find out: SetLocalRot(rotation localrot) { llSetRot(localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot())); } This function does it with llSetRot so the calculation applies for llSetPrimitiveParams as well! Reference: http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotationHappy scripting! ( you may donate me in world for letting you in on this big secret  )
_____________________
From Studio Dora
|
|
Billy Islander
Registered User
Join date: 3 Nov 2006
Posts: 35
|
09-08-2008 05:54
From: Gregory McLeod I am trying to both move a child prim and rotate it relative to the root prim at the same time. I have the correct individual llSetPos and llSetLocalPos working but the time delay is visually disturbing. I wanted to use llSetPrimitiveParams but cant work out the method. The information in the Wiki is confusing to say the least. So much text about quaternions and such. Why isn't there an option within llSetPrinitiveParams to do it? No scrub that question can't expect miracles from LSL. I've attached the best effort I have so far which works as long as the root prim is still unrotated globally. But when rotated about its Y axis the script goes wrong as I expected but can't see how to cure. here is a script i used to raise a ramp Gregory , this was posted somewhere on the forums but i lost the URL so credit to whoever posted the original , i just inserted "llSetPos(llGetLocalPos());" at line 44 to make it easier to adjust on rezz.Hope this helps. vector r_open = <0.0, 90.0, 0.0>; // This prim's rotations in degrees relative to root prim when this prim is open vector r_closed = <0.0,90.0,33.0>; // and when it's in the closed state
integer close_on_rez = TRUE; // Change to false to have the prim open on rez
// ================================================== ===== Nothing from here down needs modding.
rotation LocalRot(rotation localrot) { rotation LocRot = localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot()); return LocRot; }
open(string door) { llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_open * DEG_TO_RAD))]); }
close(string door) { llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_closed * DEG_TO_RAD))]); }
default { state_entry() { if (close_on_rez) { state closed; } else { state opened; } }
on_rez(integer rez) { llSetPos(llGetLocalPos()); llResetScript(); } }
state opened { state_entry() { open("left"); }
on_rez(integer rez) { llResetScript(); }
touch_start(integer n) { state closed; }
}
state closed { state_entry() { close("left"); }
on_rez(integer rez) { llResetScript(); }
touch_start(integer n) { state opened; }
}
Alternativeley check out Void Singers door script here , works a treat . http://forums.secondlife.com/showthread.php?t=220597&highlight=door
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
09-08-2008 08:40
From: Billy Islander here is a script i used to raise a ramp Gregory , this was posted somewhere on the forums but i lost the URL so credit to whoever posted the original , i just inserted "llSetPos(llGetLocalPos());" at line 44 to make it easier to adjust on rezz.Hope this helps. SNIPPED Alternativeley check out Void Singers door script here , works a treat . /54/a7/220597/1.htmlI had already checked out the various door scripts. Doors are usually vertical so the llSetLocalPos works fine for them. The problem is similar to car doors the rotation needed to be relative to the original rotation of the root prim. Your code is the first I have seen where the rotation is not around the Z axis. I will investigate, thanks. PS The note above from Pale Spectre is more general and I am progressing with it if I could only get the child prim to rotate 180 degrees without it flipping or rotating the wrong way.
|
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
09-08-2008 08:50
I think you want.. llSetPrimParams ([PRIM_POSITION, pos, PRIM_ROTATION, rot]); If you want to set the prims rotation to something relative to the root prims rotation, you need to do "rot /= llGetRootRotation();". See the 3rd bullet in the caveats of http://wiki.secondlife.com/wiki/LlSetRot .
|
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
09-08-2008 08:55
Also, in the OP, it looks like you've got hardcoded euler rotations that are in radians but you're multiplying by DEG_TO_RAD..
Only have to do that if you're using degrees (0-360). If you're in radians (0-TWO_PI), you don't have to (and should not!) multiply by DEG_TO_RAD.
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-08-2008 10:55
From: Gregory McLeod If I could only get the child prim to rotate 180 degrees without it flipping or rotating the wrong way. If you find a way to overcome 'flipping' please tell us!
_____________________
From Studio Dora
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
09-09-2008 01:51
From: Gregory McLeod ... if I could only get the child prim to rotate 180 degrees without it flipping or rotating the wrong way. If I understand correctly - you are rotating 180 degrees but the prim is going clockwise instead of counter-clockwise (or vice versa). One hack you could try is to rotate it just a little bit less than 180 degrees - 179.9 or something like that. If that still goes the wrong way try 180.1, or just a little bit more than 180. The prim should rotate in the direction that will take it along the shortest path, and I don't know if you can guarantee the direction used when the angle is exactly 180? Anyone know?
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
09-09-2008 03:25
From: Sindy Tsure Also, in the OP, it looks like you've got hardcoded euler rotations that are in radians but you're multiplying by DEG_TO_RAD..
Only have to do that if you're using degrees (0-360). If you're in radians (0-TWO_PI), you don't have to (and should not!) multiply by DEG_TO_RAD. I was using the Vectors in a previous attempt and switched to the radians in the absolute method to try to cure it. You will notice that the rotations use the vectors to generate them. I just didn't remove the redundant code in this version. Thanks for the reply.
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
09-09-2008 03:32
From: Ben Bacon If I understand correctly - you are rotating 180 degrees but the prim is going clockwise instead of counter-clockwise (or vice versa).
One hack you could try is to rotate it just a little bit less than 180 degrees - 179.9 or something like that. If that still goes the wrong way try 180.1, or just a little bit more than 180.
The prim should rotate in the direction that will take it along the shortest path, and I don't know if you can guarantee the direction used when the angle is exactly 180? Anyone know? It certainly takes the shortest path to get to the rotation required. I have tried the almost 180 trick you suggest and have made progress since I commented above. The movement I am doing is to move a flat square prim up a fraction flip it along one edge and then down a fraction. This works one way but not in the other unless I have made a mistake in the angles. The angles used in the vectors are -179, -180, to go one way and -1, 0 to revert. The zero gives it heart failure and flips the square. It wouldn't be a problem but the textures on the two flat faces is different and it becomes obvious it hasn't worked correctly. Ah well back the drawiing board.
|
|
Billy Islander
Registered User
Join date: 3 Nov 2006
Posts: 35
|
09-09-2008 08:44
From: Gregory McLeod I had already checked out the various door scripts. Doors are usually vertical so the llSetLocalPos works fine for them. The problem is similar to car doors the rotation needed to be relative to the original rotation of the root prim. Your code is the first I have seen where the rotation is not around the Z axis. I will investigate, thanks.
PS The note above from Pale Spectre is more general and I am progressing with it if I could only get the child prim to rotate 180 degrees without it flipping or rotating the wrong way. Using Voids door script just turn the prim over or on its side as you wish , the rotations still work, quite amazing really lol.If you wish IM me inworld and i,ll give you an example.
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
09-11-2008 14:40
From: Dora Gustafson If you find a way to overcome 'flipping' please tell us! I have used Void's door script and used a rotation angle of 179.99. This does the trick. But I now have a further problem. Using Void's door script how do you as well as rotate the door 180 degrees cause it to move out in the palen of rotation. If for example you tilt the door at 30 degrees after moving I want it to move out towards you by lets say 0.1 meters. So if the door were vertical and the face aligned with the X axis I want it to move in the Y axis direction 0.1. I cant fathom what has to be done to the PRIM_POSITION of a llSetPrimitiveParams to achieve this.
|