ogre_newbie
24-03-2009 14:39:02
Hi all
I have made a class to implement collision callback. When 2 ball objects collide, I want them to stick to together by a hinge joint. I tested the collision callback. It works, but when I add a join to link 2 collided objects, the joint doesn't work. Could anyone here tell me what the problem is? Or Is there any suggestion you could give me to join two balls when collision occurs ?
Thanks a lot!
int ballColCallback::userBegin()
{
Ogre::SceneNode* ballNode = m_body0->getOgreNode();
Ogre::Entity* ball = static_cast<Ogre::Entity*> (ballNode->getAttachedObject(0));
Ogre::SceneNode* ballNode2 = m_body1->getOgreNode();
Ogre::Entity* ball2 = static_cast<Ogre::Entity*> (ballNode2->getAttachedObject(0));
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( mWorld, Ogre::Vector3(60,60,60) );
OgreNewt::Body* ball_Newtbod = new OgreNewt::Body( mWorld, col );
ball_Newtbod->attachToNode(ballNode);
OgreNewt::Body* ball_Newtbod2 = new OgreNewt::Body( mWorld, col );
ball_Newtbod2->attachToNode(ballNode2);
// ball_Newtbod->addForce(Ogre::Vector3(0,100,0));
OgreNewt::Body* parent = NULL;
OgreNewt::Body* child = NULL;
OgreNewt::Joint* joint;
parent = ball_Newtbod;
child = ball_Newtbod2;
//Ogre::LogManager::getSingletonPtr()->logMessage(ball->getName());
//Ogre::LogManager::getSingletonPtr()->logMessage(ball2->getName());
if(!strncmp(ball->getName().c_str(),"Ball",4) && !strncmp(ball2->getName().c_str(),"Ball",4))
{
ball->setMaterialName("myMaterial/beachstone");
ball2->setMaterialName("myMaterial/ground");
joint = new OgreNewt::BasicJoints::BallAndSocket( mWorld, child, parent, Ogre::Vector3(30,0,0) );
joint = new OgreNewt::BasicJoints::Hinge( mWorld, child, parent, Ogre::Vector3(30,0,0), Ogre::Vector3(0,0,1) );
}
return 1;
}
ogre_newbie
Newcomer
Posts: 20
Joined: Tue Sep 16, 2008 11:31 am
I have made a class to implement collision callback. When 2 ball objects collide, I want them to stick to together by a hinge joint. I tested the collision callback. It works, but when I add a join to link 2 collided objects, the joint doesn't work. Could anyone here tell me what the problem is? Or Is there any suggestion you could give me to join two balls when collision occurs ?
Thanks a lot!
int ballColCallback::userBegin()
{
Ogre::SceneNode* ballNode = m_body0->getOgreNode();
Ogre::Entity* ball = static_cast<Ogre::Entity*> (ballNode->getAttachedObject(0));
Ogre::SceneNode* ballNode2 = m_body1->getOgreNode();
Ogre::Entity* ball2 = static_cast<Ogre::Entity*> (ballNode2->getAttachedObject(0));
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( mWorld, Ogre::Vector3(60,60,60) );
OgreNewt::Body* ball_Newtbod = new OgreNewt::Body( mWorld, col );
ball_Newtbod->attachToNode(ballNode);
OgreNewt::Body* ball_Newtbod2 = new OgreNewt::Body( mWorld, col );
ball_Newtbod2->attachToNode(ballNode2);
// ball_Newtbod->addForce(Ogre::Vector3(0,100,0));
OgreNewt::Body* parent = NULL;
OgreNewt::Body* child = NULL;
OgreNewt::Joint* joint;
parent = ball_Newtbod;
child = ball_Newtbod2;
//Ogre::LogManager::getSingletonPtr()->logMessage(ball->getName());
//Ogre::LogManager::getSingletonPtr()->logMessage(ball2->getName());
if(!strncmp(ball->getName().c_str(),"Ball",4) && !strncmp(ball2->getName().c_str(),"Ball",4))
{
ball->setMaterialName("myMaterial/beachstone");
ball2->setMaterialName("myMaterial/ground");
joint = new OgreNewt::BasicJoints::BallAndSocket( mWorld, child, parent, Ogre::Vector3(30,0,0) );
joint = new OgreNewt::BasicJoints::Hinge( mWorld, child, parent, Ogre::Vector3(30,0,0), Ogre::Vector3(0,0,1) );
}
return 1;
}
ogre_newbie
Newcomer
Posts: 20
Joined: Tue Sep 16, 2008 11:31 am