Box.h

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 2006, 2008 Sony Computer Entertainment Inc.
00003    All rights reserved.
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 
00015 */
00016 
00017 #ifndef __BOX_H__
00018 #define __BOX_H__
00019 
00020 
00021 #ifndef PE_REF
00022 #define PE_REF(a) a&
00023 #endif
00024 
00025 #include <math.h>
00026 
00027 
00028 #include "../PlatformDefinitions.h"
00029 
00030 
00031 
00032 
00033 enum FeatureType { F, E, V };
00034 
00035 //----------------------------------------------------------------------------
00036 // Box
00037 //----------------------------------------------------------------------------
00039 class Box
00040 {
00041 public:
00042         vmVector3 mHalf;
00043 
00044         inline Box()
00045         {}
00046         inline Box(PE_REF(vmVector3) half_);
00047         inline Box(float hx, float hy, float hz);
00048 
00049         inline void Set(PE_REF(vmVector3) half_);
00050         inline void Set(float hx, float hy, float hz);
00051 
00052         inline vmVector3 GetAABB(const vmMatrix3& rotation) const;
00053 };
00054 
00055 inline
00056 Box::Box(PE_REF(vmVector3) half_)
00057 {
00058         Set(half_);
00059 }
00060 
00061 inline
00062 Box::Box(float hx, float hy, float hz)
00063 {
00064         Set(hx, hy, hz);
00065 }
00066 
00067 inline
00068 void
00069 Box::Set(PE_REF(vmVector3) half_)
00070 {
00071         mHalf = half_;
00072 }
00073 
00074 inline
00075 void
00076 Box::Set(float hx, float hy, float hz)
00077 {
00078         mHalf = vmVector3(hx, hy, hz);
00079 }
00080 
00081 inline
00082 vmVector3
00083 Box::GetAABB(const vmMatrix3& rotation) const
00084 {
00085         return absPerElem(rotation) * mHalf;
00086 }
00087 
00088 //-------------------------------------------------------------------------------------------------
00089 // BoxPoint
00090 //-------------------------------------------------------------------------------------------------
00091 
00093 class BoxPoint
00094 {
00095 public:
00096         BoxPoint() : localPoint(0.0f) {}
00097 
00098         vmPoint3      localPoint;
00099         FeatureType featureType;
00100         int         featureIdx;
00101 
00102         inline void setVertexFeature(int plusX, int plusY, int plusZ);
00103         inline void setEdgeFeature(int dim0, int plus0, int dim1, int plus1);
00104         inline void setFaceFeature(int dim, int plus);
00105 
00106         inline void getVertexFeature(int & plusX, int & plusY, int & plusZ) const;
00107         inline void getEdgeFeature(int & dim0, int & plus0, int & dim1, int & plus1) const;
00108         inline void getFaceFeature(int & dim, int & plus) const;
00109 };
00110 
00111 inline
00112 void
00113 BoxPoint::setVertexFeature(int plusX, int plusY, int plusZ)
00114 {
00115         featureType = V;
00116         featureIdx = plusX << 2 | plusY << 1 | plusZ;
00117 }
00118 
00119 inline
00120 void
00121 BoxPoint::setEdgeFeature(int dim0, int plus0, int dim1, int plus1)
00122 {
00123         featureType = E;
00124 
00125         if (dim0 > dim1) {
00126                 featureIdx = plus1 << 5 | dim1 << 3 | plus0 << 2 | dim0;
00127         } else {
00128                 featureIdx = plus0 << 5 | dim0 << 3 | plus1 << 2 | dim1;
00129         }
00130 }
00131 
00132 inline
00133 void
00134 BoxPoint::setFaceFeature(int dim, int plus)
00135 {
00136         featureType = F;
00137         featureIdx = plus << 2 | dim;
00138 }
00139 
00140 inline
00141 void
00142 BoxPoint::getVertexFeature(int & plusX, int & plusY, int & plusZ) const
00143 {
00144         plusX = featureIdx >> 2;
00145         plusY = featureIdx >> 1 & 1;
00146         plusZ = featureIdx & 1;
00147 }
00148 
00149 inline
00150 void
00151 BoxPoint::getEdgeFeature(int & dim0, int & plus0, int & dim1, int & plus1) const
00152 {
00153         plus0 = featureIdx >> 5;
00154         dim0 = featureIdx >> 3 & 3;
00155         plus1 = featureIdx >> 2 & 1;
00156         dim1 = featureIdx & 3;
00157 }
00158 
00159 inline
00160 void
00161 BoxPoint::getFaceFeature(int & dim, int & plus) const
00162 {
00163         plus = featureIdx >> 2;
00164         dim = featureIdx & 3;
00165 }
00166 
00167 #endif /* __BOX_H__ */