Where am I on this terrain?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
pfrancke
Posts: 17
Joined: Thu Jan 01, 2009 3:06 am

Where am I on this terrain?

Post by pfrancke »

scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(

I appologize up front for asking a question that shows how little I know. I've looked at a variety of things for hours and hours and I've probably skipped right over the easy solution a number of times.

Below is a map I created by loading a greyscale bmp file into a TerrainSceneNode and then applying a hexed up texture (that needs lots and lots of work... as you can see).

Someday, I intend to drop objects onto the map -- Civil war Units of course!! And of course it would be nice to move the cursor over the map and to know things about a particular hex (that I would store in an array somewhere). Now, I can fairly easily know what hex I'm on based on the X and Y coordinate that the hex is on the map. For instance, I can know if the hex is in the third row down, or if it is around the fourth hex across - that kind of thing.

Here is my painful question - If the mouse cursor is over the terrain, How can I know where on the terrain that the mouse is? For example, is there a way that the top left of my terrain (or any known part I guess), would report as X,Y at 0,0 and points relative to that make sense. And if I could do that, I'm sure I could lift the elevation of a given point also.

Should I be studying tutorial 7 - collision?

Oh, and how can I share the image with you guys (I'm a complete beginner with web stuff!!)

Thanks,
Piet

Image
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

is this spam?

anyway the terrain in irrlicht is not done hexagonal it is rectangular.

if you wanted (in 3d) to get the terrain coordinates of where the mouse was pointing then ray casting would be the solution.

hope this helps otherwise please refine the question.
pfrancke
Posts: 17
Joined: Thu Jan 01, 2009 3:06 am

Post by pfrancke »

No a very serious question - the texture has hexes painted on it and I desire to map back to those hexes based on where on the terrain the mouse is pointing.

The screen shot in the url listed above is output from my irrlicht program - essentially tutorial 12.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

the URL you posted requires you to be logged into terraingen.org

if you would like to host an image try http://www.imgbin.org/

idk what hex you speak of.. irrlicht doesn't have hexagonal terrain.
not on tutorial 12 or any other.

if this is a serious question then please take more time to be specific and accurate for what you're asking otherwise I'm helpless to assist.
pfrancke
Posts: 17
Joined: Thu Jan 01, 2009 3:06 am

Post by pfrancke »

Thanks about imgbin.

http://www.imgbin.org/index.php?page=image&id=262

the hexes are simply part of the texture that is being displayed. Once you see the image, you will probably know exactly what I'm up to...

tut 12 is how I drew the terrain. My goal is to know the x,y of where on the terrain the mouse is -- converting that junk to the "hex coordinate" is my problem.

It may be that ray casting is my only option, I sure hope not...
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

that is a very impressive texture you have there. is it yours?

it appears as though your hexagons are part of the texture as you mentioned and to get the coordinates of that would require probably more mathematics and/or programming then a true hexagonal based terrain node.

my suggestion would be to create your own hexagonal terrain scene node within Irrlicht and from that you should easily be able to extract the coordinates you require.

if perhaps you do not need it to be very accurate then a simple formula would suffice for a given spot within the hex painted texture given that your texture is properly scaled to the terrain. you would get that the same way you would get any Irrlicht terrain coordinate. and then of course using a formula to the correct spacing of the point inside the hexagon you wish to pin point.
pfrancke
Posts: 17
Joined: Thu Jan 01, 2009 3:06 am

Post by pfrancke »

yeah, I made the texture. I downloaded usgs data of the Gettysburg area. Ran the data thru a program called 3dem and produced output that the Terragen program could read. Using Terragen I produced a colored texture where high is redish brown and low is dark green - that output went into photoshop where I added layers for roads, rivers, trees, and the hexes etc. (Recently I found national archive maps of the area that will help me do a much better job of plotting out the topography). And the terragen program also pumped out a grey-scale bmp image that I use as a heightfield -- the terrain if you will.

I won't have any problem at all with the math to resolve the "hex coordinates", all I need to know is how to know that I'm pointing to the top left corner of the terrain. or to the midpoint, or to the bottom right of the terrain. If I can do that, everything is is a walk in the park. I just don't know what I can do with the Irrlicht API.

I was programming a top down zoomable map in pure opengl, and then I stumbled onto Irlicht and said to myself - "damn, this can be 3d".

Your last para is exactly what I want to do, if I could just find that place in the sand to stand. Could you go deeper into your statement of: "you would get that the same way you would get any Irrlicht terrain coordinate."
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The ISceneCollisionManager interface has methods for doing just what you want. You need to use getRayFromScreenCoordinates() to get a line that represents the cursor position in 3d. You can then use that line and getCollisionPoint() to find the point where the line intersects the terrain.

I'm sure that if you search for those function names, you'll find some code that shows you what you need to do to get the 3d position for the intersection of a ray and a scene node.

Travis
pfrancke
Posts: 17
Joined: Thu Jan 01, 2009 3:06 am

Post by pfrancke »

Thank you vitek!

I will proceed to humbly do my homework - I appreciate very much the focus you are giving.

Piet
pfrancke
Posts: 17
Joined: Thu Jan 01, 2009 3:06 am

Post by pfrancke »

I found the link http://irrlicht.sourceforge.net/phpBB2/ ... inselector to be very useful. I've got it working on a 1024x1024 terrain with a 4096x4096 texture applied. The only thing I found strange was that for the X dimension, the 0 was on the right while the larger number was on the left. But math can deal with that if I want to number my hexes from left to right.
Post Reply