Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenGLXmRotationCallbacks.cc
Go to the documentation of this file.
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$
28//
29//
30// Andrew Walkden 16th April 1997
31// G4OpenGLXmRotationCallbacks :
32// Several callback functions used by
33// elements of the control panel to
34// rotate the view.
35
36#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
37
38#include "G4OpenGLXmViewer.hh"
39
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(1,0);
69 } else {
70 pView->rotateScene(-1,0);
71 }
72 /*
73 G4double delta_theta;
74
75 if (pView->fVP.GetLightsMoveWithCamera()) {
76 if (pView->rotate_right) {
77 delta_theta = -(pView->fRot_sens);
78 } else {
79 delta_theta = pView->fRot_sens;
80 }
81 } else {
82 if (pView->rotate_right) {
83 delta_theta = pView->fRot_sens;
84 } else {
85 delta_theta = -(pView->fRot_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,-1);
147 } else {
148 pView->rotateScene(0,1);
149 }
150 /*
151 if (pView->fVP.GetLightsMoveWithCamera()) {
152 if (pView -> rotate_up) {
153 delta_alpha = -(pView->fRot_sens);
154 } else {
155 delta_alpha = pView->fRot_sens;
156 }
157 } else {
158 if (pView -> rotate_up) {
159 delta_alpha = pView->fRot_sens;
160 } else {
161 delta_alpha = -(pView->fRot_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 {
216 ("G4OpenGLXmViewer::set_rot_sens_callback",
217 "opengl2004", FatalException,
218 "Bad value returned for dp in set_rot_sens_callback");
219 }
220
221 pView->fRot_sens = (G4float)(cbs->value) / ten_to_the_dp;
222}
223
224void G4OpenGLXmViewer::set_rot_subject_callback (Widget w,
225 XtPointer clientData,
226 XtPointer)
227{
228 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
229
230 G4int choice = get_int_userData (w);
231
232 switch (choice) {
233 case 0:
234 {
235 pView->fVP.SetLightsMoveWithCamera (true);
236 break;
237 }
238 case 1:
239 {
240 pView->fVP.SetLightsMoveWithCamera (false);
241 break;
242 }
243 default:
244 {
246 ("G4OpenGLXmViewer::set_rot_subject_callback",
247 "opengl2005", FatalException,
248 "Unrecognised choice made in set_rot_subject_callback");
249 }
250 }
251}
252
253void G4OpenGLXmViewer::wobble_callback (Widget w,
254 XtPointer,
255 XtPointer)
256{
257 G4OpenGLXmViewer* pView;
258
259 XtVaGetValues (w,
260 XmNuserData, &pView,
261 NULL);
262
263 pView->original_vp = pView->fVP.GetViewpointDirection();
264 pView->wobble_timer = XtAppAddTimeOut
265 (pView->app,
266 (long unsigned int) (1000. * (1. / pView->wob_sens)),
267 wobble_timer_callback,
268 pView);
269}
270
271void G4OpenGLXmViewer::wobble_timer_callback (XtPointer clientData,
272 XtIntervalId*)
273{
274 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
275 const G4Vector3D& up = pView->fVP.GetUpVector();
276 G4Vector3D third_axis = up.cross(pView->original_vp);
277 G4double pi_div_by_ten = pi / 10.0;
278 G4Vector3D d_up = 0.1 * (std::sin ((G4double)pView->frameNo * pi_div_by_ten * 2.)) * up;
279 G4Vector3D d_third_axis = 0.1 * (std::sin ((G4double)pView->frameNo * (pi_div_by_ten))) * third_axis;
280
281 pView->fVP.SetViewAndLights (pView->original_vp + d_up + d_third_axis);
282
283 pView->SetView ();
284 pView->ClearView ();
285 pView->DrawView ();
286
287 if (pView->frameNo++ == 20) {
288 if (pView->wobble_timer) {
289 XtRemoveTimeOut (pView->wobble_timer);
290 pView->frameNo = 0;
291 pView->fVP.SetViewAndLights (pView->original_vp);
292 pView->SetView ();
293 pView->ClearView ();
294 pView->DrawView ();
295 }
296 } else {
297 pView->wobble_timer = XtAppAddTimeOut
298 (pView->app,
299 (long unsigned int) (1000. * (1. / pView->wob_sens)),
300 wobble_timer_callback,
301 pView);
302 }
303}
304
305void G4OpenGLXmViewer::reset_callback (Widget w,
306 XtPointer,
307 XtPointer)
308{
309
310 G4OpenGLXmViewer* pView;
311
312 XtVaGetValues (w,
313 XmNuserData, &pView,
314 NULL);
315
316 pView->fVP.SetCurrentTargetPoint(G4Point3D());
317 pView->fVP.SetZoomFactor(1.0);
318 pView->fVP.SetDolly(0.0);
319 pView->SetView ();
320 pView->ClearView ();
321 pView->DrawView ();
322 pView->zoom_low = 0.1;
323 pView->zoom_high = 10.0;
324
325}
326#endif
@ FatalException
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
double G4double
Definition: G4Types.hh:64
float G4float
Definition: G4Types.hh:65
int G4int
Definition: G4Types.hh:66
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4double pi