Dynamic terrain

aspilicious

28-02-2011 09:38:41

I know there is a way to make some kind of terrain editor for ogre with ogre terrain.
I know you can create mesh files based on the terrain.
I also know how to build the .nxs files when I have the mesh files.

But is it possible to do this at runtime? Can I have an ogre terrain editor working together with nxOgre for the collision?

betajaen

28-02-2011 11:14:04

There is no terrain file format for PhysX. NxOgre has one though, it's called "xhf".

Yes, you can theoretically alter heightfields in PhysX, but the process is a little long. Essentially you have to create and destroy old heightfield (and any Static Geometries, HeightFieldGeometries using them), each time you do a modification. It may work okay in an editor, but you must do the updates in chunks (i.e. not making silly updates for a single height growing in 0.0001 in size, but for many at once); probably through a timer checking for a "Terrain is Dirty flag". You must remember to delete old Heightfields, as you'll soon run out memory with the old copies.

Real-time collision would be unpredictable, your deleting and creating a new heightfield, so PhysX may decide to let the objects fall down whilst your new heightfield is being created. In the next frame, they will notice the error, and attempt to shoot back out again. I think some sort of system would have to be written by you to freeze any objects that would be affected by the change, and move them accordingly.

aspilicious

28-02-2011 12:04:53

I found the basics of what I needed in: http://www.ogre3d.org/tikiwiki/tiki-ind ... eightfield

But it is old code and it fails on: xOgre::ManualHeightField *mhf = OGRE_NEW_T(NxOgre::ManualHeightField, Ogre::MEMCATEGORY_GENERAL);
EROR MESSAGE: Error 9 error C2660: 'NxOgre::Allocatable<Allocator>::operator new' : function does not take 2 arguments \physics.cpp 97

How can I convert this to detrius?

betajaen

28-02-2011 12:20:28

Don't use the new, just keep the class on the stack.