Bullet Collision Detection & Physics Library
Box.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006, 2008 Sony Computer Entertainment Inc.
3  All rights reserved.
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 
15 */
16 
17 #ifndef __BOX_H__
18 #define __BOX_H__
19 
20 
21 #ifndef PE_REF
22 #define PE_REF(a) a&
23 #endif
24 
25 #include <math.h>
26 
27 
28 #include "../PlatformDefinitions.h"
29 
30 
31 
32 
33 enum FeatureType { F, E, V };
34 
35 //----------------------------------------------------------------------------
36 // Box
37 //----------------------------------------------------------------------------
39 class Box
40 {
41 public:
43 
44  inline Box()
45  {}
46  inline Box(PE_REF(vmVector3) half_);
47  inline Box(float hx, float hy, float hz);
48 
49  inline void Set(PE_REF(vmVector3) half_);
50  inline void Set(float hx, float hy, float hz);
51 
52  inline vmVector3 GetAABB(const vmMatrix3& rotation) const;
53 };
54 
55 inline
57 {
58  Set(half_);
59 }
60 
61 inline
62 Box::Box(float hx, float hy, float hz)
63 {
64  Set(hx, hy, hz);
65 }
66 
67 inline
68 void
70 {
71  mHalf = half_;
72 }
73 
74 inline
75 void
76 Box::Set(float hx, float hy, float hz)
77 {
78  mHalf = vmVector3(hx, hy, hz);
79 }
80 
81 inline
83 Box::GetAABB(const vmMatrix3& rotation) const
84 {
85  return absPerElem(rotation) * mHalf;
86 }
87 
88 //-------------------------------------------------------------------------------------------------
89 // BoxPoint
90 //-------------------------------------------------------------------------------------------------
91 
93 class BoxPoint
94 {
95 public:
96  BoxPoint() : localPoint(0.0f) {}
97 
101 
102  inline void setVertexFeature(int plusX, int plusY, int plusZ);
103  inline void setEdgeFeature(int dim0, int plus0, int dim1, int plus1);
104  inline void setFaceFeature(int dim, int plus);
105 
106  inline void getVertexFeature(int & plusX, int & plusY, int & plusZ) const;
107  inline void getEdgeFeature(int & dim0, int & plus0, int & dim1, int & plus1) const;
108  inline void getFaceFeature(int & dim, int & plus) const;
109 };
110 
111 inline
112 void
113 BoxPoint::setVertexFeature(int plusX, int plusY, int plusZ)
114 {
115  featureType = V;
116  featureIdx = plusX << 2 | plusY << 1 | plusZ;
117 }
118 
119 inline
120 void
121 BoxPoint::setEdgeFeature(int dim0, int plus0, int dim1, int plus1)
122 {
123  featureType = E;
124 
125  if (dim0 > dim1) {
126  featureIdx = plus1 << 5 | dim1 << 3 | plus0 << 2 | dim0;
127  } else {
128  featureIdx = plus0 << 5 | dim0 << 3 | plus1 << 2 | dim1;
129  }
130 }
131 
132 inline
133 void
134 BoxPoint::setFaceFeature(int dim, int plus)
135 {
136  featureType = F;
137  featureIdx = plus << 2 | dim;
138 }
139 
140 inline
141 void
142 BoxPoint::getVertexFeature(int & plusX, int & plusY, int & plusZ) const
143 {
144  plusX = featureIdx >> 2;
145  plusY = featureIdx >> 1 & 1;
146  plusZ = featureIdx & 1;
147 }
148 
149 inline
150 void
151 BoxPoint::getEdgeFeature(int & dim0, int & plus0, int & dim1, int & plus1) const
152 {
153  plus0 = featureIdx >> 5;
154  dim0 = featureIdx >> 3 & 3;
155  plus1 = featureIdx >> 2 & 1;
156  dim1 = featureIdx & 3;
157 }
158 
159 inline
160 void
161 BoxPoint::getFaceFeature(int & dim, int & plus) const
162 {
163  plus = featureIdx >> 2;
164  dim = featureIdx & 3;
165 }
166 
167 #endif /* __BOX_H__ */
vmPoint3 localPoint
Definition: Box.h:98
void setFaceFeature(int dim, int plus)
Definition: Box.h:134
vmVector3 GetAABB(const vmMatrix3 &rotation) const
Definition: Box.h:83
void getVertexFeature(int &plusX, int &plusY, int &plusZ) const
Definition: Box.h:142
FeatureType
Definition: Box.h:33
void Set(PE_REF(vmVector3) half_)
Definition: Box.h:69
Definition: Box.h:33
void setVertexFeature(int plusX, int plusY, int plusZ)
Definition: Box.h:113
Box()
Definition: Box.h:44
void setEdgeFeature(int dim0, int plus0, int dim1, int plus1)
Definition: Box.h:121
vmVector3 mHalf
Definition: Box.h:42
BoxPoint()
Definition: Box.h:96
#define PE_REF(a)
Definition: Box.h:22
FeatureType featureType
Definition: Box.h:99
The Box is an internal class used by the boxBoxDistance calculation.
Definition: Box.h:39
Definition: Box.h:33
void getEdgeFeature(int &dim0, int &plus0, int &dim1, int &plus1) const
Definition: Box.h:151
Vectormath::Aos::Vector3 vmVector3
Definition: vmInclude.h:23
The BoxPoint class is an internally used class to contain feature information for boxBoxDistance calc...
Definition: Box.h:93
Definition: Box.h:33
int featureIdx
Definition: Box.h:100
void getFaceFeature(int &dim, int &plus) const
Definition: Box.h:161
const Matrix3 absPerElem(const Matrix3 &mat)
Definition: neon/mat_aos.h:233