MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Mon Oct 12, 2009 7:52 pm

sailingboy wrote:I have similar problem like this:
Jdog wrote:Second, and this is more related to MOC, my character movement works on WASD - collisions work unless I hold down 2 keys at once and move diagonally (for instance, W and A) - is there any way to prevent this without messy if statements?

Maybe someone know how solve it?

btw Thanks very much for these tools!


I use WASD, too, and move diagonally, and it works fine

You dont tell us when or where you test your collisions, i assume you do in every key check of those 4 keys - but if you want us to help you you need to tell us more because no one here (i think) is a wizard and can see your code thru some kinda fancy orb

what you might want to do is, moving your character with a vector, which can be a bit complicated cause you might need a lot of manipulations on that, or just check the collision outside your input function, if you check it in there at all (as i said, no magicians here)
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby sailingboy » Mon Oct 12, 2009 8:06 pm

thank you for quick reply! :)
that's part of my code, my camera is child of tank, method bool frameStarted(const FrameEvent &evt) is the most important from this part:
Code: Select all
MoveDemoListener( RenderWindow* win, Camera* cam, SceneManager *sceneMgr,Tank &t1, Tank &t2)
      : ExampleFrameListener(win, cam, false)
   {
      mSceneMgr = sceneMgr;
      _t1=t1;
      _t2=t2;
      a,w,s,d=false;
      up,down,left,right=false;
      change=false;
   }

   virtual bool processUnbufferedKeyInput(const FrameEvent& evt)
   {
      mKeyboard->capture();

      if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
         return false;

      if(mKeyboard->isKeyDown(OIS::KC_A))
      {
      a=true;
      change=true;
      }

      if(mKeyboard->isKeyDown(OIS::KC_W))
      {
      w=true;
       change=true;
      }

      if(mKeyboard->isKeyDown(OIS::KC_S))
      {
      s=true;
      change=true;
      }

      if(mKeyboard->isKeyDown(OIS::KC_D))
      {
      d=true;
      change=true;
      }

      if(mKeyboard->isKeyDown(OIS::KC_UP))
      up=true;
      if(mKeyboard->isKeyDown(OIS::KC_DOWN))
      down=true;
      if(mKeyboard->isKeyDown(OIS::KC_LEFT))
      left=true;
      if(mKeyboard->isKeyDown(OIS::KC_RIGHT))
      right=true;

      return true;
   }





   bool frameStarted(const FrameEvent &evt)
   {

      if (change)
       {
         Vector3 oldPos = _t1.getPosition();//real position of tank
         Vector3 oldPos2 = _t1.getPosition2();//collision point of tank(one of corner)
         Vector3 oldPos3 = _t1.getPosition3();//collision point of tank(one of corner)
         Vector3 oldPos4 = _t1.getPosition4();//collision point of tank(one of corner)
         Vector3 oldPos5 = _t1.getPosition5();//collision point of tank(one of corner)
         Vector3 oldPos6 = _t1.getPosition5();//collision point of tank(one of corner)

       if(d)
      {
         _t1.goRight(mSceneMgr,evt.timeSinceLastFrame);//yaw right(rotate)
         d=false;
      }

      if(a)
      {
         _t1.goLeft(mSceneMgr,evt.timeSinceLastFrame);//yaw left(rotate)
         a=false;
      }

   


      if(w)
      {
         _t1.goAhead(mSceneMgr,evt.timeSinceLastFrame);
         w=false;
      }

      if(s)
      {
         _t1.goBack(mSceneMgr,evt.timeSinceLastFrame);
         s=false;
      }

   


      if (oldPos.squaredDistance(_t1.getPosition()) > 100)
      {


      mCollisionTools = new MOC::CollisionTools(mSceneMgr);

      if (mCollisionTools->collidesWithEntity(oldPos2, _t1.getPosition2(), 2.5f, 0.0f, ENTITY_MASK))
      {
          _t1.setPosition(oldPos);
        }


       else if (mCollisionTools->collidesWithEntity(oldPos3, _t1.getPosition3(), 2.5f, 0.0f, ENTITY_MASK))
      {
          _t1.setPosition(oldPos);
        }

      else if (mCollisionTools->collidesWithEntity(oldPos4, _t1.getPosition4(), 2.5f, 0.0f, ENTITY_MASK))
      {
          _t1.setPosition(oldPos);
        }


      else if (mCollisionTools->collidesWithEntity(oldPos5, _t1.getPosition5(), 2.5f, 0.0f, ENTITY_MASK))
      {
          _t1.setPosition(oldPos);
        }

      }
      
      return ExampleFrameListener::frameStarted(evt);
   }
protected:

   AnimationState *mAnimationState;
   Entity *Body;               
   SceneNode *mSceneNode;             
   SceneNode *mSceneNode1; 
   SceneManager *mSceneMgr;
   MOC::CollisionTools* mCollisionTools;


   Vector3 transVector1;
   Tank _t1;
   Tank _t2;
   bool a,w,s,d;
   bool up,down,left,right;
   bool change;


};


