Blender V4.3
NodeCamera.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include <cmath>
11#include <cstring> // for memcpy
12
13#include "NodeCamera.h"
14
15namespace Freestyle {
16
17static void loadIdentity(double *matrix)
18{
19 int i;
20
21 // Build Identity matrix
22 for (i = 0; i < 16; ++i) {
23 double value;
24 if ((i % 5) == 0) {
25 value = 1.0;
26 }
27 else {
28 value = 0;
29 }
30 matrix[i] = value;
31 }
32}
33
34NodeCamera::NodeCamera(CameraType camera_type) : camera_type_(camera_type)
35{
38}
39
40#if 0 /* UNUSED, gives warning in gcc */
41NodeCamera::NodeCamera(const NodeCamera &iBrother) : camera_type_(iBrother.camera_type_)
42{
43 memcpy(modelview_matrix_, iBrother.modelview_matrix_, sizeof(double[16]));
44 memcpy(projection_matrix_, iBrother.projection_matrix_, sizeof(double[16]));
45}
46#endif
47
49{
50 v.visitNodeCamera(*this);
51}
52
53void NodeCamera::setModelViewMatrix(const double modelview_matrix[16])
54{
55 memcpy(modelview_matrix_, modelview_matrix, sizeof(double[16]));
56}
57
58void NodeCamera::setProjectionMatrix(const double projection_matrix[16])
59{
60 memcpy(projection_matrix_, projection_matrix, sizeof(double[16]));
61}
62
64 : NodeCamera(NodeCamera::ORTHOGRAPHIC),
65 left_(0),
66 right_(0),
67 bottom_(0),
68 top_(0),
69 zNear_(0),
70 zFar_(0)
71{
74}
75
77 double left, double right, double bottom, double top, double zNear, double zFar)
78 : NodeCamera(NodeCamera::ORTHOGRAPHIC),
79 left_(left),
80 right_(right),
81 bottom_(bottom),
82 top_(top),
83 zNear_(zNear),
84 zFar_(zFar)
85{
87
88 projection_matrix_[0] = 2.0 / (right - left);
89 projection_matrix_[3] = -(right + left) / (right - left);
90 projection_matrix_[5] = 2.0 / (top - bottom);
91 projection_matrix_[7] = -(top + bottom) / (top - bottom);
92 projection_matrix_[10] = -2.0 / (zFar - zNear);
93 projection_matrix_[11] = -(zFar + zNear) / (zFar - zNear);
94}
95
97
98NodePerspectiveCamera::NodePerspectiveCamera(double fovy, double aspect, double zNear, double zFar)
99 : NodeCamera(NodeCamera::PERSPECTIVE)
100{
102
103 double f = cos(fovy / 2.0) / sin(fovy / 2.0); // cotangent
104
105 projection_matrix_[0] = f / aspect;
106 projection_matrix_[5] = f;
107 projection_matrix_[10] = (zNear + zFar) / (zNear - zFar);
108 projection_matrix_[11] = (2.0 * zNear * zFar) / (zNear - zFar);
109 projection_matrix_[14] = -1.0;
110 projection_matrix_[15] = 0;
111}
112
114 double left, double right, double bottom, double top, double zNear, double zFar)
115 : NodeCamera(NodeCamera::PERSPECTIVE)
116{
118
119 projection_matrix_[0] = (2.0 * zNear) / (right - left);
120 projection_matrix_[2] = (right + left) / (right - left);
121 projection_matrix_[5] = (2.0 * zNear) / (top - bottom);
122 projection_matrix_[6] = (top + bottom) / (top - bottom);
123 projection_matrix_[10] = -(zFar + zNear) / (zFar - zNear);
124 projection_matrix_[11] = -(2.0 * zFar * zNear) / (zFar - zNear);
125 projection_matrix_[14] = -1.0;
126 projection_matrix_[15] = 0;
127}
128
129} /* namespace Freestyle */
Class to represent a light node.
ATTR_WARN_UNUSED_RESULT const BMVert * v
double projection_matrix_[16]
Definition NodeCamera.h:65
void setModelViewMatrix(const double modelview_matrix[16])
virtual void accept(SceneVisitor &v)
double modelview_matrix_[16]
Definition NodeCamera.h:63
NodeCamera(CameraType camera_type=GENERIC)
void setProjectionMatrix(const double projection_matrix[16])
ccl_device_inline float3 cos(float3 v)
static int left
inherits from class Rep
Definition AppCanvas.cpp:20
static void loadIdentity(double *matrix)