Need some help with this...

DaCracker

10-08-2006 22:57:50

Hi!
I'm a new user of nxOgre, it seems to have some nice features
and I'm currently adding support for nxOgre in my game engine.
However, I've got some problems when I'm using nxOgre with
oFusion. I use this code to create an entity:


// Create all entities in scene
void OSMScene::createEntities(TiXmlElement* pEntityNode, Ogre::SceneNode* pSceneRoot)
{
// Iterate all meshes, creating them.
for (TiXmlElement* pMeshElem = pEntityNode->FirstChildElement();
pMeshElem != 0; pMeshElem = pMeshElem->NextSiblingElement())
{
// Ogre could cast an exception, in which case we just try to
// continue reading the other meshes
try
{
const char *pszName = pMeshElem->Attribute("name");
const char *pszFileName = pMeshElem->Attribute("filename");

// Create node with full information
SceneNode *pObjNode = createNode(pMeshElem, pSceneRoot);

global->mScene->createStaticBody(pszName,pszFileName,new nxOgre::meshShape(pszFileName,global->mScene),pObjNode->getPosition());

// try to create the mesh
Entity *pEntity = mSceneMgr->createEntity(pszName, pszFileName);

if(pEntity==0) continue;

// Check if the object should cast shadows
const char *pszCastShadows=pMeshElem->Attribute("CastShadows");
if(pszCastShadows && stricmp(pszCastShadows, "no")==0)
{
pEntity->setCastShadows(false);
}
else
{
pEntity->setCastShadows(true);
}

// Attach the mesh entity to node
pObjNode->attachObject(pEntity);

// Notify
if(mCallbacks)
{
mCallbacks->OnEntityCreate(pEntity, pMeshElem);
}

// Add to entity list
mEntities.push_back(pEntity);
} catch(...)
{
continue;
}
}
}



The strange thing is that from what I've seen, the createStaticBody() method creates an entity and attach it to a SceneNode, so... I should
be able to see my objects in the scene right? The thing that I find strange
is that i can't.
I've tried to add an extra entity, which I can view... but it seems like
a very bad solution to me, the code above shows how I've done this.
The second problem is that when I create this extra entity, the collision
detection seems to be wrong, it works fine at some places but at other
places I fall through the floor!

I'm sorry if these questions are very basic, but I've never used a
physics engine before
:?

betajaen

10-08-2006 23:26:21

It's alright to ask basic questions - if your new :wink:

1. Make sure the mesh name ends with .mesh although I would expect Ogre to crash if the file didn't exist. It's worth a shot.

2. When you mean you fall through the floor, does that mean a body falls through the floor, or your using the character controller and that falls through the floor?

Oh:
Also, you might want to fiddle around with the debug viewer which will show the collision model of the scene (as line) over the existing scene.

Put this after you've created your scene and bodies:

mWorld->debug(true)l

DaCracker

10-08-2006 23:47:20

I found something strange when I did this:


global->mScene->createStaticBody(pszName,pszFileName,new nxOgre::meshShape(pszFileName,global->mScene),pObjNode->getPosition());


Ogre::Entity *pEntity = global->mSceneMgr->getEntity(pszName);


Seems like the entity can't be found by name when it's created by nxOgre? :?

anyway...
I mean that the character controller falls through the ground at some
areas (the ground is created with the createStaticBody() method).

EDIT:
I tried thee world::debug(true) method, but it failed because of
this:

00:25:17: Mesh: Loading Box01.mesh.
00:25:17: An exception has been thrown!

-----------------------------------
Details:
-----------------------------------
Error #: 4
Function: Serializer::determineEndianness
Description: Can't find a header chunk to determine endianness.
File: ..\src\OgreSerializer.cpp
Line: 79


I guess this might be the one causing the trouble with the
collision detection?

betajaen

10-08-2006 23:54:22

Ahh, the falling through the floor is "normal". Just use a very large but thin cube for it.

As for your mesh/entity problem. Have you ran it through the mesh upgrader? Also it is unrelated but to keep in mind, PhysX *hates* with a fiery passion duplicate vertices.

DaCracker

11-08-2006 00:03:21

The large cube solution would only help tempoarily since
I want my players to be able to run up and down on stairs,
have diffrent ground level on some places etc. etc.

What I simply want is:

load every mesh in my scene as a static body so that my player character (the player is a character controller) can walk and jump on objects.

Shouldn't be this hard to get this up and running?

Am i doing someting wrong? or do you have some tips
on how I can solve this problem in a better way?

betajaen

11-08-2006 10:30:07

That is how your meant to do it, and I'm puzzled why it isn't working for you.

Alright, time to see some pictures; Can you run it with debug mode on and post it here?

DaCracker

15-08-2006 21:11:08

Okey, I've finally got things up and running :D
However... loading a scene 85+ static bodies
using mesh shape isn't fun at all for a single-core
system without a physics processor :P I figured
out how to load the "ground" as a mesh shape.
I've decided to load all the other static geometry
as cube shapes, it works quite well for cube-like
buildings :).


void OSMScene::createEntities(TiXmlElement* pEntityNode, Ogre::SceneNode* pSceneRoot)
{
// Iterate all meshes, creating them.
for (TiXmlElement* pMeshElem = pEntityNode->FirstChildElement();
pMeshElem != 0; pMeshElem = pMeshElem->NextSiblingElement())
{
try
{
const char *pszName = pMeshElem->Attribute("name");
const char *pszFileName = pMeshElem->Attribute("filename");

SceneNode *pObjNode = createNode(pMeshElem, pSceneRoot);

global->mScene->createStaticBody(pszName,pszFileName,new nxOgre::meshShape(pszFileName,global->mScene),pObjNode);


}
}



The problem is how I should be able to define the size
of the "cube" for every object :?
Any suggestions?

[EDIT]
I will of course be using nxOgre::cubeShape() instead of
nxOgre::meshShape(), the code above is just what I use
to get things to work while I'm trying to find a cubeShape
solution :wink:

betajaen

15-08-2006 21:39:09

I would be interested to see why the meshShape collision isn't working very well for you. If your uncomfortable posting such screenshots on a public forum I can speak to you privately.

However as for your question, cubeShape can take a vector so:

new cubeShape(Vector3(1,2,3))

Makes a cube 1 metre in the X direction, 2 metres UP and 3 in the Z.

DaCracker

15-08-2006 21:51:54

The meshshape itself works, well... less good because
that I haven't been able to get nxOgre + oFusion
to work properly together (yet) (it's a problem
with scaling, rotation etc.). And the performance
itself is a problem, I only get around 250 FPS
on a Sapphire ATI Radeon x1900XT (512mb),
which means that the performance would be
terrible on a less good computer.
If you have an instant messenger (MSN?)
I can send som screenshots to you.

Thanks for the info about the cubeShape btw :)