Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

x,y for child prims in upper left? (versus center?)

bucky Barkley
Registered User
Join date: 15 May 2006
Posts: 200
12-19-2006 20:45
Pretty simple, hopefully..

Imagine a chessboard where you want to lay out pieces
relative to x, y with 0, 0 origin in the upper left. Since the pieces
are linked, they think the origin is in the center... They each
have their own script to handle their repositioning...

Oh, and the board can resize and rotate.. which makes calculating
the origin point I really want all the more fun.

Any good method to fake a different origin?
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
12-19-2006 22:14
To make a box prim with the origin in one corner, make the Path Cuts 0.375, 0.625
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-20-2006 00:54
From: bucky Barkley
Pretty simple, hopefully..

Imagine a chessboard where you want to lay out pieces
relative to x, y with 0, 0 origin in the upper left. Since the pieces
are linked, they think the origin is in the center... They each
have their own script to handle their repositioning...

Oh, and the board can resize and rotate.. which makes calculating
the origin point I really want all the more fun.

Any good method to fake a different origin?


why not just calculate the positions as an offset?
a chess board is 8 x 8 so each offset is 0.125
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-20-2006 12:05
From: Newgate Ludd
why not just calculate the positions as an offset?
a chess board is 8 x 8 so each offset is 0.125


sort of. offset relative to each piece yes, but since the piece's position is calculated from it's center, the first offset would have to be 1/16, 2nd would be 3/16, etc. still do-able, but using a specially cut cube to put the center at a corner would probably be less mental work when setting up the position calculators.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
12-20-2006 12:37
Or do the math once - write one function that converts from chessboard-coordinates to actual coordinates, test it, and then you won't worry have to about it after that :) For example, that might make it easier to build a board of a different size.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-20-2006 14:16
From: Senuka Harbinger
sort of. offset relative to each piece yes, but since the piece's position is calculated from it's center, the first offset would have to be 1/16, 2nd would be 3/16, etc. still do-able, but using a specially cut cube to put the center at a corner would probably be less mental work when setting up the position calculators.

Yep true, box size is 1/8th but centre will be 1/16th but from then on tehy are 1/8th apart. Its not exactly difficult maths since its a regular repeat.

From: Ziggy Puff
Or do the math once - write one function that converts from chessboard-coordinates to actual coordinates, test it, and then you won't worry have to about it after that :) For example, that might make it easier to build a board of a different size.



Exactly
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
Sample chessboard movement script
12-20-2006 14:41
Here's a sample script to do this with a normal box prim as the board.

Make a box, flatten it on Z to be your chessboard, and then put a little cylindrical piece on top of it, say, 1/10 the size of the box, to be a chess piece.

Put this script in the box
CODE
// sample chessboard piece moving script, root prim
// by Boss Spectre

integer ROWS = 8;
integer COLUMNS = 8;

float xgrain;
float ygrain;
float xcenter;
float ycenter;

get_grain()
{
vector rootscale = llGetScale();

xgrain = rootscale.x / ROWS;
ygrain = rootscale.y / COLUMNS;

xcenter = (rootscale.x - xgrain) / 2.0;
ycenter = (rootscale.y - ygrain) / 2.0;
}

vector calcpos(integer x, integer y)
{
// Note: the x coord moves along prim Y, and y along X, to simplify calcs
return <(xgrain * y) - xcenter, (ygrain * x) - ycenter, 0.0>; // swap x/y is deliberate
}


default
{
state_entry()
{
get_grain();
}

changed(integer change)
{
// this event only goes to the root prim when an object is resized as a whole
if (change & CHANGED_SCALE)
get_grain();
}

touch_start(integer total_number)
{
integer piece = 1;
integer x = llFloor(llFrand(COLUMNS));
integer y = llFloor(llFrand(ROWS));

llOwnerSay((string)x + ", " + (string)y); // tell coords

llMessageLinked(llGetLinkNumber() + piece, -1, (string)calcpos(x,y), "");
}
}

Then put this script in the little piece on top of it:
CODE
// sample chessboard piece slave script
// by Boss Spectre

default
{
link_message(integer sender, integer num, string msg, key id)
{
if (-1 == num)
{
vector v = (vector)msg;
vector pos = llGetLocalPos();
v.z = pos.z;
llSetPos(v);
}
}
}

Link them with the box as root, and click it, you should see the piece move around to random spots on an 8 x 8 grid. Resizing the linked object is accomodated. Rotating the object will not affect it. Neither rotation nor Z is changed on the piece, it simply slides along the Z plane.

To move the piece "off" the board, use coords greater or lesser than 0 to 7.
bucky Barkley
Registered User
Join date: 15 May 2006
Posts: 200
12-20-2006 15:07
thanks for the responses! I'll work a bit with Boss's answer.

I am doing a more generalized imagemap, and only used a chessboard
as an example. Each state in the map might result in a different scale
for the background (think of series of web pages.. each with their
own image and set of active regions/tiles). I might have a dozen
tiles (transparent prims) overlaying a background image, so the
last thing I want to do is have each child get into querying the
parent scale. I'll see what math I can do in the parent, and pass
along params in a linked message to the kids ...

Of course, if I didn't have linked kids, I could set positions in
regional coords, and it would run dog slow from the sheer amount
of chatting taking place :-)