PixelLightAPI  .
Rectangle.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Rectangle.h                                    *
00003  *
00004  *  Copyright (C) 2002-2012 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_RECTANGLE_H__
00024 #define __PLMATH_RECTANGLE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLMath/Vector2.h"
00032 #include "PLMath/Vector4.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLMath {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    Rectangle (2D axis aligned bounding box) class
00047 */
00048 class Rectangle {
00049 
00050 
00051     //[-------------------------------------------------------]
00052     //[ Public data                                           ]
00053     //[-------------------------------------------------------]
00054     public:
00055         Vector2 vMin;   /**< Minimum position */
00056         Vector2 vMax;   /**< Maximum position */
00057 
00058 
00059     //[-------------------------------------------------------]
00060     //[ Public functions                                      ]
00061     //[-------------------------------------------------------]
00062     public:
00063         /**
00064         *  @brief
00065         *    Default constructor setting all minimum and maximum components to 0
00066         */
00067         inline Rectangle();
00068 
00069         /**
00070         *  @brief
00071         *    Copy constructor
00072         *
00073         *  @param[in] cSource
00074         *    Source to copy from
00075         */
00076         inline Rectangle(const Rectangle &cSource);
00077 
00078         /**
00079         *  @brief
00080         *    Constructor
00081         *
00082         *  @param[in] vMin
00083         *    Minimum position
00084         *  @param[in] vMax
00085         *    Maximum position
00086         */
00087         inline Rectangle(const Vector2 &vMin, const Vector2 &vMax);
00088 
00089         /**
00090         *  @brief
00091         *    Constructor
00092         *
00093         *  @param[in] fMinX
00094         *    X component of the minimum position
00095         *  @param[in] fMinY
00096         *    Y component of the minimum position
00097         *  @param[in] fMaxX
00098         *    X component of the maximum position
00099         *  @param[in] fMaxY
00100         *    Y component of the maximum position
00101         */
00102         inline Rectangle(float fMinX, float fMinY, float fMaxX, float fMaxY);
00103 
00104         /**
00105         *  @brief
00106         *    Destructor
00107         */
00108         inline ~Rectangle();
00109 
00110         /**
00111         *  @brief
00112         *    Copy operator
00113         *
00114         *  @param[in] cSource
00115         *    Source to copy from
00116         *
00117         *  @return
00118         *    Reference to this instance
00119         */
00120         inline Rectangle &operator =(const Rectangle &cSource);
00121 
00122         /**
00123         *  @brief
00124         *    Returns the center of the rectangle
00125         *
00126         *  @return
00127         *    Center of the rectangle ((vMax+vMin)/2)
00128         */
00129         inline Vector2 GetCenter() const;
00130 
00131         /**
00132         *  @brief
00133         *    Returns the x position
00134         *
00135         *  @return
00136         *    X position
00137         */
00138         inline float GetX() const;
00139 
00140         /**
00141         *  @brief
00142         *    Returns the y position
00143         *
00144         *  @return
00145         *    Y position
00146         */
00147         inline float GetY() const;
00148 
00149         /**
00150         *  @brief
00151         *    Returns the width
00152         *
00153         *  @return
00154         *    Width
00155         */
00156         inline float GetWidth() const;
00157 
00158         /**
00159         *  @brief
00160         *    Returns the height
00161         *
00162         *  @return
00163         *    Height
00164         */
00165         inline float GetHeight() const;
00166 
00167         /**
00168         *  @brief
00169         *    Calculates the surface of the rectangle
00170         *
00171         *  @return
00172         *    Surface of the rectangle
00173         */
00174         inline float CalculateSurface() const;
00175 
00176         /**
00177         *  @brief
00178         *    Clips this rectangle with another one
00179         *
00180         *  @param[in] cEnclosed
00181         *    Rectangle to clip this rectangle with
00182         */
00183         inline void ClipByRectangle(const Rectangle &cEnclosed);
00184 
00185         /**
00186         *  @brief
00187         *    Appends a vertex to the rectangle
00188         *
00189         *  @param[in] vV
00190         *    Vertex to append
00191         */
00192         inline void AppendToRectangle(const Vector2 &vV);
00193 
00194         /**
00195         *  @brief
00196         *    Combines two rectangles
00197         *
00198         *  @param[in] cRectangle
00199         *    Rectangle to combine with this rectangle
00200         */
00201         inline void CombineRectangles(const Rectangle &cRectangle);
00202 
00203         /**
00204         *  @brief
00205         *    Calculates the screen-space bounding rectangle of the given array of points
00206         *
00207         *  @param[in] lstPoints
00208         *    Array of points
00209         *  @param[in] bZCull
00210         *    Determines whether or not the function should also return 'false' if the rectangle
00211         *    lies outside the depth range
00212         *  @param[in] mMVP
00213         *    Concatenated modelview/projection matrix
00214         *  @param[in] nX
00215         *    X screen position
00216         *  @param[in] nY
00217         *    Y screen position
00218         *  @param[in] nWidth
00219         *    Screen width
00220         *  @param[in] nHeight
00221         *    Screen height
00222         *
00223         *  @remarks
00224         *    If all went fine, this rectangle will receive the screen-space bounding rectangle of the given array of points.
00225         *
00226         *  @return
00227         *    'false' if the rectangle is entirely off-screen, else 'true'
00228         */
00229         PLMATH_API bool ScreenRectangle(const PLCore::Array<Vector3> &lstPoints, bool bZCull, const Matrix4x4 &mMVP, PLCore::uint32 nX, PLCore::uint32 nY, PLCore::uint32 nWidth, PLCore::uint32 nHeight);
00230 
00231         /**
00232         *  @brief
00233         *    Calculates the screen-space bounding rectangle of the given array of points
00234         *
00235         *  @param[in] lstPoints
00236         *    Array of points
00237         *  @param[in] bZCull
00238         *    Determines whether or not the function should also return 'false' if the rectangle
00239         *    lies outside the depth range
00240         *  @param[in] mMVP
00241         *    Concatenated modelview/projection matrix
00242         *  @param[in] nX
00243         *    X screen position
00244         *  @param[in] nY
00245         *    Y screen position
00246         *  @param[in] nWidth
00247         *    Screen width
00248         *  @param[in] nHeight
00249         *    Screen height
00250         *
00251         *  @remarks
00252         *    If all went fine, this rectangle will receive the screen-space bounding rectangle of the given array of points.
00253         *
00254         *  @return
00255         *    'false' if the rectangle is entirely off-screen, else 'true'
00256         */
00257         PLMATH_API bool ScreenRectangle(const PLCore::Array<Vector4> &lstPoints, bool bZCull, const Matrix4x4 &mMVP, PLCore::uint32 nX, PLCore::uint32 nY, PLCore::uint32 nWidth, PLCore::uint32 nHeight);
00258 
00259 
00260 };
00261 
00262 
00263 //[-------------------------------------------------------]
00264 //[ Namespace                                             ]
00265 //[-------------------------------------------------------]
00266 } // PLMath
00267 
00268 
00269 //[-------------------------------------------------------]
00270 //[ Implementation                                        ]
00271 //[-------------------------------------------------------]
00272 #include "PLMath/Rectangle.inl"
00273 
00274 
00275 #endif // __PLMATH_RECTANGLE_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:58
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported