The Lo-Fi Apocalypse Forums

kickass indie games!
It is currently Sun Sep 05, 2010 3:50 pm

All times are UTC - 4 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: SUCC collision system & pipeline
PostPosted: Sun Dec 02, 2007 2:01 am 
Offline
L.F.A. TEAM
L.F.A. TEAM
User avatar

Joined: Thu Jun 02, 2005 11:16 pm
Posts: 62
introducing:

S.U.C.C.
Simple Unfeatured Collision Class


here 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++;
         }
      }


Last edited by metaldev on Mon Mar 24, 2008 12:47 am, edited 5 times in total.

Top
 Profile  
 
 Post subject: HOW TO USE THE MAYA TOOL TO EXPORT SUCC COLLISION
PostPosted: Sun Dec 02, 2007 11:27 am 
Offline
L.F.A. TEAM
L.F.A. TEAM
User avatar

Joined: Thu Jun 02, 2005 11:16 pm
Posts: 62
Here is how to use the Maya tool that exports collisions.


first download and source the mel tool.
    -place objects around your world (ideally poly cubes) representing the collision in the game.

    -make sure they are all aligned to world

    -make sure they are in a layer called 'COL'

    -run the mel code: 'lfa_exportCollisions'

this will export the boxes to a .col file located in the export directory.

BEWARE:
    - don't put other stuff in the COL layer or they will export as a collision box too.

    - don't rotate the boxes or they wont export like you think they will. (the exporter and importer only handle world aligned boxes)



here is an example of an exported collision xml:
Code:
<col>
    <branch name="world" var="" xmin="-75.36483406" ymin="5.960464544e-008" zmin="-143.5737847" xmax="122.0028718" ymax="9.755226355" zmax="-13.35732857">
        <box name="colCube03" var="" xmin="110.2565042" ymin="0.1155821092" zmin="-19.95418206" xmax="112.6963355" ymax="1.587837578" zmax="-13.7543949" />
        <box name="colCube04" var="" xmin="105.2407563" ymin="0.1155821092" zmin="-19.73926868" xmax="107.6805876" ymax="1.587837578" zmax="-13.53948153" />
        <box name="colCube05" var="" xmin="100.3004075" ymin="0.1155821092" zmin="-19.73926868" xmax="102.7402389" ymax="1.587837578" zmax="-13.53948153" />
        <box name="colCube011" var="" xmin="105.2407563" ymin="0.1155821092" zmin="-28.69682806" xmax="107.6805876" ymax="1.587837578" zmax="-22.49704091" />
        <box name="colCube012" var="" xmin="100.3004075" ymin="0.1155821092" zmin="-28.69682806" xmax="102.7402389" ymax="1.587837578" zmax="-22.49704091" />
        <box name="colCube013" var="" xmin="95.21148446" ymin="0.1155821092" zmin="-28.69682806" xmax="97.65131578" ymax="1.587837578" zmax="-22.49704091" />
        <box name="colCube022" var="" xmin="9.984846424" ymin="0.1155821092" zmin="-93.57434391" xmax="10.53631494" ymax="4.000000112" zmax="-82.05504921" />
    </branch>
</col>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 4 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group