Guest User

Vector.cpp

a guest
Nov 29th, 2013
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Vector.h"
  2.  
  3. __device__ Vector::Vector()
  4. {
  5. }
  6.  
  7. __device__ Vector::Vector(double _x, double _y, double _z)
  8. {
  9.     x = _x;
  10.     y = _y;
  11.     z = _z;
  12. }
  13.  
  14. __device__ void Vector::makeZero()
  15. {
  16.     x = y = z = 0.0;
  17. }
  18.  
  19.  __device__ double Vector::length() const
  20. {
  21.     return sqrt(x * x + y * y + z * z);
  22. }
  23.  
  24. __device__ double Vector::lengthSqr() const
  25. {
  26.     return (x * x + y * y + z * z);
  27. }
  28.  
  29. __device__ void Vector::scale(double multiplier)
  30. {
  31.     x *= multiplier;
  32.     y *= multiplier;
  33.     z *= multiplier;
  34. }
  35.  
  36. __device__ void Vector::operator *= (double multiplier)
  37. {
  38.     scale(multiplier);
  39. }
  40.  
  41. __device__ void Vector::operator += (const Vector& rhs)
  42. {
  43.     x += rhs.x;
  44.     y += rhs.y;
  45.     z += rhs.z;
  46. }
  47.  
  48. __device__ void Vector::operator /= (double divider)
  49. {
  50.     scale(1.0 / divider);
  51. }
  52.  
  53. __device__ void Vector::normalize()
  54. {
  55.         double multiplier = 1.0 / length();
  56.         scale(multiplier);
  57. }
  58.  
  59. __device__ void Vector::setLength(double newLength)
  60. {
  61.     scale(newLength / length());
  62. }
  63.  
  64. __device__ double& Vector::operator[] (int index)
  65. {
  66.     return components[index];
  67. }
  68.  
  69. __device__ const double& Vector::operator[] (int index) const
  70. {
  71.     return components[index];
  72. }
  73.  
  74. __device__ Ray::Ray()
  75. {
  76.     debug = false;
  77. }
  78.  
  79. __device__ Ray::Ray(const Vector& _start, const Vector& _dir)
  80. {
  81.     start = _start;
  82.     dir = _dir;
  83.     debug = false;
  84. }
RAW Paste Data