Graphite  Version 3
An experimental 3D geometry processing program
arc_ball.h
Go to the documentation of this file.
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 
44 #include <geogram/basic/geometry.h>
45 
51 namespace GEO {
52 
53  /*******************************************************************/
54 
67  public:
72 
78  const mat4& get_value() const {
79  return matrix_;
80  }
81 
87  void set_value(const mat4& value);
88 
94  bool get_x_constraint() const {
95  return constrain_x_;
96  }
97 
103  void set_x_constraint(bool value) {
104  constrain_x_ = value;
105  }
106 
112  bool get_y_constraint() const {
113  return constrain_y_;
114  }
115 
121  void set_y_constraint(bool value) {
122  constrain_y_ = value;
123  }
124 
130  void grab(const vec2& value);
131 
137  void drag(const vec2& value);
138 
144  void release(const vec2& value);
145 
149  void reset();
150 
156  bool grabbed() const {
157  return grabbed_;
158  }
159 
160  protected:
171  const vec3& vector,
172  const vec3& axis
173  ) const;
174 
184  vec3 mouse_to_sphere( const vec2& p );
185 
186  private:
187  bool grabbed_;
188  bool constrain_x_;
189  bool constrain_y_;
190  vec2 center_;
191  double radius_;
192 
193  vec2 last_point_;
194  mat4 matrix_;
195  };
196 
197  /*******************************************************************/
198 
199 }
200 #endif
Enables to interactively define a rotation.
Definition: arc_ball.h:66
void release(const vec2 &value)
Callback called when the mouse button is released.
ArcBall()
ArcBall constructor.
vec3 mouse_to_sphere(const vec2 &p)
Lifts a 2d screen coordinate to 3d sphere coordinates, and applies the X or Y axis constraints.
bool get_y_constraint() const
Tests whether the Y axis is constrained.
Definition: arc_ball.h:112
vec3 constrain_vector(const vec3 &vector, const vec3 &axis) const
Discards the component of a vector that is along another vector.
void reset()
Resets this ArcBall to the default value.
bool grabbed() const
Tests whether this ArcBall is grabbed.
Definition: arc_ball.h:156
void drag(const vec2 &value)
Callback called when the mouse is moved.
void grab(const vec2 &value)
Callback called when the mouse is clicked.
void set_y_constraint(bool value)
Specifies whether the Y axis is constrained.
Definition: arc_ball.h:121
const mat4 & get_value() const
Gets the value of the rotation.
Definition: arc_ball.h:78
void set_x_constraint(bool value)
Specifies whether the X axis is constrained.
Definition: arc_ball.h:103
bool get_x_constraint() const
Tests whether the X axis is constrained.
Definition: arc_ball.h:94
void set_value(const mat4 &value)
Sets the value of the rotation.
Vector with aligned memory allocation.
Definition: memory.h:635
Geometric functions in 2d and 3d.
Common include file, providing basic definitions. Should be included before anything else by all head...
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Definition: defs.h:55
Global Vorpaline namespace.