Rebekka Revnik
Registered User
Join date: 26 Mar 2008
Posts: 18
|
09-02-2009 01:38
Hi, I have an object which tilts to the side by touching. However it wont work correctly if I rotate the object to another direction. Rotations are far beyond my knowledge, so any idea is gladly appreciated. vector Pos1 = <28.68877, 29.15979, 21.37600>; rotation Rot1 = <0.00000, 0.00000, 0.00000, 1.00000>; vector Pos2 = <28.68877, 29.15979, 21.37600>; rotation Rot2 = <-0.08716, 0.00000, 0.00000, 0.99619>; vector DiffPos; rotation DiffRot;
integer State = FALSE;
SetRot1() { rotation rot; vector pos; pos = llGetPos() + DiffPos * llGetRot(); rot = llGetRot() * DiffRot; llSetPos(pos); llSetRot(rot); }
SetRot2() { rotation rot; vector pos; pos = llGetPos() - DiffPos * llGetRot(); rot = llGetRot() / DiffRot; llSetPos(pos); llSetRot(rot); }
default { state_entry() { DiffPos = Pos2 - Pos1; DiffRot = Rot2 / Rot1; } touch_start(integer total_number) { if(!State) SetRot1(); else SetRot2(); State = !State; } }
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-02-2009 02:12
From: Rebekka Revnik Hi, I have an object which tilts to the side by touching. However it wont work correctly if I rotate the object to another direction. Rotations are far beyond my knowledge, so any idea is gladly appreciated. vector Pos1 = <28.68877, 29.15979, 21.37600>; rotation Rot1 = <0.00000, 0.00000, 0.00000, 1.00000>; vector Pos2 = <28.68877, 29.15979, 21.37600>; rotation Rot2 = <-0.08716, 0.00000, 0.00000, 0.99619>; vector DiffPos; rotation DiffRot;
integer State = FALSE;
SetRot1() { rotation rot; vector pos; pos = llGetPos() + DiffPos * llGetRot(); rot = llGetRot() * DiffRot; llSetPos(pos); llSetRot(rot); }
SetRot2() { rotation rot; vector pos; pos = llGetPos() - DiffPos * llGetRot(); rot = llGetRot() / DiffRot; llSetPos(pos); llSetRot(rot); }
default { state_entry() { DiffPos = Pos2 - Pos1; DiffRot = Rot2 / Rot1; } touch_start(integer total_number) { if(!State) SetRot1(); else SetRot2(); State = !State; } } Nice typo  I like that, it is easy to read. I will suggest you include the new rotation in the new position, something like this: SetRot1() { rotation rot; vector pos; rot = llGetRot() * DiffRot; pos = llGetPos() + DiffPos * rot; llSetPos(pos); llSetRot(rot); }
Furthermore I would concentrate on the order of rotation arguments. You know: rotationA*rotationB != rotationB*rotationA Happy scripting 
_____________________
From Studio Dora
|
Cyrielle Thespian
Registered User
Join date: 21 Nov 2008
Posts: 0
|
09-02-2009 08:49
Thanks Dora, you were right with the order. Changed my code as follows: SetRot1() { rotation rot; vector pos; pos = llGetPos() + DiffPos * llGetRot(); rot = DiffRot * llGetRot(); llSetPos(pos); llSetRot(rot); }
SetRot2() { rotation rot; vector pos; pos = llGetPos() - DiffPos * llGetRot(); rot = DiffRot / llGetRot(); llSetPos(pos); llSetRot(rot); } SetRot1 is working properly now, but there is still something wrong with SetRot2. Maybe another hint please?
|
Rebekka Revnik
Registered User
Join date: 26 Mar 2008
Posts: 18
|
09-02-2009 08:54
Thanks Dora, you were right with the order. Changed my code as follows: SetRot1() { rotation rot; vector pos; pos = llGetPos() + DiffPos * llGetRot(); rot = DiffRot * llGetRot(); llSetPos(pos); llSetRot(rot); }
SetRot2() { rotation rot; vector pos; pos = llGetPos() - DiffPos * llGetRot(); rot = DiffRot / llGetRot(); llSetPos(pos); llSetRot(rot); } SetRot1 is working properly now, but there is still something wrong with SetRot2. Maybe another hint please?
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-02-2009 12:44
From: Rebekka Revnik SetRot1 is working properly now, but there is still something wrong with SetRot2. Maybe another hint please? In that case I will suggest you try: SetRot2() { rotation rot; vector pos; pos = llGetPos() - DiffPos * llGetRot(); rot = ZERO_ROTATION / DiffRot * llGetRot(); llSetPos(pos); llSetRot(rot); }
_____________________
From Studio Dora
|
Abraxes Binder
Registered User
Join date: 23 May 2008
Posts: 205
|
09-03-2009 06:26
DiffPos = Pos2 - Pos1; that would be 0 You have vector Pos1 = <28.68877, 29.15979, 21.37600>; vector Pos2 = <28.68877, 29.15979, 21.37600>;
and subtract them and allocate val to a var 'DiffPos' -why?
br
_____________________
BR ab
|
Rebekka Revnik
Registered User
Join date: 26 Mar 2008
Posts: 18
|
09-03-2009 10:02
Thank you very much again Dora, now it's works fine  @Abraxes: It's for future use, I was concentrating on rotations first.
|