Maybe now will be better to help. I tried make sth with mouse but without effect :|
sailingboy
Gnoblar
 
Posts: 5
Kudos: 0
Joined: 06 Oct 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Mon Oct 12, 2009 10:52 pm

as i said, i dont know if thats the problem but i assume so:

you have goright and goleft and so on -> what if you make 1 function where you instead collect all the input and change the position ONCE (so goLeft and goAhead become one diagonal movement) and check the ray then once

i havent looked thru the code exactly but i assume the problem is coz you once check for only left and then for only ahead, instead of doing both in one check

however, if it fixes it or not -- i would do it like i said anyways and make a combined movement instead of a weird split, it more... organized, imho...

try it

and beat me if it doesnt work, and sorry for the late reply, i saw your pm but i was busy dude
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby sailingboy » Tue Oct 13, 2009 7:11 pm

I was trying solve this problem for few hours and I tried make this what you said in post, but without effect :x
I saw that problem is no only with 2 buttons but in general problem is with rotate (when I put tank near wall by w or s and try rotate by a or d my tank are rotate through the wall and after that i can press w and go through wall).

That's my code after same changes:
Class Tank:
Code: Select all
class Tank
{
private:
   Ogre::SceneNode *_bodyNode;
   Ogre::SceneNode *_holderNode;
   Ogre::SceneNode *_gunNode;
   Ogre::SceneNode *_bodyNode1;
   Ogre::Entity *_body;
   Ogre::Entity *_body1;
   Ogre::Entity *_holder;
   Ogre::Entity *_gun;
   Ogre::SceneManager *mSceneMgr;
   int _x;
   int _z;
   int _number;
   Real mSpeed;
   Real mRotate;
   Vector3 transVector;



public:
   Tank()
   {
   }

   void createTank(Ogre::SceneNode *parentNode, int x, int z, int number)
   {
      transVector = Vector3::ZERO;
      //transVector.z=+mSpeed;
      mSpeed=800;
      mRotate=200;
      this->_x=x;
      this->_z=z;
      this->_number=number;
      _bodyNode = parentNode->createChildSceneNode("bodyNode"+number,Vector3( x, 0, z  ));
      _body = _bodyNode->getCreator()->createEntity(_bodyNode->getName() + "::_ent", "cialoLeo.mesh");
      _bodyNode->attachObject(_body);
      _bodyNode -> scale (88, 88, 88);
      _body->addQueryFlags(ENTITY_MASK);

      _holderNode = _bodyNode->createChildSceneNode("holderNode"+number,Vector3( 0, 0, 0  ));
      _holder = _holderNode->getCreator()->createEntity(_holderNode->getName() + "::_ent", "wiezyczkaLeo.mesh");
      _holderNode->attachObject(_holder);
      _holder->addQueryFlags(ENTITY_MASK);


      _gunNode = _holderNode->createChildSceneNode("lufaNode"+number,Vector3( 0, 0, 0  ));
      _gun = _gunNode->getCreator()->createEntity(_gunNode->getName() + "::_ent", "lufaLeo.mesh");
      _gunNode->attachObject(_gun);   
      _gun->addQueryFlags(ENTITY_MASK);

   }

    void setPosition(Vector3 transVectorPOS)
   {
      _bodyNode->setPosition(transVectorPOS);   
   }

