Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Maths for object grid snap

Author
Message
BlackChaos
16
Years of Service
User Offline
Joined: 2nd May 2010
Location: London
Posted: 3rd Oct 2011 14:57
I have coded a level editor and I need to snap to objects to a grid on the floor so they can be placed with more accuracy.

So something like 3dsMax where you can see a grid and drag the objects over to snap them into position.


Thankx

bchaos101
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Oct 2011 15:26
Just carry out an integer division by your grid-size, then multiply back up again.


BlackChaos
16
Years of Service
User Offline
Joined: 2nd May 2010
Location: London
Posted: 4th Oct 2011 19:21
Thanks .. alos what about showing gridlines without using objects?? or do i have to use a textured plane?

bchaos101
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 4th Oct 2011 21:28
There's a few available options: Un-textured matrix is in wireframe. Lots of planes in wireframe. Or a plain with a high res grid texture. The option I would possibly go for is the lots of planes (this can be put into a single object as limbs if needed). Depending on how big the grid required is you can also instance the object multiple times.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th Oct 2011 22:00
Actually, this might work better:


IanM's code won't always snap to the nearest one.

[b]
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Oct 2011 22:09
True - I neglected negatives too.

BlackChaos
16
Years of Service
User Offline
Joined: 2nd May 2010
Location: London
Posted: 20th Oct 2011 12:50
@Diggsey

sorry for the late reply.
Quote: "
x# = floor(x# / GridSize + 0.5) * GridSize


"

Works great thanks

Check out my website -> Ameadus Project <- Over 2,000 free textures

Login to post a reply

Server time is: 2026-07-10 20:10:45
Your offset time is: 2026-07-10 20:10:45