Terrains, need a fast way of getting coordinate's height

xerios

09-05-2010 02:15:12

Since I'm kind of new to all this Ogre stuff, I wondered if there isn't a faster way than just casting a ray with queryType 0

My current code:

heightRay.Origin = pos + Vector3.UNIT_Y * 100;
mRaySceneQuery.Ray = heightRay;
mRaySceneQuery.QueryMask = 0;
RaySceneQueryResult result = mRaySceneQuery.Execute();

if (result.Count != 0 && result.Front.worldFragment != null) {
Vector3 destination = result.Front.worldFragment.singleIntersection;
pos.y = destination.y;
}


It's fast but not good enough when having thousands of entities execute that code =/



Also, what would be the optimal way of aligning my units on the terrain?

Thank you =)

xerios

09-05-2010 12:32:42

I found this which would help me a lot with my problem :
http://www.ogre3d.org/docs/api/html/cla ... rrain.html

but for some reason I can't find that class anywhere in Mogre, is it yet to be wrapped or am I not looking in the right places?

smiley80

09-05-2010 21:11:40

The TerrainSceneManager doesn't use that class, so it wouldn't help you anyway.

You can cache the whole terrain heights in a two-dimensional array on setup.
Or you load the height map into a Bitmap, translate the terrain coordinates to texture coordinates and get the height with:
float height = heightMap.GetPixel(x, y).GetBrightness() * maxTerrainHeight;

xerios

09-05-2010 23:04:28

I shall try that.

Any other advices? I can't do anything with this TerrainSceneManager, it's so annoying =(

xerios

10-05-2010 22:07:52

Putting heights into an array only gave me a 3~5 fps boost with 1000 of units on screen, kind of disappointing actually. I'd rather stick with the mouse picking since it offers much more precision.

I'm currently trying to use a physics engine for height picking, but have hard time converting the mesh into a collision object, ( for OgreBullet, OgreNewt crashes for me for some reason ) so anyways, I'm kind of sick of this Terrain Scene Manager, can't do anything with it, is there any alternative that WORKS and gives me more control? If not, does any one have any script that could help me convert an ogre mesh into a Bullet collision object thingy?

WarehouseJim

11-05-2010 09:15:05

Just to check, it is the process of getting the terrain height that is slowing down your render speed, not the number of batches (moveable objects / entities) that you are rendering? You may like to look at using InstancedGeometry to speed up the frame rate - Ogre 1.6 demos include an example of using it with skeletally animated entities.

The bitmap method sounds as if it should be very fast. If it's not, and you've got a few cores, I assume you could multi-thread it. I can't believe that a physics engine will be quicker for getting the height than the bitmap method.

koirat

11-05-2010 13:16:46

Are you ray casting/height check every frame for every object ? Try to ray cast/height check only when position changed.

xerios

11-05-2010 15:05:10

Height check is already made "on position change only", as for instancing I currently don't have it implemented yet since I had no luck making it work , always caused crashes and all.
Apparently I found out that heightmap array technique did help a lot , and that I was wrong about it giving me a unsatisfying performance boost.

The huge performance is eater is obviously my steering algorithm but it's ok.

Now what's the best way to calculate height, based on surrounding points to smooth out the transition between heights because right now it looks kind of jaggy ( jumps from one height to another) ?
( Basic linear implementation does a bad job cause it doesn't know when it's in between two height values)

xerios

12-05-2010 14:26:02

Either way only one thing matters to me, WHEN ARE WE GOING TO GET THE NEW TERRAIN WRAPPER?


=(

mstoyke

12-05-2010 16:26:56

Well, how about you create it, then you can make sure it does exactly what you need ;)
Otherwise you will have to wait for somebody who also needs it wrapped, creates a wrapper and is willing to provide it to other to use...

xerios

13-05-2010 19:19:23

Aww, I'll wait then =(

thanks anyway

Meanwhile, enjoy a small video I made ( before I mass optimized it ;) )
http://www.youtube.com/watch?v=pfuf5lDN18w