Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Some guidance on this rotational problem?

Archaegeo Platini
Ancient Earth University
Join date: 12 Aug 2004
Posts: 152
10-10-2004 14:29
Havent delved into it much yet, so though id ask here before trying to reinvent the wheel.

Ok, i have an object. It spawns another object at a certain Pos and Rot.

This works fine so long as the base object is not rotated (ie to position better in a room)

But lets say for positioning purposes, i want to rotate the base object around its Z axis some. Now my spawned object appear floating where the object use to be....

So, given the following.....
This is my poker table example.

deckPos is the location of the deck with the script in it, its a linked child of the main table.
nextPos is where i want the cards to appear on the table.

This works fine as is so long as the tables rotation is <0, 0, 90> and the decks rotation is <270, 0, 0>, then the following code will place the cards face down on the table at the position I wish. Again, the Deck is sitting on the Table, and is linked to the Table.

But if i rotate the table, then of course they are no longer where they should be.

So how do i need to change the below code to account for this?

CODE

rotation cardRot = ZERO_ROTATION;
vector eCardRot = ZERO_VECTOR;
vector nextPos = ZERO_VECTOR;

vector deckPos = llGetPos();
eCardRot = <90, 0, 0>;
eCardRot *= DEG_TO_RAD;
cardRot = llEuler2Rot( eCardRot );
nextPos = deckPos + <-1, 0, -0.01>;
llRezObject( "Player2Card", nextPos, ZERO_VECTOR, cardRot, y+1);
// The y+1 is used later to know which cards belong to which player
_____________________
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Dean Archaegeo Platini
Ancient Earth University

Courses for the Second Life

secondlife://Sedig/211/46
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Chris Knox
Member
Join date: 22 Apr 2004
Posts: 40
10-10-2004 17:02
try something anlong the lines of eCardRot = GetRot (this is the tables rot) + <;(rot you want here)>
Archaegeo Platini
Ancient Earth University
Join date: 12 Aug 2004
Posts: 152
10-11-2004 02:17
If only that easy, its actually the Pos that the cards susposed to appear at that changed when the table is rotated, so i think i have to....use trig, sigh.
_____________________
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Dean Archaegeo Platini
Ancient Earth University

Courses for the Second Life

secondlife://Sedig/211/46
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-11-2004 03:04
From: Chris Knox
try something anlong the lines of eCardRot = GetRot (this is the tables rot) + <;(rot you want here)>



NOOOOO this isn't valid. Yes it will compile but it won't do what you want.

To combine rotations you multiply them (and if you want to inversly rotate a rotation you devide).


I won't help you anymore, I'm against gambling in SL.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
10-11-2004 05:01
errr, you gotta transform the pos from the local axes of the table into World Axes then add that to the table pos.

To transform from World to object-local axes, multiply by the rot of that object. To transform from object-local axes into World axes, multiply by inverse rot (negate the "s" coordinate of the quaternion). Or possibly the other way around :-)

Recommend using llAxisAngle2Rot instead of Euler2Rot btw: AxisAngle is intuitive and very close to being a quaternion.

There's some examples of transforming into different axes here:

http://cvs.sourceforge.net/viewcvs.py/metaverse/metaversealpha/Editing3DScale.cpp?rev=1.8&view=markup

CODE

POS PosMouseVectorAvAxes = ScreenMouseVector * ( 1 / fScalingFromPosToScreen );
// DEBUG( "InteractiveHandleScaleEdit 4" ); // DEBUG

ROT rInverseOurRot;
InverseRot( rInverseOurRot, OurRot );

POS PosMouseVectorWorldAxes;
MultiplyPosByRot( PosMouseVectorWorldAxes, rInverseOurRot, PosMouseVectorAvAxes );

POS PosMouseVectorObjectAxes;
MultiplyPosByRot( PosMouseVectorObjectAxes, p_Object->rot, PosMouseVectorWorldAxes );


(note: MultiplyPosByRot transforms the third parameter, a vector, by the second parameter, a rot to get the first parameter, the resulting vector)

In this example, we're taking a vector on the screen, PosMouseVectorAvAxes, which is in avatar mouselook axes, then multiplying it by inverse avatar rot (rInverseOurRot) to get to World Axes (PosMouseVectorWorldAxes), then multiplying it by the rot of our target object (p_Object->rot) to get into object axes.

At that point, in the code, we apply this to the scale of the object (which is in object axes), which is basically our goal there.

In your case, you'd take your offset vector, which is in object axes, then multiply it by inverse object rot to get to world axes, then add that to the pos of the table:

CODE

RezPosWorldAxes = TablePos + InverseRot( TableRot ) * OffsetPos


Course that's in pseudo-code. I'll leave you to put that into LSL.

Azelda
_____________________
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
10-11-2004 05:06
Edit: in LSL you could probably do something like this:

CODE

RezOffsetWorldAxes = < LocalOffset.x * llRot2Fwd( rTable ),
LocalOffset.y * llRot2Left( rTable ),
LocalOffset.z * llRot2Up( rTable )) >;
_____________________