PolyVector3.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * PolyVector3.h
  3. * TAU
  4. *
  5. * Created by Ivan Safrin on 3/14/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. // @package Math
  10. #pragma once
  11. #include "PolyGlobals.h"
  12. #include <math.h>
  13. //#ifdef _WINDOWS
  14. #include <assert.h>
  15. //#endif
  16. namespace Polycode {
  17. class _PolyExport Vector3 {
  18. public:
  19. Vector3();
  20. Vector3(float x,float y,float z);
  21. ~Vector3();
  22. void set(float x, float y, float z);
  23. inline Vector3 operator - ( const Vector3& v2 ) const {
  24. return Vector3(x - v2.x, y - v2.y, z - v2.z);
  25. }
  26. inline float distance(const Vector3& rhs) const {
  27. return (*this - rhs).length();
  28. }
  29. inline Vector3& operator * (const float val) {
  30. x *= val;
  31. y *= val;
  32. z *= val;
  33. return *this;
  34. }
  35. inline Vector3& operator / (const float val) {
  36. assert( val != 0.0 );
  37. x /= val;
  38. y /= val;
  39. z /= val;
  40. return *this;
  41. }
  42. inline Vector3& operator = ( const Vector3& v2) {
  43. x = v2.x;
  44. y = v2.y;
  45. z = v2.z;
  46. return *this;
  47. }
  48. inline Vector3& operator += ( const Vector3& v2) {
  49. x += v2.x;
  50. y += v2.y;
  51. z += v2.z;
  52. return *this;
  53. }
  54. inline Vector3& operator -= ( const Vector3& v2) {
  55. x -= v2.x;
  56. y -= v2.y;
  57. z -= v2.z;
  58. return *this;
  59. }
  60. inline Vector3 operator + ( const Vector3& v2 ) const {
  61. return Vector3(x + v2.x, y + v2.y, z + v2.z);
  62. }
  63. inline float length () const {
  64. return sqrtf( x * x + y * y + z * z );
  65. }
  66. inline float dot(Vector3 &u) {
  67. return x * u.x + y * u.y + z * u.z;
  68. }
  69. inline Vector3 crossProduct( const Vector3& rkVector ) const {
  70. return Vector3(
  71. y * rkVector.z - z * rkVector.y,
  72. z * rkVector.x - x * rkVector.z,
  73. x * rkVector.y - y * rkVector.x);
  74. }
  75. void Normalize();
  76. float x;
  77. float y;
  78. float z;
  79. private:
  80. };
  81. }