Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rezzing Objects problem

Radon Hastings
Registered User
Join date: 6 Feb 2008
Posts: 5
12-06-2008 11:49
I am having some understanding problems with trying to rez an object at a location after the object has changed rotations. Ok so I will explain what I am trying to do. I build a simple rectangle that has the the size of <5.00,3.00,.500>. Now I put a marker object on each side of the rectangle. The marker blocks are not linked to the rectangle. So I use a sensor to find the marker blocks and I want an object rezzed at the edge of each side of the rectangle where a marker block is found.

So I can get this to work on my original rectangle, by finding the marker, and then rezzing the object at that side. I do this by determining that the marker is either to the back or front of the x axis or to the left or right of the y axis, then use the scale /2 to rezz the object. This all works fine when my rectangle is orientated to the rotation I built it on.

But now my problem, if I rotate the rectangle and the marker blocks, when I rezz the object it is rezzed on the scale of the original x,y orientation because when I pick up the scale of the rectangle it shows me the scale as above. This of course throws my calculation off.

So can anyone point me to a solution, or tell me what I need to do to have something like this work. I have tried to use the rotation functions to solve my problem, but I am not understanding what I should be using to solve this problem.

I am sorry if I explained it poorly, as I am confused as heck as to how to solve the problem.

Thanks for any assistance.
Hooten Haller
Wonder and Joy
Join date: 5 Feb 2007
Posts: 45
llRot2Fwd
12-07-2008 04:55
You'll need to transform the rez position, and possibly set a rez rotation. Look at llRot2Fwd and it's brother functions which cover all three axes. Use the returned vector to set the correct position on the positive X side. Multiply it by a distance from the object center. For instance if the home object's X size is 2m and the rezzed object's X size is 1m then multiply the vector by (2+1)/2 or 1.5. That way the two will just touch sides. Adjust the multiplier for more or less distance. Finally, add this resulting vector to the base objects position. Subtract it from the base object's position to red on the opposite face.

Also set the rezzed objects rotation when you do this, using the base object's rotation again. My suggested formula of (baseScale.x + rezzedScale.x)/2 will have to be modified. But really once you understand that formula it'll be easier for you to devise one that suits your need.
Radon Hastings
Registered User
Join date: 6 Feb 2008
Posts: 5
still need help
12-09-2008 17:26
Thank you for answering me, it helped a lot, But now I am totally confused. Hope someone can help me again.

Ok I have been trying to determine how to put this all together, but I am having some understanding problems. I am using the following to rezz objects around the rectangle described above. Just for testing I have inserted the values into the offsets so I can try to understand how to do the next step. But for the love of me I cannot figure how to do the next step. here is what I am using:

vector offset = <.7455,0, 0.5>;
llRezObject(llGetInventoryName(INVENTORY_OBJECT,0),llGetPos() + (llRot2Fwd(llGetRot()) * offset.x) + (llRot2Left(llGetRot()) * offset.y) + (llRot2Up(llGetRot()) * offset.z),llGetVel(), llGetRot(), llGetStartParameter());

I then changes the ofset values to the following values;

vector offset = <-.7455,0, 0.5>;
vector offset = <0,1.250, 0.5>;
vector offset = <0,-1.250, 0.5>;

The object to rez is a size of <.500,.500,.100>, the size of the rectangle is <2.00,3.00,.100>

So I got what I expected, the object being rezzed with its edge on the edge of the rectangle at the mid point on each side of the rectangle.

Now here is my problem, I have the marker objects just off the edges of the rectangle, say .200 at different points around the rectangle. I would like to rezz the objects as above with the center of the rezzed object aligned to the center of the marker objects, but not at the marker points. I have messed around with countless formulas to have this happen but cannot figure out how to do it properly, especially when the rectangle rotates to a different angle.

Not sure if this all makes sense or not, but I am hoping someone can assist me. An example formula would be great, if thats possible.

Thanks very much
Flash Axel
Registered User
Join date: 8 Jun 2008
Posts: 6
Help
12-09-2008 17:46
Sorry to use your thread to help mine, but I think you might have tackled the problem Im having.

How do i rez obj2 directly above obj1 regardless of obj1s position as if tilted etc.

default
{
state_entry()
{
llSay( 0, "Hello, Avatar!";);
}

touch_start(integer total_number)
{
llSay( 0, "Touched.";);

llRezObject("Object1", llGetPos() + < 0, 0, 1.5 >, ZERO_VECTOR,
ZERO_ROTATION, 42);
}
}

I suspect I have to edit <0, 0, 1.5 > , what does zero vector and rotation mean..I got this code from tutorial
icktoofay Kamachi
Registered User
Join date: 10 Nov 2007
Posts: 17
12-09-2008 18:49
Radon, try this:
CODE
vector offset=<.7455,0,0.5>;
llRezObject(llGetInventoryName(INVENTORY_OBJECT,0), llGetPos()+(offset*llGetRot()), <0,0,0>, llGetRot(), llGetStartParameter());