   void setOrientation(const Ogre::Quaternion & transVectorPOS)
   {
      _bodyNode->setOrientation(transVectorPOS);   
   }

   Vector3 getPosition()
   {
     return _bodyNode->_getDerivedPosition();
   }

   const Ogre::Quaternion & getOrientation()
   {
     return _bodyNode->_getDerivedOrientation();
   }

    Vector3 getPosition2()
   {
   const Ogre::AxisAlignedBox& bbox = _body->getWorldBoundingBox(true);
    return bbox.getCorner(AxisAlignedBox::FAR_RIGHT_TOP);
   }

   Vector3 getPosition3()
   {
   const Ogre::AxisAlignedBox& bbox = _body->getWorldBoundingBox(true);
    return bbox.getCorner(AxisAlignedBox::NEAR_LEFT_TOP);
   }

   Vector3 getPosition4()
   {
   const Ogre::AxisAlignedBox& bbox = _body->getWorldBoundingBox(true);
    return bbox.getCorner(AxisAlignedBox::NEAR_RIGHT_TOP);
   }

   Vector3 getPosition5()
   {
   const Ogre::AxisAlignedBox& bbox = _body->getWorldBoundingBox(true);
    return bbox.getCorner(AxisAlignedBox::FAR_LEFT_TOP);
   }


   void goDiagonalLeft(Real evt)
   {
      _bodyNode->translate(_bodyNode->getOrientation() *  Vector3(0,0,300) * evt);
      _bodyNode->yaw(Degree(mRotate * evt), Node::TS_LOCAL);
   }

   void goDiagonalRight(Real evt)
   {
      _bodyNode->translate(_bodyNode->getOrientation() *  Vector3(0,0,300) * evt);
      _bodyNode->yaw(Degree(-mRotate * evt), Node::TS_LOCAL);

   }

   void goAhead(SceneManager *mSceneMgr, Real evt)
   {   
      _bodyNode->translate(_bodyNode->getOrientation() * Vector3(0,0,300) * evt);
   }

   void goBack(SceneManager *mSceneMgr, Real evt)
   {
      _bodyNode->translate(_bodyNode->getOrientation() * Vector3(0,0,-300) * evt);
   }

   void goRight(SceneManager *mSceneMgr, Real evt)
   {
      _bodyNode->yaw(Degree(-mRotate * evt), Node::TS_LOCAL);
   }

   void goLeft(SceneManager *mSceneMgr, Real evt)
   {
      _bodyNode->yaw(Degree(mRotate * evt), Node::TS_LOCAL);
   }


   ~Tank()
   {
   }

};



virtual bool processUnbufferedKeyInput(const FrameEvent& evt)
Code: Select all
   virtual bool processUnbufferedKeyInput(const FrameEvent& evt)
   {
      mKeyboard->capture();

      if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
         return false;

      if(mKeyboard->isKeyDown(OIS::KC_A))
      {
      a=true;
      change1=true;
      }
      if(mKeyboard->isKeyDown(OIS::KC_W))
      {
      w=true;
       change=true;
      }
      if(mKeyboard->isKeyDown(OIS::KC_S))
      {
      s=true;
      change=true;
      }
      if(mKeyboard->isKeyDown(OIS::KC_D))
      {
      //change=true;
      d=true;
      change1=true;
      }
      return true;
   }



