source: trunk/geant4/visualization/OpenGL/src/G4OpenGLXmRotationCallbacks.cc @ 799

Last change on this file since 799 was 798, checked in by garnier, 16 years ago

r834@wl-72126: garnier | 2008-05-14 18:44:52 +0200
SPINNING ok

  • Property svn:mime-type set to text/cpp
File size: 9.0 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.14 2006/06/29 21:19:56 gunter 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  pView->rotateScene((G4double)pView->rot_sens,0,1);
68
69  /*
70  G4double delta_theta;
71
72  if (pView->fVP.GetLightsMoveWithCamera()) {
73    if (pView->rotate_right) {
74      delta_theta = -((G4double)pView->rot_sens);
75    } else {
76      delta_theta = (G4double)pView->rot_sens;
77    }
78  } else {
79    if (pView->rotate_right) {
80      delta_theta = (G4double)pView->rot_sens;
81    } else {
82      delta_theta = -((G4double)pView->rot_sens);
83    }
84  }   
85  delta_theta *= deg;
86  // Rotates by fixed azimuthal angle delta_theta.
87
88  const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit ();
89  const G4Vector3D& up = pView->fVP.GetUpVector ().unit ();
90  const G4Vector3D& zprime = up;
91  G4double cosalpha = up.dot (vp);
92  G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
93  G4Vector3D yprime = (zprime.cross (vp)).unit ();
94  G4Vector3D xprime = yprime.cross (zprime);
95  // Projection of vp on plane perpendicular to up...
96  G4Vector3D a1 = sinalpha * xprime;
97  // Required new projection...
98  G4Vector3D a2 =
99    sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
100  // Required Increment vector...
101  G4Vector3D delta = a2 - a1;
102  // So new viewpoint is...
103  G4Vector3D viewPoint = vp + delta;
104
105  pView->fVP.SetViewAndLights (viewPoint); 
106  */
107
108  pView->SetView ();
109  pView->ClearView ();
110  pView->DrawView ();
111
112  pView->rotation_timer = XtAppAddTimeOut
113    (pView->app,
114     timer_id == NULL ? 500 : 1,
115     rotate_in_theta,
116     pView);
117
118
119void G4OpenGLXmViewer::phi_rotation_callback (Widget w,
120                                            XtPointer clientData,
121                                            XtPointer callData)
122{
123  XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
124  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
125
126  pView->rotate_up = get_boolean_userData (w);
127
128  if (cbs->reason == XmCR_ARM) {
129    rotate_in_phi (pView, NULL);
130  } else if (cbs->reason == XmCR_DISARM) {
131    XtRemoveTimeOut (pView->rotation_timer);
132  }
133}
134
135void G4OpenGLXmViewer::rotate_in_phi (XtPointer clientData,
136                                    XtIntervalId* timer_id)
137{
138  //phi spin stuff here
139  G4double delta_alpha;
140  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
141
142  pView->rotateScene(0,(G4double)pView->rot_sens,1);
143
144  /*
145  if (pView->fVP.GetLightsMoveWithCamera()) {
146    if (pView -> rotate_up) {
147      delta_alpha = -((G4double)pView->rot_sens);
148    } else {
149      delta_alpha = (G4double)pView->rot_sens;
150    }
151  } else {
152    if (pView -> rotate_up) {
153      delta_alpha = (G4double)pView->rot_sens;
154    } else {
155      delta_alpha = -((G4double)pView->rot_sens);
156    }
157  }   
158
159  delta_alpha *= deg;
160
161  const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit ();
162  const G4Vector3D& up = pView->fVP.GetUpVector ().unit ();
163
164  const G4Vector3D& xprime = vp;
165  G4Vector3D yprime = (up.cross(xprime)).unit();
166  G4Vector3D zprime = (xprime.cross(yprime)).unit();
167
168  G4Vector3D new_vp = std::cos(delta_alpha) * xprime + std::sin(delta_alpha) * zprime;
169
170  pView->fVP.SetViewAndLights (new_vp.unit());
171
172  if (pView->fVP.GetLightsMoveWithCamera()) {
173    G4Vector3D new_up = (new_vp.cross(yprime)).unit();
174    pView->fVP.SetUpVector(new_up);
175  }
176
177  */
178  pView->SetView ();
179  pView->ClearView ();
180  pView->DrawView ();
181 
182  pView->rotation_timer = XtAppAddTimeOut
183    (pView->app,
184     timer_id == NULL ? 500 : 1,
185     rotate_in_phi,
186     pView);
187}
188
189void G4OpenGLXmViewer::set_rot_sens_callback (Widget w,
190                                            XtPointer clientData,
191                                            XtPointer callData)
192{
193  XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
194  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
195  short dp = -1;
196  G4float ten_to_the_dp = 10.;
197
198  XtVaGetValues (w,
199                 XmNdecimalPoints, &dp,
200                 NULL);
201
202  if (dp == 0) {
203    ten_to_the_dp = 1.;
204  } else if ( dp > 0) {
205    for (G4int i = 1; i < (G4int)dp; i++) {
206      ten_to_the_dp *= 10.;
207    }
208  } else {
209    G4Exception("Bad value returned for dp in set_rot_sens_callback");
210  }
211
212  pView->rot_sens = (G4float)(cbs->value) / ten_to_the_dp;
213
214
215void G4OpenGLXmViewer::set_rot_subject_callback (Widget w,
216                                               XtPointer clientData,
217                                               XtPointer)
218{
219  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
220 
221  G4int choice = get_int_userData (w);
222 
223  switch (choice) {
224  case 0:
225    {
226      pView->fVP.SetLightsMoveWithCamera (true);
227      break;
228    }
229  case 1:
230    {
231      pView->fVP.SetLightsMoveWithCamera (false);
232      break;
233    }
234  default:
235    {
236      G4Exception("Unrecognised choice made in set_rot_subject_callback");
237    }
238  }
239
240
241void G4OpenGLXmViewer::wobble_callback (Widget w,
242                                      XtPointer,
243                                      XtPointer)
244{
245  G4OpenGLXmViewer* pView;
246 
247  XtVaGetValues (w,
248                 XmNuserData, &pView,
249                 NULL);
250 
251  pView->original_vp = pView->fVP.GetViewpointDirection();
252  pView->wobble_timer = XtAppAddTimeOut
253    (pView->app,
254     (long unsigned int) (1000. * (1. / pView->wob_sens)),
255     wobble_timer_callback,
256     pView);
257
258
259void G4OpenGLXmViewer::wobble_timer_callback (XtPointer clientData,
260                                            XtIntervalId*)
261{
262  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
263  const G4Vector3D& up = pView->fVP.GetUpVector();
264  G4Vector3D third_axis = up.cross(pView->original_vp);
265  G4double pi_div_by_ten = pi / 10.0;
266  G4Vector3D d_up = 0.1 * (std::sin ((G4double)pView->frameNo * pi_div_by_ten * 2.)) * up;
267  G4Vector3D d_third_axis = 0.1 * (std::sin ((G4double)pView->frameNo * (pi_div_by_ten))) * third_axis;
268
269  pView->fVP.SetViewAndLights (pView->original_vp + d_up + d_third_axis);
270
271  pView->SetView ();
272  pView->ClearView ();
273  pView->DrawView ();
274 
275  if (pView->frameNo++ == 20) {
276    if (pView->wobble_timer) {
277      XtRemoveTimeOut (pView->wobble_timer);
278      pView->frameNo = 0;
279      pView->fVP.SetViewAndLights (pView->original_vp);
280      pView->SetView ();
281      pView->ClearView ();
282      pView->DrawView ();
283   }
284  } else {
285    pView->wobble_timer = XtAppAddTimeOut
286      (pView->app,
287       (long unsigned int) (1000. * (1. / pView->wob_sens)),
288       wobble_timer_callback,
289       pView);
290  }
291}
292
293void G4OpenGLXmViewer::reset_callback (Widget w,
294                                     XtPointer,
295                                     XtPointer)
296{
297 
298  G4OpenGLXmViewer* pView;
299 
300  XtVaGetValues (w,
301                 XmNuserData, &pView,
302                 NULL);
303 
304  pView->fVP.SetCurrentTargetPoint(G4Point3D());
305  pView->fVP.SetZoomFactor(1.0);
306  pView->fVP.SetDolly(0.0);
307  pView->SetView ();
308  pView->ClearView ();
309  pView->DrawView ();
310  pView->zoom_low = 0.1;
311  pView->zoom_high = 10.0;
312 
313}
314#endif
Note: See TracBrowser for help on using the repository browser.