ofusion .scene file + treecollisionsceneparser

aida

27-07-2007 10:44:49

hi!

I tried to find a tutorial or a sample code to build 1 collision body from the entities defined in the .scene file generated by ofusion, but I failed!
I'm just a beginner, so I'll ask basic questions.

I have a city described by many entities in a .scene file. I need to make a character move around this city without going through buildings. Walaber told me to use the TreeCollisionSceneParser to build a single body from all the entities that make my city.
The TreeCollisionSceneParser takes a node as a parameter and then goes from child to child. The thing is that in my xml file, I have many entities which don't seem to be linked. Here is a part of the .scene file :
<entities>
<entity name="Plane01" hidden="false" filename="Plane01.mesh" CastShadows="yes" ReceiveShadows="yes">
<position x="3.30108" y="0" z="18.7177" />
<rotation x="0" y="0" z="-0" w="-1" />
<scale x="1" y="1" z="1" />
</entity>
<entity name="Plane02" hidden="false" filename="Plane02.mesh" CastShadows="yes" ReceiveShadows="yes">
<position x="0" y="0" z="-0" />
<rotation x="0" y="0" z="-0" w="-1" />
<scale x="1" y="1" z="1" />
</entity>
<entity name="Object01" hidden="false" filename="Object01.mesh" CastShadows="yes" ReceiveShadows="yes">
<position x="0" y="0" z="-0" />
<rotation x="0" y="0" z="-0" w="-1" />
<scale x="1" y="1" z="1" />
</entity>
<entity name="Object04" hidden="false" filename="Object04.mesh" CastShadows="yes" ReceiveShadows="yes">
<position x="0" y="0" z="-0" />
<rotation x="0" y="0" z="-0" w="-1" />
<scale x="1" y="1" z="1" />
</entity>


So I just don't know where to start and how to use the TreeCollisionSceneParser!

Thank you for your help

aida

07-08-2007 09:18:14

I found something in the forum that might help. Here is the post :
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=2266

The thing is that I need the Plugin_DotSceneManager.dll. I searched through the Ogre3D web site but can't find where it can be downloaded. Can someone help?

Thanks

aida

08-08-2007 10:13:08

Ok,
so I eventually managed to get the DotSceneManager plugin, I also converted my osm file to .scene file. I used the code of in the post http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=2266. In Newton debug mode, I can see that all the buildings have now a collison body, but my character still walk through them!!

Here is my code :


DotSceneOctreeManager * mDotSceneMgr = (DotSceneOctreeManager *)root->createSceneManager("DotSceneOctreeManager");
mDotSceneMgr->setWorldGeometry("scene.scene");

int numMeshes;
mDotSceneMgr->getOption("NumMeshes", &numMeshes);
StringVector keyss;
mDotSceneMgr->getOptionKeys(keyss);
for (int meshIndex = 0; meshIndex < numMeshes; meshIndex++)
{
int numVerts = 0;
mDotSceneMgr->getOption("NumVertices" + StringConverter::toString(meshIndex), &numVerts);
int numIndices = 0;
mDotSceneMgr->getOption("NumIndex" + StringConverter::toString(meshIndex), &numIndices);
float* vertPtr = 0;
mDotSceneMgr->getOption("VerticesPtr" + StringConverter::toString(meshIndex), &vertPtr);
int* indicesPtr = 0;
mDotSceneMgr->getOption("IndexPtr" + StringConverter::toString(meshIndex), &indicesPtr);
OgreNewt::CollisionPrimitives::TreeCollision* col_dotscene
= new OgreNewt::CollisionPrimitives::TreeCollision
(pWorld,numVerts,numIndices,vertPtr,indicesPtr, true);
OgreNewt::Body* bod = new OgreNewt::Body(pWorld, col_dotscene);
delete col_dotscene;
}



So am I missing something?
Please help me, I've been stuck for 2 weeks now.

Here is the code for the character collision body :

//character creation
SceneNode *viewNode = pSceneManager->getRootSceneNode()->createChildSceneNode("ViewNode");
viewNode->setPosition(22.292f,0,72.3004);

Entity *character = pSceneManager->createEntity( "Character", "robot.mesh" );
SceneNode *characterNode = viewNode->createChildSceneNode( "CharacterNode");

characterNode->attachObject(character);
characterNode->rotate(Vector3(0,1,0), Radian(1.57));
characterNode->scale(.007,.007,.007);

SceneNode *camNode = viewNode->createChildSceneNode("CamNode");
camNode->translate(Vector3(0,.4,1));
camNode->attachObject(pCamera);

