Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _SPHERE_H_
- #define _SPHERE_H_
- # define M_PI 3.141592653589793238462643383279502884L /* pi */
- #include <math.h>
- #include "Vec3.h"
- #include "Ray.h"
- enum objectType { Reflective, Reflective_and_Refractive };
- class Sphere {
- public:
- Vec3f c;
- float r;
- Vec3f materialDiffuse;
- Vec3f materialSpecular;
- Vec3f materialAmbient;
- float reflectiveIndex;
- float refractiveIndex;
- objectType type;
- public:
- Sphere(const Vec3f & cen, float rad) : c(cen), r(rad) { }
- bool hit(const Ray & r, HitRec & rec) const;
- void computeSurfaceHitFields(const Ray & r, HitRec & rec) const;
- void setType(objectType t) { type = t; }
- };
- class Light {
- Vec3f position;
- Vec3f intensity;
- public:
- Light(const Vec3f & pos, const Vec3f & intensity) : position(pos), intensity(intensity) { }
- Vec3f getPosition() { return position; };
- Vec3f getIntensity() { return intensity; };
- };
- class Camera {
- public:
- Vec3f eyePoint;
- Vec3f lookAtPoint;
- const unsigned int xRes, yRes;
- public:
- Camera(const Vec3f & pos, const Vec3f & lookAt, unsigned int x, unsigned int y) : eyePoint(pos), lookAtPoint(lookAt), xRes(x), yRes(y) {
- }
- Vec3f getCameraView(int x, int y) {
- float width = xRes;
- float height = yRes;
- Vec3f toVec = lookAtPoint - eyePoint;
- //toLoc.flip();
- toVec.normalize();
- Vec3f cameraUp = { 0.0,1.0,0.0 };
- Vec3f cameraRight = toVec.cross(cameraUp);
- double i = (x / width) - 0.5;
- double j = (y / height) - 0.5;
- Vec3f pointInSpace =
- cameraRight.normalize()*i +//RIGHT
- cameraUp.normalize()*j +//UP
- eyePoint + toVec;
- return (pointInSpace - eyePoint).normalize();
- }
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement