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 / Snap to Nearest Point on 3d Grid

Author
Message
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 8th Nov 2013 22:42
The title is the question. How do you snap to the nearest point on a 3d grid assuming I already have the intersection point with that grid? Even if it's a 2d example I can translate it to 3d. Cheers in advance

By the way, it would be the grid on the XZ plane.

"Get in the Van!" - Van B
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 8th Nov 2013 23:32
Hi Sasuke
Take a look to this example....imagine you have a grid of object of 10*10 and you are in the middle. This example position objects randomly.I made this example to guess where to go with my way points pathfinder. I hope it can help



Cheers.

I'm not a grumpy grandpa
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Nov 2013 00:57 Edited at: 9th Nov 2013 01:26
Thanks chafari, surprisingly it did help, you gave me the idea to check the distance, which for a grid is simple. First we'd check the initial grid snap location X/Y, then we'd test if the next grid points are closer to the mouse than the initial and the result is the snap position.

Example:


Edit: for 3d you'd need to CEIL the grid snap calc. Got it working thou:



"Get in the Van!" - Van B

Attachments

Login to view attachments
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 9th Nov 2013 11:52
Nice future city. Take a look to this snap to grid and make objects on the floor with the mouse.



Cheers.

I'm not a grumpy grandpa
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Nov 2013 14:37 Edited at: 9th Nov 2013 14:40
Interesting bit of code there

I'm trying to imitate 3ds Max. Attached is where I'm at so far...

Note: there's an alignment bug at the mo, when dragging objects at certain angles. The GUI is actually a drop down menu, clicking on "Camera-Settings" will collapse it. And the Exit Button isn't implemented yet. Just ESC for now.

"Get in the Van!" - Van B

Attachments

Login to view attachments
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 9th Nov 2013 14:48
@Sasuke
Could you please make an exe with 1024*768...I get an Runtime Error about display using 32 bits , and I have a bit old PC

Cheers.

I'm not a grumpy grandpa
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Nov 2013 15:07 Edited at: 9th Nov 2013 15:11
Strange, it should set to whatever your desktop width/height is. Does your comp not support 32 bit?

Anyway...

Edit: Exe now supports 16/32 bit

"Get in the Van!" - Van B

Attachments

Login to view attachments
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 9th Nov 2013 15:39 Edited at: 9th Nov 2013 15:40
Quote: " Does your comp not support 32 bit?"


Yet it does, but I don't know why with some exe's it gives me this f error.

same error !!





I'm not a grumpy grandpa

Attachments

Login to view attachments
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Nov 2013 16:13 Edited at: 9th Nov 2013 16:15
I swear this is something to do with display modes Fullscreen vs Windowed Fullscreen and for some people it throws an error!

Here's the code instead, requires IanM's Matrix plugin to run (taken the gui out coz it uses advanced2d)


Note: I'm just getting everything to work, so it's alittle unoptimized.

"Get in the Van!" - Van B
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 9th Nov 2013 17:04
Thanks for the code...now I could see your programs...like old 3D Studio I had some error but at the end, it works

it carash with:

rem position object at vector3 id, p0
rem point object at vector3 id, p1


Thanks again cheers.

I'm not a grumpy grandpa
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Nov 2013 17:18
Those two commands are part of the matrix plugin (the latest anyway), without them it'll run but won't display the viewport grid correctly.

Quote: "Thanks again cheers."


Cheers I'm gonna get it working without errors and do vertex/mesh manipulation and transform manipulation. The main reason for this is to create complex blocking volumes around objects for collision/physics and brushes for engine primitives so you can setup things for test. I'm gonna put that gui in the pic above on code snippets. It's relatively compact and easy setup in only a few lines of code for ease of use. Simply made for debugging.

"Get in the Van!" - Van B
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 11th Nov 2013 14:11 Edited at: 11th Nov 2013 14:11
Well snapping works well now...



"Get in the Van!" - Van B

Attachments

Login to view attachments
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Nov 2013 18:45
Looks good...I will put an eye on this.

I'm not a grumpy grandpa
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 11th Nov 2013 23:38
Cheers. Gonna port this to my engine and build from there, this was just a test. But still need to iron out the bugs

"Get in the Van!" - Van B

Login to post a reply

Server time is: 2025-05-15 13:41:31
Your offset time is: 2025-05-15 13:41:31