//Collision body for character
Vector3 size(1,1,1);
Real mass = 10;
Vector3 inertia = OgreNewt::MomentOfInertia::CalcEllipsoidSolid( mass, size ); // calculate the inertia ov the body
Vector3 pos = viewNode->getPosition();
Quaternion orient = Ogre::Quaternion::IDENTITY;

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( pWorld, size );
OgreNewt::Body* bod = new OgreNewt::Body( pWorld, col );
delete col;

bod->attachToNode( viewNode );
bod->setMassMatrix( mass, inertia );
bod->setStandardForceCallback();
bod->setPositionOrientation( pos, orient );
bod->setAutoFreeze(0);
bod->setContinuousCollisionMode(1);

ProfesorX

09-08-2007 01:32:45

I have a similar problem in the beginning of learning Newton, so, perhaps it is the same.

How are you moving your character?

You need to move your character using forces, if you use translations, you always walk through the walls

Search the forum for character movement and first person camera for more info

aida

09-08-2007 08:17:38

Thank you ProfesorX! Gosh I thought this forum was on holidays!

Indeed I was just using translation to move my character and set the standardForcecallback. I've now created a custom Force & Torque callback, set friction to zero, and it works!!!
I just have now to make the character rotate when I press the left or right keys, instead of just pushing him on the side.

Thank you for your lights!

aida

09-08-2007 10:18:25

Maybe someone has faced the same problem as mine. Here is it :

I move my character using the 4 keys UP, DOWN, RIGHT and LEFT. I've defined a simple customForceAndTorque Callback to control the character.
When I hit the RIGHT or LEFT key once, the character rotates well. when I hit another key afterwards, the character comes back to the position he was before the first key hit.
Here is the code :

//force callback

void MyFrameListener::character_force_callback(OgreNewt::Body* me){
Real mass;
Vector3 inertia;
Real gravity = -9.8;

me->getMassMatrix(mass, inertia);
Ogre::Vector3 force(0,gravity,0);
Ogre::Vector3 force2(0,gravity,0);

Quaternion q,orient;
Vector3 qq,s,direction,pos;
me->getPositionOrientation(pos, orient);


Ogre::Vector3 V0 = me->getVelocity();
Ogre::Vector3 V1 = orient * mDirection;

Ogre::Real deltatime = me->getWorld()->getTimeStep();
Vector3 acel ((V1 - V0) / deltatime);
force2 = (Vector3(acel.x,gravity,acel.z))*mass;

me->addForce( force2 );
}


// KEY PRESSED


bool MyFrameListener::keyPressed( const OIS::KeyEvent &arg )
{
if( mKeyboard->isKeyDown(OIS::KC_ESCAPE) || mKeyboard->isKeyDown(OIS::KC_Q) )
mWindow->destroy();


if(arg.key == OIS::KC_UP){
mTranslateVector.z = mMoveScale; // Move forward
mDirection = mCamera->getDerivedOrientation() * Vector3::NEGATIVE_UNIT_Z;
}
if(arg.key == OIS::KC_DOWN){
mTranslateVector.z = -mMoveScale; // Move backward
mDirection = mCamera->getDerivedOrientation() * Vector3::UNIT_Z;
}
if(arg.key == OIS::KC_RIGHT){
mRotX = -mRotScale;
mDirection = mCamera->getDerivedOrientation() * Vector3::UNIT_X;
}

if(arg.key == OIS::KC_LEFT){
mRotX = mRotScale;
mDirection = mCamera->getDerivedOrientation() * Vector3::NEGATIVE_UNIT_X;
}


mTimeUntilNextToggle = 1;
return true;
}


//KEY RELEASED

bool MyFrameListener::keyReleased( const OIS::KeyEvent &arg )
{

if (arg.key == OIS::KC_UP) {
mTranslateVector.z = 0;
}
if(arg.key == OIS::KC_DOWN)
mTranslateVector.z = 0;

if(arg.key == OIS::KC_RIGHT){
mRotX = 0;
mTranslateVector.x = 0;
}

if(arg.key == OIS::KC_LEFT){
mRotX = 0;
mTranslateVector.x =0;
}
mDirection = Vector3::ZERO;
return true;
}


//MOVE CAMERA

void MyFrameListener::moveCamera(){

mCamera->getParentSceneNode()->getParentSceneNode()->yaw(mRotX);
mCamera->getParentSceneNode()->getParentSceneNode()->pitch(mRotY);;
mCamera->getParentSceneNode()->getParentSceneNode()->translate(-mTranslateVector, Ogre::Node::TS_LOCAL);
if (mRotX !=(Radian)0 || mRotY!=(Radian)0) mDirection = mCamera->getDerivedDirection()*mDirection;
}


Does someone know this 'phenomenon'?