Jump to content
  • Advertisement
Sign in to follow this  
LowRad

Implementing a Grid in a WorldEditor

This topic is 4607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, I'm building a WorldEditor and now i'm trying to implement a Grid System. I want grid to resize when zoom (more/less precision), options like major/minor lines and i'll also need thing like snaping and such.. so a somewhat a basic grid. The engine running the WorldEditor is based on Direct3D all written in C++/MFC. I have look at a few options: - Use GDI+ to draw the grid (it's flexible enough, but the grid doesn't show up over a SwapChain RenderTarget, there's a way?) - Use Direct3D Line Lists to draw it (it's not very flexible imo, but it will show up) I really dont have any clues, so i'm asking your opinion, how would you do it? Thanks in advance, Jonathan

Share this post


Link to post
Share on other sites
Advertisement
If you're trying to draw a 3D grid in Direct3D, you're not going to be able to use GDI+. You're going to have to use Lines in D3D.

Share this post


Link to post
Share on other sites
Build a Direct3D vertex buffer to draw the grid. That way, you can easily DrawIndexedPrimitive() the grid for each frame, with no CPU overhead. Generate sufficient fringes for the grid such that you only need to re-generate it if the camera moves a lot (so you don't need to re-generate it every frame during movement).

To snap to grid, use this function for each coordinate:


output = floor(input/gridSize+0.5)*gridSize;


To make the grid become larger on the screen when you zoom in, you have to do nothing special -- it'll be drawn in world space like any other object.

Share this post


Link to post
Share on other sites
Thanks for your response, i will try with a VertexBuffer of Line Lists type, as soon as i get my resource manager up and running.

At first, the VertexBuffer solution didn't seem to be flexible enought.

Should i create the VertexBuffer as dynamic and fill it with new vertex everytime the zoom is changed? (For translation, if i draw it with an offset of 0 or gridSize, the result will be the same on screen, so the grid simply need to fit the maximum viewport size).

output = floor(input/gridSize+0.5)*gridSize;

Are you sure? i thought about it and i think there missing a zoom factor in this function?

Thanks,
Jonathan

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!