GCC Code Coverage Report


Directory: ./
File: lib/geogram_gfx/gui/arc_ball.h
Date: 2026-09-07 02:28:19
Exec Total Coverage
Lines: 0 2 0.0%
Functions: 0 0 -%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #ifndef H_GEOGRAM_GFX_GLUP_VIEWER_ARCBALL_H
41 #define H_GEOGRAM_GFX_GLUP_VIEWER_ARCBALL_H
42
43 #include <geogram_gfx/basic/common.h>
44 #include <geogram/basic/geometry.h>
45
46 /**
47 * \file geogram_gfx/gui/arc_ball.h
48 * \brief Controls a 3d rotation from user mouse input.
49 */
50
51 namespace GEO {
52
53 /*******************************************************************/
54
55 /**
56 * \brief Enables to interactively define a rotation.
57 * \details This class is inspired by an implementation written by
58 * Paul Rademacher, in his glui library.
59 * Initial documentation by Paul Rademacher:
60 * A C++ class that implements the Arcball,
61 * as described by Ken Shoemake in Graphics Gems IV.
62 * This class takes as input mouse events (mouse down, mouse drag,
63 * mouse up), and creates the appropriate quaternions and 4x4 matrices
64 * to represent the rotation given by the mouse.
65 */
66 class GEOGRAM_GFX_API ArcBall {
67 public:
68 /**
69 * \brief ArcBall constructor.
70 */
71 ArcBall();
72
73 /**
74 * \brief Gets the value of the rotation.
75 * \return the computed rotation, as a 4x4 matrix
76 * (with a zero translational component).
77 */
78 const mat4& get_value() const {
79 return matrix_;
80 }
81
82 /**
83 * \brief Sets the value of the rotation.
84 * \param[in] value the rotation, as a 4x4 matrix
85 * (with a zero translational component).
86 */
87 void set_value(const mat4& value);
88
89 /**
90 * \brief Tests whether the X axis is constrained.
91 * \retval true if the X axis is constrained
92 * \retval false otherwise
93 */
94 bool get_x_constraint() const {
95 return constrain_x_;
96 }
97
98 /**
99 * \brief Specifies whether the X axis is constrained.
100 * \param[in] value true if the X axis should be constrained,
101 * false otherwise
102 */
103 void set_x_constraint(bool value) {
104 constrain_x_ = value;
105 }
106
107 /**
108 * \brief Tests whether the Y axis is constrained.
109 * \retval true if the Y axis is constrained
110 * \retval false otherwise
111 */
112 bool get_y_constraint() const {
113 return constrain_y_;
114 }
115
116 /**
117 * \brief Specifies whether the Y axis is constrained.
118 * \param[in] value true if the Y axis should be constrained,
119 * false otherwise
120 */
121 void set_y_constraint(bool value) {
122 constrain_y_ = value;
123 }
124
125 /**
126 * \brief Callback called when the mouse is clicked.
127 * \param[in] value the picked point, in normalized device
128 * coordinates (x and y both in [-1.0, 1.0]).
129 */
130 void grab(const vec2& value);
131
132 /**
133 * \brief Callback called when the mouse is moved.
134 * \param[in] value the point under the mouse pointer,
135 * in normalized device coordinates (x and y both in [-1.0, 1.0]).
136 */
137 void drag(const vec2& value);
138
139 /**
140 * \brief Callback called when the mouse button is released.
141 * \param[in] value the point under the mouse pointer,
142 * in normalized device coordinates (x and y both in [-1.0, 1.0]).
143 */
144 void release(const vec2& value);
145
146 /**
147 * \brief Resets this ArcBall to the default value.
148 */
149 void reset();
150
151 /**
152 * \brief Tests whether this ArcBall is grabbed.
153 * \retval true if this ArcBall is grabbed.
154 * \retval false otherwise.
155 */
156 bool grabbed() const {
157 return grabbed_;
158 }
159
160 void set_y_inverted(bool x) {
161 y_inverted_ = x;
162 }
163
164 protected:
165 /**
166 * \brief Discards the component of a vector that is
167 * along another vector.
168 * \param[in] vector the input vector
169 * \param[in] axis the axis along which the component should
170 * be discarded
171 * \return the projection of \p vector onto the plane perpendicular
172 * to \p axis
173 */
174 vec3 constrain_vector(
175 const vec3& vector,
176 const vec3& axis
177 ) const;
178
179 /**
180 * \brief Lifts a 2d screen coordinate to 3d sphere coordinates,
181 * and applies the X or Y axis constraints.
182 * \param[in] p the point, in normalized device coordinates (both
183 * X and Y coordinates in [-1.0, 1.0])
184 * \return the point lifted on the 3d sphere. X or Y can be constrained
185 * to zero according to the status of get_x_constraint() and
186 * get_y_constraint() respectively.
187 */
188 vec3 mouse_to_sphere( const vec2& p );
189
190 private:
191 bool grabbed_;
192 bool constrain_x_;
193 bool constrain_y_;
194 vec2 center_;
195 double radius_;
196
197 vec2 last_point_;
198 mat4 matrix_;
199
200 bool y_inverted_;
201 };
202
203 /*******************************************************************/
204
205 }
206 #endif
207