SHARE
TWEET

Untitled

a guest May 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef _SPHERE_H_
  2. #define _SPHERE_H_
  3. # define M_PI          3.141592653589793238462643383279502884L /* pi */
  4. #include <math.h>
  5.  
  6. #include "Vec3.h"
  7. #include "Ray.h"
  8.  
  9. enum objectType { Reflective, Reflective_and_Refractive };
  10.  
  11. class Sphere {
  12. public:
  13.     Vec3f c;
  14.     float r;
  15.     Vec3f materialDiffuse;
  16.     Vec3f materialSpecular;
  17.     Vec3f materialAmbient;
  18.     float reflectiveIndex;
  19.     float refractiveIndex;
  20.     objectType type;
  21. public:
  22.     Sphere(const Vec3f & cen, float rad) : c(cen), r(rad) { }
  23.  
  24.     bool hit(const Ray & r, HitRec & rec) const;
  25.     void computeSurfaceHitFields(const Ray & r, HitRec & rec) const;
  26.     void setType(objectType t) { type = t; }
  27.  
  28. };
  29.  
  30. class Light {
  31.     Vec3f position;
  32.     Vec3f intensity;
  33. public:
  34.     Light(const Vec3f & pos, const Vec3f & intensity) : position(pos), intensity(intensity) { }
  35.     Vec3f getPosition() { return position; };
  36.     Vec3f getIntensity() { return intensity; };
  37. };
  38.  
  39. class Camera {
  40. public:
  41.     Vec3f eyePoint;
  42.     Vec3f lookAtPoint;
  43.     const unsigned int xRes, yRes;
  44.  
  45.  
  46. public:
  47.     Camera(const Vec3f & pos, const Vec3f & lookAt, unsigned int x, unsigned int y) : eyePoint(pos), lookAtPoint(lookAt), xRes(x), yRes(y) {
  48.     }
  49.  
  50.    
  51.  
  52.     Vec3f getCameraView(int x, int y) {
  53.         float width = xRes;
  54.         float height = yRes;
  55.         Vec3f toVec = lookAtPoint - eyePoint;
  56.         //toLoc.flip();
  57.         toVec.normalize();
  58.  
  59.         Vec3f cameraUp = { 0.0,1.0,0.0 };
  60.         Vec3f cameraRight = toVec.cross(cameraUp);
  61.         double i = (x / width) - 0.5;
  62.         double j = (y / height) - 0.5;
  63.         Vec3f pointInSpace =
  64.             cameraRight.normalize()*i +//RIGHT
  65.             cameraUp.normalize()*j +//UP
  66.             eyePoint + toVec;
  67.  
  68.         return (pointInSpace - eyePoint).normalize();
  69.     }
  70. };
  71.  
  72. #endif
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