2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2010,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
45 #include "gromacs/math/3dtransforms.h"
46 #include "gromacs/math/units.h"
47 #include "gromacs/math/vec.h"
48 #include "gromacs/pbcutil/pbc.h"
49 #include "gromacs/utility/fatalerror.h"
50 #include "gromacs/utility/smalloc.h"
52 static void set_scale(t_3dview *view, real sx, real sy)
58 static void calculate_view(t_3dview *view)
61 mat4 To, Te, T1, T2, T3, T4, T5, N1, D1, D2, D3, D4, D5;
62 real dx, dy, dz, l, r;
68 l = sqrt(dx*dx+dy*dy+dz*dz);
69 r = sqrt(dx*dx+dy*dy);
71 gmx_vec4_print(debug, "eye", view->eye);
72 printf("del: %10.5f%10.5f%10.5f l: %10.5f, r: %10.5f\n", dx, dy, dz, l, r);
76 gmx_fatal(FARGS, "Error: Zero Length Vector - No View Specified");
78 gmx_mat4_init_translation(-view->origin[XX], -view->origin[YY], -view->origin[ZZ], To);
79 gmx_mat4_init_translation(-view->eye[XX], -view->eye[YY], -view->eye[ZZ], Te);
81 gmx_mat4_init_unity(T2);
82 T2[YY][YY] = 0, T2[YY][ZZ] = -1, T2[ZZ][YY] = 1, T2[ZZ][ZZ] = 0;
84 gmx_mat4_init_unity(T3);
87 T3[XX][XX] = -dy/r, T3[XX][ZZ] = dx/r, T3[ZZ][XX] = -dx/r, T3[ZZ][ZZ] = -dy/r;
90 gmx_mat4_init_unity(T4);
91 T4[YY][YY] = r/l, T4[YY][ZZ] = dz/l, T4[ZZ][YY] = -dz/l, T4[ZZ][ZZ] = r/l;
93 gmx_mat4_init_unity(T5);
96 gmx_mat4_init_unity(N1);
97 /* N1[XX][XX]=4,N1[YY][YY]=4; */
99 gmx_mat4_mmul(T1, To, view->Rot);
100 gmx_mat4_mmul(D1, Te, T2);
101 gmx_mat4_mmul(D2, T3, T4);
102 gmx_mat4_mmul(D3, T5, N1);
103 gmx_mat4_mmul(D4, T1, D1);
104 gmx_mat4_mmul(D5, D2, D3);
106 gmx_mat4_mmul(view->proj, D4, D5);
109 gmx_mat4_print(debug, "T1", T1);
110 gmx_mat4_print(debug, "T2", T2);
111 gmx_mat4_print(debug, "T3", T3);
112 gmx_mat4_print(debug, "T4", T4);
113 gmx_mat4_print(debug, "T5", T5);
114 gmx_mat4_print(debug, "N1", N1);
115 gmx_mat4_print(debug, "Rot", view->Rot);
116 gmx_mat4_print(debug, "Proj", view->proj);
120 gmx_bool zoom_3d(t_3dview *view, real fac)
127 for (i = 0; (i < DIM); i++)
135 bm = std::max(norm(view->box[XX]), std::max(norm(view->box[YY]), norm(view->box[ZZ])));
136 if (dr1*fac < 1.1*bm) /* Don't come to close */
142 for (i = 0; (i < DIM); i++)
146 calculate_view(view);
150 /* Initiates the state of 3d rotation matrices in the structure */
151 static void init_rotate_3d(t_3dview *view)
153 real rot = DEG2RAD*15;
156 for (i = 0; (i < DIM); i++)
158 gmx_mat4_init_rotation(i, rot, view->RotP[i]);
159 gmx_mat4_init_rotation(i, -rot, view->RotM[i]);
161 gmx_mat4_print(debug, "RotP", view->RotP[i]);
162 gmx_mat4_print(debug, "RotM", view->RotM[i]);
168 void rotate_3d(t_3dview *view, int axis, gmx_bool bPositive)
174 gmx_mat4_mmul(m4, view->Rot, view->RotP[axis]);
178 gmx_mat4_mmul(m4, view->Rot, view->RotM[axis]);
180 gmx_mat4_copy(m4, view->Rot);
181 calculate_view(view);
184 void translate_view(t_3dview *view, int axis, gmx_bool bPositive)
187 printf("Translate called\n");
191 view->origin[axis] += view->box[axis][axis]/8;
195 view->origin[axis] -= view->box[axis][axis]/8;
197 calculate_view(view);
200 void reset_view(t_3dview *view)
203 printf("Reset view called\n");
205 set_scale(view, 4.0, 4.0);
206 clear_rvec(view->eye);
207 calc_box_center(view->ecenter, view->box, view->origin);
208 view->eye[ZZ] = 3.0*std::max(view->box[XX][XX], view->box[YY][YY]);
210 view->eye[WW] = view->origin[WW] = 0.0;
212 /* Initiate the matrix */
213 gmx_mat4_init_unity(view->Rot);
214 calculate_view(view);
216 init_rotate_3d(view);
219 t_3dview *init_view(matrix box)
224 copy_mat(box, view->box);
225 view->ecenter = ecenterDEF;