Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Quaternion / Rotation Dummy needs help

Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-18-2005 12:54
Hi all,

I've got a script which (on command) sets free a little builder guy (we call him Bob) which looks at his current position, then shoots off in directions as told to him in his script (for example, my function might be MoveBobTo(<0,45,0>;);) which moves bob off to a set of coordinates that are 45 units in the Y direction from where he currently is. There he rez's an object and then moves off to his next move to command.

Problem is that Bob always goes to the same place to build his stuff no matter how the object that rez's him is rotated. I know it's because I'm using hard coded move commands like <0,45,0> which will always move him 45 in the Y direction.

How do I get around this? I want the Bob to shoot off in the direction the object that's rezzing him is facing :)

You guys are great, thx in advance! :cool:
Syn
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-18-2005 13:47
Hmmm, after further research, I guess I'm asking how to make bob's Y rotation equal to that of the rezzing object's Y rotation (same for X as well).

This should be the rezzing objects local rotation passed to Bob I guess. But then how do i force bob to use that rotation and still be able to send him move commands like <0,45,0> without him using the global rotation?
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-18-2005 14:05
**loves talking to himself*** lol

After even more research, I'm wondering if I passed the rezzing objects local rotatin to Bob, then on every move command Bob's llSetPos() would look something like

CODE
rotation Rezzing_Objects_Rotation = *rotation that's passed in when bob rez's*;
llSetPos(llGetPos() + (<0,45,0> * Rezzing_Objects_Rotation ));


Would this work? I'm at work & cant test :( Damn RL :rolleyes:
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-18-2005 14:58
Sorry about that. I slept in today. :D

Yes. A vector times your rotation will put the vector in your rezzer's local axis of movement. That should work for you, so long as llSetPos works (as it's limited to roughly 10m a move).
_____________________
---
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-18-2005 15:31
Ty Jeff (you must live on the forums, amazed you get anything done lol)

Yea, I'm using a while loop to move bob to his destination, so he gets there pretty quick :)

Thanks again!
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-18-2005 15:55
So Jeff I guess I'm doing this wrong

I added the local rotation of the rezzing object to Bob and he shot off the sim lol

Here's the code

CODE
MoveBobTo(vector targetposition)
{
while ( llVecDist(llGetPos(), targetposition) > 0.001 ) llSetPos(targetposition * localrot);
}


Where localrot is a global rotation variable that's passed in by the rezzing object.

What did I do wrong here?
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
03-18-2005 16:07
Ah, llSetPos uses region-relative positions, not object-relative ones (aka offsets). A region relative position is a point somewhere in the simulator, and an object-relative one is one that says something like "45 meters away on this object's local x-axis."

What you need to do, is convert the object-relative position into a region-relative one. Luckily this is simple, just change MoveBobTo() to this:
CODE

MoveBobTo(vector offset) {
vector destination = offset * localrot; // Factor in the object's rotation.
destination += llGetPos(); // Convert to region-relative.
while (llVecDist(llGetPos(), destination) > 0.001) {
llSetPos(destination);
}
}


Enjoy :)
==Chris
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-18-2005 16:13
Whoa. Well...

You rotated the entire position instead of the offset. It looks like that put it off the sim, with an infinite loop and a position that will never exist...

Anyway, two problems. If, first, you want Bob here to move between two sims, you're going to need to use global positions (read: llGetRegionCorner() + llGetPos()). Second, if you want it in the sim... you'll need the position to be a little more... conservative, and have Bob die at the edge of the sim.
_____________________
---
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
03-18-2005 16:32
From: Jeffrey Gomez
Anyway, two problems. If, first, you want Bob here to move between two sims, you're going to need to use global positions (read: llGetRegionCorner() + llGetPos()).


Not necessarily Jeff. If Synergy is using object-relative positions to move his object around (<0, 45, 0>, for example) rather then actual points in the simulator (region-relative positions such as <45, 129, 50>, for example) there is no need for him to use global positions.

