File: camera.h

package info (click to toggle)
epix1 1.0.19-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,432 kB
  • ctags: 1,529
  • sloc: cpp: 8,250; sh: 4,716; lisp: 667; makefile: 229
file content (140 lines) | stat: -rw-r--r-- 4,298 bytes parent folder | download
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* 
 * camera.h -- the ePiX camera class
 *
 * This file is part of ePiX, a preprocessor for creating high-quality 
 * line figures in LaTeX 
 *
 * Version 1.0.15
 * Last Change: October 10, 2006
 */

/* 
 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
 * Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh>
 * Department of Mathematics and Computer Science
 * College of the Holy Cross
 * Worcester, MA, 01610-2395, USA
 */

/*
 * ePiX is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * ePiX is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ePiX; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/*
 * ePiX uses a camera metaphor to view points in R^3. The camera consists
 * of:
 *   - a frame ({sea, sky, eye}, with the intuitive meanings:)
 *   - a point to look at (the "target")
 *   - the distance from the camera to the target
 *   - a projection mapping from R^3 to R^2 (the "lens")
 *
 * While specific behavior is determined by the lens, the idea is that the
 * viewer sits at given <distance> from the <target>, in the direction of
 * the <eye>. The vectors <sea> and <sky> point horizontally to the right
 * and vertically upward on the screen. A <distance> of zero is taken to
 * mean "infinitely far away"; for example, point projection (<shadow>)
 * becomes orthogonal projection along the <eye> axis. Again, a specific
 * lens can override this behavior, for example by ignoring the distance.
 *
 *
 * This file provides:
 *
 *   - the camera class and routines:
 *       void rotate_sea(double); // change camera orientation
 *       void rotate_sky(double); // about respective axes
 *       void rotate_eye(double);
 *
 *       void range(double d); // set distance from camera to origin
 *       void look_at(P arg); // set target (center of field of view)
 *       void lens(pair (*screen_projection(P))); // set projection mapping
 *
 *       pair shoot(P arg); // project a point to the screen ("take a photo")
 */

#ifndef EPIX_CAMERA
#define EPIX_CAMERA

#include "pairs.h"
#include "triples.h"
#include "frame.h"

namespace ePiX {

  // screen projection mappings ("lenses")
  pair shadow(const P& arg);
  pair fisheye(const P& arg);
  pair bubble(const P& arg);

  class epix_camera {
  public:
    // defaults to orthog projection on (x,y) plane from pos z-axis
    epix_camera();

    P get_viewpt() const;
    P get_target() const;
    double get_range() const;

    // get frame vectors
    P sea() const;
    P sky() const;
    P eye() const;

    // adjust position, orientation, and target
    // pitch: rotate camera up/down
    epix_camera& rotate_sea(double angle);

    // yaw: rotate camera left/right
    epix_camera& rotate_sky(double angle);

    // roll: rotate camera about viewing axis
    epix_camera& rotate_eye(double angle);

    // fix target, move viewpt radially along eye()
    epix_camera& range(double d);
    // fix viewpt, move target radially along eye()
    epix_camera& focus(double d);

    // fix target, set viewpt arbitrarily
    epix_camera& at(const P& arg);
    epix_camera& at(const double, const double, const double);

    // fix viewpt, set target arbitrarily
    epix_camera& look_at(const P& arg);
    epix_camera& look_at(const double, const double, const double);

    // set projection mapping
    epix_camera& lens(pair proj(const P&));

    // project a point to the screen ("shoot a photo")
    pair operator() (const P&) const;

  private:
    P viewpt;
    P target;
    frame  orient;
    double distance;
    pair (*screen_projection)(const P&);

  }; // end of class epix_camera 

  extern epix_camera camera;

  // set global camera's location
  void viewpoint(const P&);
  void viewpoint(double a1, double a2, double a3);

} // end of namespace

#endif /* EPIX_CAMERA */