-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.cpp
123 lines (110 loc) · 4 KB
/
Camera.cpp
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
// ======================================================================== //
// Copyright 2018-2020 Ingo Wald //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ======================================================================== //
/*
* Adapted by Alper Sahistan
* 03/17/2023
*/
#include "Camera.h"
namespace deltaVis
{
vec3f Camera::getFrom() const
{
return position;
}
vec3f Camera::getAt() const
{
return position - frame.vz;
}
vec3f Camera::getUp() const
{
return frame.vy;
}
// void Camera::digestInto(SimpleCamera &easy)
// {
// easy.lens.center = position;
// easy.lens.radius = 0.f;
// easy.lens.du = frame.vx;
// easy.lens.dv = frame.vy;
// const float minFocalDistance
// = max(computeStableEpsilon(position),
// computeStableEpsilon(frame.vx));
// /*
// tan(fov/2) = (height/2) / dist
// -> height = 2*tan(fov/2)*dist
// */
// float screen_height
// = 2.f*tanf(fovyInDegrees/2 * (float)M_PI/180.f)
// * max(minFocalDistance,focalDistance);
// easy.screen.vertical = screen_height * frame.vy;
// easy.screen.horizontal = screen_height * aspect * frame.vx;
// easy.screen.lower_left
// = //easy.lens.center
// /* NEGATIVE z axis! */
// - max(minFocalDistance,focalDistance) * frame.vz
// - 0.5f * easy.screen.vertical
// - 0.5f * easy.screen.horizontal;
// easy.lastModified = getCurrentTime();
// }
void Camera::setFovy(const float fovy)
{
this->fovyInDegrees = fovy;
}
void Camera::setAspect(const float aspect)
{
this->aspect = aspect;
}
void Camera::setFocalDistance(float focalDistance)
{
this->focalDistance = focalDistance;
}
/*! tilt the frame around the z axis such that the y axis is "facing upwards" */
void Camera::forceUpFrame()
{
// frame.vz remains unchanged
if (fabsf(dot(frame.vz, upVector)) < 1e-6f)
// looking along upvector; not much we can do here ...
return;
frame.vx = normalize(cross(upVector, frame.vz));
frame.vy = normalize(cross(frame.vz, frame.vx));
}
void Camera::setOrientation(/* camera origin : */ const vec3f &origin,
/* point of interest: */ const vec3f &interest,
/* up-vector : */ const vec3f &up,
/* fovy, in degrees : */ float fovyInDegrees,
/* set focal dist? : */ bool setFocalDistance)
{
this->fovyInDegrees = fovyInDegrees;
position = origin;
upVector = up;
frame.vz = (interest == origin)
? vec3f(0, 0, 1)
: /* negative because we use NEGATIZE z axis */ -normalize(interest - origin);
frame.vx = cross(up, frame.vz);
if (dot(frame.vx, frame.vx) < 1e-8f)
frame.vx = vec3f(0, 1, 0);
else
frame.vx = normalize(frame.vx);
// frame.vx
// = (fabs(dot(up,frame.vz)) < 1e-6f)
// ? vec3f(0,1,0)
// : normalize(cross(up,frame.vz));
frame.vy = normalize(cross(frame.vz, frame.vx));
poiDistance = length(interest - origin);
if (setFocalDistance)
focalDistance = poiDistance;
forceUpFrame();
}
}