Collision using StaticPlaneCollisionShape

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
luciamouriz
Gnoblar
Posts: 3
Joined: Thu Nov 05, 2015 2:00 pm

Collision using StaticPlaneCollisionShape

Post by luciamouriz »

Hi!
Please if you could help me carry my team and I with this problem for a few weeks.
The problem is that i have a plane defined with his rigid body

Code: Select all

Plane plane1(Vector3(0,1,0), -3);    
  MeshManager::getSingleton().createPlane("p1",
  ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane1,
  1000, 1000, 1, 1, true, 1, 20, 20, Vector3::UNIT_Z);
  //--------------------------------------------------------

  
  SceneNode* _groundNode = _sceneMgr->createSceneNode("ground");
  Entity* _groundEnt = _sceneMgr->createEntity("planeEnt", "p1");
  _groundEnt->setMaterialName("Ground");
  _groundNode->attachObject(_groundEnt);
  _sceneMgr->getRootSceneNode()->addChild(_groundNode);
  

 
  OgreBulletCollisions::CollisionShape *Shape;
  Shape = new OgreBulletCollisions::StaticPlaneCollisionShape
    (Ogre::Vector3(0,1,0), -3);   // Vector normal y distancia (antes estaba a 0)
  OgreBulletDynamics::RigidBody *rigidBodyPlane = new 
    OgreBulletDynamics::RigidBody("ground", _world,PhysicsMask::COL_StaticWalls,PhysicsMask::staticwalls_collides_with);

  
  rigidBodyPlane->setStaticShape(Shape, 0.1, 0.8);


  _shapes.push_back(Shape);
  _bodies.push_back(rigidBodyPlane);
But when the plane collides with an object and vice versa does not detect the plane
That is in the method of detecting collisions it take the name of all the objects and plane not

Code: Select all

void PhysicsManager::detectHeroCollision(){
	//Colisiones------------------------------
	btCollisionWorld *bulletWorld = _world->getBulletCollisionWorld();
	int numManifolds = bulletWorld->getDispatcher()->getNumManifolds();

	for (int i=0;i<numManifolds;i++) {
		btPersistentManifold* contactManifold =
				bulletWorld->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* obA =
				(btCollisionObject*)(contactManifold->getBody0());
		btCollisionObject* obB =
				(btCollisionObject*)(contactManifold->getBody1());

		//EXTRA--------------------------------------------------------
		btCollisionObject* _aux;
		//-------------------------------------------------------------

		//Compruebo colisiones con el hero -----------------------------
		OgreBulletCollisions::Object *obHero = _world->findObject(_hero->getSceneNode());
		OgreBulletCollisions::Object *obOB_A = _world->findObject(obA);
		OgreBulletCollisions::Object *obOB_B = _world->findObject(obB);

		if ((obOB_A == obHero) || (obOB_B == obHero)) {  //si uno de los objetos colisionados es el hero
			Ogre::SceneNode* node = NULL;
			if ((obOB_A != obHero) && (obOB_A)) {
				node = obOB_A->getRootNode();
				_aux=obA;
				
			}
			else if ((obOB_B != obHero) && (obOB_B)) {
				node = obOB_B->getRootNode();
				//delete obOB_B;
				_aux=obB;
			}
			[b]if (node) {
				cout << "Hero choca con: " << node->getName() << "\n" << endl;

				if(Ogre::StringUtil::startsWith(node->getName(),"SN_Floor")){
					if(_hero->getRigidBody()->getLinearVelocity().z < 0.0){
						if(_hero->getNumJumps() < N_JUMPS){
							_hero->setNumJumps(N_JUMPS);
						}
					}
				}
				else if(Ogre::StringUtil::startsWith(node->getName(),"SN_Thread")){
					//Eliminar SceneNode, Entity y Cuerpo Fisico asi--------------
					Entity* _e = static_cast<Entity*>(node->getAttachedObject(0));
					_sceneMgr->destroyEntity(_e);
					_sceneMgr->getRootSceneNode()->removeChild(node);
					_world->getBulletDynamicsWorld()->removeCollisionObject(_aux);
					//------------------------------------------------------------
					_hero->increaseScore(10);
					//Actualizar los puntos en la UI
				}
				else if(Ogre::StringUtil::startsWith(node->getName(),"SN_Reel")){
					PlayState::getSingletonPtr()->changeScenarioQ();
				}
				else if(Ogre::StringUtil::startsWith(node->getName(),"SN_Enemy")){
					_hero->loseLife();
					MovementManager::getSingletonPtr()->repositionHero(btVector3(0,0,0),_hero->getRigidBody()->getBulletRigidBody()->getOrientation());
					//Actualizar las vidas en la UI
				}
			}

		}
		//------------------------------------------------[/b]
	}
}
//----------------------------------------
If i print cout << "Collision plane: " << node->getName() << "\n" << endl; print all the names of the objects but not the planes

Thanks you for the help
User avatar
SamiTheGreat
Bronze Sponsor
Bronze Sponsor
Posts: 102
Joined: Sat Aug 30, 2008 11:57 am
Location: Finland
x 8

Re: Collision using StaticPlaneCollisionShape

Post by SamiTheGreat »

Hi! Have you set collision masks for BOTH player and plane to math each others collision category? Bullet doesn't give you collision callback from plane perspective if the plane collision mask bit doesn't math player collision category bit.

Did you mean that?
luciamouriz
Gnoblar
Posts: 3
Joined: Thu Nov 05, 2015 2:00 pm

Re: Collision using StaticPlaneCollisionShape

Post by luciamouriz »

yes, the player have rigid body and also the plane and their collision masks.
we want the name of SceneNode of the plane that its the floor.
Sorry for my English not is very good :(

Code: Select all

#ifndef PhysicsMask_H
#define PhysicsMask_H

namespace PhysicsMask{

//MASCARAS DE COLISION---
enum collisiontypes {
    COL_Player = 1,
    COL_Walls = 2,
    COL_Thread = 4,
    COL_Reel = 8,
	COL_Enemy = 16,
	COL_StaticWalls=32
};
//-----------------------

//GRUPOS DE COLISION-----
const short player_collides_with = COL_Walls | COL_StaticWalls | COL_Thread  | COL_Reel | COL_Enemy ;
const short enemy_collides_with =  COL_Walls | COL_StaticWalls | COL_Player ;
const short walls_collides_with =  COL_StaticWalls | COL_Player | COL_Enemy ;
const short staticwalls_collides_with =  COL_Walls | COL_Player | COL_Enemy ;
const short thread_collides_with = COL_Player;
const short reel_collides_with = COL_Player;
//-----------------------

}

#endif
Post Reply