Another collision detection problem..

Tano_ITA

07-06-2008 19:07:24

Hi, i need help! I'm trying to put a message when something collide with a mesh.. I tried to read all example, but i can't solve.

This is my class:

#pragma once
#include <OgreNewt.h>

class RobotDieCallBacks : public OgreNewt::ContactCallback
{
public:
RobotDieCallBacks(int robotID);
~RobotDieCallBacks(void);

int userProcess();

private:
int m_robotID;
};


#include "RobotDieCallBacks.h"
#include <OgreCEGUIRenderer.h>
#include <CEGUI/CEGUISystem.h>
#include <CEGUI/CEGUISchemeManager.h>
#include <CEGUI/CEGUI.h>

RobotDieCallBacks::RobotDieCallBacks(int robotID ) : OgreNewt::ContactCallback()
{
m_robotID = robotID;
}

RobotDieCallBacks::~RobotDieCallBacks(void)
{
}

int RobotDieCallBacks::userProcess()
{
if (m_body0->getType() == m_robotID || (m_body1->getType() == m_robotID))
{

CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
CEGUI::Window* myRoot = wmgr.createWindow( "DefaultWindow", "root" );
CEGUI::System::getSingleton().setGUISheet( myRoot );
CEGUI::FrameWindow*fWnd = (CEGUI::FrameWindow*)wmgr.createWindow( "TaharezLook/StaticText", "testWindow" );

myRoot->addChildWindow( fWnd );

// position a quarter of the way in from the top-left of parent.
fWnd->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.27f, 0 ), CEGUI::UDim( 0.27f, 0 ) ) );
// set size to be half the size of the parent
fWnd->setSize( CEGUI::UVector2( CEGUI::UDim( 0.45f, 0 ), CEGUI::UDim( 0.45f, 0 ) ) );
fWnd->setText( "Benvenuto in T");
}
return 1;
}


And this is the code for my Robot Mesh:


void OgreNewtonApplication::MakeRobot()
{
// base mass on the size of the object.
Ogre::Real massPlayer = 2.5;
// calculate the inertia based on box formula and mass
Ogre::Vector3 inertiaPlayer = OgreNewt::MomentOfInertia::CalcBoxSolid( massPlayer, Vector3(3.0,3.0,3.0) );

entRobot = mSceneMgr->createEntity("robot","Robot.mesh");
RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("robot");
entRobot->setNormaliseNormals(true);
entRobot->setMaterialName("Simple/BeachStones");
RobotNode->attachObject(entRobot);
RobotNode->setScale(0.16,0.16,0.16);


OgreNewt::Collision* colRobot = new OgreNewt::CollisionPrimitives::TreeCollision(m_World, RobotNode, true);
RobotBody = new OgreNewt::Body(m_World, colRobot);

RobotBody->attachToNode(RobotNode);
RobotBody->setMassMatrix(massPlayer, inertiaPlayer);
RobotBody->setStandardForceCallback();

delete colRobot;

RobotBody->attachToNode(RobotNode);
RobotBody->setPositionOrientation(Ogre::Vector3(-33,1.0,23),Ogre::Quaternion::IDENTITY);

RobotID = new OgreNewt::MaterialID(m_World);
RobotBody->setMaterialGroupID(RobotID);
RobotBody->setUserData(this);
mRobotDefault = m_World->getDefaultMaterialID();
mRobotCall = new OgreNewt::MaterialID( m_World );

mRobotPairDefault = new OgreNewt::MaterialPair( m_World, mRobotDefault, mRobotCall );
mRobotCallBack = new RobotDieCallBacks(1);

mRobotPairDefault->setContactCallback( mRobotCallBack );
mRobotPairDefault->setDefaultFriction( 1.5, 1.4 );

}


When i try to lunch a object on my robot nothing happen.. Anyone can help me to fix this problem?

thanks a lot!

St0rM3r

09-06-2008 15:54:11

Hi I have spend 2 or 3 week on collision detect before I find the solution on this forum and I had the same problem. To resolve it I added the code line World->setWorldSize(Box); where Box is the size of the area where physics are processed (you have to set the maximum negative value and maximum positive value to setup the box). By default the size of OgreNewt world is -100, 100, so if your objects in the scene are bigger or positionned out of this box, collisions will not being processed. Add this code line and say me if it works !

Cya

Tano_ITA

09-06-2008 17:40:27

I tried to apply World->setWorldSize(Box); but nothing happen.. have you a complete example where i can learn more?

St0rM3r

09-06-2008 21:18:45

World = new OgreNewt::World();
AxisAlignedBox physicsBox(Vector3(-10000, -10000, -10000), Vector3(10000, 10000, 10000));
World->setWorldSize(physicsBox);

With this code physics will be calculated in a cube of size 20000 around the 0 point.

If you want to see more code, read my post "OgreNewt collision detect", there is my class handling collision detect.