Ejemplo n.º 1
0
Character* CollisionManager::CheckCollisions(Character* obj)
{
	Ogre::Vector3 heading = obj->GetHeading();
	heading *= .5;//lol
	Ogre::Sphere* attackRange = new Ogre::Sphere(obj->GetSceneNode()->getPosition(), (Ogre::Real)(2*ENEMY_CLOSE_DISTANCE));

	//check if player collides with enemies
	//only attack 1 enemy maximum
	if(obj->GetCollisionType() == CT_PLAYER)
	{
		for(int i = 0; i < mCollisionObjects.size(); i++)
		{
			if(attackRange->intersects(mCollisionObjects[i]->GetBoundingBox()))
			{
				return mCollisionObjects[i];
				break;
			}
		}
	}
	else if(obj->GetCollisionType() == CT_ENEMY)
	{
		if(attackRange->intersects(GAMEENGINE.GetPlayer()->GetBoundingBox()))
			return GAMEENGINE.GetPlayer();
	}

	return NULL;
}
Ejemplo n.º 2
0
    //-----------------------------------------------------------------------
    bool Light::isInLightRange(const Ogre::Sphere& container) const
    {
        bool isIntersect = true;
        //directional light always intersects (check only spotlight and point)
        if (mLightType != LT_DIRECTIONAL)
        {
            //Check that the sphere is within the sphere of the light
            isIntersect = container.intersects(Sphere(mDerivedPosition, mRange));
            //If this is a spotlight, check that the sphere is within the cone of the spot light
            if ((isIntersect) && (mLightType == LT_SPOTLIGHT))
            {
                //check first check of the sphere surrounds the position of the light
                //(this covers the case where the center of the sphere is behind the position of the light
                // something which is not covered in the next test).
                isIntersect = container.intersects(mDerivedPosition);
                //if not test cones
                if (!isIntersect)
                {
                    //Calculate the cone that exists between the sphere and the center position of the light
                    Ogre::Vector3 lightSphereConeDirection = container.getCenter() - mDerivedPosition;
                    Ogre::Radian halfLightSphereConeAngle = Math::ASin(container.getRadius() / lightSphereConeDirection.length());

                    //Check that the light cone and the light-position-to-sphere cone intersect)
                    Radian angleBetweenConeDirections = lightSphereConeDirection.angleBetween(mDerivedDirection);
                    isIntersect = angleBetweenConeDirections <=  halfLightSphereConeAngle + mSpotOuter * 0.5;
                }
            }
        }
        return isIntersect;
    }
Ejemplo n.º 3
0
//TODO: The sphere should be created ahead of time, not inside this method
//std::vector<Character*> CollisionManager::CheckCollisions(Ogre::Sphere* collisionObj)
std::vector<Character*> CollisionManager::CheckCollisions(Character* obj, int attackType)
{
	std::vector<Character*> collisions;
	
	Ogre::Real attack = 10.0f;
	Ogre::Vector3 heading = obj->GetHeading();
	Ogre::Vector3 desiredLocation = obj->GetSceneNode()->getPosition() + (heading * attack/2);
	Ogre::Sphere attackRange = Ogre::Sphere(desiredLocation, attack);

	//check all collision objects to see if player colides	
	for(int i = 0; i < mCollisionObjects.size(); i++)
	{
		if(attackRange.intersects(mCollisionObjects[i]->GetEntity()->getWorldBoundingBox()))
		{
			if(attackType == 1)
			{
				collisions.push_back(mCollisionObjects[i]);
				break;
			}
			else
			{
				collisions.push_back(mCollisionObjects[i]);
			}
		}
	}

	return collisions;
}