radgoll problem

gugus

14-01-2007 10:36:21

Hello.
I am trying to use ragdoll.So i did a short programm from the simpelscene.
It compile fine but when i am launching the .exe, i have the error:

An exeption has been thrown

movableobjectfactory of type ODERagdoll does not exist.

my code:

Ogre::NameValuePairList params;
params["mesh"] = "robot.mesh";
OgreOde_Prefab::Ragdoll *pRagdoll = static_cast<OgreOde_Prefab::Ragdoll*>(pSceneManager->createMovableObject("robot",
OgreOde_Prefab::RagdollFactory::FACTORY_TYPE_NAME,
&params));
pRagdoll->setCastShadows(true);

Ogre::SceneNode *pRagdoll_node = pSceneManager->getRootSceneNode()->createChildSceneNode("robotNode");
pRagdoll_node->attachObject(pRagdoll);

pRagdoll_node->setScale(Ogre::Vector3(1.0,1.0,1.0));


pRagdoll->getAnimationState("Walk")->setEnabled(false);

if ("robot.ogreode" != StringUtil::BLANK) dotOgreOdeLoader.loadRagdoll("robot.ogreode", pRagdoll,"robot");

// Create the ragdoll
pRagdoll->takePhysicalControl(pSpace, false);
pRagdoll->setSelfCollisions(false);

gugus

14-01-2007 18:40:19

I solved the probleme.
But now i have another probleme:
when i launch the animation "Walk" of the robot,it work fine for one second,but the animation go slower and slower and the movement is shorter and shorter and at the end it do not move at all.

my new code:
main.cpp

#include "ragdoll.h"

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
// Create application object
Scene app;

try
{
app.InitScene();
app.run();
}

catch( Exception& e )
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " << e.getFullDescription();
#endif
}

return 0;
}


radgoll.h

#include <OgreOde_Core.h>
#include <OgreOde_Prefab.h>


class Scene : public Ogre::FrameListener ,public OgreOde::StepListener,public OgreOde::CollisionListener
{
public:
Ogre::Root* pRoot;
Ogre::RenderWindow* pRenderWindow;
Ogre::SceneManager* pSceneManager;
Ogre::Camera* pCamera;
Ogre::Viewport* pViewport;
Ogre::InputReader* pInputReader;
OgreOde::World* pWorld;
OgreOde::Space* pSpace;
OgreOde::Stepper* pStepper;


OgreOde_Prefab::RagdollFactory* pRagdollFactory;
OgreOde_Prefab::OgreOdeDotLoader dotOgreOdeLoader;
std::vector<MovableObject*> clearList;
std::vector<OgreOde_Prefab::Ragdoll *> RagDollList;
OgreOde_Prefab::Ragdoll* pRagdoll;
float TIME;


OgreOde::InfinitePlaneGeometry* plane;


public:
~Scene();
Scene();
void InitScene();
void InitEntity();
bool frameStarted(const Ogre::FrameEvent& evt);
void run();
bool preStep(Real time)
{

return true;
};
bool collision(OgreOde::Contact* contact);


};


radgoll.cpp

#include "ragdoll.h"


void Scene::InitScene()
{


pRoot=new Ogre::Root();
if(!pRoot->restoreConfig())
{ // Test si un fichier de config existe deja
if(!pRoot->showConfigDialog())
{ // Test si, suite a l'affichage de la boite de dialogue, l'utilisateur a appuyer sur OK ou Annuler
delete pRoot;
}
}
pRenderWindow=pRoot->initialise(true,"project using ogreode");
pSceneManager=pRoot->createSceneManager(Ogre::ST_GENERIC,"SceneManager generic");
pCamera=pSceneManager->createCamera("Camera");
pCamera->setPosition(Ogre::Vector3(0,50,200));
pCamera->lookAt(Ogre::Vector3(0,0,0));
pViewport = pRenderWindow->addViewport(pCamera);
pViewport->setBackgroundColour(Ogre::ColourValue(0,0,0.3));
pCamera->setAspectRatio(Ogre::Real(pViewport->getActualWidth()) / Ogre::Real(pViewport->getActualHeight()));

pInputReader=Ogre::PlatformManager::getSingleton().createInputReader();
pInputReader->initialise(pRenderWindow,true,false);
pRoot->addFrameListener(this);

//ressources
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/models","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/scripts","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/textures","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/programs","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

pWorld = new OgreOde::World(pSceneManager);
pWorld->setGravity(Vector3(0,-9.80665,0));
pWorld->setCFM(10e-15);
pWorld->setERP(0.8);
pWorld->setAutoSleep(true);
pWorld->setContactCorrectionVelocity(4.0);
pWorld->setCollisionListener(this);

pSpace=pWorld->getDefaultSpace();

pStepper=new OgreOde::ForwardFixedInterpolatedQuickStepper (0.1);
pStepper->setAutomatic(OgreOde::Stepper::AutoMode_NotAutomatic, pRoot);

pRagdollFactory = new OgreOde_Prefab::RagdollFactory();
pRoot->getSingletonPtr()->addMovableObjectFactory(pRagdollFactory);

InitEntity();

};

