Irr1.8c++| How can i project a useable grid on to my Terrain
-
- Posts: 34
- Joined: Tue Nov 06, 2007 7:22 pm
- Location: Würzburg, Germany
Irr1.8c++| How can i project a useable grid on to my Terrain
Hello forum,
I like to put a enable/disable able grid on top of my terrain and let the player put objects centered in the cells.
But I don't know how to do this. Can you please give me some tips where and how to start?
Thank you
Image to Illustrate what I mean:
I like to put a enable/disable able grid on top of my terrain and let the player put objects centered in the cells.
But I don't know how to do this. Can you please give me some tips where and how to start?
Thank you
Image to Illustrate what I mean:
Re: Irr1.8c++| How can i project a useable grid on to my Ter
it's very hard to understand what you need help with exactly.
If you want to know for each cell if players can or cannot place something, you could for example create a second 2darray of booleans, the same size as your heightfield. Then set the values where players can create something to true. Then if players want to place something at (x,y), check the boolean-2darray at (x,y) to see if they can.
btw the size of your boolean-area should be 1 less in both with and height. The values in a heightfield represent the 'corners' of your cells. So if you have a 25x25 heightfield, you have actually 24x24 cells, so you need a 24x24 area of bools.
If you want to know for each cell if players can or cannot place something, you could for example create a second 2darray of booleans, the same size as your heightfield. Then set the values where players can create something to true. Then if players want to place something at (x,y), check the boolean-2darray at (x,y) to see if they can.
btw the size of your boolean-area should be 1 less in both with and height. The values in a heightfield represent the 'corners' of your cells. So if you have a 25x25 heightfield, you have actually 24x24 cells, so you need a 24x24 area of bools.
Re: Irr1.8c++| How can i project a useable grid on to my Ter
And if it's about he display of a grid then check-out this thread: http://irrlicht.sourceforge.net/forum/v ... 8&start=60
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 34
- Joined: Tue Nov 06, 2007 7:22 pm
- Location: Würzburg, Germany
Re: Irr1.8c++| How can i project a useable grid on to my Ter
Thank you for the answers but i need help with creating the grid and putting it directly ontop of my terrain, so the grid follows the terrain up & down like in sims or rts games. And the player is then able to put objects in the cells.
@CuteAlien: I tried this grid but its only a flat one and dosnt follow the terrain. I already asked in this thread but noone seems to understand my question or just can't answer it.
@CuteAlien: I tried this grid but its only a flat one and dosnt follow the terrain. I already asked in this thread but noone seems to understand my question or just can't answer it.
-
- Competition winner
- Posts: 688
- Joined: Mon Sep 10, 2012 8:51 am
Re: Irr1.8c++| How can i project a useable grid on to my Ter
I think I get what you want.
Here's the simple solution: make two two textures - the one you normally display and one that has horizontal and vertical lines crossing it (or at whatever angle you need). Now granted, the resolution of the line will change when you zoom in and out of the terrain, but at least the lines will be there. And heck, you could always make another texture with thicker lines. You could even draw the lines on the texture when it loads (so you don't have to keep making duplicates of your files).
Here's the simple solution: make two two textures - the one you normally display and one that has horizontal and vertical lines crossing it (or at whatever angle you need). Now granted, the resolution of the line will change when you zoom in and out of the terrain, but at least the lines will be there. And heck, you could always make another texture with thicker lines. You could even draw the lines on the texture when it loads (so you don't have to keep making duplicates of your files).
Re: Irr1.8c++| How can i project a useable grid on to my Ter
@Ultraporing: You are right, that one is only flat. But it also comes with source... adapting just the y-values of the points is still easier than writing one from scratch. So it might be a start - there's rarely the perfect code out there which you can just use for your project.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Irr1.8c++| How can i project a useable grid on to my Ter
Well to be honest, I'm pretty sure that is caused by how you ask your question. It's very vague, and very big and you don't say what exactly you are are tying to do, what you already tried and where you fail.I already asked in this thread but noone seems to understand my question or just can't answer it.
I think the first part is answered, but for the second part, how to let users place objects on the grid... there are so many ways to do it and many 'problems' you have to solve, so you need to be more specific on how you want to the user to place objects, and what parts of the implementation is giving you a hard time (via mouse? see http://irrlicht.sourceforge.net/forum/v ... hp?t=38725)
-
- Posts: 34
- Joined: Tue Nov 06, 2007 7:22 pm
- Location: Würzburg, Germany
Re: Irr1.8c++| How can i project a useable grid on to my Ter
@STTrife thanks for the raycasting link thats the way i like to place the objects. The only hard time I have is with the grid, because I have no idea how to put it at the correct Y value corrosponding to the terrain height. A flat grid can i probably manage somehow but i dont know how to get the height of the terrain at the corners of the cells and place them right. Just as a Texture isnt good either because I like to show the grid only on certain areas of the map.
@CuteAlien: My main problem is I dont know how to adapt the y-values of the points, and I have no clue how to change CGridSceneNode so it does what i want.
Well it looks like i have to write my own grid class, thank you for your time and answers. The Raycasting will be most helpfull.
Last question: Dosn't Raycasting for every point of the Line take a lot of resources? I'll try now to create the grid by constructing the cells with 4 lines and repeate this for the with and height of the grid.
@CuteAlien: My main problem is I dont know how to adapt the y-values of the points, and I have no clue how to change CGridSceneNode so it does what i want.
Well it looks like i have to write my own grid class, thank you for your time and answers. The Raycasting will be most helpfull.
Last question: Dosn't Raycasting for every point of the Line take a lot of resources? I'll try now to create the grid by constructing the cells with 4 lines and repeate this for the with and height of the grid.
Last edited by Ultraporing on Fri Feb 01, 2013 12:02 pm, edited 1 time in total.
Re: Irr1.8c++| How can i project a useable grid on to my Ter
A way to do it is to copy/paste the code from CGridSceneNode into your own class. then change the RegenerateGrid() function to take the height into account. You need to pass your heightgrid to the scenenode in the constructor, so it can read from it. And you need to tell the CGridSceneNode (or however you are going to call it) at which place in your heightmap it should read the heights, and set the y-coordinate to that height.
Also I see that the CGridSceneNode really assumes a flat terrain, because it draws line from the start of the grid to the end. What you need is to make linepieces for each cell in your heightmap. So you do need to do a significant amount of work yourself. Don't know if it will be much use reusing the CGridSceneNode literally. At least you can look at the things they do in that class to see how to make your own gridscene node.
A completely different way of doing it is to make a second heightfield, with a square as repeating textures. The inside of that square should be transparant. Then put that second heightfield just a little bit heigher than your original heightfield and you can see raster lines over your heightmap (this was already suggested before too).
Also I see that the CGridSceneNode really assumes a flat terrain, because it draws line from the start of the grid to the end. What you need is to make linepieces for each cell in your heightmap. So you do need to do a significant amount of work yourself. Don't know if it will be much use reusing the CGridSceneNode literally. At least you can look at the things they do in that class to see how to make your own gridscene node.
A completely different way of doing it is to make a second heightfield, with a square as repeating textures. The inside of that square should be transparant. Then put that second heightfield just a little bit heigher than your original heightfield and you can see raster lines over your heightmap (this was already suggested before too).
Last edited by STTrife on Fri Feb 01, 2013 12:04 pm, edited 1 time in total.
-
- Posts: 34
- Joined: Tue Nov 06, 2007 7:22 pm
- Location: Würzburg, Germany
Re: Irr1.8c++| How can i project a useable grid on to my Ter
Thanks i'll try this, and sorry for not being able to communicate my problem in a understandable way.STTrife wrote:Probably the easiest way is to copy/paste the code from CGridSceneNode into your own class. then change the RegenerateGrid() function to take the height into account. You need to pass your heightgrid to the scenenode in the constructor, so it can read from it. And you need to tell the CGridSceneNode (or however you are going to call it) at which place in your heightmap it should read the heights, and set the y-coordinate to that height.
Re: Irr1.8c++| How can i project a useable grid on to my Ter
I edited my post, CSceneNode needs more work then I thought...
-
- Posts: 34
- Joined: Tue Nov 06, 2007 7:22 pm
- Location: Würzburg, Germany
Re: Irr1.8c++| How can i project a useable grid on to my Ter
Can I somehow get the height of a point on the terrain directly or do i have to use Raycasts?
Re: Irr1.8c++| How can i project a useable grid on to my Ter
There shouldn't be a need for a raycast. You can use the data you created the TerrainSceneNode with, or you can use the getHeight (f32 x, f32 y) function of the TerrainSceneNode.
Re: Irr1.8c++| How can i project a useable grid on to my Ter
Bumping in to confuse even more
I'd use a shader. In your vert shader for the terrain, calculate the world space position, and check if its modulo is ok. Then pass this ok as a varying.
In the frag shader, just draw black if the varying is 1, otherwise the terrain normally.
Or in pseudocode:
if (pos.xz % 32 < 1)
draw line here
else
draw terrain normally
I'd use a shader. In your vert shader for the terrain, calculate the world space position, and check if its modulo is ok. Then pass this ok as a varying.
In the frag shader, just draw black if the varying is 1, otherwise the terrain normally.
Or in pseudocode:
if (pos.xz % 32 < 1)
draw line here
else
draw terrain normally
-
- Posts: 34
- Joined: Tue Nov 06, 2007 7:22 pm
- Location: Würzburg, Germany
Re: Irr1.8c++| How can i project a useable grid on to my Ter
I just want to give a fast status update.
Im drawing the cells now fine , I also removed the terrain for testing purposes.
next up the grid
Im drawing the cells now fine , I also removed the terrain for testing purposes.
next up the grid