bool frameStarted(const FrameEvent &evt)
Code: Select all
bool frameStarted(const FrameEvent &evt)
//goLeft and goRight are rotates
   {
      Vector3 oldPos = _t1.getPosition();
      const Ogre::Quaternion & oldOrientation= _t1.getOrientation();
      Vector3 oldPos2 = _t1.getPosition2();
      Vector3 oldPos3 = _t1.getPosition3();
      Vector3 oldPos4 = _t1.getPosition4();
      Vector3 oldPos5 = _t1.getPosition5();
      Vector3 oldPos6 = _t1.getPosition5();

      if (change&&change1)
      {
         if(w&&a)
         {
            _t1.goDiagonalLeft(evt.timeSinceLastFrame);
            w=false;
            a=false;
         }

         if(w&&d)
         {
            _t1.goDiagonalRight(evt.timeSinceLastFrame);
            w=false;
            d=false;
         }
      }

      else if(change1&&!change)
      {
         if(a)
         {
            _t1.goLeft(mSceneMgr,evt.timeSinceLastFrame);
            a=false;
         }
         if(d)
         {
            _t1.goRight(mSceneMgr,evt.timeSinceLastFrame);
            d=false;
         }

      }



      else if (change&&(!change1))
      {      
         if(w)
         {
            _t1.goAhead(mSceneMgr,evt.timeSinceLastFrame);
            w=false;
         }

         if(s)
         {
            _t1.goBack(mSceneMgr,evt.timeSinceLastFrame);
            s=false;
         }   

      }



      if (oldPos.squaredDistance(_t1.getPosition()) > 10)
      {


         mCollisionTools = new MOC::CollisionTools(mSceneMgr);

         if (mCollisionTools->collidesWithEntity(oldPos2, _t1.getPosition2(), 2.5f, 0.0f, ENTITY_MASK))
         {
            _t1.setPosition(oldPos);
            _t1.setOrientation(oldOrientation);
         }


         else if (mCollisionTools->collidesWithEntity(oldPos3, _t1.getPosition3(), 2.5f, 0.0f, ENTITY_MASK))
         {
            _t1.setPosition(oldPos);
            _t1.setOrientation(oldOrientation);
         }

         else if (mCollisionTools->collidesWithEntity(oldPos4, _t1.getPosition4(), 2.5f, 0.0f, ENTITY_MASK))
         {
            _t1.setPosition(oldPos);
            _t1.setOrientation(oldOrientation);
         }


         else if (mCollisionTools->collidesWithEntity(oldPos5, _t1.getPosition5(), 2.5f, 0.0f, ENTITY_MASK))
         {
            _t1.setPosition(oldPos);
            _t1.setOrientation(oldOrientation);
         }
      }
      change=false;
      change1=false;

      return ExampleFrameListener::frameStarted(evt);
   }
protected:

   AnimationState *mAnimationState;
   Entity *Body;               
   SceneNode *mSceneNode;             
   SceneNode *mSceneNode1; 
   SceneManager *mSceneMgr;
   MOC::CollisionTools* mCollisionTools;


   Vector3 transVector1;
   Tank _t1;
   Tank _t2;
   bool a,w,s,d;
   bool up,down,left,right;
   bool change, change1;
   int x;


};
sailingboy
Gnoblar
 
Posts: 5
Kudos: 0
Joined: 06 Oct 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Tue Oct 13, 2009 11:24 pm

sorry i have no time to look thru all your code - but i try to help you anyways as far as i can

so: do you also have this problem, as you said, when you move like with w and a ? so if you move diagonally can you move thru walls?
you said you could, right? and there is no rotation involed there, is it?
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby sailingboy » Wed Oct 14, 2009 1:21 pm

When I press a and w i go diagonal and this is with rotate:
Code: Select all
  void goDiagonalLeft(Real evt)
   {
      _bodyNode->translate(_bodyNode->getOrientation() *  Vector3(0,0,300) * evt);
      _bodyNode->yaw(Degree(mRotate * evt), Node::TS_LOCAL);
   }


Ok is only when I make rotate (goLeft/Right, goDiagonalLeft/Left) with distance from wall and after that goAhead or goBack.

thank you for reply
sailingboy
Gnoblar
 
Posts: 5
Kudos: 0
Joined: 06 Oct 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Thu Oct 15, 2009 6:04 pm

i dont really fully understand you,..

Does diagonal movement work now or does it not?

Does your rotating collision work now because you fixed it or is it still to be done?
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby sailingboy » Fri Oct 16, 2009 7:51 pm

Ident wrote:i dont really fully understand you,..

Does diagonal movement work now or does it not?

Does your rotating collision work now because you fixed it or is it still to be done?


Diagonal movement(it part is rotate) and rotate work fine, but without collision.
sailingboy
Gnoblar
 
Posts: 5
Kudos: 0
Joined: 06 Oct 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Sat Oct 17, 2009 2:38 pm

