3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * GROningen Mixture of Alchemy and Childrens' Stories
50 void m4_op(mat4 m
,rvec x
,vec4 v
)
55 v
[i
]=m
[XX
][i
]*x
[XX
]+m
[YY
][i
]*x
[YY
]+m
[ZZ
][i
]*x
[ZZ
]+m
[WW
][i
];
70 void print_m4(FILE *fp
,const char *s
,mat4 A
)
79 fprintf(fp
,"%10.5f",A
[i
][j
]);
85 void print_v4(FILE *fp
,char *s
,int dim
,real
*a
)
92 fprintf(fp
,"%10.5f",a
[j
]);
97 void mult_matrix(mat4 A
, mat4 B
, mat4 C
)
102 for (j
=0; j
<N
; j
++) {
105 A
[i
][j
]+=B
[i
][k
]*C
[k
][j
];
109 void rotate(int axis
, real angle
, mat4 A
)
115 A
[YY
][YY
] = cos(angle
);
116 A
[YY
][ZZ
] = -sin(angle
);
117 A
[ZZ
][YY
] = sin(angle
);
118 A
[ZZ
][ZZ
] = cos(angle
);
121 A
[XX
][XX
] = cos(angle
);
122 A
[XX
][ZZ
] = sin(angle
);
123 A
[ZZ
][XX
] = -sin(angle
);
124 A
[ZZ
][ZZ
] = cos(angle
);
127 A
[XX
][XX
] = cos(angle
);
128 A
[XX
][YY
] = -sin(angle
);
129 A
[YY
][XX
] = sin(angle
);
130 A
[YY
][YY
] = cos(angle
);
133 gmx_fatal(FARGS
,"Error: invalid axis: %d",axis
);
137 void translate(real tx
, real ty
, real tz
, mat4 A
)
145 static void set_scale(t_3dview
*view
,real sx
, real sy
)
151 void calculate_view(t_3dview
*view
)
154 mat4 To
,Te
,T1
,T2
,T3
,T4
,T5
,N1
,D1
,D2
,D3
,D4
,D5
;
161 l
= sqrt(dx
*dx
+dy
*dy
+dz
*dz
);
162 r
= sqrt(dx
*dx
+dy
*dy
);
164 print_v4(debug
,"eye",N
,view
->eye
);
165 printf("del: %10.5f%10.5f%10.5f l: %10.5f, r: %10.5f\n",dx
,dy
,dz
,l
,r
);
168 gmx_fatal(FARGS
,"Error: Zero Length Vector - No View Specified");
169 translate((real
)(-view
->origin
[XX
]),
170 (real
)(-view
->origin
[YY
]),(real
)(-view
->origin
[ZZ
]),To
);
171 translate((real
)(-view
->eye
[XX
]),
172 (real
)(-view
->eye
[YY
]),(real
)(-view
->eye
[ZZ
]),Te
);
175 T2
[YY
][YY
]=0, T2
[YY
][ZZ
]=-1, T2
[ZZ
][YY
]=1, T2
[ZZ
][ZZ
]=0;
179 T3
[XX
][XX
]=-dy
/r
, T3
[XX
][ZZ
]=dx
/r
, T3
[ZZ
][XX
]=-dx
/r
, T3
[ZZ
][ZZ
]=-dy
/r
;
182 T4
[YY
][YY
]=r
/l
, T4
[YY
][ZZ
]=dz
/l
, T4
[ZZ
][YY
]=-dz
/l
, T4
[ZZ
][ZZ
]=r
/l
;
188 /* N1[XX][XX]=4,N1[YY][YY]=4; */
190 mult_matrix(T1
,To
,view
->Rot
);
191 mult_matrix(D1
,Te
,T2
);
192 mult_matrix(D2
,T3
,T4
);
193 mult_matrix(D3
,T5
,N1
);
194 mult_matrix(D4
,T1
,D1
);
195 mult_matrix(D5
,D2
,D3
);
197 mult_matrix(view
->proj
,D4
,D5
);
200 print_m4(debug
,"T1",T1
);
201 print_m4(debug
,"T2",T2
);
202 print_m4(debug
,"T3",T3
);
203 print_m4(debug
,"T4",T4
);
204 print_m4(debug
,"T5",T5
);
205 print_m4(debug
,"N1",N1
);
206 print_m4(debug
,"Rot",view
->Rot
);
207 print_m4(debug
,"Proj",view
->proj
);
211 bool zoom_3d(t_3dview
*view
,real fac
)
218 for(i
=0; (i
<DIM
); i
++) {
224 bm
=max(norm(view
->box
[XX
]),max(norm(view
->box
[YY
]),norm(view
->box
[ZZ
])));
225 if (dr1
*fac
< 1.1*bm
) /* Don't come to close */
229 for(i
=0; (i
<DIM
); i
++)
231 calculate_view(view
);
235 void init_rotate_3d(t_3dview
*view
)
240 for(i
=0; (i
<DIM
); i
++) {
241 rotate(i
, rot
,view
->RotP
[i
]);
242 rotate(i
,(real
)(-rot
),view
->RotM
[i
]);
244 print_m4(debug
,"RotP",view
->RotP
[i
]);
245 print_m4(debug
,"RotM",view
->RotM
[i
]);
251 void rotate_3d(t_3dview
*view
,int axis
,bool bPositive
)
257 mult_matrix(m4
,view
->Rot
,view
->RotP
[axis
]);
259 mult_matrix(m4
,view
->Rot
,view
->RotM
[axis
]);
262 view
->Rot
[i
][j
]=m4
[i
][j
];
264 calculate_view(view
);
267 void translate_view(t_3dview
*view
,int axis
,bool bPositive
)
270 printf("Translate called\n");
273 view
->origin
[axis
]+=view
->box
[axis
][axis
]/8;
275 view
->origin
[axis
]-=view
->box
[axis
][axis
]/8;
276 calculate_view(view
);
279 void reset_view(t_3dview
*view
)
284 printf("Reset view called\n");
286 set_scale(view
,4.0,4.0);
287 clear_rvec(view
->eye
);
288 calc_box_center(view
->ecenter
,view
->box
,view
->origin
);
289 view
->eye
[ZZ
]=3.0*max(view
->box
[XX
][XX
],view
->box
[YY
][YY
]);
291 view
->eye
[WW
]=view
->origin
[WW
]=0.0;
293 /* Initiate the matrix */
295 calculate_view(view
);
297 init_rotate_3d(view
);
300 t_3dview
*init_view(matrix box
)
307 /* Copy parameters into variables */
308 for(i
=0; (i
<DIM
); i
++)
309 for(j
=0; (j
<DIM
); j
++)
310 view
->box
[i
][j
]=box
[i
][j
];
312 view
->ecenter
= ecenterDEF
;