Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Same Offset, Different Size

Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-16-2009 11:35
So i'm scripting a cookie jar with a lid. i have the local positions saved for open/closed for the lid. but i'm not sure how to make the positions adjust for when the cookie jar changes size. i guess i could hard code several sizes and positions, but i'd rather the end customer be able to change the size manually and have the lid open/close positions adjust accordingly
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
09-16-2009 11:43
mod the door/hinge script to use llSetLocalRot/llGetLocalRot instead of llSetRot/llGetRot, and link the door to the cookie jar.

The alternative method(s) are painful, requiring setting up communication between the two objects and detecting when the jar is resized, and you might have to have the lid delete itself in order for the cookie jar to rez a resized version.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-16-2009 11:50
From: Soen Eber
mod the door/hinge script to use llSetLocalRot/llGetLocalRot instead of llSetRot/llGetRot, and link the door to the cookie jar.

The alternative method(s) are painful, requiring setting up communication between the two objects and detecting when the jar is resized, and you might have to have the lid delete itself in order for the cookie jar to rez a resized version.

but it's not a rotation, the lid would move to some spot next to the jar and i wanted it to be linked. i guess i could add another prim and have 2 lids linked to the jar, one closed and one open, and have them switch between alpha 0 alpha 1
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
09-16-2009 12:20
Hardcode the default local *size* of the lid.

Then when you open or close the lid, multiply the position by (llGetScale() / original_size). If they make the jar 50% larger, the lid will be 50% larger, and (llGetScale / original_size) will be 1.5, and bob's your uncle.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-16-2009 12:39
From: Argent Stonecutter
Hardcode the default local *size* of the lid.

Then when you open or close the lid, multiply the position by (llGetScale() / original_size). If they make the jar 50% larger, the lid will be 50% larger, and (llGetScale / original_size) will be 1.5, and bob's your uncle.


yes, the size isn't a problem, i'm wanting to adjust the local position for open/closing. the lid(s) will be linked so resizing will be done with the edit window when they resize the object anyways
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
09-16-2009 12:42
From: Ruthven Willenov
yes, the size isn't a problem, i'm wanting to adjust the local position for open/closing.
Yes, I got that. Multiply the *position* by the change in size.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-16-2009 14:32
is that supposed to be returning a float, vector what? i tried both and get a type missmatch
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
09-16-2009 14:35
Oh, yeh, sorry, I'm getting ahead of myself. You really want to pull out one coordinate of the scale

// constant at the top level
float ORIGINAL_X_SIZE = 0.34; // or whatever


float rescalePosition(vector position)
{
vector current_scale = llGetScale();

return (current_scale.x / ORIGINAL_X_SIZE) * position;
}
// Now use rescalePosition(wheer_you_want_to_move_the_lid)
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-16-2009 15:08
got it! probably looks sloppy, but it does what i needed.

this goes in the root
CODE

vector start;
list commands = ["open", "close"];
integer o;
default
{
state_entry()
{
start = llGetScale();
}

touch_start(integer n)
{
llMessageLinked(LINK_SET,0,llList2String(commands, o = !o),"");
}

changed(integer change)
{
if(change & CHANGED_SCALE)
{
vector newscale = llGetScale();
float diff = newscale.x / start.x - 1.0;//had to minus one here cause it was throwing off the math somehow
llOwnerSay((string)diff);
llMessageLinked(LINK_SET,0,"change",(key)((string)diff));
}
}
}


this goes in the lid
CODE

list pos = [<0.00000, 0.00000, 0.25000>,<0.00000, 0.41978, -0.06250>];
list rots = [<0.00000, 0.00000, 0.00000, 1.00000>, <-0.38268, 0.00000, 0.00000, 0.92388>];
float dif = 0.0;
default
{
link_message(integer sn, integer n, string m, key id)
{
if(m == "open")
{
llSetPos((llList2Vector(pos,1)*dif) + llList2Vector(pos,1));
llSetLocalRot(llList2Rot(rots,1));
}
else
if(m == "close")
{
llSetPos((llList2Vector(pos,0)*dif) + llList2Vector(pos,0));
llSetLocalRot(llList2Rot(rots,0));
}
else
if(m == "change")
{
dif = (float)((string)id);
}
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
09-16-2009 15:20
A rescale event might be lost (event delivery isn't guaranteed) and llGetScale is efficient, so I wouldn't bother tracking scale and just re-read the current scale every time. And you can do it all in the lid.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-16-2009 16:09
here we go, i was almost on the verge of pulling my hair out when i realized i was dividing backwards lol

CODE

float startx = 0.5;

vector open = <0.00000, 0.00000, 0.25000>;
vector closed = <0.00000, 0.41978, -0.06250>;

rotation roto = <0.00000, 0.00000, 0.00000, 1.00000>;
rotation rotc = <-0.38268, 0.00000, 0.00000, 0.92388>;

integer o;
default
{
touch_start(integer n)
{
vector newscale = llGetScale();
float dif = newscale.x / startx;//originally was using startx / nexscale.x
llOwnerSay((string)dif);
if(o)
{
llSetPos(open*dif);
llSetLocalRot(roto);
}
else
{
llSetPos(closed*dif);
llSetLocalRot(rotc);
}
o = !o;
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369