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 Nauk » Tue Jun 16, 2009 3:17 pm

@tdev: I was pondering with the idea of implementing caching anyway, so you don't have to pull the same vertex data each single frame over and over. I am wondering what the speed gain is like that can be gotten from a "smart" caching system or if there is any at all. Either way I am looking forward to play with your code. :)

@compvis: I am not sure if that is the best way of doing it, but you could either create a threaded projectile class that either selfterminates after a certain range or reports the hit back, or you simply just update the movement each frame and check for collision, either in your framestarted method or your applications mainloop.
User avatar
Nauk
Gnoll
 
Posts: 645
Kudos: 23
Joined: 11 May 2006
Location: Bavaria

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

Postby tdev » Tue Jun 16, 2009 11:07 pm

Nauk wrote:@tdev: I was pondering with the idea of implementing caching anyway, so you don't have to pull the same vertex data each single frame over and over. I am wondering what the speed gain is like that can be gotten from a "smart" caching system or if there is any at all. Either way I am looking forward to play with your code. :)

good to hear, looking forward to your ideas :)

meanwhile i added some simple cache discarding. You can find my latest version there:
http://rigsofrods.svn.sourceforge.net/v ... ionTools.h
http://rigsofrods.svn.sourceforge.net/v ... nTools.cpp
User avatar
tdev
Silver Sponsor
Silver Sponsor
 
Posts: 244
Kudos: 14
Joined: 12 Apr 2007
Location: Germany

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

Postby corn » Tue Jun 30, 2009 3:53 am

Hello,


I've made some updates to MOC that I wanted to share with the community. I have added both smooth stepping and falling, which also makes MOC more easy to use with 3rd person camera systems where the character is being past into updateY() instead of just the camera. Now stairs and other objects can be climbed up to a specified height, and the scene node (camera or character) will smoothly step up (if you want it even smoother, it is easy to tweak the value to your own desire). When falling, you will now fall smoothly from a high distance rather than of instantaneously warping to the ground.

Nauk, you're also more than welcome to modify it and include it in your next release as you see fit. I have only tested it out with objects, and not either of the terrain systems, but it should work fine with them as well.

If you find any bugs, fixes, or optimizations, please post them for the community. If anyone is up to also implement sliding, you'll have yourself a nice character controller! Please share your sliding implementation as well!

Here is the changed code:

Code from CollisionTools.cpp:

Updated the constructor to add some member initialization.

Code: Select all
CollisionTools::CollisionTools(Ogre::SceneManager *sceneMgr)
{
   mSceneMgr = sceneMgr;

   mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());
    if (NULL == mRaySceneQuery)
    {
      // LOG_ERROR << "Failed to create Ogre::RaySceneQuery instance" << ENDLOG;
      return;
    }
    mRaySceneQuery->setSortByDistance(true);

    mTSMRaySceneQuery =  mSceneMgr->createRayQuery(Ogre::Ray());

    _heightAdjust = 0.0f;
   _origY = 0.0f;
   _newY = 0.0f;
}


Updated calculateY().

Code: Select all
/* 
 * This function can be called to calculate the Y coordinate of a scene node
 * so it will follow ground, terrain, or other objects.  This function now also
 * supports both smooth stepping and falling.
 *
 * initial
 *      Is this the first call to set the initial height?
 *
 * steppingSize
 *      The location we should cast our ray down from.  This is useful when we want
 *      to be able to step up on objects up to a certain height.  This also adds
 *      realism so we don't just step up onto anything that is below our scene node,
 *      as realistically, we could step up on a 50 meter building.
 */
