⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrecapsule.cpp

📁 opcode是功能强大
💻 CPP
字号:
///////////////////////////////////////////////////////////////////////////////
///  @file OgreCapsule.cpp
///  @brief <TODO: insert file description here>
///
///  @author The OgreOpcode Team @date 28-05-2005
///
///////////////////////////////////////////////////////////////////////////////
///
///  This file is part of OgreOpcode.
///
///  A lot of the code is based on the Nebula Opcode Collision module, see docs/Nebula_license.txt
///
///  OgreOpcode is free software; you can redistribute it and/or
///  modify it under the terms of the GNU Lesser General Public
///  License as published by the Free Software Foundation; either
///  version 2.1 of the License, or (at your option) any later version.
///
///  OgreOpcode is distributed in the hope that it will be useful,
///  but WITHOUT ANY WARRANTY; without even the implied warranty of
///  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
///  Lesser General Public License for more details.
///
///  You should have received a copy of the GNU Lesser General Public
///  License along with OgreOpcode; if not, write to the Free Software
///  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
///
///////////////////////////////////////////////////////////////////////////////

#include "OgreCapsule.h"
#include "OgreOrientedBox.h"

namespace OgreOpcode
{
	namespace Details
    {
		//------------------------------------------------------------------------
		bool Capsule::contains( const Ogre::Vector3& point ) const
		{
			Line line( start, end );

			return line.squaredDistance(point) <= (radius*radius);
		}
		//------------------------------------------------------------------------
		bool Capsule::intersects( const Aabb& aabb ) const
		{
			// TODO: optimize this code for the AABB case.
			OrientedBox obb( aabb );
			return intersects( obb );
		}
		//------------------------------------------------------------------------
		bool Capsule::intersects( const sphere& s ) const
		{
			Line line( start, end);
			Ogre::Real sqrDist = line.squaredDistance( s.p );
			Ogre::Real rsum = radius + s.r;

			return sqrDist <= (rsum*rsum);
		}
		//------------------------------------------------------------------------
		bool Capsule::intersects( const OrientedBox& obb ) const
		{
			Line line( start, end );

			return line.squaredDistance(obb) <= (radius*radius);
		}
		//------------------------------------------------------------------------
		bool Capsule::intersects( const Capsule& cap ) const
		{
			Line me( start, end );
			Line it( cap.start, cap.end );

			Ogre::Real sqrDist = me.squaredDistance( it );
			Ogre::Real rsum = radius + cap.radius;

			return sqrDist <= (rsum*rsum);;
		}
		//------------------------------------------------------------------------
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -