00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
00037
00038 #include "G4OpenGLXmViewer.hh"
00039
00040 #include "G4PhysicalConstants.hh"
00041 #include "G4Scene.hh"
00042 #include "G4UImanager.hh"
00043 #include "G4ios.hh"
00044
00045 void G4OpenGLXmViewer::theta_rotation_callback (Widget w,
00046 XtPointer clientData,
00047 XtPointer callData)
00048 {
00049 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
00050 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00051
00052 pView->rotate_right = get_boolean_userData (w);
00053
00054 if (cbs->reason == XmCR_ARM) {
00055 rotate_in_theta (pView, NULL);
00056 } else if (cbs->reason == XmCR_DISARM) {
00057 XtRemoveTimeOut (pView->rotation_timer);
00058 }
00059 }
00060
00061 void G4OpenGLXmViewer::rotate_in_theta (XtPointer clientData,
00062 XtIntervalId* timer_id)
00063 {
00064
00065 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00066
00067 if (pView->rotate_right) {
00068 pView->rotateScene(1,0);
00069 } else {
00070 pView->rotateScene(-1,0);
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 pView->SetView ();
00112 pView->ClearView ();
00113 pView->DrawView ();
00114
00115 pView->rotation_timer = XtAppAddTimeOut
00116 (pView->app,
00117 timer_id == NULL ? 500 : 1,
00118 rotate_in_theta,
00119 pView);
00120 }
00121
00122 void G4OpenGLXmViewer::phi_rotation_callback (Widget w,
00123 XtPointer clientData,
00124 XtPointer callData)
00125 {
00126 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
00127 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00128
00129 pView->rotate_up = get_boolean_userData (w);
00130
00131 if (cbs->reason == XmCR_ARM) {
00132 rotate_in_phi (pView, NULL);
00133 } else if (cbs->reason == XmCR_DISARM) {
00134 XtRemoveTimeOut (pView->rotation_timer);
00135 }
00136 }
00137
00138 void G4OpenGLXmViewer::rotate_in_phi (XtPointer clientData,
00139 XtIntervalId* timer_id)
00140 {
00141
00142
00143 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00144
00145 if (pView -> rotate_up) {
00146 pView->rotateScene(0,-1);
00147 } else {
00148 pView->rotateScene(0,1);
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 pView->SetView ();
00185 pView->ClearView ();
00186 pView->DrawView ();
00187
00188 pView->rotation_timer = XtAppAddTimeOut
00189 (pView->app,
00190 timer_id == NULL ? 500 : 1,
00191 rotate_in_phi,
00192 pView);
00193 }
00194
00195 void G4OpenGLXmViewer::set_rot_sens_callback (Widget w,
00196 XtPointer clientData,
00197 XtPointer callData)
00198 {
00199 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
00200 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00201 short dp = -1;
00202 G4float ten_to_the_dp = 10.;
00203
00204 XtVaGetValues (w,
00205 XmNdecimalPoints, &dp,
00206 NULL);
00207
00208 if (dp == 0) {
00209 ten_to_the_dp = 1.;
00210 } else if ( dp > 0) {
00211 for (G4int i = 1; i < (G4int)dp; i++) {
00212 ten_to_the_dp *= 10.;
00213 }
00214 } else {
00215 G4Exception
00216 ("G4OpenGLXmViewer::set_rot_sens_callback",
00217 "opengl2004", FatalException,
00218 "Bad value returned for dp in set_rot_sens_callback");
00219 }
00220
00221 pView->fRot_sens = (G4float)(cbs->value) / ten_to_the_dp;
00222 }
00223
00224 void G4OpenGLXmViewer::set_rot_subject_callback (Widget w,
00225 XtPointer clientData,
00226 XtPointer)
00227 {
00228 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
00229
00230 G4int choice = get_int_userData (w);
00231
00232 switch (choice) {
00233 case 0:
00234 {
00235 pView->fVP.SetLightsMoveWithCamera (true);
00236 break;
00237 }
00238 case 1:
00239 {
00240 pView->fVP.SetLightsMoveWithCamera (false);
00241 break;
00242 }
00243 default:
00244 {
00245 G4Exception
00246 ("G4OpenGLXmViewer::set_rot_subject_callback",
00247 "opengl2005", FatalException,
00248 "Unrecognised choice made in set_rot_subject_callback");
00249 }
00250 }
00251 }
00252
00253 void G4OpenGLXmViewer::wobble_callback (Widget w,
00254 XtPointer,
00255 XtPointer)
00256 {
00257 G4OpenGLXmViewer* pView;
00258
00259 XtVaGetValues (w,
00260 XmNuserData, &pView,
00261 NULL);
00262
00263 pView->original_vp = pView->fVP.GetViewpointDirection();
00264 pView->wobble_timer = XtAppAddTimeOut
00265 (pView->app,
00266 (long unsigned int) (1000. * (1. / pView->wob_sens)),
00267 wobble_timer_callback,
00268 pView);
00269 }
00270
00271 void G4OpenGLXmViewer::wobble_timer_callback (XtPointer clientData,
00272 XtIntervalId*)
00273 {
00274 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
00275 const G4Vector3D& up = pView->fVP.GetUpVector();
00276 G4Vector3D third_axis = up.cross(pView->original_vp);
00277 G4double pi_div_by_ten = pi / 10.0;
00278 G4Vector3D d_up = 0.1 * (std::sin ((G4double)pView->frameNo * pi_div_by_ten * 2.)) * up;
00279 G4Vector3D d_third_axis = 0.1 * (std::sin ((G4double)pView->frameNo * (pi_div_by_ten))) * third_axis;
00280
00281 pView->fVP.SetViewAndLights (pView->original_vp + d_up + d_third_axis);
00282
00283 pView->SetView ();
00284 pView->ClearView ();
00285 pView->DrawView ();
00286
00287 if (pView->frameNo++ == 20) {
00288 if (pView->wobble_timer) {
00289 XtRemoveTimeOut (pView->wobble_timer);
00290 pView->frameNo = 0;
00291 pView->fVP.SetViewAndLights (pView->original_vp);
00292 pView->SetView ();
00293 pView->ClearView ();
00294 pView->DrawView ();
00295 }
00296 } else {
00297 pView->wobble_timer = XtAppAddTimeOut
00298 (pView->app,
00299 (long unsigned int) (1000. * (1. / pView->wob_sens)),
00300 wobble_timer_callback,
00301 pView);
00302 }
00303 }
00304
00305 void G4OpenGLXmViewer::reset_callback (Widget w,
00306 XtPointer,
00307 XtPointer)
00308 {
00309
00310 G4OpenGLXmViewer* pView;
00311
00312 XtVaGetValues (w,
00313 XmNuserData, &pView,
00314 NULL);
00315
00316 pView->fVP.SetCurrentTargetPoint(G4Point3D());
00317 pView->fVP.SetZoomFactor(1.0);
00318 pView->fVP.SetDolly(0.0);
00319 pView->SetView ();
00320 pView->ClearView ();
00321 pView->DrawView ();
00322 pView->zoom_low = 0.1;
00323 pView->zoom_high = 10.0;
00324
00325 }
00326 #endif