From his initial post, I take it he's using object-rel.
From: Synergy Belvedere
(for example, my function might be MoveBobTo(<0,45,0>;)... move commands like <0,45,0> which will always move him 45 in the Y direction.

==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-18-2005 16:52
Yeah. Your post went up as I was writing mine, so that works.

Usually when you loop through a position change in that manner, and it crosses a sim border, you want globals. But hey, that's just me. :p
_____________________
---
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-18-2005 18:12
Chris - I'm a guy :P

You were right, Bob was shooting off the sim and going offworld somewhere 5 sims away

I havent tested Chris' code snippet yet but will soon. This is for a game, and hopefully the owners will be smart enough not to try to set it up across sim boundaries.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
03-19-2005 10:57
From: Synergy Belvedere
Chris - I'm a guy :P

Oops! :o sorry about that, edited the post
==Chris
Steel Diamond
Registered User
Join date: 23 Mar 2005
Posts: 2
03-26-2005 15:10
No he still shoots offworld on me :(
Steel Diamond
Registered User
Join date: 23 Mar 2005
Posts: 2
03-26-2005 16:44
K i figured out why he shoots off world, i was passing in the offset + llGetPos(), so big duh there.

He now comes out & builds but the pieces he drops down are all rotated wrong.
Any ideas?
Ming Chen
Here since 0.4.1!
Join date: 3 Sep 2003
Posts: 524
03-27-2005 04:19
Jeff needs to work for LL :cool:
--Ming
_____________________
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-27-2005 04:23
Some day.... yes...

But not today. :cool:
_____________________
---
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-27-2005 08:41
So any thoughts? Do I need to add the local rotation to the objects that bob rez's?
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
Time to pull out the stops :P
03-27-2005 12:34
Ok I'll quit being stingy with the actual code being used...here it is

CODE

vector eul;
rotation quat;
integer rotate = TRUE;
rotation localrot;


MoveBobTo(vector offset)
{

vector destination = offset * localrot; // Factor in the object's rotation.

destination += llGetPos(); // Convert to region-relative.

while (llVecDist(llGetPos(), destination) > 0.001) {
llSetPos(destination);
}
}


DropObject(string piece)
{
if(piece == "object1")
{
eul = <0,270,0>;
}else if(rotate && (piece == "object2" || piece == "object3")){

eul = <0,0,270>;
}else if(piece=="object6" || piece == "object5"){
eul=<0,0,0>;
}else{
eul = <0,0,90>;
}
eul *= DEG_TO_RAD; //convert to radians
quat = llEuler2Rot(eul) * localrot; //convert to quaternion
llRezObject(piece, llGetPos() - <0,0,7>, <0,0,0>, quat, 0);
}


You'll notice in the DropObject() function I'm checking for certain pieces (renamed to keep from giving the idea away), if this was not done the objects dropped at all different rotations (I guess from the way they were linked/made , etc) and the end result was a mess.

Below this code bit is my function that actually makes the final result. It's basically
CODE

targetposition = <15,10,-5.0>; //offset to send Bob to
MoveBobTo(targetposition);
DropObject("Object1");


I'm closer now, but certain objects are not rotating correctly when dropped, and appear in different places then they did when I first had this setup working (before figuring in the local rotation bit).
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-27-2005 12:35
I should add, I'll pay GOOD money to have one of you experts hook up with me in game and just help me wade through this little problem. Shouldn't take too long I'm sure. I'll give you the code used/etc, but you'll have to promise to keep your mouth shut about the actual thing I'm working on :)
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
03-28-2005 12:04
CODE
vector   gStartPos;
rotation gStartRot;

MoveBobTo( vector offset )
{
vector dest = (offset * gStartRot) + gStartPos;
while ( llVecDist( llGetPos(), dest ) > 0.001)
llSetPos( dest );
}

// in your default state:
on_rez( integer param )
{
gStartPos = llGetPos();
gStartRot = llGetRot();
}
The big problem is to only use llGetPos() once to store the starting frame of reference.
_____________________
~ Tiger Crossing
~ (Nonsanity)
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-28-2005 20:00
Thanks Tiger, I'll try that, if it does the trick, i'll send 2K your way :)

Just a guess, but i'm thinking this wont fix the rotation of the objects that Bob drops?
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-29-2005 02:56
To fix the rotation that Bob drops the objects at, just set it when you rez the suckers:

llRezObject("Object Name",whateverPosition,<0,0,0>,desiredRot * llGetRootRotation(),1);

Where llGetRootRotation() is the rotation of Bob, and desiredRot is the extra rotational offset you want to add.

For example, say you have a 180 degree offset relative to Bob on the X axis.

<1,0,0,0> * llGetRootRotation()

Simple. :D
_____________________
---
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-29-2005 12:32
So Jeff, my code would look like the following?

CODE

DropObject(string piece)
{
if(piece == "object1")
{
eul = <0,270,0>;
}else if(rotate && (piece == "object2" || piece == "object3")){

eul = <0,0,270>;
}else if(piece=="object6" || piece == "object5"){
eul=<0,0,0>;
}else{
eul = <0,0,90>;
}
eul *= DEG_TO_RAD; //convert to radians
quat = llEuler2Rot(eul); //convert to quaternion
llRezObject(piece, llGetPos() - <0,0,7>, <0,0,0>, quat * llGetRootRotation(), 1);
}
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-29-2005 14:32
Looks right, assuming quat is the proper rotation.
_____________________
---
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
03-29-2005 15:00
UGH I give up!

Well now it seems to lay down the pieces in the proper rotation, but Bob just seems to put them all over the place :(

Please, I'm beggin anyone out there, let me pay you to help me with this... Just come & Supervise :) :) :)