00001 //============================================================================= 00002 // filename: RmMath.h 00003 // 00004 // ATI Research, Inc. 00005 // 3D Application Research Group 00006 // 00007 // Description: RenderMonkey's Math Definition 00008 // 00009 //============================================================================= 00010 // (C) 2004 ATI Research, Inc. All rights reserved. 00011 //============================================================================= 00012 00013 #ifndef _RM_CORE_MATH_H_ 00014 #define _RM_CORE_MATH_H_ 00015 00016 #include <Core/RmTypes.h> 00017 #include <Core/RmDefines.h> 00018 #include <Core/RmEffect.h> 00019 00020 class RmMatrix4x4; 00021 00022 //============================================================================= 00023 // We will add more functionality to those math code. 00024 // Right now, I am adding just necssary functions ( DotProduct, CrossProduct, Normalize 00025 // for 3D Vector etc ) 00026 //============================================================================= 00027 00028 //============================================================================= 00034 //============================================================================= 00035 class RM_API RmVector2D 00036 { 00037 public : 00038 //-------------------------------------------------------------------------- 00043 //-------------------------------------------------------------------------- 00044 RmVector2D(); 00045 00046 //-------------------------------------------------------------------------- 00053 //-------------------------------------------------------------------------- 00054 RmVector2D( float x, float y ); 00055 00056 public : 00057 // Make them public for easy access 00058 float x; 00059 float y; 00060 }; // End of RmVector2D 00061 00062 00063 //============================================================================= 00069 //============================================================================= 00070 class RM_API RmVector3D 00071 { 00072 public : 00073 //-------------------------------------------------------------------------- 00078 //-------------------------------------------------------------------------- 00079 RmVector3D(); 00080 00081 //-------------------------------------------------------------------------- 00089 //-------------------------------------------------------------------------- 00090 RmVector3D( float x, float y, float z ); 00091 00092 public : 00093 // Make them public for easy access 00094 float x; 00095 float y; 00096 float z; 00097 00098 // Functions 00099 public : 00100 //-------------------------------------------------------------------------- 00106 //-------------------------------------------------------------------------- 00107 float DotProduct(const RmVector3D &v) const; 00108 00109 //-------------------------------------------------------------------------- 00117 //-------------------------------------------------------------------------- 00118 RmVector3D CrossProduct(const RmVector3D &v) const; 00119 00120 //-------------------------------------------------------------------------- 00126 //-------------------------------------------------------------------------- 00127 float Magnitude() const; 00128 00129 //-------------------------------------------------------------------------- 00139 //-------------------------------------------------------------------------- 00140 float Normalize(); 00141 00142 // Operators 00143 public : 00144 //-------------------------------------------------------------------------- 00151 //-------------------------------------------------------------------------- 00152 void operator = ( const RmVector3D &src ); 00153 00154 //-------------------------------------------------------------------------- 00161 //-------------------------------------------------------------------------- 00162 RmVector3D operator + ( const RmVector3D &src ) const; 00163 00164 //-------------------------------------------------------------------------- 00171 //-------------------------------------------------------------------------- 00172 RmVector3D operator - ( const RmVector3D &src ) const; 00173 00174 //-------------------------------------------------------------------------- 00181 //-------------------------------------------------------------------------- 00182 void operator += ( const RmVector3D &src ); 00183 00184 //-------------------------------------------------------------------------- 00191 //-------------------------------------------------------------------------- 00192 void operator -= ( const RmVector3D &src ); 00193 00194 //-------------------------------------------------------------------------- 00203 //-------------------------------------------------------------------------- 00204 RmVector3D operator * ( const RmMatrix4x4 &mat ) const; 00205 00206 //-------------------------------------------------------------------------- 00216 //-------------------------------------------------------------------------- 00217 void operator *= ( const RmMatrix4x4 &mat ); 00218 00219 //-------------------------------------------------------------------------- 00227 //-------------------------------------------------------------------------- 00228 RmVector3D operator * ( float val ) const; 00229 00230 //-------------------------------------------------------------------------- 00238 //-------------------------------------------------------------------------- 00239 RmVector3D operator / ( float val ) const; 00240 00241 //-------------------------------------------------------------------------- 00250 //-------------------------------------------------------------------------- 00251 void operator *= ( float val ); 00252 00253 //-------------------------------------------------------------------------- 00262 //-------------------------------------------------------------------------- 00263 void operator /= ( float val ); 00264 }; // End of RmVector3D 00265 00266 00267 //============================================================================= 00273 //============================================================================= 00274 class RM_API RmVector4D 00275 { 00276 public : 00277 //-------------------------------------------------------------------------- 00282 //-------------------------------------------------------------------------- 00283 RmVector4D(); 00284 00285 //-------------------------------------------------------------------------- 00294 //-------------------------------------------------------------------------- 00295 RmVector4D( float x, float y, float z, float w ); 00296 00297 //-------------------------------------------------------------------------- 00306 //-------------------------------------------------------------------------- 00307 RmVector4D operator * ( const RmMatrix4x4 &mat ) const; 00308 00309 //-------------------------------------------------------------------------- 00319 //-------------------------------------------------------------------------- 00320 void operator *= ( const RmMatrix4x4 &mat ); 00321 00322 public : 00323 // Make them public for easy access 00324 float x; 00325 float y; 00326 float z; 00327 float w; 00328 }; // End of RmVector4D 00329 00330 00331 //============================================================================= 00335 // BoundBox class 00337 //============================================================================= 00338 class RM_API RmBoundBox 00339 { 00340 public : 00341 //-------------------------------------------------------------------------- 00346 //-------------------------------------------------------------------------- 00347 RmBoundBox(); 00348 00349 //-------------------------------------------------------------------------- 00356 //-------------------------------------------------------------------------- 00357 RmBoundBox( RmVector3D minPoint, RmVector3D maxPoint ); 00358 00359 //-------------------------------------------------------------------------- 00366 //-------------------------------------------------------------------------- 00367 void SetEmpty( bool bEmpty ) { m_isEmpty = bEmpty; }; 00368 00369 //-------------------------------------------------------------------------- 00375 //-------------------------------------------------------------------------- 00376 bool IsEmpty() const { return m_isEmpty; }; 00377 00378 //-------------------------------------------------------------------------- 00384 //-------------------------------------------------------------------------- 00385 RmVector3D& GetMin() { return m_minPoint; }; 00386 00387 //-------------------------------------------------------------------------- 00393 //-------------------------------------------------------------------------- 00394 const RmVector3D& GetMin() const { return m_minPoint; }; 00395 00396 //-------------------------------------------------------------------------- 00402 //-------------------------------------------------------------------------- 00403 RmVector3D& GetMax() { return m_maxPoint; }; 00404 00405 //-------------------------------------------------------------------------- 00411 //-------------------------------------------------------------------------- 00412 const RmVector3D& GetMax() const { return m_maxPoint; }; 00413 00414 //-------------------------------------------------------------------------- 00420 //-------------------------------------------------------------------------- 00421 RmVector3D GetCenter(); 00422 00423 //-------------------------------------------------------------------------- 00429 //-------------------------------------------------------------------------- 00430 RmVector3D GetRange(); 00431 00432 //-------------------------------------------------------------------------- 00440 //-------------------------------------------------------------------------- 00441 void Union( const RmVector3D &point ); 00442 00443 //-------------------------------------------------------------------------- 00451 //-------------------------------------------------------------------------- 00452 void Union( const RmBoundBox &box ); 00453 00454 //-------------------------------------------------------------------------- 00462 //-------------------------------------------------------------------------- 00463 void GetCornerVertices( RmVector3D *pCornerVerts ); 00464 00465 //-------------------------------------------------------------------------- 00472 //-------------------------------------------------------------------------- 00473 RmBoundBox operator * ( const RmMatrix4x4 &mat ); 00474 00475 private : 00476 bool m_isEmpty; 00477 RmVector3D m_minPoint; 00478 RmVector3D m_maxPoint; 00479 }; // End of RmBoundBox 00480 00481 //-------------------------------------------------------------------------- 00488 //-------------------------------------------------------------------------- 00489 RM_API inline bool RmIsNumberPow2( int nNumber ); 00490 00491 //-------------------------------------------------------------------------- 00498 //-------------------------------------------------------------------------- 00499 RM_API inline int RmGetCeilingPow2( int nValue ); 00500 00501 //-------------------------------------------------------------------------- 00508 //-------------------------------------------------------------------------- 00509 RM_API inline float RmGetCeilingPow2( float fValue ); 00510 00511 //-------------------------------------------------------------------------- 00518 //-------------------------------------------------------------------------- 00519 RM_API inline double RmGetCeilingPow2( double dValue ); 00520 00521 00522 00523 #endif
1.3.6