Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Math Gurus Please Help

Raiden Karuna
Registered User
Join date: 1 Sep 2004
Posts: 65
10-07-2004 12:19
Hello Im making a object that needs to rez another object at a certain position relative to the object Rezing it, using the same rotation of the object who rez'd it, so that no matter which rotation the rezzing object is, it will correctly rez the 2nd object in the correct location.
The problem is... Here is the code I use....

rotation rotty;
rotty = llGetRot();
llRezObject("object2", llGetPos(), ZERO_VECTOR, rotty, 0);

This code Rez's the object in the correct rotation, but since its a large cone object, and the cone objects *center* is not located at the pointy part of the cone (like i need it to) it spawns it in the wrong spot. What I know I need to do, is.. crate a offset to the xyz position based on the rotation of the object spawnning it, so that.. when rez'd in any direction the rez'd object will be rez'd in the right spot. Im not very good at the whole "Quaternions" thing, so I need some help in creating a math *function* that will do this for me.

If this helps, I have *linked* the rezzed object to the object that rezzed it, but put it in the CORRECT position it needs to be rezzed in before linking.. manually..
so what ever math function I use, must hold true to these numbers below... the formula/function must make Object's xyz result in object2's xyz using the rot shown for each.

Object: xyz = <209.54430, 128.64497, 71.94125> rot = <0.35838, 0.00000, -0.00000, 0.93358>
Object2: xyz = <209.54430, 131.04245, 69.28536> rot = <0.35838, 0.00000, -0.00000, 0.93358>

Object: xyz = <210.14034, 129.32277, 71.94125> rot = <0.23695, 0.26887, 0.70045, 0.61720>
Object2: xyz = <207.76189, 129.02122, 69.28537> rot = <0.23695, 0.26887, 0.70045, 0.61720>

Object: xyz = <209.53857, 129.32277, 70.37775> rot = <-0.73898, -0.67241, -0.02622, 0.03308>
Object2: xyz = <209.56349, 129.02126, 73.94287> rot = <-0.73898, -0.67241, -0.02622, 0.03308>


Object: xyz = <210.13492, 128.66025, 70.90325> rot = <0.72125, 0.45272, 0.13829, 0.50569>
Object2: xyz = <207.78523, 130.82182, 72.51825> rot = <0.72125, 0.45272, 0.13829, 0.50569>

Object: xyz = <209.91782, 129.87544, 70.84396> rot = <0.25703, 0.83199, 0.48099, 0.10191>
Object2: xyz = <208.42792, 127.20109, 72.69588> rot = <0.25703, 0.83199, 0.48099, 0.10191>

Object: xyz = <210.33446, 128.82976, 71.51678> rot = <-0.52347, 0.33201, -0.77858, 0.09778>
Object2: xyz = <207.18483, 130.30989, 70.68571> rot = <-0.52347, 0.33201, -0.77858, 0.09778>

Object: xyz = <210.33446, 129.30046, 71.72417> rot = <0.47690, 0.20344, 0.82160, 0.23697>
Object2: xyz = <207.18478, 128.90953, 70.07239> rot = <0.47690, 0.20344, 0.82160, 0.23697>

Object: xyz = <208.94295, 129.30046, 70.64684> rot = <-0.89193, -0.26869, 0.32699, 0.15920>
Object2: xyz = <211.33772, 128.90953, 73.27625> rot = <-0.89193, -0.26869, 0.32699, 0.15920>

Also, if there is a obvious easier way of doing this, that I am un-aware of, please let me know!
thanks for any help anyone can provide!!
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
10-07-2004 12:24
So, allow me to sum this up (correct me if I have this wrong), you need to be able to rez the object perpendicular to the current object around the rotational axis?

If so; you can multiply a rotation by a offset vector, and have LSL handle that for you (neat little trick.).

So, to do what I summarised, use

float distFromX = 10.0;
float distFromY = 0.0;
float distFromZ = 0.0;

vector newPosition = (llGetRot() * <distFromX,distFromY,distFromZ>;) + llGetPos();

If the compiler throws a syntax error (this has been an odd bug), seperate that onto a new line for each operation.

-Adam
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Raiden Karuna
Registered User
Join date: 1 Sep 2004
Posts: 65
10-07-2004 12:49
nothing has to be perpendicular ...
it is actually for a *party light* im making, it has to rez the light cone object inside of the *can* object, so that the pointy part of the cone is hitting the back of the top of the can object.
also that code doesn't work

vector newPosition = (llGetRot() * <distFromX,distFromY,distFromZ>;) + llGetPos();


look at that closer... i think its giving TYPE errors (not syntax) because you cant convert a rotation (llgetrot) into a vector... nor multiply it by a vector.. I looked for a function to convert rotation to vector before multiplying it but there is none that I know of.
Or I may be wrong, Id like to see the new code after you "seperate that onto a new line for each operation. " (which i tried, still doesnt compile) Just because im curious at what this code will do.
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
10-07-2004 13:52
From: Raiden Karuna

vector newPosition = (llGetRot() * <distFromX,distFromY,distFromZ>;) + llGetPos();


I think you need
vector vOffset = <distX, distY, distZ>; // seperate this just because it looks nice
...
vector vNewPos = llGetPost() + (vOffset * llGetRot());
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
10-07-2004 14:49
I believe you have to multiply the vector by the rot, not the rot by the vector.

ie:
llGetRot() * llGetPos() DOESN"T work
llGetPos() * llGetRot() DOES work

could be wrong, but it's what I seem to remember from my own tinkering