SHARE
TWEET

GLSL tutorial 1 - vector3d.cpp

thecplusplusguy Jul 26th, 2012 2,635 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //http://www.youtube.com/user/thecplusplusguy
  2. #include "vector3d.h"
  3.  
  4.  
  5. vector3d::vector3d()
  6. {
  7.         x=y=z=0;
  8. }
  9. vector3d::vector3d(float a,float b)
  10. {
  11.         x=a;
  12.         y=b;
  13.         z=0;
  14. }
  15.  
  16. vector3d::vector3d(float a,float b,float c)
  17. {
  18.         x=a;
  19.         y=b;
  20.         z=c;
  21. }
  22.                
  23. float vector3d::dotProduct(const vector3d& vec2)
  24. {
  25.         return (x*vec2.x+y*vec2.y+z*vec2.z);
  26. }
  27.  
  28. vector3d vector3d::crossProduct(const vector3d& vec2)
  29. {
  30.         return vector3d();
  31. }
  32.  
  33. float vector3d::length()
  34. {
  35.         return sqrt(x*x+y*y+z*z);
  36. }
  37.  
  38. void vector3d::normalize()
  39. {
  40.         float len=length();
  41.         if(len!=0)
  42.         {
  43.                 x/=len;
  44.                 y/=len;
  45.                 z/=len;
  46.         }
  47. }
  48.                
  49. void vector3d::change(float a,float b,float c)
  50. {
  51.         x=a;
  52.         y=b;
  53.         z=c;
  54. }
  55.  
  56. void vector3d::change(vector3d vec2)
  57. {
  58.         x=vec2.x;
  59.         y=vec2.y;
  60.         z=vec2.z;
  61. }
  62.  
  63. void vector3d::changeX(float a)
  64. {
  65.         x=a;
  66. }
  67. void vector3d::changeY(float a)
  68. {
  69.         y=a;
  70. }
  71. void vector3d::changeZ(float a)
  72. {
  73.         z=a;
  74. }
  75.                
  76. vector3d vector3d::operator+(const vector3d& vec2)
  77. {
  78.         return vector3d(x+vec2.x,y+vec2.y,z+vec2.z);
  79. }
  80.  
  81. vector3d vector3d::operator-(const vector3d& vec2)
  82. {
  83.         return vector3d(x-vec2.x,y-vec2.y,z-vec2.z);
  84. }
  85.  
  86. vector3d vector3d::operator*(float num)
  87. {
  88.         return vector3d(x*num,y*num,z*num);
  89. }
  90.  
  91. vector3d vector3d::operator/(float num)
  92. {
  93.         if(num!=0)
  94.                 return vector3d(x/num,y/num,z/num);
  95.         else
  96.                 return vector3d();
  97. }
  98.  
  99. vector3d& vector3d::operator+=(const vector3d& vec2)
  100. {
  101.         x+=vec2.x;
  102.         y+=vec2.y;
  103.         z+=vec2.z;
  104.         return *this;
  105. }
  106.  
  107. vector3d& vector3d::operator-=(const vector3d& vec2)
  108. {
  109.         x-=vec2.x;
  110.         y-=vec2.y;
  111.         z-=vec2.z;
  112.         return *this;
  113. }
  114.  
  115. vector3d& vector3d::operator*=(float num)
  116. {
  117.         x*=num;
  118.         y*=num;
  119.         z*=num;
  120.         return *this;
  121. }
  122.  
  123. vector3d& vector3d::operator/=(float num)      
  124. {
  125.         if(num!=0)
  126.         {
  127.                 x/=num;
  128.                 y/=num;
  129.                 z/=num;
  130.         }
  131.         return *this;
  132. }
  133.  
  134. bool vector3d::operator==(const vector3d vec2)
  135. {
  136.         return (x==vec2.x && y==vec2.y && z==vec2.z);
  137. }
  138.  
  139. bool vector3d::operator!=(const vector3d vec2)
  140. {
  141.         !(*this==vec2);
  142. }
  143.                
  144. std::ostream& operator<<(std::ostream& out,const vector3d& vec)
  145. {
  146.         out << vec.x << " " << vec.y << " " << vec.z << std::endl;
  147.         return out;
  148. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top