Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Auto Snap to Grid after rezing?

Sean Martin
Yesnomaybe.
Join date: 13 Sep 2005
Posts: 584
03-18-2006 03:20
This might be a simple task but I can't seem to find any examples.
I thought there was an llSnaptoGrid somewhere but I asked a linden and they didn't know of any.

So I just need an object to snap to the world grid after rezing so it's already lined up for editing.
I figured it would be something with rounding the vector values to some point before putting that into the llSetpos somehow.
I can see how it should work in logic but getting this to compile has been another story. I'm just having problems with syntax I think. (I hope)

I haven't been able to find many examples so I thought I would ask you guys. :)
Anyone know how that would be setup? Thank ya much! :)
_____________________
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
03-18-2006 04:11
Something like...:

CODE

float step_size = 0.5;
vector myvec;

float round(float x)
{
return step_size * llRound(x / step_size);
}
vector_round()
{
myvec.x = round(myvec.x);
myvec.y = round(myvec.y);
myvec.z = round(myvec.z);
}
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Sean Martin
Yesnomaybe.
Join date: 13 Sep 2005
Posts: 584
03-18-2006 05:05
This is what I got so far but it won't compile. :confused:


CODE
default
{


on_rez(integer total_number)
{

vector myvec.x = llRound(myvec.x);
vector myvec.y = llRound(myvec.y);
vector myvec.z = llRound(myvec.z);

vector myposition = (<myvec.x, myvec.y, myvec.z>);


llSay(0, "I'm at " + (string)myposition);
llSetPos(vector myposition);
}
}


Another variation I tried:
CODE
default
{


on_rez(integer total_number)
{

vector myvecx = llRound(llGetPos.x);
vector myvecy = llRound(llGetPos.y);
vector myvecz = llRound(llGetPos.z);

vector myposition = (<myvecx, myvecy, myvecz>);


llSay(0, "I'm snaping to" + (string)myposition);
llSetPos(myposition);
}
}


I think I just can't get the small stuff right. :(
Like where every bracket goes or something.
Even if this did compile, I got a feeling it won't snap to the grid like I need it to. I'll probably have to edit the llRound to a certain point like that 0.5 you had?
I couldn't figure that part out.
_____________________
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
03-18-2006 05:22
What do you mean by "snap to the world grid"?

If you just means that it should line up with region coordinates, all you need to do is set its rotation to zero.

I didn't think objects could place themselves at a resolution greater than you could edit them..?
Sean Martin
Yesnomaybe.
Join date: 13 Sep 2005
Posts: 584
03-18-2006 05:37
From: Yumi Murakami
What do you mean by "snap to the world grid"?

If you just means that it should line up with region coordinates, all you need to do is set its rotation to zero.

I didn't think objects could place themselves at a resolution greater than you could edit them..?


Instead of rezing at a vector like:
(110.253, 135.244, 100.435)

I need it to rez at something like:
(110.00, 135.00, 100.00)


This way, when the object is rezed, it will auto align to the editing grid. Or whatever its called. (The white lines in edit mode)

Then I can rez another copy of the object, and have them all snap to their own rounded vector.

Or maybe in a touch_start event it could align. So all I have to do is click it to snap it instead of going into edit mode, draging the arrows, then zooming in to snap it, just to get it all even.

How does that set rotation to zero work?
lol I haven't a clue on half this stuff. :rolleyes:
_____________________
Sean Martin
Yesnomaybe.
Join date: 13 Sep 2005
Posts: 584
03-18-2006 06:29
Nevermind I figured out what Seifert Surface posted. :rolleyes: It was right in front of me. :p
Thanks Seifert :)
_____________________
Patch Lamington
Blumfield SLuburban
Join date: 2 Nov 2005
Posts: 188
03-18-2006 07:37
Glad you got it working.
For anyone wondering, the big error here is in the 3 lines
'vector myvec.x =....'

This should have been (as in Seifert's more comprehensive solution):
CODE

...
vector myvec;
myvec.x = llRound(myvec.x);
myvec.y = llRound(myvec.y);
myvec.z = llRound(myvec.z);
...


The original code was trying to create 3 different vectors all with the same variable name... which simply wont compile.
The revised version above creates a single vector then sets the x, y and z values.

Compare:

From: Sean Martin

CODE
default
{
on_rez(integer total_number)
{

vector myvec.x = llRound(myvec.x);
vector myvec.y = llRound(myvec.y);
vector myvec.z = llRound(myvec.z);

...