PixelLightAPI  .
Plane.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Plane.h                                        *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLMATH_PLANE_H__
00024 #define __PLMATH_PLANE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLMath/Vector4.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLMath {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    Plane class
00046 *
00047 *  @remarks
00048 *    A plane is defined in 3D space by the equation: Ax + By + Cz - D = 0\n
00049 *    This equates to a vector - the normal of the plane, whose x, y
00050 *    and z components equate to the coefficients A, B and C
00051 *    respectively, and a constant D which is the distance along
00052 *    the normal you have to go to move the plane back to the origin.
00053 */
00054 class Plane {
00055 
00056 
00057     //[-------------------------------------------------------]
00058     //[ Public definitions                                    ]
00059     //[-------------------------------------------------------]
00060     public:
00061         /**
00062         *  @brief
00063         *    Component
00064         */
00065         enum Component {
00066             X = 0,  /**< X component */
00067             Y = 1,  /**< Y component */
00068             Z = 2,  /**< Z component */
00069             W = 3   /**< Z component */
00070         };
00071 
00072         /**
00073         *  @brief
00074         *    Plane/point relation
00075         */
00076         enum ESide {
00077             Behind     = -1,    /**< Behind the plane (distance < 0) */
00078             Coinciding =  0,    /**< Lies on the plane (distance = 0) */
00079             InFront    =  1     /**< In font of the plane (distance > 0) */
00080         };
00081 
00082 
00083     //[-------------------------------------------------------]
00084     //[ Public data                                           ]
00085     //[-------------------------------------------------------]
00086     public:
00087         union {
00088             float fVector[4];       /**< Coefficients */
00089             struct {
00090                 float a, b, c, d;   /**< Coefficients */
00091             };
00092             struct {
00093                 float fN[3];        /**< Plane normal */
00094                 float fD;           /**< Distance to origin */
00095             };
00096         };
00097 
00098 
00099     //[-------------------------------------------------------]
00100     //[ Public functions                                      ]
00101     //[-------------------------------------------------------]
00102     public:
00103         /**
00104         *  @brief
00105         *    Default constructor setting all components to 0
00106         */
00107         inline Plane();
00108 
00109         /**
00110         *  @brief
00111         *    Constructor
00112         *
00113         *  @param[in] fA
00114         *    Plane equation value A
00115         *  @param[in] fB
00116         *    Plane equation value B
00117         *  @param[in] fC
00118         *    Plane equation value C
00119         *  @param[in] fD
00120         *    Plane equation value D
00121         */
00122         inline Plane(float fA, float fB, float fC, float fD);
00123 
00124         /**
00125         *  @brief
00126         *    Constructor
00127         *
00128         *  @param[in] vOrigin
00129         *    Plane origin
00130         *  @param[in] vNormal
00131         *    Plane normal (will be normalized automatically)
00132         */
00133         inline Plane(const Vector3 &vOrigin, const Vector3 &vNormal);
00134 
00135         /**
00136         *  @brief
00137         *    Constructor
00138         *
00139         *  @param[in] vV1
00140         *    First vertex on the plane
00141         *  @param[in] vV2
00142         *    Second vertex on the plane
00143         *  @param[in] vV3
00144         *    Third vertex on the plane
00145         */
00146         inline Plane(const Vector3 &vV1, const Vector3 &vV2, const Vector3 &vV3);
00147 
00148         /**
00149         *  @brief
00150         *    Destructor
00151         */
00152         inline ~Plane();
00153 
00154         /**
00155         *  @brief
00156         *    Copy operator
00157         *
00158         *  @param[in] cSource
00159         *    Source to copy from
00160         *
00161         *  @return
00162         *    Reference to this instance
00163         */
00164         inline Plane &operator =(const Plane &cSource);
00165 
00166         //[-------------------------------------------------------]
00167         //[ Comparison                                            ]
00168         //[-------------------------------------------------------]
00169         inline bool operator ==(const Plane &cPlane) const;
00170         inline bool operator !=(const Plane &cPlane) const;
00171 
00172         //[-------------------------------------------------------]
00173         //[ Transformation                                        ]
00174         //[-------------------------------------------------------]
00175         PLMATH_API Plane  operator *(const Matrix3x3 &mRot) const;
00176         PLMATH_API Plane  operator *(const Matrix3x4 &mTrans) const;
00177         PLMATH_API Plane  operator *(const Matrix4x4 &mTrans) const;
00178         PLMATH_API Plane &operator *=(const Matrix3x3 &mRot);
00179         PLMATH_API Plane &operator *=(const Matrix3x4 &mTrans);
00180         PLMATH_API Plane &operator *=(const Matrix4x4 &mTrans);
00181 
00182         /**
00183         *  @brief
00184         *    Calculates the plane
00185         *
00186         *  @param[in] vOrigin
00187         *    Plane origin
00188         *  @param[in] vNormal
00189         *    Plane normal (will be normalized automatically)
00190         *
00191         *  @return
00192         *    This instance
00193         */
00194         inline Plane &ComputeND(const Vector3 &vOrigin, const Vector3 &vNormal);
00195 
00196         /**
00197         *  @brief
00198         *    Calculates the plane
00199         *
00200         *  @param[in] vV1
00201         *    First vertex on the plane
00202         *  @param[in] vV2
00203         *    Second vertex on the plane
00204         *  @param[in] vV3
00205         *    Third vertex on the plane
00206         *
00207         *  @return
00208         *    This instance
00209         */
00210         PLMATH_API Plane &ComputeND(const Vector3 &vV1, const Vector3 &vV2, const Vector3 &vV3);
00211 
00212         /**
00213         *  @brief
00214         *    Computes the tangent plane of an ellipsoid
00215         *
00216         *  @param[in] vPointPos
00217         *    Point on the plane
00218         *  @param[in] vEllipsoidPos
00219         *    Ellipsoid position
00220         *  @param[in] vEllipsoidRadius
00221         *    Ellipsoid radius
00222         *
00223         *  @return
00224         *    This instance
00225         */
00226         PLMATH_API Plane &ComputeTangentPlaneOfEllipsoid(const Vector3 &vPointPos, const Vector3 &vEllipsoidPos,
00227                                                          const Vector3 &vEllipsoidRadius);
00228 
00229         /**
00230         *  @brief
00231         *    Normalizes the plane
00232         *
00233         *  @return
00234         *    This instance
00235         */
00236         inline Plane &Normalize();
00237 
00238         /**
00239         *  @brief
00240         *    Calculates the interpolated plane from two other planes
00241         *
00242         *  @param[in] cP2
00243         *    Other plane to interpolate with
00244         *  @param[in] fFactor
00245         *    Interpolation factor. 0.0 = this plane, 1.0 = cP2
00246         *
00247         *  @return
00248         *    The resulting interpolated plane
00249         */
00250         PLMATH_API Plane Lerp(const Plane &cP2, float fFactor);
00251 
00252         /**
00253         *  @brief
00254         *    Returns the side of the plane the given point is on
00255         *
00256         *  @param[in] vPoint
00257         *    Point to check
00258         *
00259         *  @return
00260         *    The side of the plane the given point is on
00261         */
00262         inline ESide GetSide(const Vector3 &vPoint) const;
00263 
00264         /**
00265         *  @brief
00266         *    Calculates the distance from a point to the plane
00267         *
00268         *  @param[in] vPoint
00269         *    Point the distance should be calculated
00270         *
00271         *  @return
00272         *    The distance from the point to the plane
00273         */
00274         inline float GetDistance(const Vector3 &vPoint) const;
00275 
00276         /**
00277         *  @brief
00278         *    Calculates the distance from a point to the plane
00279         *
00280         *  @param[in] vPoint
00281         *    Point the distance should be calculated
00282         *
00283         *  @return
00284         *    The distance from the point to the plane
00285         */
00286         inline float GetDistance(const Vector4 &vPoint) const;
00287 
00288         /**
00289         *  @brief
00290         *    Calculates the distance to the ray/intersection point
00291         *
00292         *  @param[in] vRayPos
00293         *    Ray position
00294         *  @param[in] vRayDir
00295         *    Ray direction (must be normalized)
00296         *
00297         *  @return
00298         *    Distance to ray/plane intersection point (-1.0 if there's no intersection)
00299         */
00300         inline float GetDistance(const Vector3 &vRayPos, const Vector3 &vRayDir) const;
00301 
00302         /**
00303         *  @brief
00304         *    Returns a point on the plane
00305         *
00306         *  @return
00307         *    A point on the plane (-D*N)
00308         */
00309         inline Vector3 GetPointOnPlane() const;
00310 
00311         /**
00312         *  @brief
00313         *    Clips an edge by this plane
00314         *
00315         *  @param[in] vV1
00316         *    The first vertex of the edge
00317         *  @param[in] vV2
00318         *    The second vertex of the edge
00319         *
00320         *  @return
00321         *    The clipped vertex of the edge on this plane
00322         */
00323         inline Vector3 ClipEdge(const Vector3 &vV1, const Vector3 &vV2) const;
00324 
00325 
00326 };
00327 
00328 
00329 //[-------------------------------------------------------]
00330 //[ Namespace                                             ]
00331 //[-------------------------------------------------------]
00332 } // PLMath
00333 
00334 
00335 //[-------------------------------------------------------]
00336 //[ Implementation                                        ]
00337 //[-------------------------------------------------------]
00338 #include "PLMath/Plane.inl"
00339 
00340 
00341 #endif // __PLMATH_PLANE_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:59
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported