29 #include "../precompiled.h"
121 static int boxPlaneBitsSilVerts[64][7] = {
122 { 0, 0, 0, 0, 0, 0, 0 },
123 { 4, 7, 4, 0, 3, 0, 0 },
124 { 4, 5, 6, 2, 1, 0, 0 },
125 { 0, 0, 0, 0, 0, 0, 0 },
126 { 4, 4, 5, 1, 0, 0, 0 },
127 { 6, 3, 7, 4, 5, 1, 0 },
128 { 6, 4, 5, 6, 2, 1, 0 },
129 { 0, 0, 0, 0, 0, 0, 0 },
130 { 4, 6, 7, 3, 2, 0, 0 },
131 { 6, 6, 7, 4, 0, 3, 2 },
132 { 6, 5, 6, 7, 3, 2, 1 },
133 { 0, 0, 0, 0, 0, 0, 0 },
134 { 0, 0, 0, 0, 0, 0, 0 },
135 { 0, 0, 0, 0, 0, 0, 0 },
136 { 0, 0, 0, 0, 0, 0, 0 },
137 { 0, 0, 0, 0, 0, 0, 0 },
138 { 4, 0, 1, 2, 3, 0, 0 },
139 { 6, 0, 1, 2, 3, 7, 4 },
140 { 6, 3, 2, 6, 5, 1, 0 },
141 { 0, 0, 0, 0, 0, 0, 0 },
142 { 6, 1, 2, 3, 0, 4, 5 },
143 { 6, 1, 2, 3, 7, 4, 5 },
144 { 6, 2, 3, 0, 4, 5, 6 },
145 { 0, 0, 0, 0, 0, 0, 0 },
146 { 6, 0, 1, 2, 6, 7, 3 },
147 { 6, 0, 1, 2, 6, 7, 4 },
148 { 6, 0, 1, 5, 6, 7, 3 },
149 { 0, 0, 0, 0, 0, 0, 0 },
150 { 0, 0, 0, 0, 0, 0, 0 },
151 { 0, 0, 0, 0, 0, 0, 0 },
152 { 0, 0, 0, 0, 0, 0, 0 },
153 { 0, 0, 0, 0, 0, 0, 0 },
154 { 4, 7, 6, 5, 4, 0, 0 },
155 { 6, 7, 6, 5, 4, 0, 3 },
156 { 6, 5, 4, 7, 6, 2, 1 },
157 { 0, 0, 0, 0, 0, 0, 0 },
158 { 6, 4, 7, 6, 5, 1, 0 },
159 { 6, 3, 7, 6, 5, 1, 0 },
160 { 6, 4, 7, 6, 2, 1, 0 },
161 { 0, 0, 0, 0, 0, 0, 0 },
162 { 6, 6, 5, 4, 7, 3, 2 },
163 { 6, 6, 5, 4, 0, 3, 2 },
164 { 6, 5, 4, 7, 3, 2, 1 },
165 { 0, 0, 0, 0, 0, 0, 0 },
166 { 0, 0, 0, 0, 0, 0, 0 },
167 { 0, 0, 0, 0, 0, 0, 0 },
168 { 0, 0, 0, 0, 0, 0, 0 },
169 { 0, 0, 0, 0, 0, 0, 0 },
170 { 0, 0, 0, 0, 0, 0, 0 },
171 { 0, 0, 0, 0, 0, 0, 0 },
172 { 0, 0, 0, 0, 0, 0, 0 },
173 { 0, 0, 0, 0, 0, 0, 0 },
174 { 0, 0, 0, 0, 0, 0, 0 },
175 { 0, 0, 0, 0, 0, 0, 0 },
176 { 0, 0, 0, 0, 0, 0, 0 },
177 { 0, 0, 0, 0, 0, 0, 0 },
178 { 0, 0, 0, 0, 0, 0, 0 },
179 { 0, 0, 0, 0, 0, 0, 0 },
180 { 0, 0, 0, 0, 0, 0, 0 },
181 { 0, 0, 0, 0, 0, 0, 0 },
182 { 0, 0, 0, 0, 0, 0, 0 },
183 { 0, 0, 0, 0, 0, 0, 0 },
184 { 0, 0, 0, 0, 0, 0, 0 },
185 { 0, 0, 0, 0, 0, 0, 0 },
205 bounds1[0][0] = bounds1[1][0] =
center *
axis[0];
206 bounds1[0][1] = bounds1[1][1] =
center * axis[1];
207 bounds1[0][2] = bounds1[1][2] =
center * axis[2];
210 if ( !bounds1.
AddPoint(
idVec3( v * axis[0], v * axis[1], v * axis[2] ) ) ) {
216 axis2[0].Normalize();
217 axis2[1] = axis[
Min3Index( axis2[0] * axis[0], axis2[0] * axis[1], axis2[0] * axis[2] ) ];
218 axis2[1] = axis2[1] - ( axis2[1] * axis2[0] ) * axis2[0];
219 axis2[1].Normalize();
220 axis2[2].Cross( axis2[0], axis2[1] );
223 bounds2.
AddPoint(
idVec3( v * axis2[0], v * axis2[1], v * axis2[2] ) );
227 center = ( bounds1[0] + bounds1[1] ) * 0.5
f;
232 center = ( bounds2[0] + bounds2[1] ) * 0.5
f;
265 bounds[0][0][0] = bounds[0][1][0] =
center * ax[0][0];
266 bounds[0][0][1] = bounds[0][1][1] =
center * ax[0][1];
267 bounds[0][0][2] = bounds[0][1][2] =
center * ax[0][2];
271 if ( !bounds[0].AddBounds( b ) ) {
278 bounds[1][0][0] = bounds[1][1][0] = a.
center * ax[1][0];
279 bounds[1][0][1] = bounds[1][1][1] = a.
center * ax[1][1];
280 bounds[1][0][2] = bounds[1][1][2] = a.
center * ax[1][2];
284 if ( !bounds[1].AddBounds( b ) ) {
295 for ( i = 2; i < 4; i++ ) {
297 ax[
i][1] = ax[i-2][
Min3Index( dir * ax[i-2][0], dir * ax[i-2][1], dir * ax[i-2][2] ) ];
298 ax[
i][1] = ax[
i][1] - ( ax[
i][1] * dir ) * dir;
300 ax[
i][2].Cross( dir, ax[i][1] );
310 for ( i = 0; i < 4; i++ ) {
319 center = ( bounds[besti][0] + bounds[besti][1] ) * 0.5
f;
340 if ( d1 - d2 > 0.0
f ) {
343 if ( d1 + d2 < 0.0
f ) {
362 if ( d1 - d2 > epsilon ) {
365 if ( d1 + d2 < -epsilon ) {
389 axisdir[0] =
axis[0] * dir;
405 axisdir[1] =
axis[1] * dir;
421 axisdir[2] =
axis[2] * dir;
458 d =
idMath::Fabs( axisdir[2] * c[1][0] - axisdir[1] * c[2][0] );
466 d =
idMath::Fabs( axisdir[2] * c[1][1] - axisdir[1] * c[2][1] );
474 d =
idMath::Fabs( axisdir[2] * c[1][2] - axisdir[1] * c[2][2] );
482 d =
idMath::Fabs( axisdir[0] * c[2][0] - axisdir[2] * c[0][0] );
490 d =
idMath::Fabs( axisdir[0] * c[2][1] - axisdir[2] * c[0][1] );
498 d =
idMath::Fabs( axisdir[0] * c[2][2] - axisdir[2] * c[0][2] );
506 d =
idMath::Fabs( axisdir[1] * c[0][0] - axisdir[0] * c[1][0] );
514 d =
idMath::Fabs( axisdir[1] * c[0][1] - axisdir[0] * c[1][1] );
522 d =
idMath::Fabs( axisdir[1] * c[0][2] - axisdir[0] * c[1][2] );
541 idVec3 lineCenter = start + lineDir;
581 static bool BoxPlaneClip(
const float denom,
const float numer,
float &scale0,
float &scale1 ) {
582 if ( denom > 0.0
f ) {
583 if ( numer > denom * scale1 ) {
586 if ( numer > denom * scale0 ) {
587 scale0 = numer / denom;
591 else if ( denom < 0.0
f ) {
592 if ( numer > denom * scale0 ) {
595 if ( numer > denom * scale1 ) {
596 scale1 = numer / denom;
601 return ( numer <= 0.0
f );
615 idVec3 localStart, localDir;
622 return BoxPlaneClip( localDir.
x, -localStart.
x -
extents[0], scale1, scale2 ) &&
623 BoxPlaneClip( -localDir.
x, localStart.
x -
extents[0], scale1, scale2 ) &&
624 BoxPlaneClip( localDir.
y, -localStart.
y -
extents[1], scale1, scale2 ) &&
625 BoxPlaneClip( -localDir.
y, localStart.
y -
extents[1], scale1, scale2 ) &&
626 BoxPlaneClip( localDir.
z, -localStart.
z -
extents[2], scale1, scale2 ) &&
627 BoxPlaneClip( -localDir.
z, localStart.
z -
extents[2], scale1, scale2 );
639 float invNumPoints, sumXX, sumXY, sumXZ, sumYY, sumYZ, sumZZ;
647 for ( i = 1; i < numPoints; i++ ) {
650 invNumPoints = 1.0f / numPoints;
654 sumXX = 0.0f; sumXY = 0.0f; sumXZ = 0.0f;
655 sumYY = 0.0f; sumYZ = 0.0f; sumZZ = 0.0f;
656 for ( i = 0; i < numPoints; i++ ) {
658 sumXX += dir.
x * dir.
x;
659 sumXY += dir.
x * dir.
y;
660 sumXZ += dir.
x * dir.
z;
661 sumYY += dir.
y * dir.
y;
662 sumYZ += dir.
y * dir.
z;
663 sumZZ += dir.
z * dir.
z;
665 sumXX *= invNumPoints;
666 sumXY *= invNumPoints;
667 sumXZ *= invNumPoints;
668 sumYY *= invNumPoints;
669 sumYZ *= invNumPoints;
670 sumZZ *= invNumPoints;
676 eigenVectors[0][0] = sumXX;
677 eigenVectors[0][1] = sumXY;
678 eigenVectors[0][2] = sumXZ;
679 eigenVectors[1][0] = sumXY;
680 eigenVectors[1][1] = sumYY;
681 eigenVectors[1][2] = sumYZ;
682 eigenVectors[2][0] = sumXZ;
683 eigenVectors[2][1] = sumYZ;
684 eigenVectors[2][2] = sumZZ;
688 axis[0][0] = eigenVectors[0][0];
689 axis[0][1] = eigenVectors[0][1];
690 axis[0][2] = eigenVectors[0][2];
691 axis[1][0] = eigenVectors[1][0];
692 axis[1][1] = eigenVectors[1][1];
693 axis[1][2] = eigenVectors[1][2];
694 axis[2][0] = eigenVectors[2][0];
695 axis[2][1] = eigenVectors[2][1];
696 axis[2][2] = eigenVectors[2][2];
704 for ( i = 0; i < numPoints; i++ ) {
705 bounds.
AddPoint(
idVec3( points[i] *
axis[0], points[i] * axis[1], points[i] * axis[2] ) );
707 center = ( bounds[0] + bounds[1] ) * 0.5
f;
770 temp[2] = ax[1] - ax[2];
771 temp[3] = ax[1] + ax[2];
772 points[0] = temp[0] - temp[3];
773 points[1] = temp[1] - temp[3];
774 points[2] = temp[1] + temp[2];
775 points[3] = temp[0] + temp[2];
776 points[4] = temp[0] - temp[2];
777 points[5] = temp[1] - temp[2];
778 points[6] = temp[1] + temp[3];
779 points[7] = temp[0] + temp[3];
794 dir1 = points[0] - projectionOrigin;
795 dir2 = points[6] - projectionOrigin;
809 index = boxPlaneBitsSilVerts[planeBits];
810 for ( i = 0; i < index[0]; i++ ) {
811 silVerts[
i] = points[index[i+1]];
830 f = projectionDir *
axis[0];
834 f = projectionDir * axis[1];
838 f = projectionDir * axis[2];
843 index = boxPlaneBitsSilVerts[planeBits];
844 for ( i = 0; i < index[0]; i++ ) {
845 silVerts[
i] = points[index[i+1]];
bool AddPoint(const idVec3 &v)
GLsizei const GLfloat * points
bool AddBounds(const idBounds &a)
static const float INFINITY
void FromPointRotation(const idVec3 &point, const idRotation &rotation)
bool Eigen_SolveSymmetric(idVecX &eigenValues)
void cross(float a[], float b[], float c[])
const idVec3 & Normal(void) const
idMat3 mat3_identity(idVec3(1, 0, 0), idVec3(0, 1, 0), idVec3(0, 0, 1))
bool AddBox(const idBox &a)
idMat3 Transpose(void) const
float Distance(const idVec3 &v) const
void ToPoints(idVec3 points[8]) const
float GetVolume(void) const
void FromBoxTranslation(const idBox &box, const idVec3 &translation)
void FromPointTranslation(const idVec3 &point, const idVec3 &translation)
bool AddPoint(const idVec3 &v)
#define FLOATSIGNBITSET(f)
int GetParallelProjectionSilhouetteVerts(const idVec3 &projectionDir, idVec3 silVerts[6]) const
static float Fabs(float f)
idBox box_zero(vec3_zero, vec3_zero, mat3_identity)
GLubyte GLubyte GLubyte a
ID_INLINE int Min3Index(T x, T y, T z)
bool IntersectsBox(const idBox &a) const
void FromBoxRotation(const idBox &box, const idRotation &rotation)
#define FLOATSIGNBITNOTSET(f)
void SetData(int rows, int columns, float *data)
void SetData(int length, float *data)
int GetProjectionSilhouetteVerts(const idVec3 &projectionOrigin, idVec3 silVerts[6]) const
float PlaneDistance(const idPlane &plane) const
void Eigen_SortIncreasing(idVecX &eigenValues)
bool LineIntersection(const idVec3 &start, const idVec3 &end) const
bool RayIntersection(const idVec3 &start, const idVec3 &dir, float &scale1, float &scale2) const
int PlaneSide(const idPlane &plane, const float epsilon=ON_EPSILON) const
void FromPoints(const idVec3 *points, const int numPoints)
void AxisProjection(const idVec3 &dir, float &min, float &max) const