Game Development Community

Question regarding custom terrain object placement

by Nic Biondi · in General Discussion · 01/28/2004 (3:13 pm) · 2 replies

I need to be able to place objects on the terrain in a specific manner. Instead of being able to place an object anywhere you like, I want to divide the placement erea into blocks. So that objects need to be placed in a grid.

What I have done:
I already have the object creation and raycasing done so that I can place my objects. Now i need to find a way to make those objects "snap to grid".

this function :
%item.setTransform(%x SPC %y SPC %z);
is what I am using, populating the x,y, and z values using:
%object = ContainerRayCast(%startPoint,%endPoint,%searchMasks, %player);


Is there an easy way to do this? I am thinking somewhere along the lines of an equation. I just need something to get me on the right track

#1
01/28/2004 (4:05 pm)
I have an idea that looks like it will work and it is something like a rounding function. My pieces are 25*25 units and so I need to somehow round the last two didgets down based on a 4 nested if's.

For instance, using just the x-val as an illustration:
if I have a block that is x=555, I need to round it down to x=550.
if I have a block that is x=520, I need to round it down to x=500.

This can be accomplished by nested if's, for example:

(meta-code)
if x<25
     -round to 0
     if x<50
       -round to 25
       if x<75
         -round to 50
         if x<100
           -round to 75

I still have one problem though. I can isolate the last two didgets of my possition number by multiplying the number by .01.
ie: 555*.01=5.55

but how can I extract just the decimal?
#2
04/06/2004 (2:56 pm)
Why not just use [url="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_ceil.asp"]ceil,ceilf[/url] or [url="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_floor.asp"]floor,floorf[/url]?