Debian Codegraph @

src/Gui/Camera.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
5 * *
6 * This file is part of FreeCAD. *
7 * *
8 * FreeCAD is free software: you can redistribute it and/or modify it *
9 * under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation, either version 2.1 of the *
11 * License, or (at your option) any later version. *
12 * *
13 * FreeCAD is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with FreeCAD. If not, see *
20 * <https://www.gnu.org/licenses/>. *
21 * *
22 **************************************************************************/
23
24 #include "Camera.h"
25 #include "Utilities.h"
26
27 using namespace Gui;
28
29
30 SbRotation Camera::top()
31 {
32 return {0, 0, 0, 1};
33 }
34
35 SbRotation Camera::bottom()
36 {
37 return {1, 0, 0, 0};
38 }
39
40 SbRotation Camera::front()
41 {
42 auto root = sqrtf(2.0) / 2.0f;
43 return {root, 0, 0, root};
44 }
45
46 SbRotation Camera::rear()
47 {
48 auto root = sqrtf(2.0) / 2.0f;
49 return {0, root, root, 0};
50 }
51
52 SbRotation Camera::right()
53 {
54 return {0.5, 0.5, 0.5, 0.5};
55 }
56
57 SbRotation Camera::left()
58 {
59 return {-0.5, 0.5, 0.5, -0.5};
60 }
61
62 SbRotation Camera::isometric()
63 {
64 // The values here are precalculated as our quaternion implementation
65 // does not support calculating the values in compile time.
66 // The values are verified with unit tests.
67 return {0.424708F, 0.17592F, 0.339851F, 0.820473F};
68 }
69
70 SbRotation Camera::dimetric()
71 {
72 // The values here are precalculated as our quaternion implementation
73 // does not support calculating the values in compile time.
74 // The values are verified with unit tests.
75
76 // While there are multiple ways to calculate the dimetric rotation,
77 // we use one which is similar to other CAD applications.
78 return {0.567952F, 0.103751F, 0.146726F, 0.803205F};
79 }
80
81 SbRotation Camera::trimetric()
82 {
83 // The values here are precalculated as our quaternion implementation
84 // does not support calculating the values in compile time.
85 // The values are verified with unit tests.
86
87 // While there are multiple ways to calculate the trimetric rotation,
88 // we use one which is similar to other CAD applications.
89 return {0.446015F, 0.119509F, 0.229575F, 0.856787F};
90 }
91
92 SbRotation Camera::rotation(Camera::Orientation view)
93 {
94 switch (view) {
95 case Top:
96 return top();
97 case Bottom:
98 return bottom();
99 case Front:
100 return front();
101 case Rear:
102 return rear();
103 case Right:
104 return right();
105 case Left:
106 return left();
107 case Isometric:
108 return isometric();
109 case Dimetric:
110 return dimetric();
111 case Trimetric:
112 return trimetric();
113 default:
114 return top();
115 }
116 }
117
118 Base::Rotation Camera::convert(Camera::Orientation view)
119 {
120 return convert(Camera::rotation(view));
121 }
122
123 Base::Rotation Camera::convert(const SbRotation& rot)
124 {
125 return Base::convertTo<Base::Rotation>(rot);
126 }
127
128 SbRotation Camera::convert(const Base::Rotation& rot)
129 {
130 return Base::convertTo<SbRotation>(rot);
131 }