[Solved] Object floats in the air

Celest

29-06-2008 20:35:01

I used OgreMax with OgreNewt to load entity and scene into space.
But cylinder floats in the air.




OgreMax::OgreMaxScene* mScene = new OgreMax::OgreMaxScene();
mScene->Load("demoField.scene",mWindow, OgreMax::OgreMaxScene::NO_OPTIONS,mSceneMgr,mSceneMgr->getRootSceneNode(),0);
SceneManager *mgr = mScene->GetSceneManager();

OgreNewt::CollisionPrimitives::TreeCollisionSceneParser *col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(mWorld);
col->parseScene ( mgr->getSceneNode("terrain"), true );

mSceneMgr->showBoundingBoxes(true);

OgreNewt::Body *body = new OgreNewt::Body(mWorld,col);
body->attachToNode( mgr->getSceneNode("terrain") );

Ogre::Vector3 size = Ogre::Vector3( 10.3, 10.5, 10.5 );
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Ogre::Entity* ent = mSceneMgr->createEntity("cylinder_body", "cylinder.mesh" );
node->attachObject( ent );
node->setScale( size );

// rigid body.
OgreNewt::Collision* col2 = new OgreNewt::CollisionPrimitives::Cylinder( mWorld, 10.5, 10.3 );
OgreNewt::Body* bod = new OgreNewt::Body( mWorld, col2 );
bod->attachToNode( node );

// initial position
bod->setPositionOrientation( Ogre::Vector3(-2,900,2), Ogre::Quaternion::IDENTITY );
delete col2;

Ogre::Real mass = 10000.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcCylinderSolid( mass, 40.0, 40.0 );

bod->setMassMatrix( mass, inertia );
bod->setStandardForceCallback();


<scene formatVersion="1.0" upAxis="y" unitsPerMeter="39.3701" minOgreVersion="1.4" author="OgreMax Scene Exporter by Derek Nedelman (www.ogremax.com)">
<resourceLocations>
<resourceLocation type="FileSystem" name="../material/" recursive="false" />
<resourceLocation type="FileSystem" name="../material/shader/" recursive="false" />
<resourceLocation type="FileSystem" name="../mesh/" recursive="false" />
<resourceLocation type="FileSystem" name="../mesh/char/" recursive="false" />
<resourceLocation type="FileSystem" name="../mesh/object/" recursive="false" />
<resourceLocation type="FileSystem" name="../mesh/plant/" recursive="false" />
<resourceLocation type="FileSystem" name="../mesh/terrain/" recursive="false" />
<resourceLocation type="FileSystem" name="../texture/char/" recursive="false" />
<resourceLocation type="FileSystem" name="../texture/object/" recursive="false" />
<resourceLocation type="FileSystem" name="../texture/plant/" recursive="false" />
<resourceLocation type="FileSystem" name="../texture/sky/" recursive="false" />
<resourceLocation type="FileSystem" name="../texture/temp/" recursive="false" />
<resourceLocation type="FileSystem" name="../texture/terrain/" recursive="false" />
<resourceLocation type="FileSystem" name="../texture/water/" recursive="false" />
</resourceLocations>
<environment>
<clipping near="1" far="10000" />
<colourAmbient r="0.776471" g="0.776471" b="0.776471" />
<colourBackground r="1" g="1" b="1" />
<skyBox enable="true" material="SkyBox" distance="4000" drawFirst="true">
<rotation qx="0" qy="0" qz="0" qw="1" />
</skyBox>
</environment>
<nodes>
<node name="Direct01">
<scale x="77.2652" y="77.2652" z="77.2652" />
<position x="175.049" y="2899.07" z="2793.34" />
<rotation qx="-0.916921" qy="-0.0077486" qz="0.0178248" qw="-0.398595" />
<trackTarget nodeName="Direct01.Target">
<localDirection x="0" y="0" z="1" />
</trackTarget>
<animations>
<animation name="Direct01" enable="true" loop="true" interpolationMode="spline" length="3.33354">
<keyframe time="0">
<translation x="175.049" y="2899.07" z="2793.34" />
<rotation qx="-0.916921" qy="-0.0077486" qz="0.0178248" qw="-0.398595" />
<scale x="77.2652" y="77.2652" z="77.2652" />
</keyframe>
<keyframe time="3.33333">
<translation x="435.146" y="2899.07" z="2167.74" />
<rotation qx="-0.904715" qy="-0.019946" qz="0.0426195" qw="-0.423409" />
<scale x="77.2652" y="77.2652" z="77.2652" />
</keyframe>
</animation>
</animations>
<light name="Direct01" id="91" type="directional" castShadows="false" power="1">
<colourDiffuse r="1" g="1" b="1" />
<colourSpecular r="1" g="1" b="1" />
<lightAttenuation range="200" constant="1" linear="0" quadric="0" />
</light>
</node>
<node name="Direct01.Target" id="107">
<scale x="4.06697" y="4.06697" z="4.06698" />
<position x="-48.4979" y="-3266.94" z="-2954.2" />
<rotation qx="0.340231" qy="0.23592" qz="-0.0886005" qw="0.905944" />
</node>
<node name="terrain">
<scale x="1" y="1" z="1" />
<position x="0" y="0" z="0" />
<rotation qx="0" qy="0" qz="0" qw="1" />
<entity name="terrain" id="110" meshFile="terrain.mesh" castShadows="true" receiveShadows="true">
<subentities>
<subentity index="0" materialName="Terrain" />
</subentities>
</entity>
</node>
</nodes>
</scene>


How can I fix this problem ?
How can I get scenenode from scene script ?
Why cylinder floats in the air ? :cry:

ProfesorX

29-06-2008 22:27:31


// initial position
bod->setPositionOrientation( Ogre::Vector3(-2,900,2), Ogre::Quaternion::IDENTITY


This line tells me that may be you are not setting the worldsize, by default, the world size is (-100,-100,-100)(100,100,100), try using mWorld->setWorldSize().

And use OgreNewt::Debugger class, to see the collision bodies, this help a lot to find problems.

Celest

30-06-2008 22:52:16

Thanks ProfesorX. It works!

I can't see debugger line or any addition line when i use debugger class. :oops:

mSceneMgr = mRoot->createSceneManager(ST_GENERIC , "ExampleSMInstance");
OgreNewt::Debugger &debugger = OgreNewt::Debugger::getSingleton();
debugger.init(mSceneMgr);
debugger.showLines(mWorld);

walaber

30-06-2008 23:47:18

you need to call "showLines" each frame, to see the physics world update.

Celest

01-07-2008 02:00:21

you need to call "showLines" each frame, to see the physics world update.

Thanks walaber.
You should put this into doxygen doc :wink:

QXman

04-06-2010 13:50:21

col->parseScene ( mgr->getSceneNode("terrain"), true );

why , I cant find the "parseScene()"???

I use Ogremax2.3.