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