terrain picking

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
drulz
Posts: 11
Joined: Thu Jun 09, 2005 5:08 am

terrain picking

Post by drulz »

how can i pierform terrain picking in irrlicht? i want to knw where in my terrain the user clicked like of those in an RTS game
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

getRayFromScreenCoordinates with cursor coordinates.

Then getCollisionPoint, with terrain selector and ray from above function.
Image
drulz
Posts: 11
Joined: Thu Jun 09, 2005 5:08 am

Post by drulz »

hi spitz thanks for the reply

i have a followup question

a)using this i can get the coordinates of the area clicked on the terrain?

b)in using terrain rendering what are the exact coordinates of the terrain? i mean is the terrain centered at 0,0,0? or the terrain upper left coord starts at 0,0,0? or what?

thanks
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

0,y,0 is the first vertex in the meshbuffer, the vertices go up the Z axis, then the X axis, so second vertex is 0,y,1

and yes to your first question, if done right
Image
drulz
Posts: 11
Joined: Thu Jun 09, 2005 5:08 am

Post by drulz »

cool!

one last thing spintz,

Is there any limitation on the size of the terrain( or the heightmap) i can use/render? for example a heightmap bigger than 1024x1024? is there any culling in the terrain implementation in irrlicht thats culled away unnecessary vertices in the terrain?
ps. Sorry if i ask too much question coz my style in coding is i research some things before doing it and these question just pop my mind one at a time :)
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

patches within a terrainNode are culled by the viewFrustrum.
Image
Guest

Post by Guest »

hi spintz seems like the picking approach u mentioned above doesnt work when the terrain is scaled :) u have any other way of doing this?
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

the only reason i can see it not working, is if you create your selector from the node, and then scale your node afterwards. The selector will have triangle data from before the scaling, so it won't match up.
Image
Crivens

Post by Crivens »

I'm definitely creating and scaling my terrain before creating my selector. It definitely doesn't work with scaled terrains. Any chance you could try it out and see if we're correct or mistaken spintz? Thanks!
Fred

Post by Fred »

Bump - this is an issue that needs resolving I think.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

You all do know, that the Terrain Example that ships with Irrlicht, scales the terrain, and the selector works just fine with it.

I've already posted my suggestions as to what the problem could possibly be. I've tested it, it works for me.

Unless code is given to look at, this is a non-issue for me.
Image
Fred

Post by Fred »

I wonder if it's related to creating objects before the terrain is rendered for the first time.
Fred

Post by Fred »

Should stay live for 24 hours:

http://rafb.net/paste/results/Wjw2sD34.html
Foole
Posts: 87
Joined: Mon Aug 29, 2005 10:08 am

Post by Foole »

Does the problem still occur if you pass the new scale to addTerrainSceneNode when you first create the terrain?

I think there's a difference between the way the terrain is scaled when its created and the way its scaled when the scale is changed.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

I see you're problem.

It's not the terrain, it's the Irrlicht collision. I'd seriously recommend using a physics engine, even just for basic collision. Irrlicht collision, obviously has bugs and is slower than any physics engine out there.

When TrueAxis first came out, it had a bug in it's own line tests when a line was parallel with the Y axis, or ran straight up and down. Irrlicht seems to have that bug, as well as others. I've modifed your code a bit -

http://pastebin.com/353607

I've added the triangle drawn on the terrain, similar to collision example 6. You'll notice with this code, many more boxes are placed on the terrain, that's because of this -

Code: Select all

// Make sure the start.Y is higher than the highest point of your terrain
// Make sure the end.Y is lower than the lowest point of your terrain
myline.start = core::vector3df ( x + 100.0f, 2500.0f, z - 100.0f );
myline.end = core::vector3df ( x - 100.0f, -2500.0f, z + 100.0f );
I'm forcing the line to be at an angle, instead of straight up and down, this works for the most part, but some boxes still aren't drawn on the terrain. You'll notice if you move around, the red triangle is always drawn on the terrain. However, check the console for locations where the collision filed ( I output them now ) and then restart, without calling any addObjects and set your camera position and target to the line start and end respectively( you can shrink the Y's ) and you'll see the triangle isn't drawn. Then move around a little bit ( side to side ) but stay focused on that area and eventually, the line test will start working.

This isn't the terrain, nothing I can do, post it in the Bug Forums for Niko to look at. I wish I could help more, but I don't have time to debug the Irrlicht collision code. It'd be much easier for you to just integrate into a physics engine, TrueAxis, Novodex, ODE, Newton, and there are most likely others to look into.

Sorry I couldn't help more!!!
Image
Post Reply