VECTOR.h
资源名称:g.rar [点击查看]
上传用户:laitongbao
上传日期:2021-02-20
资源大小:8176k
文件大小:2k
源码类别:

射击游戏

开发平台:

Visual C++

  1. // VECTOR.h: interface for the VECTOR class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_VECTOR_H__2F4A6770_82E4_417E_BA2C_E19DBFD2993F__INCLUDED_)
  5. #define AFX_VECTOR_H__2F4A6770_82E4_417E_BA2C_E19DBFD2993F__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. struct VECTOR
  10. {
  11. float x,y,z;
  12. };
  13. class VECTOR3:public VECTOR  
  14. {
  15. public:
  16. VECTOR3()
  17. {
  18. x = 0;
  19. y = 0;
  20. z = 0;
  21. }
  22. VECTOR3(D3DXVECTOR3 source)
  23. {
  24. x = source.x;
  25. y = source.y;
  26. z = source.z;
  27. }
  28. VECTOR3(VECTOR3& source)
  29. {
  30. x = source.x;
  31. y = source.y;
  32. z = source.z;
  33. }
  34. VECTOR3(float x,float y,float z)
  35. {
  36. this->x = x;
  37. this->y = y;
  38. this->z = z;
  39. }
  40. VECTOR3(int x,int y,int z)
  41. {
  42. this->x = (float)x;
  43. this->y = (float)y;
  44. this->z = (float)z;
  45. }
  46. VECTOR3 operator+(VECTOR operand)
  47. {
  48. return VECTOR3(x + operand.x,y + operand.y,z + operand.z);
  49. }
  50. VECTOR3 operator-(VECTOR operand)
  51. {
  52. return VECTOR3(x - operand.x,y - operand.y,z - operand.z);
  53. }
  54. void operator+=(VECTOR operand)
  55. {
  56. x += operand.x;
  57. y += operand.y;
  58. z += operand.z;
  59. }
  60. void operator-=(VECTOR operand)
  61. {
  62. x -= operand.x;
  63. y -= operand.y;
  64. z -= operand.z;
  65. }
  66. VECTOR3 operator*(float operand)
  67. {
  68. return VECTOR3(x * operand,y * operand,z * operand);
  69. }
  70. VECTOR3 operator/(float operand)
  71. {
  72. if(operand != 0)
  73. return VECTOR3(x / operand,y / operand,z / operand);
  74. else
  75. return VECTOR3();
  76. }
  77. void operator*=(float operand)
  78. {
  79. x *= operand;
  80. y *= operand;
  81. z *= operand;
  82. }
  83. void operator/=(float operand)
  84. {
  85. if(operand !=0)
  86. {
  87. x /= operand;
  88. y /= operand;
  89. z /= operand;
  90. }
  91. }
  92. bool operator>(VECTOR operand)
  93. {
  94. return x>operand.x&&y>operand.y&&z>operand.z;
  95. }
  96. bool operator>=(VECTOR operand)
  97. {
  98. return x>=operand.x&&y>=operand.y&&z>=operand.z;
  99. }
  100. bool operator<(VECTOR operand)
  101. {
  102. return x<operand.x&&y<operand.y&&z<operand.z;
  103. }
  104. bool operator<=(VECTOR operand)
  105. {
  106. return x<=operand.x&&y<=operand.y&&z<=operand.z;
  107. }
  108. bool operator==(VECTOR operand)
  109. {
  110. return x==operand.x&&y==operand.y&&z==operand.z;
  111. }
  112. float Length()
  113. {
  114. return sqrtf(x*x + y*y + z*z);
  115. }
  116. VECTOR3 Normalize()
  117. { float len;
  118. if((len = sqrtf(x*x+y*y+z*z)) != 0)
  119. return (*this)/len;
  120. else return VECTOR3();
  121. }
  122. D3DXVECTOR3 toD3dVector3()
  123. {
  124. return D3DXVECTOR3(x,y,z);
  125. }
  126. };
  127. #endif // !defined(AFX_VECTOR_H__2F4A6770_82E4_417E_BA2C_E19DBFD2993F__INCLUDED_)