well i guess the problem is, that whenever you rotate an object, they rays get rotated too, but the startpoint of the rays at the end of the rotation may lay at a point where they dont have a collision like if you rotate something and it's partially inside another mesh at the end of the rotation


also if you rotate and translate, i personally would first rotate, then translate, otherwise the rotation wont have an effect on the translation in this step (only next step it will) but it doesnt matter much in this case i guess

when you said move diagnoally, i thought you mean moving forward + strafing to the side, not rotating and moving forward, whatever

i dont know a real solution for the problem with rotating, you d have to cast rays into different directions so you wont rotate into another object, i guess, but thats not a nice solution (performance and not accurate) hmmm...
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby hedphelym » Tue Oct 20, 2009 11:50 am

Hi,
I try to use this CS file for Mogre,
when i import it into my project it says : "cannot resolve symbol 'TerrainInfo' in the code.

Is there something I'm missing?

thanks in advance.
hedphelym
Halfling
 
Posts: 78
Kudos: 6
Joined: 25 Nov 2008

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Tue Oct 20, 2009 11:59 am

hedphelym wrote:Hi,
I try to use this CS file for Mogre,
when i import it into my project it says : "cannot resolve symbol 'TerrainInfo' in the code.

Is there something I'm missing?

thanks in advance.

look into the header file, there it says what you have to do in case you don't use the special terrain
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Sat Nov 21, 2009 9:12 pm

I'm using MoC and create ManualObjects in runtime which then get converted into Meshes. However although, whenever i cast a ray into the direction of that mesh generated from a ManualObject i get a crash.

Same problem as here basically: viewtopic.php?f=2&t=23440&p=264657#p264657

i use OT_TRIANGLE_FAN at the moment

crash appears in this function: Ogre::Math::intersects()


being called here:
Code: Select all
for (int i = 0; i < static_cast<int>(index_count); i += 3)
            {
               // check for a hit against this triangle
               std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
                  vertices[indices[i+1]], vertices[indices[i+2]], true, false);
*snip*


i = 24
index_count = 26
vertex_count = 25

indices array has valid values till [23] (although it should be filled till [24] afaik)
vertices array has valid values till [24]


this is all i found out during debugging,- just seems like the i+=3 is set for triangle lists, won't work at all or not completly correct for strips and fans.
i won't mind rewriting this as this is just some graphic object which i ll tag with a certain QueryFlag so this is done for me, but just wondering why no one really served a fix or an explanation for this so far- so maybe this gives someone some more information than i could find
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby lmas19820607 » Mon Nov 23, 2009 9:52 am

I found a tiny bug in your code.

bool CollisionTools::raycastFromPoint(const Ogre::Vector3 &point,
const Ogre::Vector3 &normal,
Ogre::Vector3 &result,Ogre::MovableObject* &target,
float &closest_distance,
const Ogre::uint32 queryMask)
{
// create the ray to test
static Ogre::Ray ray;
ray.setOrigin(point - normal * 1000); //Modified by #lium back move the start point, or can't get correct closest_distance
ray.setDirection(normal);
return raycast(ray, result, target, closest_distance, queryMask);
}

I don't know whether anybody has refer that, too much replys in this thread. Hopes it helps.
Btw, the MOC works perfectly in my project, thanks for share.
lmas19820607
Halfling
 
Posts: 72
Kudos: 0
Joined: 06 Dec 2006

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Tue Nov 24, 2009 3:19 pm

how is this a bug or a bugfix? why 1000? this is random and makes the collision not work anymore
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby lmas19820607 » Wed Nov 25, 2009 7:57 am

sorry for your confuse, I should describe the detail.
I just use GetHeight function and never use Collision Detecting.
Before my fix, GetHeight function can't get correct result... I don't know how the fix affect collision detecting.
lmas19820607
Halfling
 
Posts: 72
Kudos: 0
Joined: 06 Dec 2006

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Wed Nov 25, 2009 10:08 am

hmmmmmmmmm


but why is the value 1000?


just an idea but maybe you can give the method used by collision and the height function calculateY a parameter and when using calculateY you can pass normal*1000 as parameter and add it and else 0 and add the parameter at the point you changed the code


but i dunno why this would be necessary at all


