예제 #1
0
///////////////////////////////////////////////////////////////
// collides with any other bounding boxes?
bool
Agent::intersects(Ogre::Entity* e)
{
	if (e == NULL) { return false; }

	Ogre::AxisAlignedBox mBox = mBodyEntity->getWorldBoundingBox();
	Ogre::AxisAlignedBox eBox = e->getWorldBoundingBox();

	return mBox.intersects(eBox);
}
예제 #2
0
bool
Agent::intersectsSphere(Ogre::Entity* e)
{
	if (e == NULL) { return false; }

	Ogre::AxisAlignedBox mBox = mBodyEntity->getWorldBoundingBox();
	//Ogre::Real radius= e->getBoundingRadius();
	Ogre::AxisAlignedBox eBox = e->getBoundingBox();
	//e->getWorldBoundingSphere
	e->getBoundingBox();
	return mBox.intersects(eBox);
}
예제 #3
0
/////////////////////////////////////////////////////////////////
//updates the current velocity and position of the agent
//sets a new position according to math
//agent stops when he touches the ground
//need to adjust for barrel collision
void
Agent::shoot(Ogre::Real deltaTime) // lecture 12 call for every frame of the animation
{
	using namespace Ogre;

	Vector3 pos = this->mBodyNode->getPosition();
	vel = vel + (mass*gravity * deltaTime);
	pos = pos + (vel * speed * deltaTime); // velocity
	pos = pos + 0.5 * mass*gravity * deltaTime * deltaTime; // acceleration

	this->mBodyNode->setPosition(pos);
	this->mBodyNode->pitch(Ogre::Degree(20));

	Ogre::AxisAlignedBox objBox = this->mBodyEntity->getWorldBoundingBox();
	objBox.intersects(objBox);

	if (this->mBodyNode->getPosition().y <= -0.5) // if it get close to the ground, stop
	{
		reload();	// finished reset
	}
}
void InputGeometry::_convertOgreEntities(const Ogre::AxisAlignedBox& tileBounds)
{
	std::vector<Ogre::Entity*> selectedEntities;
	Ogre::AxisAlignedBox boundingBox;
	Ogre::Matrix4 transform;
	for(auto itr = _sourceMeshes.begin(); itr != _sourceMeshes.end(); ++itr)
	{
		transform = _referenceNode->_getFullTransform().inverse() * (*itr)->getParentSceneNode()->_getFullTransform();
		boundingBox = (*itr)->getBoundingBox();
		boundingBox.transform(transform);
		if(boundingBox.intersects(tileBounds))
		{
			selectedEntities.push_back(*itr);
		}
	}

	_sourceMeshes.clear();
	_sourceMeshes = selectedEntities;

	_convertOgreEntities();
}
예제 #5
0
    //-----------------------------------------------------------------------
    bool Light::isInLightRange(const Ogre::AxisAlignedBox& container) const
    {
        bool isIntersect = true;
        //Check the 2 simple / obvious situations. Light is directional or light source is inside the container
        if ((mLightType != LT_DIRECTIONAL) && (container.intersects(mDerivedPosition) == false))
        {
            //Check that the container is within the sphere of the light
            isIntersect = Math::intersects(Sphere(mDerivedPosition, mRange),container);
            //If this is a spotlight, do a more specific check
            if ((isIntersect) && (mLightType == LT_SPOTLIGHT) && (mSpotOuter.valueRadians() <= Math::PI))
            {
                //Create a rough bounding box around the light and check if
                Quaternion localToWorld = Vector3::NEGATIVE_UNIT_Z.getRotationTo(mDerivedDirection);

                Real boxOffset = Math::Sin(mSpotOuter * 0.5) * mRange;
                AxisAlignedBox lightBoxBound;
                lightBoxBound.merge(Vector3::ZERO);
                lightBoxBound.merge(localToWorld * Vector3(boxOffset, boxOffset, -mRange));
                lightBoxBound.merge(localToWorld * Vector3(-boxOffset, boxOffset, -mRange));
                lightBoxBound.merge(localToWorld * Vector3(-boxOffset, -boxOffset, -mRange));
                lightBoxBound.merge(localToWorld * Vector3(boxOffset, -boxOffset, -mRange));
                lightBoxBound.setMaximum(lightBoxBound.getMaximum() + mDerivedPosition);
                lightBoxBound.setMinimum(lightBoxBound.getMinimum() + mDerivedPosition);
                isIntersect = lightBoxBound.intersects(container);
                
                //If the bounding box check succeeded do one more test
                if (isIntersect)
                {
                    //Check intersection again with the bounding sphere of the container
                    //Helpful for when the light is at an angle near one of the vertexes of the bounding box
                    isIntersect = isInLightRange(Sphere(container.getCenter(), 
                        container.getHalfSize().length()));
                }
            }
        }
        return isIntersect;
    }