daily pastebin goal
11%
SHARE
TWEET

Camera

a guest Jan 23rd, 2014 5 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Camera.cuh"
  2.  
  3. __device__
  4. void Camera::beginFrame()
  5. {
  6.         double x = -aspect;
  7.         double y = +1;
  8.        
  9.         Vector corner = Vector(x, y, 1);
  10.         Vector center = Vector(0, 0, 1);
  11.        
  12.         double lenXY = (corner - center).length();
  13.         double wantedLength = tan(toRadians(fov / 2));
  14.        
  15.         double scaling = wantedLength / lenXY;
  16.        
  17.         x *= scaling;
  18.         y *= scaling;
  19.  
  20.         this->upLeft = Vector(x, y, 1);
  21.         this->upRight = Vector(-x, y, 1);
  22.         this->downLeft = Vector(x, -y, 1);
  23.        
  24.         Matrix rotation = rotationAroundZ(toRadians(roll))
  25.                         * rotationAroundX(toRadians(pitch))
  26.                         * rotationAroundY(toRadians(yaw));
  27.         upLeft *= rotation;
  28.         upRight *= rotation;
  29.         downLeft *= rotation;
  30.  
  31.         rightDir = Vector(-1, 0, 0) * rotation;
  32.         upDir    = Vector(0, -1, 0) * rotation;
  33.         frontDir = Vector(0, 0, -1) * rotation;
  34.        
  35.         upLeft += pos;
  36.         upRight += pos;
  37.         downLeft += pos;
  38. }
  39.  
  40. __device__
  41. Ray Camera::getScreenRay(double x, double y)
  42. {
  43.         Ray result; // A, B -     C = A + (B - A) * x
  44.         result.start = this->pos;
  45.         Vector target = upLeft +
  46.                 (upRight - upLeft) * (x / (double) RES_X) +
  47.                 (downLeft - upLeft) * (y / (double) RES_Y);
  48.        
  49.         // A - camera; B = target
  50.         result.dir = target - this->pos;
  51.        
  52.         result.dir.normalize();
  53.        
  54.         return result;
  55. }
  56.  
  57. __device__
  58. void Camera::move(double dx, double dz)
  59. {
  60.         pos += dx * rightDir;
  61.         pos += dz * frontDir;
  62. }
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