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 
00028 #if defined(__CELLOS_LV2__) || defined (USE_SYSTEM_VECTORMATH)
00029 #include <vectormath_aos.h>
00030 #else
00031 #include "BulletMultiThreaded/vectormath/scalar/cpp/vectormath_aos.h"
00032 #endif
00033 
00034 
00035 
00036 using namespace Vectormath::Aos;
00037 
00038 enum FeatureType { F, E, V };
00039 
00040 //----------------------------------------------------------------------------
00041 // Box
00042 //----------------------------------------------------------------------------
00044 class Box
00045 {
00046 public:
00047         Vector3 half;
00048 
00049         inline Box()
00050         {}
00051         inline Box(PE_REF(Vector3) half_);
00052         inline Box(float hx, float hy, float hz);
00053 
00054         inline void Set(PE_REF(Vector3) half_);
00055         inline void Set(float hx, float hy, float hz);
00056 
00057         inline Vector3 GetAABB(const Matrix3& rotation) const;
00058 };
00059 
00060 inline
00061 Box::Box(PE_REF(Vector3) half_)
00062 {
00063         Set(half_);
00064 }
00065 
00066 inline
00067 Box::Box(float hx, float hy, float hz)
00068 {
00069         Set(hx, hy, hz);
00070 }
00071 
00072 inline
00073 void
00074 Box::Set(PE_REF(Vector3) half_)
00075 {
00076         half = half_;
00077 }
00078 
00079 inline
00080 void
00081 Box::Set(float hx, float hy, float hz)
00082 {
00083         half = Vector3(hx, hy, hz);
00084 }
00085 
00086 inline
00087 Vector3
00088 Box::GetAABB(const Matrix3& rotation) const
00089 {
00090         return absPerElem(rotation) * half;
00091 }
00092 
00093 //-------------------------------------------------------------------------------------------------
00094 // BoxPoint
00095 //-------------------------------------------------------------------------------------------------
00096 
00098 class BoxPoint
00099 {
00100 public:
00101         BoxPoint() : localPoint(0.0f) {}
00102 
00103         Point3      localPoint;
00104         FeatureType featureType;
00105         int         featureIdx;
00106 
00107         inline void setVertexFeature(int plusX, int plusY, int plusZ);
00108         inline void setEdgeFeature(int dim0, int plus0, int dim1, int plus1);
00109         inline void setFaceFeature(int dim, int plus);
00110 
00111         inline void getVertexFeature(int & plusX, int & plusY, int & plusZ) const;
00112         inline void getEdgeFeature(int & dim0, int & plus0, int & dim1, int & plus1) const;
00113         inline void getFaceFeature(int & dim, int & plus) const;
00114 };
00115 
00116 inline
00117 void
00118 BoxPoint::setVertexFeature(int plusX, int plusY, int plusZ)
00119 {
00120         featureType = V;
00121         featureIdx = plusX << 2 | plusY << 1 | plusZ;
00122 }
00123 
00124 inline
00125 void
00126 BoxPoint::setEdgeFeature(int dim0, int plus0, int dim1, int plus1)
00127 {
00128         featureType = E;
00129 
00130         if (dim0 > dim1) {
00131                 featureIdx = plus1 << 5 | dim1 << 3 | plus0 << 2 | dim0;
00132         } else {
00133                 featureIdx = plus0 << 5 | dim0 << 3 | plus1 << 2 | dim1;
00134         }
00135 }
00136 
00137 inline
00138 void
00139 BoxPoint::setFaceFeature(int dim, int plus)
00140 {
00141         featureType = F;
00142         featureIdx = plus << 2 | dim;
00143 }
00144 
00145 inline
00146 void
00147 BoxPoint::getVertexFeature(int & plusX, int & plusY, int & plusZ) const
00148 {
00149         plusX = featureIdx >> 2;
00150         plusY = featureIdx >> 1 & 1;
00151         plusZ = featureIdx & 1;
00152 }
00153 
00154 inline
00155 void
00156 BoxPoint::getEdgeFeature(int & dim0, int & plus0, int & dim1, int & plus1) const
00157 {
00158         plus0 = featureIdx >> 5;
00159         dim0 = featureIdx >> 3 & 3;
00160         plus1 = featureIdx >> 2 & 1;
00161         dim1 = featureIdx & 3;
00162 }
00163 
00164 inline
00165 void
00166 BoxPoint::getFaceFeature(int & dim, int & plus) const
00167 {
00168         plus = featureIdx >> 2;
00169         dim = featureIdx & 3;
00170 }
00171 
00172 #endif /* __BOX_H__ */

Generated on Mon Feb 15 22:17:01 2010 for Bullet Collision Detection & Physics Library by  doxygen 1.6.1