Flash:
ZERO_VECTOR is a vector (three floating point numbers) which is initialized to all zeros. ZERO_ROTATION is a rotation which defines a nonrotated orientation. You might want to try this code:
CODE
default {
state_entry() {
llSay(0,"Hello, Avatar!");
}
touch_start(integer total_number) {
llRezObject("Object",llGetPos()+(<0,0,1.5>*llGetRot()),ZERO_VECTOR,llGetRot(),0);
}
}
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-09-2008 19:21
From: Flash Axel
Sorry to use your thread to help mine, but I think you might have tackled the problem Im having.

How do i rez obj2 directly above obj1 regardless of obj1s position as if tilted etc.

default
{
state_entry()
{
llSay( 0, "Hello, Avatar!";);
}

touch_start(integer total_number)
{
llSay( 0, "Touched.";);

llRezObject("Object1", llGetPos() + < 0, 0, 1.5 >, ZERO_VECTOR,
ZERO_ROTATION, 42);
}
}

I suspect I have to edit <0, 0, 1.5 > , what does zero vector and rotation mean..I got this code from tutorial


I saw in your original post that this is for a switchblade. The trick people use for weapons is to switch back and forth between visible or not with llSetAlpha using two copies of the weapon. For instance they will have an invisible gun in hand and a visible gun in holster. Touch the holster, gun in holster goes alpha and gun in hand shows and you have a "fast draw". You could do the same with the switchblade using llSetLinkAlpha for the blade. Blade will always be attached but is either showing or not.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
12-09-2008 19:28
Here is a simple sample, which rezzes 8 red balls on each corner of a box.

//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

// Put this code into a prim and it will turn into a red ball.
// Take this ball and put it in a simple box content.

default
{
state_entry()
{
llSetPrimitiveParams([PRIM_SIZE,<0.3,0.3,0.3>, PRIM_COLOR, ALL_SIDES, <1.0,0.0,0.0>,1.0,PRIM_TYPE,PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT,<0.0,1.0,0.0>,0.0,ZERO_VECTOR,<0.0,1.0,0.0>]);
}
}





//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

// Put this code to a box.
// Touch it then it will rez a ball on each of the 8 corners.

vector my_scale = ZERO_VECTOR;
string rez_object = "";
vector root_pos = ZERO_VECTOR;
rotation root_rot = ZERO_ROTATION;

//=====================================================
rez(vector input_pos)
{
vector rez_pos = root_pos + input_pos * root_rot;
rotation rez_rot = root_rot;

vector rez_speed = ZERO_VECTOR;

llRezAtRoot( rez_object, rez_pos, rez_speed, rez_rot, -1 );
}
//=====================================================
default
{
state_entry()
{
llOwnerSay(" touch me to rez ...";);
}
touch_start(integer int)
{
my_scale = llGetScale();
rez_object = llGetInventoryName(INVENTORY_OBJECT,0);

root_pos = llGetPos();
root_rot = llGetRot();

if (rez_object != "";)
{
float offset_x = my_scale.x * 0.5;
float offset_y = my_scale.y * 0.5;
float offset_z = my_scale.z * 0.5;

rez(< offset_x, offset_y, offset_z >;);
rez(< offset_x, -offset_y, offset_z >;);
rez(< -offset_x, offset_y, offset_z >;);
rez(< -offset_x, -offset_y, offset_z >;);

rez(< offset_x, offset_y, -offset_z >;);
rez(< offset_x, -offset_y, -offset_z >;);
rez(< -offset_x, offset_y, -offset_z >;);
rez(< -offset_x, -offset_y, -offset_z >;);
}
}
}

//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


The box size, position, and rotation can be totally arbitrary. As long as the size its within the rezzing limit, you can see the balls.

I've separated it into a few local variables. Hope this helps for understanding a bit more on the rezzing. :)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-09-2008 19:57
Nice, clear, concise demo script Klug!
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Flash Axel
Registered User
Join date: 8 Jun 2008
Posts: 6
Thanks
12-09-2008 20:08
Hey it worked! Thanks icktoofay

Also I did see that approach using invisibility for a work around, I'll fall back on that if all else fails.
Radon Hastings
Registered User
Join date: 6 Feb 2008
Posts: 5
Problem Restated
12-10-2008 07:03
Well seems we have a few solutions to peoples problems in this thread, which is great. I still have my problem though.

Let me try and explain again, with a different example. Lets say my my rectangle is a training table and its size is <2.0,3.0,.100>. So when a training session is about to start I will drag a chair to the table, there could be 6 chairs around the table. I would like to rez a workbook in front of the chairs which contains the training manual. So I use the chair x,y location to determine where the chair resides, and what I need to do is rez the workbook on the table at the center point in front of the chair.