void CollisionTools::calculateY(Ogre::SceneNode *n, const bool initial, const bool doTerrainCheck,
                        const bool doGridCheck, const float gridWidth,
                        const float steppingSize, const Ogre::uint32 queryMask)
{
   // Get the current position of the scene node:
   Ogre::Vector3 pos = n->getPosition();

   // Save the y position to a member variable as we may need to use it later:
   _origY = pos.y;

   float x = pos.x;
   float z = pos.z;
   float y = pos.y + steppingSize - _heightAdjust;      // Use the actual height of the object and the stepping size.

   Ogre::Vector3 myResult(0,0,0);
   Ogre::MovableObject *myObject=NULL;
   float distToColl = 0.0f;

   float terrY = 0, colY = 0, colY2 = 0;

   if( raycastFromPoint(Ogre::Vector3(x,y,z),Ogre::Vector3::NEGATIVE_UNIT_Y,myResult,myObject, distToColl, queryMask)){
      if (myObject != NULL) {
         colY = myResult.y;
      } else {
         colY = -99999;
      }
   }

   //if doGridCheck is on, repeat not to fall through small holes for example when crossing a hangbridge
   if (doGridCheck) {
      if( raycastFromPoint(Ogre::Vector3(x,y,z)+(n->getOrientation()*Ogre::Vector3(0,0,gridWidth)),Ogre::Vector3::NEGATIVE_UNIT_Y,myResult, myObject, distToColl, queryMask)){
         if (myObject != NULL) {
            colY = myResult.y;
         } else {
            colY = -99999;
         }
      }
      if (colY<colY2) colY = colY2;
   }

   // set the parameter to false if you are not using ETM or TSM
   if (doTerrainCheck) {

#ifdef ETM_TERRAIN
      // ETM height value
      terrY = mTerrainInfo->getHeightAt(x,z);
#else
      // TSM height value
      terrY = getTSMHeightAt(x,z);
#endif

      if(terrY < colY ) {
         _newY = colY+_heightAdjust;
      } else {
         _newY = terrY+_heightAdjust;
      }
   } else {
      if (!doTerrainCheck && colY == -99999)
         colY = y;
         
      _newY = colY+_heightAdjust;
   }

   // If this is the first time the function is called to set an initial y position,
   // we aren't stepping or falling, so rather than animating toward the new position
   // over time, we just set it now:
   if (initial)   {
      n->setPosition(x, _newY, z);
   }
}


Added updateY().

Code: Select all
/* 
 * This function should be called to smoothly update the Y coordinate of a
 * scene node so it follows the ground or other objects.  This function
 * supports both smooth stepping and falling.
 */
void CollisionTools::updateY(Ogre::SceneNode *n)
{
   // Get the position of the scene node:
   float currY = n->getPosition().y;

   // If we don't need to update, just return:
   if (_newY == currY)
      return;

   // Determine the distance as the difference between the new height
   // and the original height:
   float distY = _newY - _origY;

   // If the distance is greater than 2 meters, fall at a rate of 4%,
   // otherwise, fall or step at a rate of 20%, both giving the appearance
   // of a smooth transition:
   float newY;
   if (abs(distY) > 2)
      newY = distY * 0.04;
   else
      newY = distY * 0.2;

   // If the current update will put us higher or lower than the amount we are
   // supposed to go, just use the amount we're supposed to go instead.  We do
   // this for precision:
   if ( ( (newY >= 0) && ((currY + newY) > _newY) ) || ( (newY < 0) && ((currY + newY) < _newY) ) )
   {
      newY = _newY;
      n->translate( 0, newY - currY, 0 );
   }
   else
   {
      // Otherwise, move from the current position by the new Y amount:
      n->translate( 0, newY, 0 );
   }
}


Sample code from a camera controller using the new features:

Code: Select all
//--------------------------------------------------------------------------------------
//  Function used to test for collisions between the camera and objects in the scene.
//--------------------------------------------------------------------------------------
void Camera1P::collisionTestWithMOC(Real timeSinceLastFrame)
{
   // Continue moving toward a new Y position until it is reached:
   mCollisionTools->updateY(mMoveCamNode);

   // If the camera is moving via input:
   if (mDirection != Vector3::ZERO)
   {
      // Save the last position
      Vector3 oldPos = mMoveCamNode->getPosition();
      
      // Commit move
      moveCamera(timeSinceLastFrame);

      // Calculate the new Y position.  Check terrain and all objects flagged with ENTITY_MASK.
      // Multiple masks are possible like e.g. ENTITY_MASK|MY_MASK|ETC_MASK.
      // doGridCheck casts a 2nd ray.  gridWidth=2.0f ogre units away from the exact camera position to
      // avoid falling through small holes or gaps in hangbridges for example.
      mCollisionTools->calculateY(mMoveCamNode, false, false, true, 0.1f, 1.0f, CollisionTools::WALKABLE_OBJECTS);

      // Start moving toward the new Y position immediately after finishing calculations:
      mCollisionTools->updateY(mMoveCamNode);

      // Check if we are colliding with anything.  We pass in the camera's previous position,
      // the camera's new position that will occur if there is no collision, and a collision radius
      // of 1.0 units, which means that we will leave 1.0 units between the player and a collision.
      // The next parameter is the height we want the ray to originate from, and the last parameter
      // is the query mask which we have assigned all objects we want to check against for collisions.
      // The query mask is used for efficiency so only objects we want tested are tested.
      // If we collide, we undo the move:
      if (mCollisionTools->collidesWithEntity(oldPos, mMoveCamNode->getPosition(), 1.0f,
         -((mMoveCamNode->getPosition()).y * .8), CollisionTools::STATIONARY_OBJECTS))
         mMoveCamNode->setPosition(oldPos);
   }
}


