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

Last change on this file since 1039 was 1038, checked in by garnier, 17 years ago

en test pour les refresh, ne marche pas bien

  • Property svn:mime-type set to text/cpp
File size: 9.1 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->RepaintGLView ();
112
113 pView->rotation_timer = XtAppAddTimeOut
114 (pView->app,
115 timer_id == NULL ? 500 : 1,
116 rotate_in_theta,
117 pView);
118}
119
120void G4OpenGLXmViewer::phi_rotation_callback (Widget w,
121 XtPointer clientData,
122 XtPointer callData)
123{
124 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
125 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
126
127 pView->rotate_up = get_boolean_userData (w);
128
129 if (cbs->reason == XmCR_ARM) {
130 rotate_in_phi (pView, NULL);
131 } else if (cbs->reason == XmCR_DISARM) {
132 XtRemoveTimeOut (pView->rotation_timer);
133 }
134}
135
136void G4OpenGLXmViewer::rotate_in_phi (XtPointer clientData,
137 XtIntervalId* timer_id)
138{
139 //phi spin stuff here
140 // G4double delta_alpha;
141 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
142
143 if (pView -> rotate_up) {
144 pView->rotateScene(0,-(G4double)pView->rot_sens,1);
145 } else {
146 pView->rotateScene(0,(G4double)pView->rot_sens,1);
147 }
148 /*
149 if (pView->fVP.GetLightsMoveWithCamera()) {
150 if (pView -> rotate_up) {
151 delta_alpha = -((G4double)pView->rot_sens);
152 } else {
153 delta_alpha = (G4double)pView->rot_sens;
154 }
155 } else {
156 if (pView -> rotate_up) {
157 delta_alpha = (G4double)pView->rot_sens;
158 } else {
159 delta_alpha = -((G4double)pView->rot_sens);
160 }
161 }
162
163 delta_alpha *= deg;
164
165 const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit ();
166 const G4Vector3D& up = pView->fVP.GetUpVector ().unit ();
167
168 const G4Vector3D& xprime = vp;
169 G4Vector3D yprime = (up.cross(xprime)).unit();
170 G4Vector3D zprime = (xprime.cross(yprime)).unit();
171
172 G4Vector3D new_vp = std::cos(delta_alpha) * xprime + std::sin(delta_alpha) * zprime;
173
174 pView->fVP.SetViewAndLights (new_vp.unit());
175
176 if (pView->fVP.GetLightsMoveWithCamera()) {
177 G4Vector3D new_up = (new_vp.cross(yprime)).unit();
178 pView->fVP.SetUpVector(new_up);
179 }
180
181 */
182 pView->RepaintGLView ();
183
184 pView->rotation_timer = XtAppAddTimeOut
185 (pView->app,
186 timer_id == NULL ? 500 : 1,
187 rotate_in_phi,
188 pView);
189}
190
191void G4OpenGLXmViewer::set_rot_sens_callback (Widget w,
192 XtPointer clientData,
193 XtPointer callData)
194{
195 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
196 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
197 short dp = -1;
198 G4float ten_to_the_dp = 10.;
199
200 XtVaGetValues (w,
201 XmNdecimalPoints, &dp,
202 NULL);
203
204 if (dp == 0) {
205 ten_to_the_dp = 1.;
206 } else if ( dp > 0) {
207 for (G4int i = 1; i < (G4int)dp; i++) {
208 ten_to_the_dp *= 10.;
209 }
210 } else {
211 G4Exception("Bad value returned for dp in set_rot_sens_callback");
212 }
213
214 pView->rot_sens = (G4float)(cbs->value) / ten_to_the_dp;
215}
216
217void G4OpenGLXmViewer::set_rot_subject_callback (Widget w,
218 XtPointer clientData,
219 XtPointer)
220{
221 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
222
223 G4int choice = get_int_userData (w);
224
225 switch (choice) {
226 case 0:
227 {
228 pView->fVP.SetLightsMoveWithCamera (true);
229 break;
230 }
231 case 1:
232 {
233 pView->fVP.SetLightsMoveWithCamera (false);
234 break;
235 }
236 default:
237 {
238 G4Exception("Unrecognised choice made in set_rot_subject_callback");
239 }
240 }
241}
242
243void G4OpenGLXmViewer::wobble_callback (Widget w,
244 XtPointer,
245 XtPointer)
246{
247 G4OpenGLXmViewer* pView;
248
249 XtVaGetValues (w,
250 XmNuserData, &pView,
251 NULL);
252
253 pView->original_vp = pView->fVP.GetViewpointDirection();
254 pView->wobble_timer = XtAppAddTimeOut
255 (pView->app,
256 (long unsigned int) (1000. * (1. / pView->wob_sens)),
257 wobble_timer_callback,
258 pView);
259}
260
261void G4OpenGLXmViewer::wobble_timer_callback (XtPointer clientData,
262 XtIntervalId*)
263{
264 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
265 const G4Vector3D& up = pView->fVP.GetUpVector();
266 G4Vector3D third_axis = up.cross(pView->original_vp);
267 G4double pi_div_by_ten = pi / 10.0;
268 G4Vector3D d_up = 0.1 * (std::sin ((G4double)pView->frameNo * pi_div_by_ten * 2.)) * up;
269 G4Vector3D d_third_axis = 0.1 * (std::sin ((G4double)pView->frameNo * (pi_div_by_ten))) * third_axis;
270
271 pView->fVP.SetViewAndLights (pView->original_vp + d_up + d_third_axis);
272
273 pView->RepaintGLView ();
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->RepaintGLView();
281 }
282 } else {
283 pView->wobble_timer = XtAppAddTimeOut
284 (pView->app,
285 (long unsigned int) (1000. * (1. / pView->wob_sens)),
286 wobble_timer_callback,
287 pView);
288 }
289}
290
291void G4OpenGLXmViewer::reset_callback (Widget w,
292 XtPointer,
293 XtPointer)
294{
295
296 G4OpenGLXmViewer* pView;
297
298 XtVaGetValues (w,
299 XmNuserData, &pView,
300 NULL);
301
302 pView->fVP.SetCurrentTargetPoint(G4Point3D());
303 pView->fVP.SetZoomFactor(1.0);
304 pView->fVP.SetDolly(0.0);
305 pView->RepaintGLView();
306 pView->ClearView ();
307 pView->DrawView ();
308 pView->zoom_low = 0.1;
309 pView->zoom_high = 10.0;
310
311}
312#endif
Note: See TracBrowser for help on using the repository browser.