Jump to content

position relative to size/scale


Lash Carver
 Share

You are about to reply to a thread that has been inactive for 3227 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Can anybody tell me how to calculate a change in position and have it be the same based on the scale/size of the root prim?

 

So if you resize the object, and the link moves, it still moves to the same position if the linkset is tiny or if it's huge.

 

I am guessing it's something like... ?

<position.x*scale.x , position.y*scale.y , position.z*scale.z>

 

Any help would be great!

Link to comment
Share on other sites

When you know position and rotation for two prims the relation can be computed like this:

relativeRot = P2Rot / P1Rot;
relativePos = (P2Pos - P1Pos) / P1Rot;

When you know the relation and position and rotation for prim 1 you can compute position and rotation for prim 2 like this:

P2Rot = relativeRot * P1Rot;
P2Pos = P1Pos + relativePos * P1Rot;

 When you want to scale the position with a factor: F, use:

P2Rot = relativeRot * P1Rot;
P2Pos = P1Pos + F*relativePos * P1Rot;

:smileysurprised::):smileyvery-happy:

Reference

Note:

If you are trying to resize a linkset you should take a look at llScaleByFactor()

llScaleByFactor() includes what is said above and more, in one function

Note 2:

The snippets above are general and work for any two linked or unlinked prims or link sets
Inside a linkset where we use local positions and local rotation we can simplify the snippets to:

Child_new_local_position = F*Child_local_position;

 ...provided P1 is the root prim and P2 is a child prim

Link to comment
Share on other sites

Thank you Dora for trying to help!

 

I think you gave me good info but it's everything except what I needed. You gave me calculations for rotation and position but the position is only going to change according to scale and the scale isn't in these calculations. So to be clear, the root prim will never change positions, only size.

 

...and I have the resizing part, I just need to calculate the link position based on the always changing prim sizes.

Link to comment
Share on other sites

list p=llGetLinkPrimitiveParams(1,[PRIM_SIZE]);        float Scale=(llVecMag(llList2Vector(p,0)));

I tried doing that for the scale, then multiplying the position by the scale but again it doesn't work. Then I got to thinking, this also wouldn't work if you adjust the scale only on one axis anyways.

 

Then I tried this...

list p=llGetLinkPrimitiveParams(1,[PRIM_SIZE]);vector Scale=llList2Vector(p,0);llSetLinkPrimitiveParamsFast(7,[PRIM_POS_LOCAL,<obj.x*Scale.x,obj.y*Scale.y,obj.z*Scale.z>]);

 But again no luck.

 

 

Ugh I just can't get it!

Link to comment
Share on other sites

Oh dear!
You are confusing the prim-Scale(or prim size) with the amount of change in scale you want to apply

Say, you want to double the size

vector S = llGetScale();vector P = llGetLocalPos();float amount_of_size_change = 2.0;llSetScale( amount_of_size_change * S);llSetPos( amount_of_size_change * P);

This will double the size and local position of the child prim that contains the script/snippet

I see you know your way with 'PrimitiveParams', so it should be easy for you to adopt the snippet in a central script

:smileysurprised::):smileyvery-happy:

I can understand if you are trying to learn and want to know what goes on
Still llScaleByFactor() can do it all for you
You can even look under the hood here in deep notes

 

Link to comment
Share on other sites

I have another script that handles the changing of scale. It automatically resizes all the prims in the linkset and relocates them. I just need to be able to toggle a linked prim to two locations, regardless of size. Right now if I set local position, it's wrong once it changes scale, it's jumping to the wrong place.

 

Hope I'm explaining myself correctly!

Link to comment
Share on other sites

You probably do, I just don't understand your problem
Maybe we just understand 'scale' differently

  1. Do you want to change size AND local position?
  2. Are the two local positions on a straight line through local zero?

If they are on a straight line you can obtain one from the other by multiplying by a constant float number, say:

vector P = llGetLocalPos();float amount_of_size_change = 2.0;llSetPos( amount_of_size_change * P);

If they are not in line with local zero you must code the local positions into your program

:smileysurprised::):smileyvery-happy:

 

Link to comment
Share on other sites

I've been following this and I think part of the story is missing.   At the moment, the script knows to flip the child prim between position A and position B.  

How does it know what positions A and B are?  How is that information stored, and what are you telling it to do at the moment when resizing isn't an issue?

Link to comment
Share on other sites

So right now I just have a vector set for the current local position of the child prim. Then I was hoping to calculate it from there using the scale (and yes I mean size). 

 

Take a look at this terrible example I threw together. So when the box is enlarged, the line is too so the actual resizing is correct (from the other script) but when I tell the "line" to go from one position to the other using local position, where the line NEEDS to be is now moved. The 3rd colomn here is larger so the line needs to move along the X AND Z axis. But the 4th Column the box is only wider so it only needs to move along the X axis...

1212121.jpg

So what I'm needing is a way to set a static local position, then multiply (according to the new size) so the "line" goes into the correct positon. And no, the child prim is not moving on any one axis from the root, it is off center on all 3 axis.

Link to comment
Share on other sites

Which brings us back to the beginning.
Since neither the box prim nor the line prim is the root prim you need almost all the bells and whistles

This is a case derived from the general solution in this post

float amount_of_size_change;
vector linePrimPos;
vector boxPrimPos;
rotation boxPrimRot;
vector relativePos = linePrimPos - boxPrimPos;
vector newlinePrimPos = boxPrimPos + amount_of_size_change * relativePos;

assuming:
'boxPrimPos' is the same before and after
rotation of box prim is the same before and after
rotation of line prim is the same before and after

If you use different scaling on the three axes it is an entirely different story

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

Well, I think we know the thing can scale differently on each axis, so the scaling factor is a vector rather than a float.

Innula gets to the crux of the problem: how is the script currently representing the two alternate local positions of the to-be-toggled prim? When the assembly is rescaled, those target local position need to be adjusted not according to the new scale, but (as Dora said earlier) according to the change in scale.

Because another script is supposedly correclty scaling the whole linkset at the same time, I'd suggest storing the target local positions with the root prim's scale "backed-out" of the positions -- that is, something like

unitScaledChildPos1 = <childPos1.x/rootScale.x, childPos1.y/rootScale.y, childPos1.z/rootScale.z>

so the resulting vector would be the correct local position of the child if the root prim were scaled <1.0, 1.0, 1.0>. 

Obviously we'll need to store two such vectors for the two alternate positions (but we won't need to store the original scale because we've already normalized that out of the positions we are storing).

Then, when toggling to the different position, it gets scaled directly according to the root prim's new scale:

<unitScaledChildPos1.x * rootScale.x, unitScaledChildPos1.y * rootScale.y, unitScaledChildPos1.z * rootScale.z)

Look familiar?

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3227 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...