Enjoy!

-- Corn
corn
Gnoblar
 
Posts: 16
Kudos: 0
Joined: 07 Feb 2009

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

Postby corn » Tue Jun 30, 2009 6:03 am

I just realized when testing it in release build that it goes a little fast and isn't quite as smooth as debug build...therefore, just as a heads up, you may want to tweak the above code just a bit for framerate independence, or lower the speed multipliers in updateY(). :)
corn
Gnoblar
 
Posts: 16
Kudos: 0
Joined: 07 Feb 2009

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

Postby Nauk » Tue Jun 30, 2009 9:33 am

Very nice corn, those are good and usefull additions, thanks a lot for sharing, I will definately add them :)
User avatar
Nauk
Gnoll
 
Posts: 645
Kudos: 23
Joined: 11 May 2006
Location: Bavaria

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

Postby Am3oo » Fri Jul 03, 2009 7:22 pm

quick question:
how can I exclude the nodes/objects I don't want to detect collisions for?
User avatar
Am3oo
Gnoblar
 
Posts: 20
Kudos: 0
Joined: 25 Feb 2009

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

Postby Nauk » Fri Jul 03, 2009 10:02 pm

Assign a query mask for the objects you want to include. http://www.ogre3d.org/docs/api/html/cla ... ff5a74f54d

... and then you can pass the masks to the MOC methods as parameter.

HTH :)
User avatar
Nauk
Gnoll
 
Posts: 645
Kudos: 23
Joined: 11 May 2006
Location: Bavaria

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

Postby andrewfenn » Sat Jul 04, 2009 11:48 am

I got a real head scratcher of a problem here. I'm using MOC for ray casts but it is acting weird. I already made a thread if you don't mind taking a look for me. :D
User avatar
andrewfenn
Halfling
 
Posts: 60
Kudos: 1
Joined: 23 Mar 2007

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

Postby Am3oo » Sat Jul 04, 2009 7:48 pm

Nauk wrote:Assign a query mask for the objects you want to include. http://www.ogre3d.org/docs/api/html/cla ... ff5a74f54d

... and then you can pass the masks to the MOC methods as parameter.

HTH :)

Thank you. Works now.
User avatar
Am3oo
Gnoblar
 
Posts: 20
Kudos: 0
Joined: 25 Feb 2009

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

Postby Jdog » Sun Jul 05, 2009 5:23 pm

Thanks very much for these tools! Very useful. And thanks for your additions as well corn, they're great!

I do have 2 minor problems though - first, I'm using this on a third-person system and (depending on ray height) it seems to catch the character model itself and prevent strafing left and right (model is wider in this area) - but I think my masks are just messed up, although they should be working ok...can anyone direct me to help with that?

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?
User avatar
Jdog
Gnoblar
 
Posts: 12
Kudos: 0
Joined: 05 Apr 2009
Location: Pretoria, South Africa

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

Postby adanar » Tue Jul 07, 2009 1:29 pm

Hello,

I recently came across another issue. Has anyone tried to integrate MOC and PLSM2? I have modified the method to also return world fragment results, and it worked fine with the generic scene manager. when I switched to PLSM2, it stopped working. Reading the plsm forum it seems that it might work if I set WFT_SINGLE_INTERSECTION however, I don't want only a single result..
adanar
Gnoblar
 
Posts: 23
Kudos: 0
Joined: 19 Feb 2006
Location: Greece, Crete

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

Postby vikyg13 » Sun Jul 12, 2009 4:14 pm

Hi, I'm a new user.
I don't know how I have to use MOC. I need implement collision between a car and a track, both of them are maya mesh exported
thank you
vikyg13
Gnoblar
 
