summaryrefslogtreecommitdiff
path: root/hw5/include/camera.h
blob: 9e3be04e2f9d28038c1a19e6b31be18ca518cdbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/******************************************************************/
/* 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_ */