1 | #ifndef __CAMERA_H
|
---|
2 | #define __CAMERA_H
|
---|
3 |
|
---|
4 | #include "Vector3.h"
|
---|
5 | #include "AxisAlignedBox3.h"
|
---|
6 |
|
---|
7 | namespace GtpVisibilityPreprocessor {
|
---|
8 |
|
---|
9 | class KdTree;
|
---|
10 | class SceneGraph;
|
---|
11 | class RayCaster;
|
---|
12 |
|
---|
13 | class Camera
|
---|
14 | {
|
---|
15 | public:
|
---|
16 | Vector3 mPosition;
|
---|
17 | Vector3 mDirection;
|
---|
18 | /** up vector takes into account the FOV at a unit distance from the origin */
|
---|
19 | Vector3 mUp;
|
---|
20 | /** right vector takes into account the FOV at a unit distance from the origin */
|
---|
21 | Vector3 mRight;
|
---|
22 |
|
---|
23 | float mFovy;
|
---|
24 | int mWidth;
|
---|
25 | int mHeight;
|
---|
26 |
|
---|
27 | Camera() {
|
---|
28 | mWidth = 100;
|
---|
29 | mHeight = 100;
|
---|
30 | mFovy = 90.0f*(float)M_PI/180.0f;
|
---|
31 | }
|
---|
32 |
|
---|
33 | Camera(int width, int height) {
|
---|
34 | mWidth = width;
|
---|
35 | mHeight = height;
|
---|
36 | mFovy = 90.0f*(float)M_PI/180.0f;
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | void Precompute() {
|
---|
41 | mDirection.Normalize();
|
---|
42 | Vector3 side = CrossProd(Vector3(0,1,0), mDirection);
|
---|
43 | mUp = Normalize(CrossProd(side, mDirection));
|
---|
44 | mRight = Normalize(CrossProd(mDirection, mUp));
|
---|
45 | float k = tan(mFovy/2);
|
---|
46 | mUp *= k;
|
---|
47 | mRight *= k*mWidth/mHeight;
|
---|
48 | }
|
---|
49 |
|
---|
50 | void SetPosition(const Vector3 &pos) {
|
---|
51 | mPosition = pos;
|
---|
52 | Precompute();
|
---|
53 | }
|
---|
54 |
|
---|
55 | void SetDirection(const Vector3 &dir) {
|
---|
56 | mDirection = dir;
|
---|
57 | Precompute();
|
---|
58 | }
|
---|
59 |
|
---|
60 | void LookInBox(const AxisAlignedBox3 &box)
|
---|
61 | {
|
---|
62 | mDirection = Vector3(0,0,1);
|
---|
63 | mPosition = box.Center();
|
---|
64 | Precompute();
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | void LookAtBox(const AxisAlignedBox3 &box)
|
---|
69 | {
|
---|
70 | mDirection = box.Max() - box.Min();
|
---|
71 | mPosition = box.Min() - mDirection;
|
---|
72 | Precompute();
|
---|
73 | }
|
---|
74 |
|
---|
75 | bool
|
---|
76 | SnapImage(std::string filename,
|
---|
77 | KdTree *tree,
|
---|
78 | SceneGraph *sceneGraph
|
---|
79 | );
|
---|
80 |
|
---|
81 | bool
|
---|
82 | SnapImage(std::string filename,
|
---|
83 | RayCaster *raycaster,
|
---|
84 | AxisAlignedBox3 &bbox,
|
---|
85 | SceneGraph *sceneGraph
|
---|
86 | );
|
---|
87 |
|
---|
88 | bool
|
---|
89 | SnapImagePacket(std::string filename,
|
---|
90 | RayCaster *raycaster,
|
---|
91 | AxisAlignedBox3 &bbox,
|
---|
92 | SceneGraph *sceneGraph
|
---|
93 | );
|
---|
94 |
|
---|
95 | void SetupRay(Ray &ray, const int x, const int y);
|
---|
96 |
|
---|
97 | void SetupRay(SimpleRay &ray, const int x, const int y);
|
---|
98 | };
|
---|
99 |
|
---|
100 | };
|
---|
101 |
|
---|
102 | #endif
|
---|