Posts: 19
Kudos: 0
Joined: 27 Jun 2009

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

Postby aguru » Sun Jul 12, 2009 5:27 pm

what have you tried? there is an example application you know...
User avatar
aguru
Goblin
 
Posts: 236
Kudos: 3
Joined: 26 Feb 2008

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

Postby corn » Mon Jul 13, 2009 6:13 am

Jdog wrote: I do have 2 minor problems though - first, I'm using this on a third-person system and (depending on ray height) it seems to catch the character model itself and prevent strafing left and right (model is wider in this area) - but I think my masks are just messed up, although they should be working ok...can anyone direct me to help with that?

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?


So far, I set one mask for objects that I wanted to test for collisions against, and a different mask for shapes that I wanted my character to be able to walk on or climb up (in the case of stairs and other objects that I wanted to support stepping).

I'll be happy to share my MOC related code in the third person camera controller I'm using in hopes that it helps you to identify and solve your problems.

Code: Select all
//--------------------------------------------------------------------------------------
void Camera3P::update ( Real timeSinceLastFrame )
{
   // If we should use MOC for collision detection:
   if (mCollisionType == collision_moc)   {
      collisionTestWithMOC(timeSinceLastFrame);
   } else {
      moveCharacter(timeSinceLastFrame);
      moveCamera();
   }
}


Code: Select all
//--------------------------------------------------------------------------------------
//  Function used to test for collisions between the character and objects in the scene.
//--------------------------------------------------------------------------------------
void Camera3P::collisionTestWithMOC(Real timeSinceLastFrame)
{
   // If we're still updating the Y position due to a step or a fall that
   // was too large to complete in a single frame:
   mCollisionTools->updateY(mCharMainNode);

   // If there's no direction or orientation change:
   if ((mDirection == 0) && (mOrientation == 0))
   {
      // Even if the character isn't moving, we may still need to complete both
      // camera nodes' translation based on displacement:
      moveCamera();
      return;
   }

   // If we're only orienting the character:
   if ((mDirection == 0) && (mOrientation != 0))
   {
      // Orient the character, and also adjust the camera diplacement
      // if necessary by calling moveCamera():
      moveCharacter(timeSinceLastFrame);
      moveCamera();
      return;
   }

   // If the character is moving via input:
   if (mDirection != 0)
   {
      // Save the position of the character node before we commit
      // the current move:
      Vector3 charMainNode_PrevPos = mCharMainNode->getPosition();

      // Commit move
      moveCharacter(timeSinceLastFrame);

      // Calculate the new Y position.  Check terrain and all objects flagged with ENTITY_MASK.
      // Multiple masks are possible like e.g. ENTITY_MASK|MY_MASK|ETC_MASK.
      // doGridCheck casts a 2nd ray.
      mCollisionTools->calculateY(mCharMainNode, false, false, true, 0.5f, 1.0f, CollisionTools::WALKABLE_OBJECTS);

      // Move toward the new Y position at a rate of 1 m/s.  If the return value is true, the
      // update couldn't complete in one shot, so we will need to block movement and continue
      // to update until completion:
      mCollisionTools->updateY(mCharMainNode);

      // Check if we are colliding with anything.  We pass in the player's previous position,
      // the player's new position that will occur if there is no collision, and a collision radius
      // of 1.0 units, which means that we will leave 1.0 units between the player and a collision.
      // The next parameter is the height we want the ray to originate from, and the last parameter
      // is the query mask which we have assigned all objects we want to check against for collisions.
      // The query mask is used for efficiency so only objects we want tested are tested.
      // If we collide, we undo the move:
      if (mCollisionTools->collidesWithEntity(charMainNode_PrevPos, mCharMainNode->getPosition(), 1.0f,
         0.35f, CollisionTools::STATIONARY_OBJECTS))
      {
         // There was a collision with the sweep, so revert back to the last position so we don't
         // collide:
         mCharMainNode->setPosition(charMainNode_PrevPos);
      }
      else   // If there was no collision:
      {
         moveCamera();

         // If the y-position changed due to the ground changing, make sure the camera's nodes
         // are also updated to the new height:
         Ogre::Real r = mCharMainNode->getPosition().y - charMainNode_PrevPos.y;
         if(r != 0)
         {
            mCameraNode->translate(0, r, 0);
            mCameraTargetNode->translate(0, r, 0);
         }

      }
   }
}
corn
Gnoblar
 
