Пример #1
0
void CollisionTools::calculateY(Ogre::SceneNode *n, const bool doTerrainCheck, const bool doGridCheck, const float gridWidth, const Ogre::uint32 queryMask)
{
	Ogre::Vector3 pos = n->getPosition();

	float x = pos.x;
	float z = pos.z;
	float y = pos.y;

	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 ) {
			n->setPosition(x,colY+_heightAdjust,z);
		} else {
			n->setPosition(x,terrY+_heightAdjust,z);
		}
	} else {
		if (!doTerrainCheck && colY == -99999) colY = y;
		n->setPosition(x,colY+_heightAdjust,z);
	}
}
Пример #2
0
// raycast from a point in to the scene.
// returns success or failure.
// on success the point is returned in the result.
bool CollisionTools::raycastFromPoint(const Ogre::Vector3 &point, 
                                        const Ogre::Vector3 &normal,
										Ogre::Vector3 &result,Ogre::Entity* &target,
										float &closest_distance,
										const Ogre::uint32 queryMask) 
{
	return raycastFromPoint(point, normal, result,(Ogre::MovableObject*&) target, closest_distance, queryMask);
}		
Пример #3
0
	Ogre::Entity* CollisionTools::collidesWithObject(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, const float collisionRadius, const Ogre::uint32 queryMask)
	{
		Ogre::Vector3 normal = toPoint - fromPoint;
		float distToDest = normal.normalise();

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

		if (raycastFromPoint(fromPoint, normal, myResult, myObject, distToColl, queryMask))
		{
			distToColl -= collisionRadius;
			if (distToColl <= distToDest)
				return myObject;
		}

		return NULL;
	}
Пример #4
0
bool CollisionTools::collidesWithEntity(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, const float collisionRadius, const float rayHeightLevel, const Ogre::uint32 queryMask)
{
	Ogre::Vector3 fromPointAdj(fromPoint.x, fromPoint.y + rayHeightLevel, fromPoint.z);
	Ogre::Vector3 toPointAdj(toPoint.x, toPoint.y + rayHeightLevel, toPoint.z);
	Ogre::Vector3 normal = toPointAdj - fromPointAdj;
	float distToDest = normal.normalise();

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

	if (raycastFromPoint(fromPointAdj, normal, myResult, myObject, distToColl, queryMask))
	{
		distToColl -= collisionRadius;
		return (distToColl <= distToDest);
	}
	else
	{
		return false;
	}
}