~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/ogreopcode/include/OgreCapsule.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
///
 
6
///  @author The OgreOpcode Team
 
7
///  
 
8
///////////////////////////////////////////////////////////////////////////////
 
9
///  
 
10
///  This file is part of OgreOpcode.
 
11
///  
 
12
///  A lot of the code is based on the Nebula Opcode Collision module, see docs/Nebula_license.txt
 
13
///  
 
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.
 
18
///  
 
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.
 
23
///  
 
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
 
27
///  
 
28
///////////////////////////////////////////////////////////////////////////////
 
29
#ifndef __OgreOpcodeCapsule_h__
 
30
#define __OgreOpcodeCapsule_h__
 
31
 
 
32
#include "OgreOpcodeLine.h"
 
33
 
 
34
namespace OgreOpcode
 
35
{
 
36
        namespace Details
 
37
    {
 
38
                /// Represents a Capsule defined by 2 endpoints and a radius
 
39
                /// TODO: add methods to this capsule.
 
40
                class _OgreOpcode_Export Capsule
 
41
                {
 
42
                public:
 
43
 
 
44
                        /** Default constructor: degenerated as an unitary sphere at origin
 
45
                         */
 
46
                        Capsule():start(),end(),radius(1.0)
 
47
                        {
 
48
                        }
 
49
 
 
50
                        /** Copy-constructor
 
51
                         */
 
52
                        Capsule(const Capsule& c):start(c.start),end(c.end),radius(c.radius)
 
53
                        {
 
54
                        }
 
55
 
 
56
                        /** Complete constructor
 
57
                         */
 
58
                        Capsule(const Ogre::Vector3& s, const Ogre::Vector3& e, Ogre::Real r ):start(s),end(e),radius(r)
 
59
                        {
 
60
                        }
 
61
 
 
62
                        /** Complete, headache constructor
 
63
                         */
 
64
                        Capsule( Ogre::Real sx, Ogre::Real sy, Ogre::Real sz,
 
65
                                     Ogre::Real ex, Ogre::Real ey, Ogre::Real ez, 
 
66
                                         Ogre::Real r
 
67
                                   ):start(sx,sy,sz),end(ex,ey,ez),radius(r)
 
68
                        {
 
69
                        }
 
70
 
 
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(); }
 
75
 
 
76
                        /// Gets the surface area of this capsule
 
77
                        Ogre::Real area() const
 
78
                        {                                       
 
79
                                return Ogre::Math::TWO_PI*radius*(2.0*radius + length() );
 
80
                        }
 
81
 
 
82
                        /// Gets the volume are this capsule
 
83
                        Ogre::Real volume() const
 
84
                        {
 
85
                                return Ogre::Math::PI*radius*radius*( 1.333333333333333*length() );
 
86
                        }
 
87
// --------------------------------------------------------------------
 
88
// intersection tests
 
89
 
 
90
                        /** Does this capsule contain the given point?
 
91
                         */
 
92
                        bool contains( const Ogre::Vector3& point ) const;
 
93
 
 
94
                        /** Tests intersection between this capsule and the given Axis-Aligned
 
95
                         *  Bounding Box
 
96
             */
 
97
                        bool intersects( const Aabb& aabb ) const;
 
98
 
 
99
                        /** Tests intersection between this capsule and the given sphere
 
100
                         */
 
101
                        bool intersects( const sphere& s ) const;
 
102
 
 
103
                        /** Tests intersection between this capsule and the given Oriented Bounding Box
 
104
                         */
 
105
                        bool intersects( const OrientedBox& obb ) const;
 
106
 
 
107
                        /** Tests intersection between this capsule and the given one
 
108
                         */
 
109
                        bool intersects( const Capsule& cap ) const;
 
110
 
 
111
 
 
112
                        /** The start point of this capsule.
 
113
                         */
 
114
                        Ogre::Vector3 start;
 
115
                        /** The end point of this capsule.
 
116
                         */
 
117
                        Ogre::Vector3 end;
 
118
                        /** The radius of this capsule.
 
119
                         */
 
120
                        Ogre::Real radius;                      
 
121
                };
 
122
        }
 
123
}
 
124
 
 
125
#endif