Posts: 16
Kudos: 0
Joined: 07 Feb 2009

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

Postby corn » Mon Jul 13, 2009 6:17 am

Nauk wrote:Very nice corn, those are good and usefull additions, thanks a lot for sharing, I will definately add them :)


My pleasure. You've done a great job on MOC! If I make any additional useful changes, I will continue to post them for the community to share.
corn
Gnoblar
 
Posts: 16
Kudos: 0
Joined: 07 Feb 2009

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

Postby vikyg13 » Mon Jul 13, 2009 3:22 pm

I begin implementing MOC in myFrameListeners adding this string to the code

m_collisionTools = new CollisionTools(m_scene);

When I compile the program it crashes. The program says that the error is in the line:

mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());

of the CollisionTools constructor. Someone can help me?
vikyg13
Gnoblar
 
Posts: 19
Kudos: 0
Joined: 27 Jun 2009

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

Postby vikyg13 » Mon Jul 13, 2009 5:10 pm

I solved my problem.

Now the program crashes when I use the collidesWithEntity() method in myFrameListeners

m_collision = m_collisionTools->collidesWithEntity(oldPosition, m_animData->corpo->getPosition());
if(m_collision)
m_animData->corpo->setPosition(oldPosition);

Someone can help me?
vikyg13
Gnoblar
 
Posts: 19
Kudos: 0
Joined: 27 Jun 2009

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

Postby vikyg13 » Fri Jul 17, 2009 11:50 am

Hello. Now the method collidesWithEntity() works. I use this code

if(oldPosition.squaredDistance(m_animData->corpo->getPosition()) > 10) {
if (m_collisionTools->collidesWithEntity(oldPosition, m_animData->corpo->_getDerivedPosition(), 10.0f, 5.0f,SceneManager::ENTITY_TYPE_MASK))
{
// undo move
m_animData->corpo->setPosition(oldPosition);
}
}

to detect collision between character and walls.
The method works but I don't know why sometimes character stops even if it doesn't touch any wall.
vikyg13
Gnoblar
 
Posts: 19
Kudos: 0
Joined: 27 Jun 2009

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

Postby suny2000 » Tue Sep 15, 2009 9:15 pm

Thanks for MOC and your great work.

I would like to implement collision sliding for an FPS camera and use the common method:
1) know the point of collision with the sphere
2) Calculate the normal of collision : normal = (CameraPos - CollisionPos).normalised()
3) Create a sliding vector: CameraVelocity -= normal * (CameraVelocity .dotProduct(normal ));

How can I know the position of the point where the sphere collide with an entity, using collidesWithEntity() ?

Thanks,
S.
http://bulostudio.com: website and devlog of a small indie studio working on SHMUP CREATOR
https://twitter.com/bulostudio : follow me on twitter!
User avatar
suny2000
Kobold
 
Posts: 33
Kudos: 0
Joined: 06 Sep 2009

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Postby aerique » Thu Sep 24, 2009 3:44 pm

edit: This question is moot. I don't know how I missed the check fro "Entity" in the MOC code. I blame a lack of coffee!

mickeyren wrote:Does this work on manual objects or just entity?

Since its based from the wiki entry - the wiki entry needs the mesh information from the entity - i don't think manual objects returns these information?

It currently, using the 1.0 release, doesn't work with manual objects for me. I've tried looking at the code but I haven't done anything with ray casting in Ogre yet.

I'm aware of manualObject->convertToMesh but I'm using a lot of dynamically generated manual objects in my project that need to be updated pretty often so converting them to a mesh every time would not be ideal.

Is there any way to make MOC work for manual objects?
Last edited by aerique on Mon Sep 28, 2009 2:51 pm, edited 1 time in total.
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 iisystem » Sat Sep 26, 2009 6:40 pm

Hi,

MOC is really great thing ;)

I'm using the latest version of it (1.0) with latest Ogre 1.6.3. And there are some problems with demo (I've recompiled it in order to support Ogre 1.6.3, with one minor change in the SampleApp.cpp):
- in OpenGL mode, all the terrain is white-colored - and there are errors about CG in the console;
- in DirectX mode, water is static now (it was dynamic in the original demo, however);
- FPS value sometimes breaks down to 12-15 FPS, especially when entering the house (enabling-disabling MOC does not change anything).
iisystem
Gnoblar
 
