Advertisement
xerpi

Untitled

Aug 25th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #ifndef _VECTOR3F_H_
  2. #define _VECTOR3F_H_
  3.  
  4.  
  5. class Vector3f
  6. {
  7. public:
  8. Vector3f() {setZero();}
  9. Vector3f(float _x, float _y, float _z) : x(_x), y(_y), z(_z){}
  10.  
  11. Vector3f operator+(Vector3f v) const
  12. {
  13. return Vector3f(x + v.getX(), y + v.getY(), z + v.getZ());
  14. }
  15.  
  16. Vector3f operator-(Vector3f v) const
  17. {
  18. return Vector3f(x - v.getX(), y - v.getY(), z - v.getZ());
  19. }
  20.  
  21. Vector3f operator-() const
  22. {
  23. return Vector3f(-x, -y, -z);
  24. }
  25.  
  26. void operator-=(Vector3f v)
  27. {
  28. x -= v.getX();
  29. y -= v.getY();
  30. z -= v.getZ();
  31. }
  32.  
  33. void operator+=(Vector3f v)
  34. {
  35. x += v.getX();
  36. y += v.getY();
  37. z += v.getZ();
  38. }
  39.  
  40. Vector3f operator*(float n) const
  41. {
  42. return Vector3f(x*n, y*n, z*n);
  43. }
  44.  
  45. Vector3f operator/(float n)
  46. {
  47. return Vector3f(x/n, y/n, z/n);
  48. }
  49.  
  50. float Dot(Vector3f& vec2)
  51. {
  52. return x*vec2.x + y*vec2.y + z*vec2.z;
  53. }
  54.  
  55. Vector3f Cross(const Vector3f& vec2)
  56. {
  57. return Vector3f(y*vec2.z - z*vec2.y,
  58. z*vec2.x - x*vec2.z,
  59. x*vec2.y - y*vec2.x);
  60. }
  61.  
  62. void doCross(Vector3f& vec2)
  63. {
  64. Vector3f tmp = *this;
  65. tmp.x = y*vec2.z - z*vec2.y;
  66. tmp.y = z*vec2.x - x*vec2.z;
  67. tmp.z = x*vec2.y - y*vec2.x;
  68. *this = tmp;
  69. }
  70.  
  71. float getX() {return x;}
  72. float getY() {return y;}
  73. float getZ() {return z;}
  74.  
  75. void setZero()
  76. {
  77. x = 0.0f; y = 0.0f; z = 0.0f;
  78. }
  79. //private:
  80. float x, y, z;
  81. };
  82.  
  83. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement