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