4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * Great Red Owns Many ACres of Sand
44 void m4_op(mat4 m
,rvec x
,vec4 v
)
49 v
[i
]=m
[XX
][i
]*x
[XX
]+m
[YY
][i
]*x
[YY
]+m
[ZZ
][i
]*x
[ZZ
]+m
[WW
][i
];
64 void print_m4(FILE *fp
,char *s
,mat4 A
)
73 fprintf(fp
,"%10.5f",A
[i
][j
]);
79 void print_v4(FILE *fp
,char *s
,int dim
,real
*a
)
86 fprintf(fp
,"%10.5f",a
[j
]);
91 void mult_matrix(mat4 A
, mat4 B
, mat4 C
)
99 A
[i
][j
]+=B
[i
][k
]*C
[k
][j
];
103 void rotate(int axis
, real angle
, mat4 A
)
109 A
[YY
][YY
] = cos(angle
);
110 A
[YY
][ZZ
] = -sin(angle
);
111 A
[ZZ
][YY
] = sin(angle
);
112 A
[ZZ
][ZZ
] = cos(angle
);
115 A
[XX
][XX
] = cos(angle
);
116 A
[XX
][ZZ
] = sin(angle
);
117 A
[ZZ
][XX
] = -sin(angle
);
118 A
[ZZ
][ZZ
] = cos(angle
);
121 A
[XX
][XX
] = cos(angle
);
122 A
[XX
][YY
] = -sin(angle
);
123 A
[YY
][XX
] = sin(angle
);
124 A
[YY
][YY
] = cos(angle
);
127 fatal_error(0,"Error: invalid axis: %d",axis
);
131 void translate(real tx
, real ty
, real tz
, mat4 A
)
139 static void set_scale(t_3dview
*view
,real sx
, real sy
)
145 void calculate_view(t_3dview
*view
)
148 mat4 To
,Te
,T1
,T2
,T3
,T4
,T5
,N1
,D1
,D2
,D3
,D4
,D5
;
155 l
= sqrt(dx
*dx
+dy
*dy
+dz
*dz
);
156 r
= sqrt(dx
*dx
+dy
*dy
);
158 print_v4(debug
,"eye",N
,view
->eye
);
159 printf("del: %10.5f%10.5f%10.5f l: %10.5f, r: %10.5f\n",dx
,dy
,dz
,l
,r
);
162 fatal_error(0,"Error: Zero Length Vector - No View Specified");
163 translate((real
)(-view
->origin
[XX
]),
164 (real
)(-view
->origin
[YY
]),(real
)(-view
->origin
[ZZ
]),To
);
165 translate((real
)(-view
->eye
[XX
]),
166 (real
)(-view
->eye
[YY
]),(real
)(-view
->eye
[ZZ
]),Te
);
169 T2
[YY
][YY
]=0, T2
[YY
][ZZ
]=-1, T2
[ZZ
][YY
]=1, T2
[ZZ
][ZZ
]=0;
173 T3
[XX
][XX
]=-dy
/r
, T3
[XX
][ZZ
]=dx
/r
, T3
[ZZ
][XX
]=-dx
/r
, T3
[ZZ
][ZZ
]=-dy
/r
;
176 T4
[YY
][YY
]=r
/l
, T4
[YY
][ZZ
]=dz
/l
, T4
[ZZ
][YY
]=-dz
/l
, T4
[ZZ
][ZZ
]=r
/l
;
182 /* N1[XX][XX]=4,N1[YY][YY]=4; */
184 mult_matrix(T1
,To
,view
->Rot
);
185 mult_matrix(D1
,Te
,T2
);
186 mult_matrix(D2
,T3
,T4
);
187 mult_matrix(D3
,T5
,N1
);
188 mult_matrix(D4
,T1
,D1
);
189 mult_matrix(D5
,D2
,D3
);
191 mult_matrix(view
->proj
,D4
,D5
);
194 print_m4(debug
,"T1",T1
);
195 print_m4(debug
,"T2",T2
);
196 print_m4(debug
,"T3",T3
);
197 print_m4(debug
,"T4",T4
);
198 print_m4(debug
,"T5",T5
);
199 print_m4(debug
,"N1",N1
);
200 print_m4(debug
,"Rot",view
->Rot
);
201 print_m4(debug
,"Proj",view
->proj
);
205 bool zoom_3d(t_3dview
*view
,real fac
)
212 for(i
=0; (i
<DIM
); i
++) {
218 bm
=max(norm(view
->box
[XX
]),max(norm(view
->box
[YY
]),norm(view
->box
[ZZ
])));
219 if (dr1
*fac
< 1.1*bm
) /* Don't come to close */
223 for(i
=0; (i
<DIM
); i
++)
225 calculate_view(view
);
229 void init_rotate_3d(t_3dview
*view
)
234 for(i
=0; (i
<DIM
); i
++) {
235 rotate(i
, rot
,view
->RotP
[i
]);
236 rotate(i
,(real
)(-rot
),view
->RotM
[i
]);
238 print_m4(debug
,"RotP",view
->RotP
[i
]);
239 print_m4(debug
,"RotM",view
->RotM
[i
]);
245 void rotate_3d(t_3dview
*view
,int axis
,bool bPositive
)
251 mult_matrix(m4
,view
->Rot
,view
->RotP
[axis
]);
253 mult_matrix(m4
,view
->Rot
,view
->RotM
[axis
]);
256 view
->Rot
[i
][j
]=m4
[i
][j
];
258 calculate_view(view
);
261 void translate_view(t_3dview
*view
,int axis
,bool bPositive
)
264 printf("Translate called\n");
267 view
->origin
[axis
]+=view
->box
[axis
][axis
]/8;
269 view
->origin
[axis
]-=view
->box
[axis
][axis
]/8;
270 calculate_view(view
);
273 void reset_view(t_3dview
*view
)
278 printf("Reset view called\n");
280 set_scale(view
,4.0,4.0);
281 clear_rvec(view
->eye
);
282 calc_box_center(view
->box
,view
->origin
);
283 view
->eye
[ZZ
]=3.0*max(view
->box
[XX
][XX
],view
->box
[YY
][YY
]);
285 view
->eye
[WW
]=view
->origin
[WW
]=0.0;
287 /* Initiate the matrix */
289 calculate_view(view
);
291 init_rotate_3d(view
);
294 t_3dview
*init_view(matrix box
)
301 /* Copy parameters into variables */
302 for(i
=0; (i
<DIM
); i
++)
303 for(j
=0; (j
<DIM
); j
++)
304 view
->box
[i
][j
]=box
[i
][j
];