So my problem is I have an x,y and need to calculate the proper position on the table to rez the book. I can get this to work if I have a zero rotation of the table, but when I move the table to another rotation I can't seem to figure a calculation that would give me the proper location on the table. I do understand that I need to take into account the scale of the workbook and the table.

So does anyone have any insights on how I can accomplish this.

Thanks, and I hope one of you expert scripters will have some solutions for me.
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
12-10-2008 18:29
From: Radon Hastings
So my problem is I have an x,y and need to calculate the proper position on the table to rez the book. I can get this to work if I have a zero rotation of the table, but when I move the table to another rotation I can't seem to figure a calculation that would give me the proper location on the table. I do understand that I need to take into account the scale of the workbook and the table.



In the above example, the trick is
vector rez_pos = root_pos + input_pos * root_rot;


Simply add the * root_rot, so it will "turn" the offset vector into the correct position according to your table rotation.
Radon Hastings
Registered User
Join date: 6 Feb 2008
Posts: 5
12-11-2008 00:21
Klug, thanks for replying to me, appreciate it very much.

My problem is that I can't figure a calculation to place the book in front of the chair. For example, I have root position of the table at <122.685,218.919,601.078>. Ok so now I have a chair at position 124.011,219.563,600.703>. So I want to rez a book in front of the chair. So the book needs to have some <x,y,z> location in front of the chair. So I am struggling with a proper calculation to determine the x,y location of the book on the table, especially once the table has been turned to some arbitrary angle. I know I can use the chair x,y because the chair is outside the boundries of the table, so I just want to be able to calculate a value of x,y to where the book should be on the table.

So what I need to figure out is a proper calculation that would tell me the x,y value needs to be x+n, y+n value down the left side of the table. Does this make any sense?.
icktoofay Kamachi
Registered User
Join date: 10 Nov 2007
Posts: 17
12-11-2008 18:45
It makes sense somewhat. You might want to try this...
CODE
vector chair_pos=llGetPos(); // if this is the chair itself, this should be fine
rotation chair_rot=llGetRot(); // same as above
vector book_pos=(<1,0,0>*chair_rot)+chair_pos; // <1,0,0> is the offset from the chair
rotation book_rot=chair_rot; // just sets the book's rotation to the chair's rotation
// now do something with book_pos and book_rot (like rezzing it...)
Rudolf Cleanslate
Registered User
Join date: 1 Dec 2006
Posts: 13
12-15-2008 07:27
This works as long as the child object is rezzed under zero_rotation, which is easy for a sphere.

I challenge anybody to do the same with 8 prisms, always pointing at the corners of the cube.

I have been working on this for months, just stopping short of getting insane.
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
12-15-2008 23:01
From: Radon Hastings

My problem is that I can't figure a calculation to place the book in front of the chair. For example, I have root position of the table at <122.685,218.919,601.078>. Ok so now I have a chair at position 124.011,219.563,600.703>. So I want to rez a book in front of the chair. So the book needs to have some <x,y,z> location in front of the chair. So I am struggling with a proper calculation to determine the x,y location of the book on the table, especially once the table has been turned to some arbitrary angle. I know I can use the chair x,y because the chair is outside the boundries of the table, so I just want to be able to calculate a value of x,y to where the book should be on the table.

So what I need to figure out is a proper calculation that would tell me the x,y value needs to be x+n, y+n value down the left side of the table. Does this make any sense?.


This shouldn't be that hard indeed, since you know the chair pos already. The logic would be something like this:

1. ➛ Rez the chair and make it zero rotation. Re-arrange the root prim if not zero rot.

2. ➛ Rez the book and make it also zero rotation. Re-arrange the root prim if not zero rot.

3. ➛ Find out an offset vector between the chair and the book, e.g. the chair pos is <124.0, 219.0, 600.0>, and the book will be rezzed 1m front and 1m high with respected to the chair. So the offset vector will be <1.0, 0.0, 1.0>. The book will be rezzed at <125.0, 219.0, 601.0>.

4. ➛ To find out the rez_rot of the book, it will be according to the rezzing prim of the table. e.g.
rez_rot = llGetRot() * book_rot;
where book_rot is the book rotation from 2. with respected to the table.

5. ➛ To find out the rez_pos of the book, it will be according to the chair pos then to the book offset. e.g.
rez_pos = chair_pos + offset;
where offset is found from 3. hardcoded.

6. ➛ However as mentioned earlier, also needed to take account on the rotation, so the rez_pos should be:
rez_pos = chair_pos + offset * llGetRot();


This is done to that particular chair only. If you have say 4 chairs, you need to do 4 books independently. Imo, it would be easier to rez the book from the chair instead of the table, so that you don't have to worry about a certain chair rotation with respected to the table. :)