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