1
///////////////////////////////////////////////////////////////////////////////
2
/// @file OgreCapsule.h
3
/// @brief This class represents a Capsule, which is defined by 2 endpoints and a radius.
4
/// You can interpret it as a sphere that is sweept along a line.
6
/// @author The OgreOpcode Team
8
///////////////////////////////////////////////////////////////////////////////
10
/// This file is part of OgreOpcode.
12
/// A lot of the code is based on the Nebula Opcode Collision module, see docs/Nebula_license.txt
14
/// OgreOpcode is free software; you can redistribute it and/or
15
/// modify it under the terms of the GNU Lesser General Public
16
/// License as published by the Free Software Foundation; either
17
/// version 2.1 of the License, or (at your option) any later version.
19
/// OgreOpcode is distributed in the hope that it will be useful,
20
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
21
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
/// Lesser General Public License for more details.
24
/// You should have received a copy of the GNU Lesser General Public
25
/// License along with OgreOpcode; if not, write to the Free Software
26
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
///////////////////////////////////////////////////////////////////////////////
29
#ifndef __OgreOpcodeCapsule_h__
30
#define __OgreOpcodeCapsule_h__
32
#include "OgreOpcodeLine.h"
38
/// Represents a Capsule defined by 2 endpoints and a radius
39
/// TODO: add methods to this capsule.
40
class _OgreOpcode_Export Capsule
44
/** Default constructor: degenerated as an unitary sphere at origin
46
Capsule():start(),end(),radius(1.0)
52
Capsule(const Capsule& c):start(c.start),end(c.end),radius(c.radius)
56
/** Complete constructor
58
Capsule(const Ogre::Vector3& s, const Ogre::Vector3& e, Ogre::Real r ):start(s),end(e),radius(r)
62
/** Complete, headache constructor
64
Capsule( Ogre::Real sx, Ogre::Real sy, Ogre::Real sz,
65
Ogre::Real ex, Ogre::Real ey, Ogre::Real ez,
67
):start(sx,sy,sz),end(ex,ey,ez),radius(r)
71
/// Gets the length of this line segment
72
Ogre::Real length() const { return (start - end).length(); }
73
/// Gets the squared length of this line segment
74
Ogre::Real length2() const { return (start - end).squaredLength(); }
76
/// Gets the surface area of this capsule
77
Ogre::Real area() const
79
return Ogre::Math::TWO_PI*radius*(2.0*radius + length() );
82
/// Gets the volume are this capsule
83
Ogre::Real volume() const
85
return Ogre::Math::PI*radius*radius*( 1.333333333333333*length() );
87
// --------------------------------------------------------------------
90
/** Does this capsule contain the given point?
92
bool contains( const Ogre::Vector3& point ) const;
94
/** Tests intersection between this capsule and the given Axis-Aligned
97
bool intersects( const Aabb& aabb ) const;
99
/** Tests intersection between this capsule and the given sphere
101
bool intersects( const sphere& s ) const;
103
/** Tests intersection between this capsule and the given Oriented Bounding Box
105
bool intersects( const OrientedBox& obb ) const;
107
/** Tests intersection between this capsule and the given one
109
bool intersects( const Capsule& cap ) const;
112
/** The start point of this capsule.
115
/** The end point of this capsule.
118
/** The radius of this capsule.