How to do a Debug Renderer

SiWi

22-08-2007 17:55:45

I´m working with PythonOgre and I´m trying to make some Tutorials for NxOgre. The Debugger is fine, but how can I show a debug model of the shapes? I know from searching this is included in old versions, but not in the new one, right?
I need it to make the Terrain Collison Shape fit to the Terrain from the Ogre Demo.
Thank you for your help.

betajaen

22-08-2007 18:10:34

I don't know with the Python NxOgre has the debug renderer enabled; it's a compiler flag.

If the option isn't there, then it isn't in.

[Edit]

However the debug renderer isn't very good, and terrain seems to overload it. Perhaps I can help with your terrain code?

SiWi

22-08-2007 18:48:23

The thing about my terrain code is that I want to take the Ogre Terrain Demo and add Physic to it. The terrain in the demo is generated via a config file. I took the terrain example from your 0.6-0.9 quickporting guide. I figured out that the second parameter passed to TerrainShape is maxhight, but I don´t konw how to use the other ones to fit the Ogre Terrain.

betajaen

22-08-2007 19:24:10

Say an image is 512 by 512 pixels, by default NxOgre treats one pixel as on metre, so the terrain is 512x512 metres big.

To scale it, you add it to a param. I don't know how it is handled in Python, but, in C++ NxOgre we do it via:

ShapeParams sp;
sp.setToDefault();
sp.meshScale = Vector3(2,0,2);

...

new TerrainShape("image", height, sp);



Which means each pixel is 2 metres big.

SiWi

22-08-2007 19:59:50

Thank you. Porting the Code to PythonOgre is no problem. Looks like it isn´t easy to get the Scale from Ogre to fit a NxOgre Terrain.

betajaen

22-08-2007 20:27:39

Actually it is:

http://www.ogre3d.org/phpBB2addons/view ... 9230#29230

His terrain size is 3000x3000, so you scale it by "5.859375 1 5.859375" to get the right size.

It's just basic maths.

SiWi

23-08-2007 09:25:41

Thank you. My problem was that I didn´t understand that Ogre also uses metres for Terrain Size.
EDIT:
I do this:

mWorld = new World();
mScene = mWorld->createScene("Main", mSceneMgr, "gravity: yes, floor: yes");
ShapeParams sp;
sp.setToDefault();
sp.meshScale = Vector3(2.9296875,0,2.9296875);
mActor = mScene->createActor("terrain", new TerrainShape("terrain.png", 100,sp), Vector3::ZERO, "static: yes");

for (int i=0;i<10;i++)
mScene->createBody("cube.1m.mesh", new CubeShape(10,10,10), Vector3(2030,64+i,2048), "mass: 10 node-scale: 10 10 10");

The Cubes fall on the terrain, bounce off, fall through the terrain.

betajaen

23-08-2007 10:22:23

Try this:

mActor = mScene->createActor("terrain", new TerrainShape("terrain.png", 100,sp), Vector3(0,50,0), "static: yes");

SiWi

23-08-2007 13:52:27

Doesn´t work. Why do you do this? Maybe it´s because my terrain.cfg settings are a little differnet to yours. My terrain was 1500*1500 for example.

betajaen

23-08-2007 14:15:19

How big is the image?

SiWi

23-08-2007 14:26:02

512*512.

betajaen

23-08-2007 14:27:41

The scale seems right. Let's see your terrain.cfg

SiWi

23-08-2007 15:50:20

# The main world texture (if you wish the terrain manager to create a material for you)
WorldTexture=terrain_texture.jpg

# The detail texture (if you wish the terrain manager to create a material for you)
DetailTexture=terrain_detail.jpg

#number of times the detail texture will tile in a terrain tile
DetailTile=3

# Heightmap source
PageSource=Heightmap

# Heightmap-source specific settings
Heightmap.image=terrain.png

# If you use RAW, fill in the below too
# RAW-specific setting - size (horizontal/vertical)
#Heightmap.raw.size=513
# RAW-specific setting - bytes per pixel (1 = 8bit, 2=16bit)
#Heightmap.raw.bpp=2

# How large is a page of tiles (in vertices)? Must be (2^n)+1
PageSize=513

# How large is each tile? Must be (2^n)+1 and be smaller than PageSize
TileSize=65

# The maximum error allowed when determining which LOD to use
MaxPixelError=3

# The size of a terrain page, in world units
PageWorldX=1500
PageWorldZ=1500
# Maximum height of the terrain
MaxHeight=100

# Upper LOD limit
MaxMipMapLevel=5

#VertexNormals=yes
#VertexColors=yes
#UseTriStrips=yes

# Use vertex program to morph LODs, if available
VertexProgramMorph=yes

# The proportional distance range at which the LOD morph starts to take effect
# This is as a proportion of the distance between the current LODs effective range,
# and the effective range of the next lower LOD
LODMorphStart=0.2

betajaen

23-08-2007 16:03:13

That seems pretty much up to check.

Although your image is 513x513 right? It won't make that much difference to the scale though, but worth a try.

When you say they fall on the terrain, through or bounce off; Does that mean parts of the terrain seem right, and the other parts don't?

Any chance for a screenshot?

SiWi

23-08-2007 16:27:25

When they fall to the terrain and bounce of, they first fall in the terrrain with one edge, then jump back where they came from foor a few metres.
EDIT: Changed the Params for 513. Did nothing.

TMT

23-08-2007 20:48:58

I had trouble at first where my objects would drop onto the terrain, roll around and then drop through the terrain. Then I changed the PageWorldX/Z fields to the proper values. I use the Ogre example terrain files, but I push it to 5kmx5km, so PageWorldX/Z=5000. The difference with creating the terrain in NxOgre is as follows:

mScene->createActor("terrain",new NxOgre::TerrainShape("terrain.png", 100, "mesh-scale: 9.765625 1 9.765625"),Vector3(0,1,0),"static: yes");
Maybe using the string version of mesh-scale works and passing the vector in directly does not.

Now it all works for me.

betajaen

23-08-2007 20:58:19

Odd, they are nearly exactly the same. But if it works, go for it. ;)

SiWi

24-08-2007 08:15:51

Working for me. :D It´s also working with PageWorldX/Y = 1500. I think the key is the '1' in the mesh scale I think. Any ideas why? His first post only to help me. :oops:

betajaen

24-08-2007 10:10:12

Do you mean the Y portion of the mesh-scale? It's not used at all with the terrain code.

SiWi

24-08-2007 11:33:46

Upps no I meant the Vector3(0,1,0). :oops: Thats the key, why?

TMT

24-08-2007 19:00:55

I see now that there is something odd about NOT using Vector3::ZERO. With mine at Vector3(0,1,0) my objects actually sit exactly 1 meter above the terrain. Due to my perspective I hadn't noticed this. It was only when I tried Vector3(0,50,0) that I noticed my objects sitting way off the terrain.

So it seems that unless you specify Vector3::ZERO, your rendered terrain and physics models will be offset somewhat. But Vector3::ZERO definitely works for me.

betajaen

24-08-2007 19:14:26

I think it depends on the terrain. When I first started the terrain code, I settled on having the actor's Y position to be half the maximum height. Now it seems it's a variation of 0, or 1.

I would investigate it further but the Cakebox I'm working with right now, is having a little spring clean. ;)