Posts: 24
Kudos: 0
Joined: 27 Aug 2009

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

Postby iisystem » Sun Sep 27, 2009 9:37 am

and there is a question on MOC usage:
how to correctly make sure that the camera does not pass through small gaps in walls?
i.e. in my app, i have 2 walls and a small gap between them, is it possible to tell MOC to still "collide" with the walls if the gap is less than some value?
iisystem
Gnoblar
 
Posts: 24
Kudos: 0
Joined: 27 Aug 2009

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Postby aerique » Mon Sep 28, 2009 2:55 pm

aerique wrote:Is there any way to make MOC work for manual objects?

Yes, there is. Read the source code better next time.

Anyway, I've got this working for ManualObjects now with a really ugly hack that suffices for now :). I changed the check for an Entity into a check for an Entity or a ManualObject in the raycast method and I made sure the MeshPtr that's passed to GetMeshInformation comes from either Entity->getMesh() or ManualObject->convertToMesh().

You can find the changes here, but like I said it's very hackish: http://github.com/aerique/okra/commit/3209eee94cf4de572e88780d0cec4b809563e694#diff-0

edit: Oh! and I also added a check for MovableObject->isVisible which might be handy for other people as well:

Code: Select all
...
// Only check this result if its a hit against an Entity or a ManualObject.
if ((query_result[qr_idx].movable != NULL) &&
    (query_result[qr_idx].movable->isVisible()) &&
    ((query_result[qr_idx].movable->getMovableType().compare("Entity") == 0) || (query_result[qr_idx].movable->getMovableType().compare("ManualObject") == 0)))
{
...
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 sailingboy » Mon Oct 12, 2009 7:35 pm

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!
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 7:46 pm

I thought i might report this and also suggest it as a change for the next version:

The method raycastFromCamera(...) uses a MouseEvent as parameter, in my opinion this is quite bad because it requires being called after a mouseEvent was produced, sounds not THAT bad at first but think of some issues like this one:
You don't move the mouse -> so no mouseevents are being produced, however although your surroundings move or some object moves at the position your mouse is pointing to- what happens is that there wont be an update on the object / point your target with your mouse, however altho it is in fact pointing on something different than what you have as result
Or: You make your character run into the direction you point at and you point somewhere on the ground and start moving character, but you dont move your mouse anymore -> the character will move to this point and then move back and forth on that point, altho meanwhile because your camera might have moved, too, the mouse is pointing on another point on the ground mesh

LONG BORING STORY SHORT:
To solve this small issues just use a mouseCursor Object or a pointer to such an object as parameter instead, and every time you actualize the mouseEvent you also actualize that pointer, thus you can update the targeted point even without a mouseevent and thus in the end guaranteeing that YOU GET WHAT YOU SEE and not some old buggy result because you didn't move your mouse around like a maniac without a break


nothing big really

Code: Select all
bool CollisionTools::raycastFromCamera(RenderWindow* rw, Camera* camera, Generals::mouseCursor* mouseCursorPos, Vector3 &result, ulong &target,float &closest_distance, const uint32 queryMask)
{
   // Create the ray to test
   Real tx = (Real) mouseCursorPos->x / (Real) rw->getWidth();
   Real ty = (Real) mouseCursorPos->y / (Real) rw->getHeight();
   Ray ray = camera->getCameraToViewportRay(tx, ty);

   return raycast(ray, result, target, closest_distance, queryMask);
}


Define this in any header file you use it
Code: Select all
struct mouseCursor
{
   int x;
   int y;
};


and dont forget to update the cursor on every mouseMove, in the mouseMoved(...) method:
Code: Select all
   //update mouseCursor
   mouseCursor.x = evt.state.X.abs;
   mouseCursor.y = evt.state.Y.abs;


i think this is something small but in some cases very important to be changed, also the mouseCursor object can be generally of use

any suggestions, criticism, or praises are appreciated (except maybe for the criticism)
Last edited by Ident on Mon Oct 12, 2009 7:54 pm, edited 1 time in total.
Ident
Greenskin
 
Posts: 148
Kudos: 5
Joined: 17 Sep 2009

PreviousNext

Return to Showcase

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests