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