NxOgre and units / Character floating [SOLVED]

Night Elf

21-08-2007 20:58:55

I'm considering using NxOgre but I have a lot of models that were built using the 1 = 1 cm scale (instead of 1 = 1 m, that I understand is default in NxOgre). Will I have any problems with this?

betajaen

21-08-2007 21:52:18

A little. In your scale gravity would be -0.98 metres a second than -9.8, and "mass: 10" would mean 10 grams than 10 kilograms.

Any chance you can change your scale, or at least tell the exporter to scale by 100x100x100 when you export?

Night Elf

23-08-2007 15:03:34

In your scale gravity would be -0.98 metres a second than -9.8

But I would use -980, because now units would be cm, am I right?

"mass: 10" would mean 10 grams than 10 kilograms

Why would mass have to change? Couldn't it still be kilograms?

Any chance you can change your scale, or at least tell the exporter to scale by 100x100x100 when you export?

Unfortunately, no. The problem is, everything in my code and external files (not only meshes) assume length units are centimetres not metres, so it'd be impossible to change.

What would you think would be necessary for PhysX to work correctly with centimetres? For starters, I guess setting a bigger "skin width" would be needed...

betajaen

23-08-2007 16:09:17

Yep, Your right with those conversions. I must of had a brain fart there.

Go for it and see how it fairs. But you'll see floating point errors more often than you would do with the metres scale - when you move very far away from the centre of the Scene for example.

Night Elf

23-08-2007 20:45:07

Ok, I'm giving it a shot.

Here's a problem that I've run into: I'm using the Character controller with a capsule shape and the capsule never touches the ground... (the same happens with a box).

Here's the code I'm using so far:

Initialisation:
g_nxWorld = new NxOgre::World;
g_nxScene = g_nxWorld->createScene("Main", g_sceneMgr, "gravity:0 -980 0, floor:yes");
g_nxWorld->getPhysXDriver()->getSDK()->setParameter(NX_SKIN_WIDTH, 1);


Character code:
_nxCharacter = g_nxScene->createCharacter(
_name,
NxOgre::Pose(Ogre::Vector3(0, size.y * 0.5f + _type->size.x, 0), Ogre::Quaternion::IDENTITY),
"type: capsule, dimensions: "
+ Ogre::StringConverter::toString(size.x) + " "
+ Ogre::StringConverter::toString(size.y - 2 * size.x) + " "
+ Ogre::StringConverter::toString(size.z));

_nxCharacter->attachMesh(meshName);
_entity = _nxCharacter->getEntity();
_node = _nxCharacter->getNode();


Here's a screenshot of what I get in the Visual Debugger (click for full size image):



If I walk out of the terrain, the character falls, so gravity is indeed affecting it. Any ideas...?

betajaen

23-08-2007 20:56:27

Characters don't work on flat planes, they just fall through. You need to place a large flat (0.25 height) static actor with a cube for it to walk on.

Also, I don't think you should be setting the skin width like that.

Night Elf

23-08-2007 21:17:40

Yes, I noticed they fall through floors. It's walking on a mesh I loaded:

_nxActor = g_nxScene->createActor(meshName, new NxOgre::TriangleMeshShape(meshName), Ogre::Vector3::ZERO, "static: yes");

Also, I don't think you should be setting the skin width like that.

How should I do it, instead?

betajaen

23-08-2007 21:23:43

I'd leave it until you have a full scene to work with, then adjust it. You can test it by stacking boxes and how stable the stack is.

Night Elf

23-08-2007 21:36:21

Ok, I'll leave the default skin settings...

Do you have any ideas as to why the character's floating?

Night Elf

24-08-2007 23:49:11

Finally I could solve this problem.

Firstly, the debug output shows the capsule "floating" because of the skin around it. There appears to be a skin around the capsule that accounts for 20% of the actual dimensions you use. (For example, if you use a radius of 1, you get a 0.8 radius in your capsule plus an extra 0.2 radius). This seems to be independent of the skinWidth parameter...

To get the character to display correctly, I did:

// size.x is the desired radius and size.y is the TOTAL
// length of the capsule (not just the cylindrical centre)
nxCharacter = g_nxScene->createCharacter(
name,
Ogre::Vector3::ZERO,
"type: capsule, dimensions: "
+ Ogre::StringConverter::toString(Ogre::Vector3(size.x, size.y - 2 * size.x, size.z))
);
nxCharacter->createNode();
node = _nxCharacter->getNode()->createChildSceneNode();
entity = g_sceneMgr->createEntity(name, meshName);
node->attachObject(entity);
node->setPosition(0, -0.5f * size.y, 0);

betajaen

25-08-2007 09:44:15

That seems about right. The "Skin" is just how far the character needs to float in the air for the RayCaster, so it can move over uneven terrain, slopes or stairs. I should make that clearer in the code.

dbrock

20-01-2008 19:21:13

I know this thread is old, but I'm just curious as to where the pivot point was located in the mesh file. Was it centered on the Y axis? Located at the bottom? I'm sure this question would influence the code on whether or not it would work for other people using similar dimensions.

These settings worked for me when I had the pivot set to the bottom of the character, but for our game, the y-alignment is in the middle, so I'm just trying to figure out the adjustments I'll have the make to keep my character with his feet touching the ground.