source: trunk/source/visualization/OpenGL/src/G4OpenGLXmRotationCallbacks.cc@ 1252

Last change on this file since 1252 was 1160, checked in by garnier, 16 years ago

mise en place de Vis dans UI

  • Property svn:mime-type set to text/cpp
File size: 9.2 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4OpenGLXmRotationCallbacks.cc,v 1.17 2009/01/19 16:53:42 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31// Andrew Walkden 16th April 1997
32// G4OpenGLXmRotationCallbacks :
33// Several callback functions used by
34// elements of the control panel to
35// rotate the view.
36
37#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
38
39#include "G4OpenGLXmViewer.hh"
40
41#include "G4Scene.hh"
42#include "G4UImanager.hh"
43#include "G4ios.hh"
44
45void G4OpenGLXmViewer::theta_rotation_callback (Widget w,
46 XtPointer clientData,
47 XtPointer callData)
48{
49 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
50 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
51
52 pView->rotate_right = get_boolean_userData (w);
53
54 if (cbs->reason == XmCR_ARM) {
55 rotate_in_theta (pView, NULL);
56 } else if (cbs->reason == XmCR_DISARM) {
57 XtRemoveTimeOut (pView->rotation_timer);
58 }
59}
60
61void G4OpenGLXmViewer::rotate_in_theta (XtPointer clientData,
62 XtIntervalId* timer_id)
63{
64 //theta spin stuff here
65 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
66
67 if (pView->rotate_right) {
68 pView->rotateScene((G4double)pView->rot_sens,0,1);
69 } else {
70 pView->rotateScene(-(G4double)pView->rot_sens,0,1);
71 }
72 /*
73 G4double delta_theta;
74
75 if (pView->fVP.GetLightsMoveWithCamera()) {
76 if (pView->rotate_right) {
77 delta_theta = -((G4double)pView->rot_sens);
78 } else {
79 delta_theta = (G4double)pView->rot_sens;
80 }
81 } else {
82 if (pView->rotate_right) {
83 delta_theta = (G4double)pView->rot_sens;
84 } else {
85 delta_theta = -((G4double)pView->rot_sens);
86 }
87 }
88 delta_theta *= deg;
89 // Rotates by fixed azimuthal angle delta_theta.
90
91 const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit ();
92 const G4Vector3D& up = pView->fVP.GetUpVector ().unit ();
93 const G4Vector3D& zprime = up;
94 G4double cosalpha = up.dot (vp);
95 G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
96 G4Vector3D yprime = (zprime.cross (vp)).unit ();
97 G4Vector3D xprime = yprime.cross (zprime);
98 // Projection of vp on plane perpendicular to up...
99 G4Vector3D a1 = sinalpha * xprime;
100 // Required new projection...
101 G4Vector3D a2 =
102 sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
103 // Required Increment vector...
104 G4Vector3D delta = a2 - a1;
105 // So new viewpoint is...
106 G4Vector3D viewPoint = vp + delta;
107
108 pView->fVP.SetViewAndLights (viewPoint);
109 */
110
111 pView->SetView ();
112 pView->ClearView ();
113 pView->DrawView ();
114
115 pView->rotation_timer = XtAppAddTimeOut
116 (pView->app,
117 timer_id == NULL ? 500 : 1,
118 rotate_in_theta,
119 pView);
120}
121
122void G4OpenGLXmViewer::phi_rotation_callback (Widget w,
123 XtPointer clientData,
124 XtPointer callData)
125{
126 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
127 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
128
129 pView->rotate_up = get_boolean_userData (w);
130
131 if (cbs->reason == XmCR_ARM) {
132 rotate_in_phi (pView, NULL);
133 } else if (cbs->reason == XmCR_DISARM) {
134 XtRemoveTimeOut (pView->rotation_timer);
135 }
136}
137
138void G4OpenGLXmViewer::rotate_in_phi (XtPointer clientData,
139 XtIntervalId* timer_id)
140{
141 //phi spin stuff here
142 // G4double delta_alpha;
143 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
144
145 if (pView -> rotate_up) {
146 pView->rotateScene(0,-(G4double)pView->rot_sens,1);
147 } else {
148 pView->rotateScene(0,(G4double)pView->rot_sens,1);
149 }
150 /*
151 if (pView->fVP.GetLightsMoveWithCamera()) {
152 if (pView -> rotate_up) {
153 delta_alpha = -((G4double)pView->rot_sens);
154 } else {
155 delta_alpha = (G4double)pView->rot_sens;
156 }
157 } else {
158 if (pView -> rotate_up) {
159 delta_alpha = (G4double)pView->rot_sens;
160 } else {
161 delta_alpha = -((G4double)pView->rot_sens);
162 }
163 }
164
165 delta_alpha *= deg;
166
167 const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit ();
168 const G4Vector3D& up = pView->fVP.GetUpVector ().unit ();
169
170 const G4Vector3D& xprime = vp;
171 G4Vector3D yprime = (up.cross(xprime)).unit();
172 G4Vector3D zprime = (xprime.cross(yprime)).unit();
173
174 G4Vector3D new_vp = std::cos(delta_alpha) * xprime + std::sin(delta_alpha) * zprime;
175
176 pView->fVP.SetViewAndLights (new_vp.unit());
177
178 if (pView->fVP.GetLightsMoveWithCamera()) {
179 G4Vector3D new_up = (new_vp.cross(yprime)).unit();
180 pView->fVP.SetUpVector(new_up);
181 }
182
183 */
184 pView->SetView ();
185 pView->ClearView ();
186 pView->DrawView ();
187
188 pView->rotation_timer = XtAppAddTimeOut
189 (pView->app,
190 timer_id == NULL ? 500 : 1,
191 rotate_in_phi,
192 pView);
193}
194
195void G4OpenGLXmViewer::set_rot_sens_callback (Widget w,
196 XtPointer clientData,
197 XtPointer callData)
198{
199 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
200 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
201 short dp = -1;
202 G4float ten_to_the_dp = 10.;
203
204 XtVaGetValues (w,
205 XmNdecimalPoints, &dp,
206 NULL);
207
208 if (dp == 0) {
209 ten_to_the_dp = 1.;
210 } else if ( dp > 0) {
211 for (G4int i = 1; i < (G4int)dp; i++) {
212 ten_to_the_dp *= 10.;
213 }
214 } else {
215 G4Exception("Bad value returned for dp in set_rot_sens_callback");
216 }
217
218 pView->rot_sens = (G4float)(cbs->value) / ten_to_the_dp;
219}
220
221void G4OpenGLXmViewer::set_rot_subject_callback (Widget w,
222 XtPointer clientData,
223 XtPointer)
224{
225 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
226
227 G4int choice = get_int_userData (w);
228
229 switch (choice) {
230 case 0:
231 {
232 pView->fVP.SetLightsMoveWithCamera (true);
233 break;
234 }
235 case 1:
236 {
237 pView->fVP.SetLightsMoveWithCamera (false);
238 break;
239 }
240 default:
241 {
242 G4Exception("Unrecognised choice made in set_rot_subject_callback");
243 }
244 }
245}
246
247void G4OpenGLXmViewer::wobble_callback (Widget w,
248 XtPointer,
249 XtPointer)
250{
251 G4OpenGLXmViewer* pView;
252
253 XtVaGetValues (w,
254 XmNuserData, &pView,
255 NULL);
256
257 pView->original_vp = pView->fVP.GetViewpointDirection();
258 pView->wobble_timer = XtAppAddTimeOut
259 (pView->app,
260 (long unsigned int) (1000. * (1. / pView->wob_sens)),
261 wobble_timer_callback,
262 pView);
263}
264
265void G4OpenGLXmViewer::wobble_timer_callback (XtPointer clientData,
266 XtIntervalId*)
267{
268 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
269 const G4Vector3D& up = pView->fVP.GetUpVector();
270 G4Vector3D third_axis = up.cross(pView->original_vp);
271 G4double pi_div_by_ten = pi / 10.0;
272 G4Vector3D d_up = 0.1 * (std::sin ((G4double)pView->frameNo * pi_div_by_ten * 2.)) * up;
273 G4Vector3D d_third_axis = 0.1 * (std::sin ((G4double)pView->frameNo * (pi_div_by_ten))) * third_axis;
274
275 pView->fVP.SetViewAndLights (pView->original_vp + d_up + d_third_axis);
276
277 pView->SetView ();
278 pView->ClearView ();
279 pView->DrawView ();
280
281 if (pView->frameNo++ == 20) {
282 if (pView->wobble_timer) {
283 XtRemoveTimeOut (pView->wobble_timer);
284 pView->frameNo = 0;
285 pView->fVP.SetViewAndLights (pView->original_vp);
286 pView->SetView ();
287 pView->ClearView ();
288 pView->DrawView ();
289 }
290 } else {
291 pView->wobble_timer = XtAppAddTimeOut
292 (pView->app,
293 (long unsigned int) (1000. * (1. / pView->wob_sens)),
294 wobble_timer_callback,
295 pView);
296 }
297}
298
299void G4OpenGLXmViewer::reset_callback (Widget w,
300 XtPointer,
301 XtPointer)
302{
303
304 G4OpenGLXmViewer* pView;
305
306 XtVaGetValues (w,
307 XmNuserData, &pView,
308 NULL);
309
310 pView->fVP.SetCurrentTargetPoint(G4Point3D());
311 pView->fVP.SetZoomFactor(1.0);
312 pView->fVP.SetDolly(0.0);
313 pView->SetView ();
314 pView->ClearView ();
315 pView->DrawView ();
316 pView->zoom_low = 0.1;
317 pView->zoom_high = 10.0;
318
319}
320#endif
Note: See TracBrowser for help on using the repository browser.