atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
arcball.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'arcball.c'
24*
25* Contains:
26*
27
28 - The mouse trackball rotation functions
29
30*
31* List of functions:
32
33 void arc_ball_rotation (glwin * view, int x, int y);
34
35*/
36
37#include "global.h"
38#include "glview.h"
39
40extern void rotate_quat (project * this_proj, vec4_t q, int status, int axis);
41
45
47{
48 vec3_t vect;
49 vect.x = 2.0*x/view -> pixels[0] - 1.0;
50 y = view -> pixels[1] - y;
51 vect.y = 2.0*y/view -> pixels[1] - 1.0;
52 float norm_arc = vect.x*vect.x + vect.y*vect.y;
53 if (norm_arc > 1.0)
54 {
55 vect.z = 0.0;
56 }
57 else
58 {
59 vect.z = sqrt(1.0 - norm_arc);
60 }
61 return v3_norm (vect);
62}
63
73void arc_ball_rotation (glwin * view, int x, int y)
74{
76 vec3_t rot_axis = v3_cross (arc_ball_init, arc_ball_new);
77 if (v3_length(rot_axis) > 0.0)
78 {
79 double rot_angle = - acos(v3_dot (arc_ball_init, arc_ball_new));
80 vec4_t quat = axis_to_quat (rot_axis, rot_angle);
81 if (view -> mode != EDITION)
82 {
83 view -> anim -> last -> img -> rotation_quaternion = q4_mul (old_rotation_quaternion, quat);
84 }
85 else
86 {
87 rotate_quat (get_project_by_id(view -> proj), quat, 1, 1);
88 }
89 }
90}
vec3_t get_arc_ball_vector(glwin *view, int x, int y)
Definition arcball.c:46
vec4_t old_rotation_quaternion
Definition arcball.c:44
void arc_ball_rotation(glwin *view, int x, int y)
Perform arcball rotation.
Definition arcball.c:73
vec3_t arc_ball_init
Definition arcball.c:42
void rotate_quat(project *this_proj, vec4_t q, int status, int axis)
rotate using quaternion
Definition atom_move.c:269
vec3_t arc_ball_new
Definition arcball.c:43
gchar * axis[3]
Definition w_axis.c:65
Global variable declarations Global convenience function declarations Global data structure defin...
project * proj
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
@ EDITION
Definition glview.h:158
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
Definition glwin.h:875
float y
Definition math_3d.h:130
float x
Definition math_3d.h:130
float z
Definition math_3d.h:130
int status
Definition w_advance.c:160
GtkWidget * img
Definition workspace.c:70