Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotating point(b) in 3d space around point(a)...

Grantly Hamilton
Registered User
Join date: 31 Mar 2004
Posts: 38
03-01-2007 21:38
I'm not sure of the formula behind this and require some help if anyone knows...

Basically, I have the 1st points(a) coordinates (x,y,z), and I need to find the 2nd points(b) coordinates (x, y, z)... Which is say, 1 meter from a, using degrees as the input(0 - 360(transfered to radians)) for rotation on the horizontal and vertical...

I've got it to work on just the horizontal, but I'm unsure as to how to get a vector based on combining the horizontal & vertical so point b is always 1 meter from point a...

It's basically pretty much the same thing as rotating your view around a centered object but with coded input instead of the user moving the mouse.

Thanks in advance...

- Grantly
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
03-02-2007 00:29
http://lslwiki.net/lslwiki/wakka.php?wakka=rotation

From: someone
Note: An object can be rotated around an arbitrary point by multiplying a vector by a rotation in the manner described above. The vector should be the difference between the object's current position and the desired "center-point" of rotation. Take the result of the multiplication and add it to the point of rotation. This vector will be the "new location" the object should be moved to.

CODE
vector currentPos = llGetPos();
vector rotPoint = llGetPos() + <1, 1, 1>; // in global coordinates
vector newPos = rotPoint + ((currentPos - rotPoint) * x_45);
llSetPos(newPos);
Grantly Hamilton
Registered User
Join date: 31 Mar 2004
Posts: 38
03-02-2007 11:31
How would you combine the rotations to get a vector to always be 1 meter from the target position...

I basically need the same effect as holding down CTRL + ALT and rotating the view around the an object with the mouse always being the same distance away...

Instead of using the X & Y axis on the mouse, it's done through pressing buttons...

I've messed with everything, I just don't know how to do it properly.
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
03-02-2007 13:37
That's exactly what Masakazu's quoted example does. Multiplying a vector <a> by a rotation (quaternion) <r> results in a vector <b> which is the same distance from the origin as <a>, rotated around the origin as specified by <r>.

If you don't want to rotate <a> around the true origin, <0,0,0>, subtract your desired pivot vector <p> from <a>, multiply by <r>, and add that result to <p>.

CODE

// Pivot vector
vector p = <0,0,1>;

// Starting point vector, 1m directly above pivot
vector a = <0,0,2>;

// Rotation, 45° around X-axis
rotation r = llEuler2Rot( <45,0,0> * DEG_TO_RAD );

// Result (approximate): < 0, -0.7071, 1.7071> still 1m from pivot,
// rotated 45° around X-axis from it's initial position
vector b = ( a - p ) * r + p;
Grantly Hamilton
Registered User
Join date: 31 Mar 2004
Posts: 38
03-02-2007 16:30
Ahhh, It's working properly now... Thanks alot!
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
Ok, how about this one:
09-12-2007 13:02
i start from point a, at a certain distance and direction from point b and having the same heading (z-rot) as said point.

i teleport to a point c, having a z-rotation diverse from b; and rotate to c's heading. i now want to place myself at a point that has the same rapport with c that i had between a and b.

basically i want to have the 6 radially-distributed TP beams come up at the right pads on arrival, instead of all in the middle. i know i can solve this simply by hard coding in each beam it's place in the set, but this should be easy and i once again have gone blank ...
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
09-13-2007 08:24
ok, what follows will always place the rezed object at distance and heading constant from base... even once i rotate base, obj. goes to same world cordinates... what i basically need to get is how to aply to local coordinates derived from local rotation... i do not mean localrot as in linked set, i mean as in non aligned to world axes...



CODE

vector finalpos;
integer param=0;
vector a;
vector b;
default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}

touch_start(integer total_number)
{
a=<180.106,102.544,351.109>; //

b=<181.145,101.943,351.109>;

float dist= llVecDist(a,b);
vector offset = (b-a);

llSay(0,"distance: "+(string)dist);

llSay(0,"offset: "+(string)offset);

rotation my_rot=llGetRot();

rotation dir_rot=llGetRot()+(llEuler2Rot(<0,0,PI/3>));

vector offset_direction=llRot2Fwd(dir_rot);

finalpos = llGetPos() + offset;

//Below is what i need to get at... how do i rez

// vector finalpos= unknown;

llRezObject("Object",finalpos,<0,0,0>,my_rot,param);
}
}
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
Found It!
09-13-2007 09:49
CODE


lBuzz = llParseString2List(msg,([";"]),([]));

vector vMyoffset=llGetPos();

vector vBasoff = (vector)llList2String(lBuzz,3);

float offsetx = vMyoffset.x-vBasoff.x;

float offsety = vMyoffset.y-vBasoff.y;

particles();

llSetAlpha(0.0,ALL_SIDES);

vWarpDest = (vector) llList2String(lBuzz,0);

rWarpRot = (rotation) llList2String(lBuzz,1);

sWarpArr =llList2String(lBuzz,2);

////////////// this is where it happens:

rotation funky = llEuler2Rot(llRot2Euler(ZERO_ROTATION) -llRot2Euler(llGetRot()));

vector newx=llRot2Fwd(rWarpRot*funky)*offsetx;

vector newy=llRot2Left(rWarpRot*funky)*offsety;

vector adj=newx+newy;

//////////// and that does it!! the difference in start rot from rotation east
//////////// adjusted out by the variable "funky". there's probably
//////////// a less cludgy way of doing it but I finally got where i could fix it!!

vector finalpos=vWarpDest+adj;

warpPos(finalpos);
llSetRot (rWarpRot);