introducing:
S.U.C.C.
Simple Unfeatured Collision Classhere is the code for a simple 3-dimensional collision system with pipeline to Maya.
It currently only collides with world aligned boxes. (AABB collision)
Despite this drawback, it has several advantages:
- very easy to implement
- very easy to understand
- runs very fast!
here is the
c++ header.
here is the
c++ source.
here is the
maya tool. (check the next post for more info.)
to load the xml generated from maya into memory:
Code:
mColMgr->loadCollisionFile("exportedFile.col", "myResourceGrp");
this will collide a given box against the loaded collisions and returns an array with boxes that collided
Code:
std::vector<collisionBox> collisions = mColMgr->boxCollide(playerBox);
this collides a point against the loaded collisions and returns an array with boxes that collided
Code:
std::vector <collisionHit> collisions = mColMgr->pointCollide(camNode->getPosition());
this casts a line through the loaded collisions and returns an array with points of collision (of struct collisionHit) with quaternion vectors pointing away from the colliding surface, in order from nearest to farthest relative to the first point
Code:
std::vector <collisionHit> collisions = mColMgr->lineCollide(camPos, mCamNode->getChild("camRotateNode")->getWorldPosition());
here is an example of how you can use the returned collision. This code iterates through the returned array from a line collision and places and orients objects called one, two, three, and four to the first four collisions encountered.
Code:
std::vector <collisionHit> collisions = mColMgr->lineCollide(camPos, mCamNode->getChild("camRotateNode")->getWorldPosition());
if (collisions.size()) //if we are colliding
{
Ogre::SceneNode *node;
//LogManager::getSingleton().logMessage( "we are colliding." );
std::vector<collisionHit>::iterator hits_iter = collisions.begin();
std::vector<collisionHit>::iterator hits_end = collisions.end();
int x = 0;
for(; hits_iter != hits_end; ++hits_iter)
{
if (x == 0)
node = mSceneMgr->getSceneNode("oneNode");
if (x == 1)
node = mSceneMgr->getSceneNode("twoNode");
if (x == 2)
node = mSceneMgr->getSceneNode("threeNode");
if (x == 3)
node = mSceneMgr->getSceneNode("fourNode");
if ( x <= 3)
{
node->setPosition((*hits_iter).posX,(*hits_iter).posY,(*hits_iter).posZ);
node->setOrientation((*hits_iter).qVector);
}
x++;
}
}