| [5420] | 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | ### File Specific: |
|---|
| 12 | main-programmer: Christian Meyer |
|---|
| 13 | co-programmer: ... |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| [4578] | 16 | /*! |
|---|
| [6617] | 17 | * @file plane.h |
|---|
| 18 | * A basic 3D plane math framework |
|---|
| [5008] | 19 | * |
|---|
| [6617] | 20 | * Contains class to handle planes |
|---|
| [4578] | 21 | */ |
|---|
| [2043] | 22 | |
|---|
| [6617] | 23 | #ifndef __PLANE_H_ |
|---|
| 24 | #define __PLANE_H_ |
|---|
| [2043] | 25 | |
|---|
| [3860] | 26 | #include "compiler.h" |
|---|
| [6617] | 27 | #include "vector.h" |
|---|
| 28 | #include "line.h" |
|---|
| [2043] | 29 | |
|---|
| 30 | //! 3D plane |
|---|
| 31 | /** |
|---|
| 32 | Class to handle planes in 3-dimensional space |
|---|
| [4578] | 33 | |
|---|
| [2043] | 34 | Critical for polygon-based collision detection |
|---|
| 35 | */ |
|---|
| 36 | class Plane |
|---|
| 37 | { |
|---|
| 38 | public: |
|---|
| [4578] | 39 | |
|---|
| [2043] | 40 | Vector n; //!< Normal vector |
|---|
| 41 | float k; //!< Offset constant |
|---|
| [4578] | 42 | |
|---|
| [5688] | 43 | Plane (const Vector& a, const Vector& b, const Vector& c); |
|---|
| 44 | Plane (const Vector& norm, const Vector& p); |
|---|
| 45 | Plane (const Vector& norm, const sVec3D& p); |
|---|
| 46 | Plane (const Vector& n, float k) : n(n), k(k) {} //!< assignment constructor |
|---|
| [2043] | 47 | Plane () : n(Vector(1,1,1)), k(0) {} |
|---|
| 48 | ~Plane () {} |
|---|
| [4578] | 49 | |
|---|
| [3228] | 50 | Vector intersectLine (const Line& l) const; |
|---|
| 51 | float distancePoint (const Vector& p) const; |
|---|
| [7711] | 52 | // float distancePoint (const sVec3D& p) const; |
|---|
| 53 | float distancePoint (const float* p) const; |
|---|
| [3228] | 54 | float locatePoint (const Vector& p) const; |
|---|
| [2043] | 55 | }; |
|---|
| 56 | |
|---|
| [4845] | 57 | |
|---|
| 58 | |
|---|
| 59 | //! A class that represents a rectangle, this is needed for SpatialSeparation |
|---|
| 60 | class Rectangle |
|---|
| 61 | { |
|---|
| 62 | |
|---|
| 63 | public: |
|---|
| [5215] | 64 | Rectangle() { this->center = Vector(); } |
|---|
| 65 | Rectangle(const Vector ¢er, float len) { this->center = Vector(center.x, center.y, center.z); this->axis[0] = len; this->axis[1] = len; } |
|---|
| [4845] | 66 | virtual ~Rectangle() {} |
|---|
| 67 | |
|---|
| 68 | /** \brief sets the center of the rectangle to a defined vector @param center the new center */ |
|---|
| [5215] | 69 | inline void setCenter(const Vector ¢er) { this->center = center;} |
|---|
| [4845] | 70 | /** \brief sets the center of the rectangle to a defined vector @param x coord of the center @param y coord of the center @param z coord of the center */ |
|---|
| [5215] | 71 | inline void setCenter(float x, float y, float z) { this->center.x = x; this->center.y = y; this->center.z = z; } |
|---|
| [4845] | 72 | /** \brief returns the center of the rectangle to a defined vector @returns center the new center */ |
|---|
| [5215] | 73 | inline const Vector& getCenter() const { return this->center; } |
|---|
| [4845] | 74 | |
|---|
| 75 | /** \brief sets both axis of the rectangle to a defined vector @param unityLength the new center */ |
|---|
| 76 | inline void setAxis(float unityLength) { this->axis[0] = unityLength; this->axis[1] = unityLength; } |
|---|
| 77 | /** \brief sets both axis of the rectangle to a defined vector @param v1 the length of the x axis @param v2 the length of the z axis*/ |
|---|
| 78 | inline void setAxis(float v1, float v2) { this->axis[0] = v1; this->axis[1] = v2; } |
|---|
| [4853] | 79 | /** \brief gets one axis length of the rectangle @returns the length of the axis 0 */ |
|---|
| 80 | inline float getAxis() { return this-> axis[0]; } |
|---|
| [4845] | 81 | |
|---|
| 82 | private: |
|---|
| [5215] | 83 | Vector center; |
|---|
| [4851] | 84 | float axis[2]; |
|---|
| [4845] | 85 | }; |
|---|
| [4851] | 86 | |
|---|
| 87 | |
|---|
| [6617] | 88 | #endif /* __PLANE_H_ */ |
|---|
| [4997] | 89 | |
|---|