Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / Ice / IceSegment.h
1 /*
2  *      ICE / OPCODE - Optimized Collision Detection
3  * http://www.codercorner.com/Opcode.htm
4  * 
5  * Copyright (c) 2001-2008 Pierre Terdiman,  pierre@codercorner.com
6
7 This software is provided 'as-is', without any express or implied warranty.
8 In no event will the authors be held liable for any damages arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose, 
10 including commercial applications, and to alter it and redistribute it freely, 
11 subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
14 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
15 3. This notice may not be removed or altered from any source distribution.
16 */
17 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 /**
19  *      Contains code for segments.
20  *      \file           IceSegment.h
21  *      \author         Pierre Terdiman
22  *      \date           April, 4, 2000
23  */
24 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25
26 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 // Include Guard
28 #ifndef __ICESEGMENT_H__
29 #define __ICESEGMENT_H__
30
31         class ICEMATHS_API Segment
32         {
33                 public:
34                 //! Constructor
35                 inline_                                 Segment()                                                                                                                       {}
36                 //! Constructor
37                 inline_                                 Segment(const Point& p0, const Point& p1) : mP0(p0), mP1(p1)            {}
38                 //! Copy constructor
39                 inline_                                 Segment(const Segment& seg) : mP0(seg.mP0), mP1(seg.mP1)                        {}
40                 //! Destructor
41                 inline_                                 ~Segment()                                                                                                                      {}
42
43                 inline_ const   Point&  GetOrigin()                                             const   { return mP0;                                           }
44                 inline_                 Point   ComputeDirection()                              const   { return mP1 - mP0;                                     }
45                 inline_                 void    ComputeDirection(Point& dir)    const   { dir = mP1 - mP0;                                      }
46                 inline_                 float   ComputeLength()                                 const   { return mP1.Distance(mP0);                     }
47                 inline_                 float   ComputeSquareLength()                   const   { return mP1.SquareDistance(mP0);       }
48
49                 inline_                 void    SetOriginDirection(const Point& origin, const Point& direction)
50                                                                 {
51                                                                         mP0 = mP1 = origin;
52                                                                         mP1 += direction;
53                                                                 }
54
55                 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56                 /**
57                  *      Computes a point on the segment
58                  *      \param          pt      [out] point on segment
59                  *      \param          t       [in] point's parameter [t=0 => pt = mP0, t=1 => pt = mP1]
60                  */
61                 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62                 inline_                 void    ComputePoint(Point& pt, float t)        const   {       pt = mP0 + t * (mP1 - mP0);             }
63
64                                                 float   SquareDistance(const Point& point, float* t=null)       const;
65                 inline_                 float   Distance(const Point& point, float* t=null)                     const                   { return sqrtf(SquareDistance(point, t));       }
66
67                                                 Point   mP0;            //!< Start of segment
68                                                 Point   mP1;            //!< End of segment
69         };
70
71 #endif // __ICESEGMENT_H__