summaryrefslogtreecommitdiff
path: root/hw2/include/ray.h
blob: 743375f7cf818eea21896ce420bda7e6c84be9e8 (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
/******************************************************************/
/* 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 _RAY_H_
#define _RAY_H_

#include <ostream>
#include "vec3d.h"
#include "transformation3d.h"

class ray {
 public:
  //////////////////
  // Constructors //
  //////////////////
  ray(const vec3d& origin = vec3d(), const vec3d& direction = vec3d());
  ray(const ray& src);

  ////////////////
  // Inspectors //
  ////////////////
  const vec3d& origin(void) const    { return _origin; }
  const vec3d& direction(void) const { return _direction; }

  ///////////////
  // Operators //
  ///////////////
  ray& operator=(const ray& r);
  vec3d operator()(float t) const;
  float operator()(const vec3d& point) const;

  //////////////
  // Mutators //
  //////////////
  ray& transform(const transformation3d& t);
  ray& inverseTransform(const transformation3d& t);

  /////////////
  // Friends //
  /////////////
  friend void swap(ray& a, ray& b)  { a._swap(b); }
  friend ray transform(const ray& r, const transformation3d& t) { return ray(r).transform(t); }
  friend ray inverseTransform(const ray& r, const transformation3d& t) { return ray(r).inverseTransform(t); }
  friend std::ostream& operator<<(std::ostream& s, const ray& r)
  {
    s << r.origin() << "->" << r.direction();
    return s;
  }

 private:
  /////////////////////
  // Private Methods //
  /////////////////////
  void _swap(ray& r);
  void _assign(const ray& r);

  //////////////////
  // Data Members //
  //////////////////
  vec3d _origin;
  vec3d _direction;
};

#endif /* _RAY_H_ */