Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

Box.h File Reference

#include "Vec3d.h"
#include "XForm3d.h"

Go to the source code of this file.

Compounds

struct  geBox

Defines

#define GE_BOX_H

Typedefs

typedef geBox geBox

Functions

void geBox_Set (geBox *Box, geFloat xScale, geFloat yScale, geFloat zScale, const geXForm3d *Transform)
void geBox_SetXForm (geBox *Box, const geXForm3d *Transform)
geBoolean geBox_DetectCollisionBetween (const geBox *Box1, const geBox *Box2)


Define Documentation

#define GE_BOX_H
 

Definition at line 24 of file Box.h.


Typedef Documentation

typedef struct geBox geBox
 


Function Documentation

geBoolean geBox_DetectCollisionBetween const geBox Box1,
const geBox Box2
 

Definition at line 113 of file Box.c.

References GE_FALSE, GE_TRUE, geBoolean, geFloat, geVec3d_Subtract(), geXForm3d_IsOrthonormal(), geXForm3d_Rotate(), geBox::GlobalFrameAxes, NULL, geBox::Transform, geBox::TransformInv, geXForm3d::Translation, geVec3d::X, geBox::xScale, geVec3d::Y, geBox::yScale, Z, geVec3d::Z, and geBox::zScale.

00114 {
00115         int i, c;
00116         geFloat radius;
00117         const geBox* BoxA;
00118         const geBox* BoxB;
00119         static geVec3d centerToCenterVector, xformedCenterToCenterVector;
00120         static geVec3d inverseXFormedGlobalFrameAxes[3];
00121         geBoolean isOrthonormal;
00122 
00123         assert(Box1 != NULL);
00124         assert(Box2 != NULL);
00125 
00126         // assert orthonormality
00127 
00128         isOrthonormal = geXForm3d_IsOrthonormal(&(Box1->Transform));
00129         assert(isOrthonormal);
00130 
00131         isOrthonormal = geXForm3d_IsOrthonormal(&(Box2->Transform));
00132         assert(isOrthonormal);
00133 
00134         // test B against A and if necessary A against B
00135 
00136         for (c = 0; c < 2; c ++)
00137         {
00138                 if (c == 0)
00139                 {
00140                         BoxA = Box1;
00141                         BoxB = Box2;
00142                 }
00143 
00144                 else
00145                 {
00146                         BoxA = Box2;
00147                         BoxB = Box1;
00148                 }
00149 
00150                 // rotate B's global frame axes by the amount A was rotated to bring it
00151                 // back into its local coord system
00152 
00153                 for (i = 0; i < 3; i++)
00154                 {
00155                         geXForm3d_Rotate(&(BoxA->TransformInv), &(BoxB->GlobalFrameAxes[i]),
00156                                 &inverseXFormedGlobalFrameAxes[i]);
00157                 }
00158 
00159                 // get B's translation offset from A in global coord system
00160 
00161                 geVec3d_Subtract(&(BoxB->Transform.Translation), &(BoxA->Transform.Translation),
00162                         &centerToCenterVector);
00163 
00164                 // rotate offset by the amount A was rotated to bring it
00165                 // back into its local coord system
00166                 
00167                 geXForm3d_Rotate(&(BoxA->TransformInv), &centerToCenterVector,
00168                         &xformedCenterToCenterVector);
00169 
00170                 xformedCenterToCenterVector.X = (geFloat)fabs(xformedCenterToCenterVector.X);
00171                 xformedCenterToCenterVector.Y = (geFloat)fabs(xformedCenterToCenterVector.Y);
00172                 xformedCenterToCenterVector.Z = (geFloat)fabs(xformedCenterToCenterVector.Z);
00173 
00174                 // test every radius of BoxB
00175                 // for every global frame-axis-aligned axis of BoxA
00176                 // to see if overlap occurred
00177 
00178                 // test overlap in X axis
00179 
00180                 radius = (geFloat)(fabs(inverseXFormedGlobalFrameAxes[0].X) +
00181                         fabs(inverseXFormedGlobalFrameAxes[1].X) +
00182                         fabs(inverseXFormedGlobalFrameAxes[2].X));
00183 
00184                 if ((radius + BoxA->xScale) < xformedCenterToCenterVector.X)
00185                         return GE_FALSE;
00186 
00187                 // test overlap in Y axis
00188 
00189                 radius = (geFloat)(fabs(inverseXFormedGlobalFrameAxes[0].Y) +
00190                         fabs(inverseXFormedGlobalFrameAxes[1].Y) +
00191                         fabs(inverseXFormedGlobalFrameAxes[2].Y));
00192 
00193                 if ((radius + BoxA->yScale) < xformedCenterToCenterVector.Y)
00194                         return GE_FALSE;
00195 
00196                 // test overlap in Z axis
00197 
00198                 radius = (geFloat)(fabs(inverseXFormedGlobalFrameAxes[0].Z) +
00199                         fabs(inverseXFormedGlobalFrameAxes[1].Z) +
00200                         fabs(inverseXFormedGlobalFrameAxes[2].Z));
00201 
00202                 if ((radius + BoxA->zScale) < xformedCenterToCenterVector.Z)
00203                         return GE_FALSE;
00204 
00205         } // c
00206 
00207         return GE_TRUE; // all tests checked out, overlap occurred
00208 }

void geBox_Set geBox Box,
geFloat  xScale,
geFloat  yScale,
geFloat  zScale,
const geXForm3d Transform
 

Definition at line 67 of file Box.c.

References geBoolean, geBox_SetXForm(), geXForm3d_IsOrthonormal(), NULL, geBox::Transform, geBox::xScale, geBox::yScale, and geBox::zScale.

00068 {
00069         geBoolean isOrthonormal;
00070 
00071         assert(Box != NULL);
00072         assert(Transform != NULL);
00073 
00074         isOrthonormal = geXForm3d_IsOrthonormal(&(Box->Transform));
00075         assert(isOrthonormal);
00076 
00077         Box->xScale = xScale;
00078         Box->yScale = yScale;
00079         Box->zScale = zScale;
00080 
00081         geBox_SetXForm(Box, Transform); 
00082 }

void geBox_SetXForm geBox Box,
const geXForm3d Transform
 

Definition at line 86 of file Box.c.

References geBoolean, geBox_ComputeGlobalFrameAxes(), geXForm3d_Copy(), geXForm3d_GetTranspose(), geXForm3d_IsOrthonormal(), NULL, geBox::Transform, and geBox::TransformInv.

Referenced by geBox_Set().

00087 {
00088         geBoolean isOrthonormal;
00089 
00090         assert(Box != NULL);
00091         assert(Transform != NULL);
00092 
00093         isOrthonormal = geXForm3d_IsOrthonormal(Transform);
00094         assert(isOrthonormal);
00095 
00096         geXForm3d_Copy(Transform, &(Box->Transform));
00097 
00098         isOrthonormal = geXForm3d_IsOrthonormal(&(Box->Transform));
00099         assert(isOrthonormal);
00100 
00101         geXForm3d_GetTranspose(Transform, &(Box->TransformInv));
00102 
00103         isOrthonormal = geXForm3d_IsOrthonormal(&(Box->TransformInv));
00104         assert(isOrthonormal);
00105 
00106         geBox_ComputeGlobalFrameAxes(Box);
00107 }


Generated on Tue Sep 30 12:37:10 2003 for GTestAndEngine by doxygen 1.3.2