Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.6 KiB

  1. /*******************************************************************************
  2. * DXVector.h *
  3. *------------*
  4. * Description:
  5. * This is the header file for the vector helper classes.
  6. *
  7. ;begin_internal
  8. *-------------------------------------------------------------------------------
  9. * Created By: Mike Arnstein Date: 04/11/97
  10. * Copyright (C) 1997 Microsoft Corporation
  11. * All Rights Reserved
  12. *
  13. *-------------------------------------------------------------------------------
  14. * Revisions:
  15. *
  16. ;end_internal
  17. *******************************************************************************/
  18. #ifndef DXVector_h
  19. #define DXVector_h
  20. //=== Constants ====================================================
  21. //=== Class, Struct and Union Definitions ==========================
  22. /*** CDXVec ************
  23. * This template implements basic vector operations for each of the
  24. * union types
  25. */
  26. #define CDXV_C CDXVec<TYPE, eBndType>
  27. #define CDXV_T ((TYPE*)u.D)
  28. #define CDXV_O( OtherVec ) ((TYPE*)OtherVec.u.D)
  29. template<class TYPE, DXBNDTYPE eBndType>
  30. class CDXVec : public DXVEC
  31. {
  32. /*=== Methods =======*/
  33. public:
  34. /*--- Constructors ---*/
  35. CDXVec() { eType = eBndType; ZeroVector(); }
  36. CDXVec(BOOL bInit) { eType = eBndType; if (bInit) ZeroVector(); }
  37. CDXVec( TYPE x, TYPE y, TYPE z, TYPE t )
  38. { eType = eBndType; CDXV_T[DXB_X] = x; CDXV_T[DXB_Y] = y;
  39. CDXV_T[DXB_Z] = z; CDXV_T[DXB_T] = t; }
  40. CDXVec( const CDXVec& Other ) { memcpy( this, (void *)&Other, sizeof(DXVEC) ); }
  41. CDXVec( const DXVEC Other ) { memcpy( this, &Other, sizeof(DXVEC) ); }
  42. operator TYPE *() { return CDXV_T; }
  43. operator const TYPE *() { return CDXV_T; }
  44. /*--- operations ---*/
  45. void ZeroVector( void ) { memset( u.D, 0, sizeof(TYPE) * 4); }
  46. /*--- operators ---*/
  47. TYPE& operator[]( int index ) const { return CDXV_T[index]; }
  48. TYPE& operator[]( long index ) const { return CDXV_T[index]; }
  49. TYPE& operator[]( USHORT index ) const { return CDXV_T[index]; }
  50. TYPE& operator[]( DWORD index ) const { return CDXV_T[index]; }
  51. CDXV_C operator+(const CDXV_C& v);
  52. CDXV_C operator-(const CDXV_C& v);
  53. void operator=(const CDXV_C& srcVector);
  54. void operator+=(const CDXV_C& vOther);
  55. void operator-=(const CDXV_C& vOther);
  56. BOOL operator==(const CDXV_C& otherVector) const;
  57. BOOL operator!=(const CDXV_C& otherVector) const;
  58. };
  59. template<class TYPE, DXBNDTYPE eBndType>
  60. CDXV_C CDXV_C::operator+( const CDXV_C& srcVector )
  61. {
  62. CDXV_C Result( this );
  63. CDXV_O( Result )[DXB_X] += CDXV_O( srcVector )[DXB_X];
  64. CDXV_O( Result )[DXB_Y] += CDXV_O( srcVector )[DXB_Y];
  65. CDXV_O( Result )[DXB_Z] += CDXV_O( srcVector )[DXB_Z];
  66. CDXV_O( Result )[DXB_T] += CDXV_O( srcVector )[DXB_T];
  67. return Result;
  68. } /* CDXVec::operator+ */
  69. template<class TYPE, DXBNDTYPE eBndType>
  70. CDXV_C CDXV_C::operator-( const CDXV_C& srcVector )
  71. {
  72. CDXV_C Result( this );
  73. CDXV_O( Result )[DXB_X] -= CDXV_O( srcVector )[DXB_X];
  74. CDXV_O( Result )[DXB_Y] -= CDXV_O( srcVector )[DXB_Y];
  75. CDXV_O( Result )[DXB_Z] -= CDXV_O( srcVector )[DXB_Z];
  76. CDXV_O( Result )[DXB_T] -= CDXV_O( srcVector )[DXB_T];
  77. return Result;
  78. } /* CDXVec::operator- */
  79. template<class TYPE, DXBNDTYPE eBndType>
  80. void CDXV_C::operator=( const CDXV_C& srcVector )
  81. {
  82. memcpy( this, &srcVector, sizeof(CDXVec) );
  83. } /* CDXVec::operator= */
  84. template<class TYPE, DXBNDTYPE eBndType>
  85. BOOL CDXV_C::operator==(const CDXV_C& otherVector) const
  86. {
  87. return !memcmp( this, &otherVector, sizeof(otherVector) );
  88. } /* CDXVec::operator== */
  89. template<class TYPE, DXBNDTYPE eBndType>
  90. BOOL CDXV_C::operator!=(const CDXV_C& otherVector) const
  91. {
  92. return memcmp( this, &otherVector, sizeof(otherVector) );
  93. } /* CDXVec::operator!= */
  94. template<class TYPE, DXBNDTYPE eBndType>
  95. void CDXV_C::operator+=(const CDXV_C& vOther)
  96. {
  97. CDXV_T[DXB_X] += CDXV_O( vOther )[DXB_X];
  98. CDXV_T[DXB_Y] += CDXV_O( vOther )[DXB_Y];
  99. CDXV_T[DXB_Z] += CDXV_O( vOther )[DXB_Z];
  100. CDXV_T[DXB_T] += CDXV_O( vOther )[DXB_T];
  101. } /* CDXVec::operator+= */
  102. template<class TYPE, DXBNDTYPE eBndType>
  103. void CDXV_C::operator-=(const CDXVec& vOther)
  104. {
  105. CDXV_T[DXB_X] -= CDXV_O( vOther )[DXB_X];
  106. CDXV_T[DXB_Y] -= CDXV_O( vOther )[DXB_Y];
  107. CDXV_T[DXB_Z] -= CDXV_O( vOther )[DXB_Z];
  108. CDXV_T[DXB_T] -= CDXV_O( vOther )[DXB_T];
  109. } /* CDXVec::operator-= */
  110. typedef CDXVec<long, DXBT_DISCRETE> CDXDVec;
  111. typedef CDXVec<LONGLONG, DXBT_DISCRETE64> CDXDVec64;
  112. typedef CDXVec<float, DXBT_CONTINUOUS> CDXCVec;
  113. typedef CDXVec<double, DXBT_CONTINUOUS64> CDXCVec64;
  114. #endif // DXVector_h