Servian Serevi
Registered User
Join date: 17 Apr 2008
Posts: 10
|
09-30-2009 21:24
Ok... I have a chess board that stores the positions of the pieces, ie. saves the game, so that the board can be reset later to the same setup.
The pieces are single prims, not linked, and send the board their global positions: llGetPos() and llGetRot(), via llSay().
I want to convert the region pos and rot to ones relative to the board, and convert back again when the board restores the saved game. That way, it won't matter if the move or rotate the board, the pieces will rez and be moved to the same square on the board, regardless...
Here are the calculations I'm doing:
// Convert region coords to local coords relative to the base. (here posn and rot are coming from the piece last called): posn = posn - (llGetPos() / llGetRot()); rot = rot / llGetRot();
// Convert position of piece relative to base, back into region coords. (here posn and rot are coming from a list): posn = (posn * llGetRot()) + llGetPos(); rot = rot * llGetRot();
The script then tells the pieces where to move to...
These conversions work fine and dandy when the base is at zero rotation, all the pieces rez and get moved to the right positions and rotations. But, rotate the damned thing and when you restore the game, the pieces rez and move several meters away and all huddled togeather like I get when I try to mess with rotations...
Can anyone help me? If you are a rotation guru, I will trade money, gifts, or adult favors for a solution... ok.. jk about the adult favors... ;p
Feel free to IM me in world if you want to see the insanity inducing problem in 3d...
Thanks! Love you all! Servian Serevi
|
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
|
09-30-2009 21:58
To get a rotated offset you multiply the offset times the rotation to get a rotated offset then add it to the start position.
starting position = center of board offset = position of piece relative to starting position assuming zero rotation rotation = rotation of board offset position after rotation = offset times rotation final position = starting position += offset position after rotation
Basically the board would be rezzed and record its position and rotation in world coords. Each playing piece would have to know its board position and what offset is required to achieve that board position by applying an offset to a zero rotated board. As each piece is rezzed, you'd use the above to calculate its new position based off its offset combined with the board's rotation to achieve a rotated offset. Then you'd apply the board's rotation to the piece so it is rotated correctly on the rotated board.
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
10-01-2009 00:21
Take a look at /54/84/334239/1.html , where i think you will find the solution in Jesse Barnett's reply to my question about something similar. Though, if I've misunderstood and you're rezzing the stuff rather than simply moving it into position, have a look at http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryBuildersBuddy -- there's a lot more there than you need, but that has the calculations you'll need for putting things into a rezzer at an arbitrary initial rotation rather than basing them on ZERO_ROTATION.
|
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
|
10-01-2009 01:15
From: Innula Zenovka Take a look at /54/84/334239/1.html , where i think you will find the solution in Jesse Barnett's reply to my question about something similar. Though, if I've misunderstood and you're rezzing the stuff rather than simply moving it into position, have a look at http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryBuildersBuddy -- there's a lot more there than you need, but that has the calculations you'll need for putting things into a rezzer at an arbitrary initial rotation rather than basing them on ZERO_ROTATION. Arbitrary rotations are generally calculated from ZERO_ROTATION as a constant using offsets from a calculated vector (such as using llGetPos())
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
10-01-2009 05:39
From: Jeredin Denimore Arbitrary rotations are generally calculated from ZERO_ROTATION as a constant using offsets from a calculated vector (such as using llGetPos()) Yes, I know that. Clearly I didn't express myself too well, but I thought the OP couldn't guarantee that the chess board would be at ZERO_ROTATION when a game is interrupted and wanted to be able to cause the pieces to re-position themselves correctly when play is resumed. I was just suggesting two places to look for examples of how to calculate things so as to allow for the possibility that the rezzer's not rotated at ZERO_ROTATION when you calculate the offsets. I agree it's far simpler and better to make sure your rezzer is properly aligned before you start, but if you can't do that, there's another way to manage things.
|
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
|
10-01-2009 21:02
Your calculations were almost correct, you just misplaced some parentheses...
// Convert region coords to local coords relative to the base. (here posn and rot are coming from the piece last called): posn = (posn - llGetPos()) / llGetRot(); // <<<< Here! rot = rot / llGetRot(); The other conversion is correct.
|
Servian Serevi
Registered User
Join date: 17 Apr 2008
Posts: 10
|
Solved!
10-02-2009 04:32
HUGE HUGGS TO Kaluura Boa!!!! And, all my thanks to everyone who posted their help! I'll be sending you all a chess board!
To recap: I wanted to save the positions and rotations of several unlinked prims relative to a 'base' prim. Then I wanted to rez those pieces again and move them back into their positions relative to the base. I wanted this to work at any rotation of the base prim.
Here's the full solution for the conversions (these code snippets are in the base prim):
// Convert region coords to local coords relative to the base. (here posn and rot are coming from the piece last called): posn = (posn - llGetPos()) / llGetRot(); rot = rot / llGetRot();
// Convert position of piece relative to base, back into region coords. (here posn and rot are coming from a list): posn = (posn * llGetRot()) + llGetPos(); rot = rot * llGetRot();
~Servian Serevi
|
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
|
10-04-2009 07:15
From: Innula Zenovka Yes, I know that. Clearly I didn't express myself too well, but I thought the OP couldn't guarantee that the chess board would be at ZERO_ROTATION when a game is interrupted and wanted to be able to cause the pieces to re-position themselves correctly when play is resumed.
I was just suggesting two places to look for examples of how to calculate things so as to allow for the possibility that the rezzer's not rotated at ZERO_ROTATION when you calculate the offsets. I agree it's far simpler and better to make sure your rezzer is properly aligned before you start, but if you can't do that, there's another way to manage things. Heh, I obviously didn't express myself too well either. My point was you should start with ZERO_ROTATION and a known offset that produces a board position from the board's center. Then apply the board's rotation to the offset to arrive at the destination position. Then rotate the chess piece as well. Basically start with ZERO_ROTATION and arrive at your destination from that starting point. It's just semantics anyway, all rotations are just an offset from ZERO_ROTATION 
|