Scene::~Scene()
{
delete pRoot;
delete pStepper;
delete pWorld;
};

Scene::Scene()
{
pRoot=NULL;
pRenderWindow=NULL;
pSceneManager=NULL;
pCamera=NULL;
TIME=0;
};

bool Scene::frameStarted(const Ogre::FrameEvent& evt)
{
pInputReader->capture();
if(pInputReader->isKeyDown(Ogre::KC_ESCAPE)) return false;


Real time = evt.timeSinceLastFrame;


pRagdoll->getAnimationState("Walk")->addTime(time);


if (pStepper->step(time)) pWorld->synchronise();


return true;

};

void Scene::run()
{
pRoot->startRendering();
};

bool Scene::collision(OgreOde::Contact* contact)
{
// Check for collisions between things that are connected and ignore them
OgreOde::Geometry * const g1 = contact->getFirstGeometry();
OgreOde::Geometry * const g2 = contact->getSecondGeometry();

if (g1 && g2)
{
const OgreOde::Body * const b1 = g1->getBody();
const OgreOde::Body * const b2 = g2->getBody();
if (b1 && b2 && OgreOde::Joint::areConnected(b1, b2))
return false;
}

// Set the friction at the contact
contact->setCoulombFriction(OgreOde::Utility::Infinity);

// Yes, this collision is valid
return true;
}

void Scene::InitEntity()
{

//ROBOT
Ogre::NameValuePairList params;
params["mesh"] = "robot.mesh";
pRagdoll = static_cast<OgreOde_Prefab::Ragdoll*>(pSceneManager-&l");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/textures","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/programs","FileSystem","General");
Ogre::gt;createMovableObject("robot",
OgreOde_Prefab::RagdollFactory::FACTORY_TYPE_NAME,
&params));
pRagdoll->setCastShadows(true);

Ogre::SceneNode *pRagdoll_node = pSceneManager->getRootSceneNode()->createChildSceneNode("robotNode");
pRagdoll_node->attachObject(pRagdoll);

pRagdoll_node->setScale(Ogre::Vector3(1.0,1.0,1.0));

pRagdoll_node->setPosition(Vector3(0,20,0));

pRagdoll->getAnimationState("Walk")->setLoop(true);
pRagdoll->getAnimationState("Walk")->setEnabled(true);

if ("robot.ogreode" != StringUtil::BLANK) dotOgreOdeLoader.loadRagdoll("robot.ogreode", pRagdoll,"robot");

// Create the ragdoll
pRagdoll->takePhysicalControl(pSpace, false);
pRagdoll->setSelfCollisions(false);

RagDollList.push_back(pRagdoll);

//FLOUR
plane = new OgreOde::InfinitePlaneGeometry(Plane(Vector3(0,1,0),0),pWorld->getDefaultSpace());

int i = 0;
for (Real z = -80.0;z <= 80.0;z += 20.0)
{
for (Real x = -80.0;x <= 80.0;x += 20.0)
{
String name = String("Plane_") + StringConverter::toString(i++);
Ogre::Entity* mPlane = pSceneManager->createEntity(name, "Plane.mesh");
mPlane->setCastShadows(false);

Ogre::SceneNode* mPlaneNode = pSceneManager->getRootSceneNode()->createChildSceneNode(name);
mPlaneNode->attachObject(mPlane);
mPlaneNode->setPosition(x,0,z);
}
}
};


I know that the code is hulgy,but it is just a test.

tuan kuranes

16-01-2007 13:50:37

comment
// pRagdoll->getAnimationState("Walk")->addTime(time);

gugus

16-01-2007 13:58:52

Hello.
If i comment pRagdoll->getAnimationState("Walk")->addTime(time);
Nothing appen , the animation does not work at all.

tuan kuranes

16-01-2007 14:28:15

Nothing appen , the animation does not work at all.
I tought it was ragdoll physics animation.

If just using basic Ogre animation, then it's an Ogre only problem.
Try to make it work disabling all physics,
try to change Ogre::Root::setSmoothFramePeriod(),
etc...

gugus

16-01-2007 16:11:04

In fact i want to do a small FPS.So i need collision detection with animation.Do i have to use ragdoll or can i use somthing else?

tuan kuranes

16-01-2007 16:31:16

Just use entityinformer and raycasting against it, like OgreODe demo does in order to know if zombies are hit or not.

gugus

16-01-2007 19:37:14

but is it taking animation for ratcasting?And if i want to make a knif or a sword , how can i use collision with an animate object?

tuan kuranes

16-01-2007 19:49:36

but is it taking animation for ratcasting?
yes.
And if i want to make a knif or a sword , how can i use collision with an animate object?
just update the "knif or sword" body with node which it's attached to position and orientation at each frame, before calling for collision.

gugus

17-01-2007 11:50:24

Ok thank a lot!
PS:are you french?

tuan kuranes

17-01-2007 12:16:58

Indeed.

gugus

17-01-2007 14:57:23

Cool sa va simplifier mes problemes d'ecritures et de comprehension.