home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry1.iso / carterrain / src / trig.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-17  |  1.3 KB  |  84 lines

  1. #include "trig.h"
  2. #include <math.h>
  3.  
  4. CVector::CVector(void)
  5. {
  6.     x=0;
  7.     y=0;
  8.     z=0;
  9. }
  10.  
  11. CVector::CVector(double x0, double y0, double z0)
  12. {
  13.     x=x0;
  14.     y=y0;
  15.     z=z0;
  16. }
  17.  
  18. CVector::~CVector(void)
  19. {
  20. }
  21.  
  22. CVector CVector::operator+(const CVector & b) const
  23. {
  24.     CVector sum(x+b.x, y+b.y, z+b.z);
  25.     return sum;
  26. }
  27.  
  28. CVector CVector::operator-(const CVector & b) const
  29. {
  30.     CVector diff(x-b.x, y-b.y, z-b.z);
  31.     return diff;
  32. }
  33.  
  34. CVector CVector::operator-() const
  35. {
  36.     CVector neg(-x, -y, -z);
  37.     return neg;
  38. }
  39.  
  40. CVector CVector::operator*(double n) const
  41. {
  42.     CVector mult(x*n, y*n, z*n);
  43.     return mult;
  44. }
  45.  
  46. CVector operator*(double n, const CVector & a)
  47. {
  48.     return a*n;
  49. }
  50.  
  51. CVector CVector::operator/(double n) const
  52. {
  53.     CVector div(x/n, y/n, z/n);
  54.     return div;
  55. }
  56.  
  57. double CVector::length(void) const
  58. {
  59.     return sqrt(x*x + y*y + z*z);
  60. }
  61.  
  62. double CVector::operator*(const CVector & b) const
  63. {
  64.     return (x*b.x + y*b.y + z*b.z);
  65. }
  66.  
  67. double CVector::operator^(const CVector & b) const
  68. {
  69.     CVector a(x, y, z);
  70.     return acos((a*b)/(a.length()*b.length()))*180/PI;
  71. }
  72.  
  73. CVector CVector::operator%(const CVector & b) const
  74. {
  75.     CVector cross(y*b.z - z*b.y, z*b.x - x*b.z, x*b.y - y*b.x);
  76.     return cross;
  77. }
  78.  
  79. CVector CVector::unit(void) const
  80. {
  81.     CVector a(x/length(), y/length(), z/length());
  82.     return a;
  83. }
  84.