summaryrefslogblamecommitdiff
path: root/hw2/include/camera.h
blob: 9e3be04e2f9d28038c1a19e6b31be18ca518cdbd (plain) (tree)















































































                                                                                                             
/******************************************************************/
/* This file is part of the homework assignments for CSCI-427/527 */
/* at The College of William & Mary and authored by Pieter Peers. */
/* No part of this file, whether altered or in original form, can */
/* be distributed or used outside the context of CSCI-427/527     */
/* without consent of either the College of William & Mary or     */
/* Pieter Peers.                                                  */
/******************************************************************/
#ifndef _CAMERA_H_
#define _CAMERA_H_

#include <ostream>

#include "ray.h"
#include "vec2d.h"
#include "boundingBox.h"

/**************************************************************/
/* Note: Field of View (fov) is expressed in degrees, and     */
/* represents the angular spread in the horizontal direction. */
/**************************************************************/
class camera {
 public:
  /////////////////
  // Constructor //
  /////////////////
  camera(void);
  camera(const vec3d& eye, const vec3d& viewDirection, const vec3d& up, float fov, size_t xres, size_t yres);
  camera(const camera& cam);

  ///////////////
  // Operators //
  ///////////////
  camera& operator=(const camera& cam);

  ray operator()(float x, float y) const;

  ////////////////
  // Inspectors //
  ////////////////
  size_t width(void) const { return _width; }
  size_t height(void) const { return _height; }

  //////////////
  // Mutators //
  //////////////
  void frameBoundingBox(const boundingBox& bb);

  /////////////
  // Friends //
  /////////////
  friend void swap(camera& a, camera& b) { a._swap(b); }
  friend std::ostream& operator<<(std::ostream& s, const camera& cam)
  {
    s << "Camera: {";
    s << "eye=" << cam._eye << ", ";
    s << "view=" << cam._view << ", ";
    s << "up=" << cam._up << "}, ";
    s << "fov=" << cam._fov << ", ";
    s << "resolution=[" << cam._width << "x" << cam._height << "]";
    return s;
  }

 private:
  /////////////////////
  // Private Methods //
  /////////////////////
  void _swap(camera& cam);
  void _assign(const camera& cam);

  //////////////////
  // Data Members //
  //////////////////
  vec3d _eye, _view, _up;
  float _fov;
  size_t _width, _height;
};

#endif /* _CAMERA_H_ */