Esempio 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;
}
Esempio n. 2
0
Ogre::Sphere EditSphere::scaleSphere(const Ogre::Sphere _sp, const double scale)
{
    Ogre::Sphere sp = _sp;
    sp.setCenter(sp.getCenter()/scale);
    sp.setRadius(sp.getRadius()/scale);
    return sp;
}
Esempio 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;
}
Esempio n. 4
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;
    }
Esempio n. 5
0
BOOL CCamera_Scene::_IsValidEye(
    const Fairy::TerrainData* pTerrainData,	//地形数据
    const fVector3& fvEye,					//眼睛点
    FLOAT fCameraNearDis)					//近距离
{
    //近距碰撞球
    Ogre::Sphere ballNear;
    ballNear.setCenter(Ogre::Vector3(fvEye.x, fvEye.y, fvEye.z));
    ballNear.setRadius(fCameraNearDis);

    CAMERA_INTER_GRIDS gridsTerrain;
    if(!_GetInterPatch(
                pTerrainData,
                fvEye,
                gridsTerrain))
    {
        //眼睛在地形外面
        return TRUE;
    }

    //近距球是否在地形下面
    for(INT i=0; i<(INT)gridsTerrain.m_fvGrid.size(); i++)
    {
        const Ogre::AxisAlignedBox& theGridBox = gridsTerrain.m_fvGrid[i];

        //是否相交
        if(Ogre::Math::intersects(ballNear, theGridBox)) return FALSE;
    }

    return TRUE;
}
Esempio n. 6
0
Ogre::AxisAlignedBox EditSphere::aab(double scale) const
{
    Ogre::Sphere sp = scaleSphere(m_sp, scale);
    Ogre::AxisAlignedBox aabb(sp.getCenter().x-((int)sp.getRadius()+1), sp.getCenter().y-((int)sp.getRadius()+1), sp.getCenter().z-((int)sp.getRadius()+1),
                        sp.getCenter().x+((int)sp.getRadius()+1), sp.getCenter().y+((int)sp.getRadius()+1), sp.getCenter().z+((int)sp.getRadius()+1));
    return aabb;
}
Esempio n. 7
0
void OrbitCamera( ::Ogre::Camera* a_pCam, const::Ogre::Sphere& a_subjSphr,
                  const Ogre::Vector2& a_curTouch, const Ogre::Vector2& a_oldTouch )
{
    const ::Ogre::Vector3& center = a_subjSphr.getCenter() ;
    const ::Ogre::Vector3& camPos = a_pCam->getPosition() ;
    
    // gets the current looked-at point.
    const ::Ogre::Vector3 camDir = a_pCam->getDirection().normalisedCopy() ;
    const ::Ogre::Vector3 lookAt = camDir.dotProduct(center - camPos) * camDir + camPos  ;
    
    // makes the ray from the subjet's center to the camera.
    const ::Ogre::Ray rayToCam( center, (camPos - center).normalisedCopy() ) ;
    
    // makes the tangent plane to the sphere whose normal is toward the camera.
    ::Ogre::Real fDist = center.distance( camPos ) ;
    if( a_subjSphr.getRadius() < fDist )
        fDist = a_subjSphr.getRadius() ;        
    const ::Ogre::Plane touchPlane( rayToCam.getDirection(), fDist ) ;
    
    // gets the touch points on the plane.
    ::Ogre::Ray ray ;
    a_pCam->getCameraToViewportRay( a_curTouch.x, a_curTouch.y, &ray ) ;
    const ::Ogre::Vector3 curPoint = ray.getPoint( ray.intersects( touchPlane ).second ) ;
    a_pCam->getCameraToViewportRay( a_oldTouch.x, a_oldTouch.y, &ray ) ;
    const ::Ogre::Vector3 oldPoint = ray.getPoint( ray.intersects( touchPlane ).second ) ;
    
    // gets the quaternion.
    const ::Ogre::Quaternion qtnn = (curPoint - center).getRotationTo( oldPoint - center ) ;
    
    // gets the new camera position.
    ::Ogre::Vector3 newCamPos = camPos - center ;
    newCamPos = qtnn * newCamPos ;
    newCamPos += center ;
    
    // gest the new look-at.
    ::Ogre::Vector3 newLookAt = lookAt - center ;
    newLookAt = qtnn * newLookAt ;
    newLookAt += center ;
    
    // sets the camera to the new properties.
    a_pCam->setPosition( newCamPos ) ;
    a_pCam->lookAt( newLookAt ) ;
}
Esempio n. 8
0
double EditSphere::calcVoxel(const Ogre::Vector3& pos, const double &scale)
{
    Ogre::Sphere sp = scaleSphere(m_sp, scale);
    double dist = sp.getRadius() - sp.getCenter().distance(pos);
    return dist;
}