are you maybe elevating th character by 1000 before callin the function?
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Ident » Sun Nov 29, 2009 1:15 am

i implemented some small changes in my collisionTool

first to give my raycasts a maximum distance, as very far away objects shouldn't be checked in my case, to save some performance, in the raycast(..) method i added an else if(){}

Code: Select all
      for (size_t qr_idx = 0; qr_idx < query_result.size(); qr_idx++)
      {
         // stop checking if we have found a raycast hit that is closer
         // than all remaining entities
         if ((closest_distance >= 0.0f) &&
            (closest_distance < query_result[qr_idx].distance))
         {
            break;
         }
         else if(query_result[qr_idx].distance > MAX_CHECK_DISTANCE) // if distance bigger than ... don't check - added by Lukas
            break;


ususally you won't need this

what could be useful however is this code snippet i added after the code i just posted:

Code: Select all
//For just checking some Entities' Bounding Boxes instead of the raycasting them to polygon level
         else if(query_result[qr_idx].movable->getQueryFlags() == ONLY_CHECK_BOUNDINGBOX_MASK)
         {
            if ((closest_distance < 0.0f) ||
               (query_result[qr_idx].distance < closest_distance))
            {
               // this is the closest AABB so far, saving it
               closest_distance = query_result[qr_idx].distance;
               target = static_cast<Ogre::MovableObject*>(query_result[qr_idx].movable);
               closest_result = query_result[qr_idx].movable->getWorldBoundingSphere().getCenter();
               //Hitpoint = not correct (middle Entity)
            }
         }

   // only check this result if its a hit against an entity
         else if ((query_result[qr_idx].movable != NULL)  &&
            (query_result[qr_idx].movable->getMovableType().compare("Entity") == 0))
         {...

this might be useful if you don't need an exact raycast for every entity, but only for some - the flag makes the difference

again this might save some performance, and also make it easier to click on some smaller objects (which is the main reason i do this)

just wanted to share this, maybe it's useful for anyone
Ident
Greenskin
 
Posts: 146
Kudos: 5
Joined: 17 Sep 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby kurty » Mon Dec 14, 2009 4:04 pm

hi nauk , any problem with artifexterra3d.com ? i can't get on the site since 1 week or more ...
Communauté Francophone
#ogre3d-fr sur irc.freenode.net
kurty
Gnoblar
 
Posts: 14
Kudos: 0
Joined: 12 Nov 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby Nauk » Fri Dec 18, 2009 12:14 pm

Sorry guys for not supporting MOC at the moment the way I should, but I have too many other things going on. About the Aritfex website: viewtopic.php?f=11&t=42507&start=200#p367540 - thanks for telling me Kurty, I hope it will be up soon again.
User avatar
Nauk
Gnoll
 
Posts: 644
Kudos: 23
Joined: 11 May 2006
Location: Bavaria

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby aerique » Fri Dec 18, 2009 3:02 pm

Nauk wrote:Sorry guys for not supporting MOC at the moment the way I should, but I have too many other things going on.


Thanks for the update, I was wondering what the status was. Especially with all the small additions people have posted in this thread.
Okra: Common Lisp bindings for Ogre
User avatar
aerique
Halfling
 
Posts: 59
Kudos: 0
Joined: 18 Oct 2007
Location: The Netherlands

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby CorPetit09 » Tue Dec 22, 2009 1:06 pm

Hi,

At first, sorry for my english. I'm using MOC and I 'm having problems for collides one object (which I can move) with another object (it is a static object, like a house or wall) that I translated in the X and Z axis.
In some parts of the static object, collision works fine, but in anothers parts, my first object doesn't collides with my second object.
I have done a lot of tests and if I don't translate the static object, it works fine always. I don't know if is a problem of the .mesh or if a programming problem.

Thanks
User avatar
CorPetit09
Gnoblar
 
Posts: 10
Kudos: 0
Joined: 05 Oct 2009

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby shadow82 » Tue Jun 01, 2010 9:04 am

For my project I made a little extension to MOC. For every method in the CollisionTools class I added an argument bool testPolys, which decides in the raycast()-method, where the actual work is done, if the test is done only on the bounding box or on the mesh polygons. I know that I actually don't need MOC for testing bounding boxes, which can also be done via RaySceneQuery. But I didn't want to use two different collision APIs for slightly the same thing, also because MOC uses RaySceneQuery for testing bounding boxes too. For this reason I see MOC as a wrapper for both purposes.
So I can use the convenient methods such as raycastFromCamera() for example, even if I only need the bounding box result, which is a lot faster than testing on polygon level.

If anyone is interested in this little adaption of the code, I can modify it a little further so that the interface stays the same and can be used it in your projects exactly like before. I only have to pass a default value (true) for my new argument bool testPolys.
shadow82
Kobold
 
Posts: 26
Kudos: 0
Joined: 12 Apr 2010

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby so0os » Fri Jun 11, 2010 12:52 pm

Hi!
I implemented method to text collisions with single entity / object
Code: Select all
   bool CollisionTools::raycastSingle(const Ogre::Ray &ray, Ogre::Vector3 &result,Ogre::Entity* target,float &closest_distance, const Ogre::uint32 queryMask) 
   {
      return raycastSingle(ray, result, (Ogre::MovableObject*)target, closest_distance, queryMask);
   }

   bool CollisionTools::raycastSingle(const Ogre::Ray &ray, Ogre::Vector3 &result,Ogre::MovableObject* target,float &closest_distance, const Ogre::uint32 queryMask)
   {
    closest_distance = -1.0f;
      Ogre::Vector3 closest_result;
      Ogre::MovableObject *pentity = target;

      // mesh data to retrieve
      size_t vertex_count;
      size_t index_count;
      Ogre::Vector3 *vertices;
      Ogre::uint32 *indices;

      // get the mesh information
      GetMeshInformation(((Ogre::Entity*)pentity)->getMesh(), vertex_count, vertices, index_count, indices,
         pentity->getParentNode()->_getDerivedPosition(),
         pentity->getParentNode()->_getDerivedOrientation(),
         pentity->getParentNode()->_getDerivedScale());

      // test for hitting individual triangles on the mesh
      bool new_closest_found = false;
      for (size_t i = 0; i < index_count; i += 3)
      {
         // check for a hit against this triangle
         std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
            vertices[indices[i+1]], vertices[indices[i+2]], true, false);

         // if it was a hit check if its the closest
         if (hit.first)
         {
            if ((closest_distance < 0.0f) ||
               (hit.second < closest_distance))
            {
               // this is the closest so far, save it off
               closest_distance = hit.second;
               new_closest_found = true;
            }
         }
      }

      // free the verticies and indicies memory
      delete[] vertices;
      delete[] indices;

      // if we found a new closest raycast for this object, update the
      // closest_result before moving on to the next object.

   


   // return the result
   if (closest_distance >= 0.0f)
   {
      // raycast success
      result = closest_result;
      return (true);
   }
   else
   {
      // raycast failed
      return (false);
   }
}


It's mostly a rewrite but it might be helpful.

Also I cannot seem to get collisions with movable objects working :(
Sos Sosowski :)
http://www.sos.gd
User avatar
so0os
Bugbear
 
Posts: 833
Kudos: 32
Joined: 15 Apr 2010
Location: Poznan, Poland

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby aoth » Sat Jun 12, 2010 2:06 pm

While trying the binary demo I noticed some problem with the edges of the house - if you don't walk straight into walls, but with a angle around the edges, you sometimes run up/on top of the house. (Professional paint screens attached. :P)
Attachments
col1.png
Collision bug
aoth
Gnoblar
 
Posts: 2
Kudos: 0
Joined: 12 Jun 2010

Re: MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

Postby crazymath87 » Sun Jul 18, 2010 4:48 pm

Hi,
I just got moc to work. I like a lot it's really lightweight and easy to use. For me there is only one Problem, i have to check if the two vectors I call collidesWithEntity() with, are actually different (otherwise I get a black screen). It seems to me that this should be done by moc internally. Or is there a reason not to do it?

Regards,
crazymath
crazymath87
Gnoblar
 
Posts: 19
Kudos: 0
Joined: 17 Nov 2009

PreviousNext

Return to Showcase

Who is online

Users browsing this forum: Google [Bot] and 4 guests