[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 | // |
---|
[1046] | 27 | // $Id: G4OpenGLViewer.cc,v 1.56 2009/05/14 16:38:23 lgarnier Exp $ |
---|
[873] | 28 | // GEANT4 tag $Name: $ |
---|
[529] | 29 | // |
---|
| 30 | // |
---|
| 31 | // Andrew Walkden 27th March 1996 |
---|
| 32 | // OpenGL view - opens window, hard copy, etc. |
---|
| 33 | |
---|
| 34 | #ifdef G4VIS_BUILD_OPENGL_DRIVER |
---|
| 35 | |
---|
| 36 | #include "G4ios.hh" |
---|
| 37 | #include "G4OpenGLViewer.hh" |
---|
| 38 | #include "G4OpenGLSceneHandler.hh" |
---|
| 39 | #include "G4OpenGLTransform3D.hh" |
---|
[923] | 40 | #include "G4OpenGL2PSAction.hh" |
---|
[529] | 41 | |
---|
| 42 | #include "G4Scene.hh" |
---|
| 43 | #include "G4VisExtent.hh" |
---|
| 44 | #include "G4LogicalVolume.hh" |
---|
| 45 | #include "G4VSolid.hh" |
---|
| 46 | #include "G4Point3D.hh" |
---|
| 47 | #include "G4Normal3D.hh" |
---|
| 48 | #include "G4Plane3D.hh" |
---|
[593] | 49 | #include "G4AttHolder.hh" |
---|
| 50 | #include "G4AttCheck.hh" |
---|
[918] | 51 | |
---|
[923] | 52 | // GL2PS |
---|
| 53 | #include "Geant4_gl2ps.h" |
---|
| 54 | |
---|
[593] | 55 | #include <sstream> |
---|
[529] | 56 | |
---|
| 57 | G4OpenGLViewer::G4OpenGLViewer (G4OpenGLSceneHandler& scene): |
---|
| 58 | G4VViewer (scene, -1), |
---|
[916] | 59 | fPrintColour (true), |
---|
| 60 | fVectoredPs (true), |
---|
[593] | 61 | fOpenGLSceneHandler(scene), |
---|
[529] | 62 | background (G4Colour(0.,0.,0.)), |
---|
| 63 | transparency_enabled (true), |
---|
| 64 | antialiasing_enabled (false), |
---|
| 65 | haloing_enabled (false), |
---|
[789] | 66 | fStartTime(-DBL_MAX), |
---|
| 67 | fEndTime(DBL_MAX), |
---|
[529] | 68 | fFadeFactor(0.), |
---|
| 69 | fDisplayHeadTime(false), |
---|
| 70 | fDisplayHeadTimeX(-0.9), |
---|
| 71 | fDisplayHeadTimeY(-0.9), |
---|
| 72 | fDisplayHeadTimeSize(24.), |
---|
| 73 | fDisplayHeadTimeRed(0.), |
---|
| 74 | fDisplayHeadTimeGreen(1.), |
---|
| 75 | fDisplayHeadTimeBlue(1.), |
---|
| 76 | fDisplayLightFront(false), |
---|
| 77 | fDisplayLightFrontX(0.), |
---|
| 78 | fDisplayLightFrontY(0.), |
---|
| 79 | fDisplayLightFrontZ(0.), |
---|
| 80 | fDisplayLightFrontT(0.), |
---|
| 81 | fDisplayLightFrontRed(0.), |
---|
| 82 | fDisplayLightFrontGreen(1.), |
---|
[916] | 83 | fDisplayLightFrontBlue(0.), |
---|
[1041] | 84 | fPrintSizeX(-1), |
---|
| 85 | fPrintSizeY(-1), |
---|
[1042] | 86 | fPrintFilename ("G4OpenGL"), |
---|
[1041] | 87 | fPrintFilenameIndex(0), |
---|
[1039] | 88 | fPointSize (0), |
---|
| 89 | fSizeHasChanged(0) |
---|
[529] | 90 | { |
---|
| 91 | // Make changes to view parameters for OpenGL... |
---|
| 92 | fVP.SetAutoRefresh(true); |
---|
| 93 | fDefaultVP.SetAutoRefresh(true); |
---|
[897] | 94 | fWinSize_x = fVP.GetWindowSizeHintX(); |
---|
| 95 | fWinSize_y = fVP.GetWindowSizeHintY(); |
---|
[529] | 96 | |
---|
[921] | 97 | fGL2PSAction = new G4OpenGL2PSAction(); |
---|
| 98 | |
---|
[529] | 99 | // glClearColor (0.0, 0.0, 0.0, 0.0); |
---|
| 100 | // glClearDepth (1.0); |
---|
| 101 | // glDisable (GL_BLEND); |
---|
| 102 | // glDisable (GL_LINE_SMOOTH); |
---|
| 103 | // glDisable (GL_POLYGON_SMOOTH); |
---|
| 104 | |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | G4OpenGLViewer::~G4OpenGLViewer () {} |
---|
| 108 | |
---|
| 109 | void G4OpenGLViewer::InitializeGLView () |
---|
| 110 | { |
---|
| 111 | glClearColor (0.0, 0.0, 0.0, 0.0); |
---|
| 112 | glClearDepth (1.0); |
---|
| 113 | glDisable (GL_BLEND); |
---|
| 114 | glDisable (GL_LINE_SMOOTH); |
---|
| 115 | glDisable (GL_POLYGON_SMOOTH); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void G4OpenGLViewer::ClearView () { |
---|
[959] | 119 | #ifdef G4DEBUG_VIS_OGL |
---|
[948] | 120 | printf("G4OpenGLViewer::ClearView\n"); |
---|
[959] | 121 | #endif |
---|
[529] | 122 | glClearColor (background.GetRed(), |
---|
| 123 | background.GetGreen(), |
---|
| 124 | background.GetBlue(), |
---|
| 125 | 1.); |
---|
| 126 | glClearDepth (1.0); |
---|
| 127 | //Below line does not compile with Mesa includes. |
---|
| 128 | //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
---|
| 129 | glClear (GL_COLOR_BUFFER_BIT); |
---|
| 130 | glClear (GL_DEPTH_BUFFER_BIT); |
---|
| 131 | glClear (GL_STENCIL_BUFFER_BIT); |
---|
[955] | 132 | #ifdef G4DEBUG_VIS_OGL |
---|
| 133 | printf("G4OpenGLViewer::ClearView flush\n"); |
---|
| 134 | #endif |
---|
[529] | 135 | glFlush (); |
---|
| 136 | } |
---|
| 137 | |
---|
[906] | 138 | |
---|
[1039] | 139 | void G4OpenGLViewer::ResizeWindow(unsigned int aWidth, unsigned int aHeight) { |
---|
[1038] | 140 | if ((fWinSize_x != aWidth) || (fWinSize_y != aHeight)) { |
---|
[1037] | 141 | fWinSize_x = aWidth; |
---|
| 142 | fWinSize_y = aHeight; |
---|
[1039] | 143 | fSizeHasChanged = true; |
---|
| 144 | } else { |
---|
| 145 | fSizeHasChanged = false; |
---|
[1037] | 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
[906] | 149 | /** |
---|
| 150 | * Set the viewport of the scene |
---|
[945] | 151 | * MAXIMUM SIZE is : |
---|
| 152 | * GLint dims[2]; |
---|
| 153 | * glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims); |
---|
[906] | 154 | */ |
---|
| 155 | void G4OpenGLViewer::ResizeGLView() |
---|
| 156 | { |
---|
[959] | 157 | #ifdef G4DEBUG_VIS_OGL |
---|
[949] | 158 | printf("G4OpenGLViewer::ResizeGLView %d %d\n",fWinSize_x,fWinSize_y); |
---|
[959] | 159 | #endif |
---|
[945] | 160 | // Check size |
---|
| 161 | GLint dims[2]; |
---|
| 162 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims); |
---|
| 163 | if (fWinSize_x > (unsigned)dims[0]) { |
---|
| 164 | G4cerr << "Try to resize view greater than max X viewport dimension. Desired size "<<dims[0] <<" is resize to "<< dims[0] << G4endl; |
---|
| 165 | fWinSize_x = dims[0]; |
---|
| 166 | } |
---|
| 167 | if (fWinSize_y > (unsigned)dims[1]) { |
---|
| 168 | G4cerr << "Try to resize view greater than max Y viewport dimension. Desired size "<<dims[0] <<" is resize to "<< dims[1] << G4endl; |
---|
| 169 | fWinSize_y = dims[1]; |
---|
| 170 | } |
---|
[949] | 171 | GLsizei side = fWinSize_x; |
---|
[906] | 172 | if (fWinSize_y < fWinSize_x) side = fWinSize_y; |
---|
[949] | 173 | |
---|
| 174 | // SPECIAL CASE if fWinSize_x is even (69 for example) |
---|
| 175 | // Ex : X: 69 Y: 26 |
---|
| 176 | // side = 26 |
---|
| 177 | // width / 2 = 21,5 |
---|
| 178 | // height / 2 = 0 |
---|
| 179 | // Should be fixed to closed : 21 0 for ex |
---|
| 180 | // Then size must by change to : |
---|
| 181 | // X:68 Y: 26 |
---|
| 182 | |
---|
| 183 | // SPECIAL CASE |
---|
| 184 | if ((fWinSize_x - side)%2) { |
---|
[950] | 185 | // fWinSize_x --; |
---|
| 186 | |
---|
| 187 | side = fWinSize_x; |
---|
| 188 | if (fWinSize_y < fWinSize_x) side = fWinSize_y; |
---|
[949] | 189 | } |
---|
| 190 | if ((fWinSize_y - side)%2) { |
---|
[950] | 191 | // fWinSize_y --; |
---|
| 192 | |
---|
| 193 | side = fWinSize_x; |
---|
| 194 | if (fWinSize_y < fWinSize_x) side = fWinSize_y; |
---|
[949] | 195 | } |
---|
| 196 | |
---|
[950] | 197 | GLint X = (fWinSize_x - side) / 2; |
---|
| 198 | GLint Y = (fWinSize_y - side) / 2; |
---|
[949] | 199 | |
---|
[959] | 200 | #ifdef G4DEBUG_VIS_OGL |
---|
[950] | 201 | printf("G4OpenGLViewer::ResizeGLView X:%d Y:%d W:%d H:%d --side%d\n",(fWinSize_x - side) / 2,(fWinSize_y - side) / 2,fWinSize_x,fWinSize_y,side); |
---|
[959] | 202 | #endif |
---|
[950] | 203 | glViewport(X, Y, side, side); |
---|
| 204 | // glViewport(0, 0, fWinSize_x,fWinSize_y); |
---|
| 205 | |
---|
| 206 | |
---|
[906] | 207 | } |
---|
| 208 | |
---|
| 209 | |
---|
[529] | 210 | void G4OpenGLViewer::SetView () { |
---|
[858] | 211 | |
---|
| 212 | if (!fSceneHandler.GetScene()) { |
---|
[908] | 213 | G4cerr << "G4OpenGLStoredViewer: Creating a Viewer without a scene is not allowed. \nPlease use /vis/scene/create before /vis/open/.... " |
---|
[858] | 214 | << G4endl; |
---|
| 215 | return; |
---|
| 216 | } |
---|
[529] | 217 | // Calculates view representation based on extent of object being |
---|
| 218 | // viewed and (initial) viewpoint. (Note: it can change later due |
---|
| 219 | // to user interaction via visualization system's GUI.) |
---|
| 220 | |
---|
| 221 | // Lighting. |
---|
| 222 | GLfloat lightPosition [4]; |
---|
| 223 | lightPosition [0] = fVP.GetActualLightpointDirection().x(); |
---|
| 224 | lightPosition [1] = fVP.GetActualLightpointDirection().y(); |
---|
| 225 | lightPosition [2] = fVP.GetActualLightpointDirection().z(); |
---|
| 226 | lightPosition [3] = 0.; |
---|
| 227 | // Light position is "true" light direction, so must come after gluLookAt. |
---|
| 228 | GLfloat ambient [] = { 0.2, 0.2, 0.2, 1.}; |
---|
| 229 | GLfloat diffuse [] = { 0.8, 0.8, 0.8, 1.}; |
---|
| 230 | glEnable (GL_LIGHT0); |
---|
| 231 | glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); |
---|
| 232 | glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); |
---|
| 233 | |
---|
| 234 | // Get radius of scene, etc. |
---|
| 235 | // Note that this procedure properly takes into account zoom, dolly and pan. |
---|
| 236 | const G4Point3D targetPoint |
---|
| 237 | = fSceneHandler.GetScene()->GetStandardTargetPoint() |
---|
| 238 | + fVP.GetCurrentTargetPoint (); |
---|
| 239 | G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); |
---|
| 240 | if(radius<=0.) radius = 1.; |
---|
| 241 | const G4double cameraDistance = fVP.GetCameraDistance (radius); |
---|
| 242 | const G4Point3D cameraPosition = |
---|
| 243 | targetPoint + cameraDistance * fVP.GetViewpointDirection().unit(); |
---|
[906] | 244 | const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius); |
---|
| 245 | const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius); |
---|
[529] | 246 | const GLdouble right = fVP.GetFrontHalfHeight (pnear, radius); |
---|
| 247 | const GLdouble left = -right; |
---|
| 248 | const GLdouble bottom = left; |
---|
| 249 | const GLdouble top = right; |
---|
| 250 | |
---|
[906] | 251 | // FIXME |
---|
[1039] | 252 | ResizeGLView(); |
---|
[908] | 253 | //SHOULD SetWindowsSizeHint()... |
---|
[906] | 254 | |
---|
[529] | 255 | glMatrixMode (GL_PROJECTION); // set up Frustum. |
---|
| 256 | glLoadIdentity(); |
---|
| 257 | |
---|
[906] | 258 | const G4Vector3D scaleFactor = fVP.GetScaleFactor(); |
---|
| 259 | glScaled(scaleFactor.x(),scaleFactor.y(),scaleFactor.z()); |
---|
[529] | 260 | |
---|
| 261 | if (fVP.GetFieldHalfAngle() == 0.) { |
---|
| 262 | glOrtho (left, right, bottom, top, pnear, pfar); |
---|
| 263 | } |
---|
| 264 | else { |
---|
| 265 | glFrustum (left, right, bottom, top, pnear, pfar); |
---|
[908] | 266 | } |
---|
[906] | 267 | |
---|
[529] | 268 | glMatrixMode (GL_MODELVIEW); // apply further transformations to scene. |
---|
| 269 | glLoadIdentity(); |
---|
| 270 | |
---|
| 271 | const G4Normal3D& upVector = fVP.GetUpVector (); |
---|
| 272 | G4Point3D gltarget; |
---|
| 273 | if (cameraDistance > 1.e-6 * radius) { |
---|
| 274 | gltarget = targetPoint; |
---|
| 275 | } |
---|
| 276 | else { |
---|
| 277 | gltarget = targetPoint - radius * fVP.GetViewpointDirection().unit(); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | const G4Point3D& pCamera = cameraPosition; // An alias for brevity. |
---|
| 281 | gluLookAt (pCamera.x(), pCamera.y(), pCamera.z(), // Viewpoint. |
---|
| 282 | gltarget.x(), gltarget.y(), gltarget.z(), // Target point. |
---|
| 283 | upVector.x(), upVector.y(), upVector.z()); // Up vector. |
---|
[906] | 284 | |
---|
[529] | 285 | // Light position is "true" light direction, so must come after gluLookAt. |
---|
| 286 | glLightfv (GL_LIGHT0, GL_POSITION, lightPosition); |
---|
| 287 | |
---|
| 288 | // OpenGL no longer seems to reconstruct clipped edges, so, when the |
---|
| 289 | // BooleanProcessor is up to it, abandon this and use generic |
---|
| 290 | // clipping in G4OpenGLSceneHandler::CreateSectionPolyhedron. Also, |
---|
| 291 | // force kernel visit on change of clipping plane in |
---|
| 292 | // G4OpenGLStoredViewer::CompareForKernelVisit. |
---|
| 293 | if (fVP.IsSection () ) { // pair of back to back clip planes. |
---|
| 294 | const G4Plane3D& s = fVP.GetSectionPlane (); |
---|
| 295 | double sArray[4]; |
---|
| 296 | sArray[0] = s.a(); |
---|
| 297 | sArray[1] = s.b(); |
---|
| 298 | sArray[2] = s.c(); |
---|
| 299 | sArray[3] = s.d() + radius * 1.e-05; |
---|
| 300 | glClipPlane (GL_CLIP_PLANE0, sArray); |
---|
| 301 | glEnable (GL_CLIP_PLANE0); |
---|
| 302 | sArray[0] = -s.a(); |
---|
| 303 | sArray[1] = -s.b(); |
---|
| 304 | sArray[2] = -s.c(); |
---|
| 305 | sArray[3] = -s.d() + radius * 1.e-05; |
---|
| 306 | glClipPlane (GL_CLIP_PLANE1, sArray); |
---|
| 307 | glEnable (GL_CLIP_PLANE1); |
---|
| 308 | } else { |
---|
| 309 | glDisable (GL_CLIP_PLANE0); |
---|
| 310 | glDisable (GL_CLIP_PLANE1); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | const G4Planes& cutaways = fVP.GetCutawayPlanes(); |
---|
| 314 | size_t nPlanes = cutaways.size(); |
---|
| 315 | if (fVP.IsCutaway() && |
---|
| 316 | fVP.GetCutawayMode() == G4ViewParameters::cutawayIntersection && |
---|
| 317 | nPlanes > 0) { |
---|
| 318 | double a[4]; |
---|
| 319 | a[0] = cutaways[0].a(); |
---|
| 320 | a[1] = cutaways[0].b(); |
---|
| 321 | a[2] = cutaways[0].c(); |
---|
| 322 | a[3] = cutaways[0].d(); |
---|
| 323 | glClipPlane (GL_CLIP_PLANE2, a); |
---|
| 324 | glEnable (GL_CLIP_PLANE2); |
---|
| 325 | if (nPlanes > 1) { |
---|
| 326 | a[0] = cutaways[1].a(); |
---|
| 327 | a[1] = cutaways[1].b(); |
---|
| 328 | a[2] = cutaways[1].c(); |
---|
| 329 | a[3] = cutaways[1].d(); |
---|
| 330 | glClipPlane (GL_CLIP_PLANE3, a); |
---|
| 331 | glEnable (GL_CLIP_PLANE3); |
---|
| 332 | } |
---|
| 333 | if (nPlanes > 2) { |
---|
| 334 | a[0] = cutaways[2].a(); |
---|
| 335 | a[1] = cutaways[2].b(); |
---|
| 336 | a[2] = cutaways[2].c(); |
---|
| 337 | a[3] = cutaways[2].d(); |
---|
| 338 | glClipPlane (GL_CLIP_PLANE4, a); |
---|
| 339 | glEnable (GL_CLIP_PLANE4); |
---|
| 340 | } |
---|
| 341 | } else { |
---|
| 342 | glDisable (GL_CLIP_PLANE2); |
---|
| 343 | glDisable (GL_CLIP_PLANE3); |
---|
| 344 | glDisable (GL_CLIP_PLANE4); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | // Background. |
---|
| 348 | background = fVP.GetBackgroundColour (); |
---|
| 349 | |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | void G4OpenGLViewer::HaloingFirstPass () { |
---|
| 353 | |
---|
| 354 | //To perform haloing, first Draw all information to the depth buffer |
---|
| 355 | //alone, using a chunky line width, and then Draw all info again, to |
---|
| 356 | //the colour buffer, setting a thinner line width an the depth testing |
---|
| 357 | //function to less than or equal, so if two lines cross, the one |
---|
| 358 | //passing behind the other will not pass the depth test, and so not |
---|
| 359 | //get rendered either side of the infront line for a short distance. |
---|
| 360 | |
---|
| 361 | //First, disable writing to the colo(u)r buffer... |
---|
| 362 | glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
---|
| 363 | |
---|
| 364 | //Now enable writing to the depth buffer... |
---|
| 365 | glDepthMask (GL_TRUE); |
---|
| 366 | glDepthFunc (GL_LESS); |
---|
| 367 | glClearDepth (1.0); |
---|
| 368 | |
---|
| 369 | //Finally, set the line width to something wide... |
---|
| 370 | glLineWidth (3.0); |
---|
| 371 | |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | void G4OpenGLViewer::HaloingSecondPass () { |
---|
| 375 | |
---|
| 376 | //And finally, turn the colour buffer back on with a sesible line width... |
---|
| 377 | glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
---|
| 378 | glDepthFunc (GL_LEQUAL); |
---|
| 379 | glLineWidth (1.0); |
---|
| 380 | |
---|
| 381 | } |
---|
| 382 | |
---|
[593] | 383 | void G4OpenGLViewer::Pick(GLdouble x, GLdouble y) |
---|
| 384 | { |
---|
| 385 | //G4cout << "X: " << x << ", Y: " << y << G4endl; |
---|
| 386 | const G4int BUFSIZE = 512; |
---|
| 387 | GLuint selectBuffer[BUFSIZE]; |
---|
| 388 | glSelectBuffer(BUFSIZE, selectBuffer); |
---|
| 389 | glRenderMode(GL_SELECT); |
---|
| 390 | glInitNames(); |
---|
| 391 | glPushName(0); |
---|
| 392 | glMatrixMode(GL_PROJECTION); |
---|
| 393 | G4double currentProjectionMatrix[16]; |
---|
| 394 | glGetDoublev(GL_PROJECTION_MATRIX, currentProjectionMatrix); |
---|
| 395 | glPushMatrix(); |
---|
| 396 | glLoadIdentity(); |
---|
| 397 | GLint viewport[4]; |
---|
| 398 | glGetIntegerv(GL_VIEWPORT, viewport); |
---|
| 399 | // Define 5x5 pixel pick area |
---|
| 400 | gluPickMatrix(x, viewport[3] - y, 5., 5., viewport); |
---|
| 401 | glMultMatrixd(currentProjectionMatrix); |
---|
| 402 | glMatrixMode(GL_MODELVIEW); |
---|
| 403 | DrawView(); |
---|
| 404 | GLint hits = glRenderMode(GL_RENDER); |
---|
| 405 | if (hits < 0) |
---|
| 406 | G4cout << "Too many hits. Zoom in to reduce overlaps." << G4cout; |
---|
| 407 | else if (hits > 0) { |
---|
| 408 | //G4cout << hits << " hit(s)" << G4endl; |
---|
| 409 | GLuint* p = selectBuffer; |
---|
| 410 | for (GLint i = 0; i < hits; ++i) { |
---|
| 411 | GLuint nnames = *p++; |
---|
| 412 | *p++; //OR GLuint zmin = *p++; |
---|
| 413 | *p++; //OR GLuint zmax = *p++; |
---|
| 414 | //G4cout << "Hit " << i << ": " << nnames << " names" |
---|
| 415 | // << "\nzmin: " << zmin << ", zmax: " << zmax << G4endl; |
---|
| 416 | for (GLuint j = 0; j < nnames; ++j) { |
---|
| 417 | GLuint name = *p++; |
---|
| 418 | //G4cout << "Name " << j << ": PickName: " << name << G4endl; |
---|
| 419 | std::map<GLuint, G4AttHolder*>::iterator iter = |
---|
| 420 | fOpenGLSceneHandler.fPickMap.find(name); |
---|
| 421 | if (iter != fOpenGLSceneHandler.fPickMap.end()) { |
---|
| 422 | G4AttHolder* attHolder = iter->second; |
---|
| 423 | if(attHolder && attHolder->GetAttDefs().size()) { |
---|
| 424 | for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) { |
---|
| 425 | G4cout << G4AttCheck(attHolder->GetAttValues()[i], |
---|
| 426 | attHolder->GetAttDefs()[i]); |
---|
| 427 | } |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | G4cout << G4endl; |
---|
| 432 | } |
---|
| 433 | } |
---|
| 434 | glMatrixMode(GL_PROJECTION); |
---|
| 435 | glPopMatrix(); |
---|
| 436 | glMatrixMode(GL_MODELVIEW); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | |
---|
[754] | 440 | |
---|
[593] | 441 | |
---|
[914] | 442 | GLubyte* G4OpenGLViewer::grabPixels (int inColor, unsigned int width, unsigned int height) { |
---|
| 443 | |
---|
| 444 | GLubyte* buffer; |
---|
| 445 | GLint swapbytes, lsbfirst, rowlength; |
---|
| 446 | GLint skiprows, skippixels, alignment; |
---|
| 447 | GLenum format; |
---|
| 448 | int size; |
---|
| 449 | |
---|
| 450 | if (inColor) { |
---|
| 451 | format = GL_RGB; |
---|
| 452 | size = width*height*3; |
---|
| 453 | } else { |
---|
| 454 | format = GL_LUMINANCE; |
---|
| 455 | size = width*height*1; |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | buffer = new GLubyte[size]; |
---|
| 459 | if (buffer == NULL) |
---|
| 460 | return NULL; |
---|
| 461 | |
---|
| 462 | glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes); |
---|
| 463 | glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst); |
---|
| 464 | glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength); |
---|
| 465 | |
---|
| 466 | glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows); |
---|
| 467 | glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels); |
---|
| 468 | glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment); |
---|
| 469 | |
---|
| 470 | glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); |
---|
| 471 | glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); |
---|
| 472 | glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); |
---|
| 473 | |
---|
| 474 | glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); |
---|
| 475 | glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); |
---|
| 476 | glPixelStorei (GL_UNPACK_ALIGNMENT, 1); |
---|
| 477 | |
---|
[980] | 478 | glReadBuffer(GL_FRONT); |
---|
[914] | 479 | glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, format, GL_UNSIGNED_BYTE, (GLvoid*) buffer); |
---|
| 480 | |
---|
| 481 | glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes); |
---|
| 482 | glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst); |
---|
| 483 | glPixelStorei (GL_UNPACK_ROW_LENGTH, rowlength); |
---|
| 484 | |
---|
| 485 | glPixelStorei (GL_UNPACK_SKIP_ROWS, skiprows); |
---|
| 486 | glPixelStorei (GL_UNPACK_SKIP_PIXELS, skippixels); |
---|
| 487 | glPixelStorei (GL_UNPACK_ALIGNMENT, alignment); |
---|
| 488 | |
---|
| 489 | return buffer; |
---|
| 490 | } |
---|
| 491 | |
---|
[941] | 492 | void G4OpenGLViewer::printEPS() { |
---|
| 493 | bool res; |
---|
[942] | 494 | #ifdef G4DEBUG_VIS_OGL |
---|
[1041] | 495 | printf("G4OpenGLViewer::printEPS file:%s Vec:%d\n",getRealPrintFilename().c_str(),fVectoredPs); |
---|
[942] | 496 | #endif |
---|
[941] | 497 | if (fVectoredPs) { |
---|
| 498 | res = printVectoredEPS(); |
---|
| 499 | } else { |
---|
[1008] | 500 | res = printNonVectoredEPS(); |
---|
[941] | 501 | } |
---|
| 502 | if (res == false) { |
---|
[1041] | 503 | G4cerr << "Error while saving file... "<<getRealPrintFilename().c_str()<< G4endl; |
---|
[941] | 504 | } else { |
---|
[1042] | 505 | G4cout << "File "<<getRealPrintFilename().c_str()<<" has been saved " << G4endl; |
---|
[941] | 506 | } |
---|
[1041] | 507 | |
---|
| 508 | // increment index if necessary |
---|
| 509 | if ( fPrintFilenameIndex != -1) { |
---|
| 510 | fPrintFilenameIndex++; |
---|
| 511 | } |
---|
| 512 | |
---|
[941] | 513 | } |
---|
[914] | 514 | |
---|
[941] | 515 | bool G4OpenGLViewer::printVectoredEPS() { |
---|
| 516 | return printGl2PS(); |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | bool G4OpenGLViewer::printNonVectoredEPS () { |
---|
| 520 | |
---|
[1041] | 521 | int width = getRealPrintSizeX(); |
---|
| 522 | int height = getRealPrintSizeY(); |
---|
[941] | 523 | |
---|
[942] | 524 | #ifdef G4DEBUG_VIS_OGL |
---|
[1041] | 525 | printf("G4OpenGLViewer::printNonVectoredEPS file:%s Vec:%d X:%d Y:%d col:%d\n",getRealPrintFilename().c_str(),fVectoredPs,width,height,fPrintColour); |
---|
[942] | 526 | #endif |
---|
[914] | 527 | FILE* fp; |
---|
| 528 | GLubyte* pixels; |
---|
| 529 | GLubyte* curpix; |
---|
| 530 | int components, pos, i; |
---|
| 531 | |
---|
[941] | 532 | pixels = grabPixels (fPrintColour, width, height); |
---|
[914] | 533 | |
---|
[941] | 534 | if (pixels == NULL) { |
---|
| 535 | G4cerr << "Failed to get pixels from OpenGl viewport" << G4endl; |
---|
| 536 | return false; |
---|
| 537 | } |
---|
| 538 | if (fPrintColour) { |
---|
[914] | 539 | components = 3; |
---|
| 540 | } else { |
---|
| 541 | components = 1; |
---|
| 542 | } |
---|
[1041] | 543 | std::string name = getRealPrintFilename(); |
---|
| 544 | fp = fopen (name.c_str(), "w"); |
---|
[914] | 545 | if (fp == NULL) { |
---|
[1041] | 546 | G4cerr << "Can't open filename " << name.c_str() << G4endl; |
---|
[941] | 547 | return false; |
---|
[914] | 548 | } |
---|
| 549 | |
---|
| 550 | fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); |
---|
[1041] | 551 | fprintf (fp, "%%%%Title: %s\n", name.c_str()); |
---|
[914] | 552 | fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n"); |
---|
| 553 | fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", width, height); |
---|
| 554 | fprintf (fp, "%%%%EndComments\n"); |
---|
| 555 | fprintf (fp, "gsave\n"); |
---|
| 556 | fprintf (fp, "/bwproc {\n"); |
---|
| 557 | fprintf (fp, " rgbproc\n"); |
---|
| 558 | fprintf (fp, " dup length 3 idiv string 0 3 0 \n"); |
---|
| 559 | fprintf (fp, " 5 -1 roll {\n"); |
---|
| 560 | fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n"); |
---|
| 561 | fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n"); |
---|
| 562 | fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n"); |
---|
| 563 | fprintf (fp, " { 2 1 roll } ifelse\n"); |
---|
| 564 | fprintf (fp, " }forall\n"); |
---|
| 565 | fprintf (fp, " pop pop pop\n"); |
---|
| 566 | fprintf (fp, "} def\n"); |
---|
| 567 | fprintf (fp, "systemdict /colorimage known not {\n"); |
---|
| 568 | fprintf (fp, " /colorimage {\n"); |
---|
| 569 | fprintf (fp, " pop\n"); |
---|
| 570 | fprintf (fp, " pop\n"); |
---|
| 571 | fprintf (fp, " /rgbproc exch def\n"); |
---|
| 572 | fprintf (fp, " { bwproc } image\n"); |
---|
| 573 | fprintf (fp, " } def\n"); |
---|
| 574 | fprintf (fp, "} if\n"); |
---|
| 575 | fprintf (fp, "/picstr %d string def\n", width * components); |
---|
| 576 | fprintf (fp, "%d %d scale\n", width, height); |
---|
| 577 | fprintf (fp, "%d %d %d\n", width, height, 8); |
---|
| 578 | fprintf (fp, "[%d 0 0 %d 0 0]\n", width, height); |
---|
| 579 | fprintf (fp, "{currentfile picstr readhexstring pop}\n"); |
---|
| 580 | fprintf (fp, "false %d\n", components); |
---|
| 581 | fprintf (fp, "colorimage\n"); |
---|
| 582 | |
---|
| 583 | curpix = (GLubyte*) pixels; |
---|
| 584 | pos = 0; |
---|
| 585 | for (i = width*height*components; i>0; i--) { |
---|
| 586 | fprintf (fp, "%02hx ", *(curpix++)); |
---|
| 587 | if (++pos >= 32) { |
---|
| 588 | fprintf (fp, "\n"); |
---|
| 589 | pos = 0; |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | if (pos) |
---|
| 593 | fprintf (fp, "\n"); |
---|
| 594 | |
---|
| 595 | fprintf (fp, "grestore\n"); |
---|
| 596 | fprintf (fp, "showpage\n"); |
---|
| 597 | delete pixels; |
---|
| 598 | fclose (fp); |
---|
[941] | 599 | |
---|
| 600 | // Reset for next time (useful is size change) |
---|
[1041] | 601 | // fPrintSizeX = -1; |
---|
| 602 | // fPrintSizeY = -1; |
---|
[941] | 603 | |
---|
| 604 | return true; |
---|
[914] | 605 | } |
---|
| 606 | |
---|
[918] | 607 | |
---|
[941] | 608 | bool G4OpenGLViewer::printGl2PS() { |
---|
[918] | 609 | |
---|
[1041] | 610 | int width = getRealPrintSizeX(); |
---|
| 611 | int height = getRealPrintSizeY(); |
---|
[941] | 612 | |
---|
[938] | 613 | if (!fGL2PSAction) return false; |
---|
[929] | 614 | |
---|
[1041] | 615 | fGL2PSAction->setFileName(getRealPrintFilename().c_str()); |
---|
[938] | 616 | // try to resize |
---|
| 617 | int X = fWinSize_x; |
---|
| 618 | int Y = fWinSize_y; |
---|
[929] | 619 | |
---|
[1039] | 620 | fWinSize_x = width; |
---|
| 621 | fWinSize_y = height; |
---|
| 622 | ResizeGLView(); |
---|
[921] | 623 | if (fGL2PSAction->enableFileWriting()) { |
---|
[945] | 624 | |
---|
[948] | 625 | // By default, we choose the line width (trajectories...) |
---|
| 626 | fGL2PSAction->setLineWidth(1); |
---|
| 627 | // By default, we choose the point size (markers...) |
---|
| 628 | fGL2PSAction->setPointSize(2); |
---|
[945] | 629 | |
---|
[931] | 630 | DrawView (); |
---|
[921] | 631 | fGL2PSAction->disableFileWriting(); |
---|
| 632 | } |
---|
[929] | 633 | |
---|
[1039] | 634 | fWinSize_x = X; |
---|
| 635 | fWinSize_y = Y; |
---|
| 636 | ResizeGLView(); |
---|
[929] | 637 | |
---|
[941] | 638 | // Reset for next time (useful is size change) |
---|
[1041] | 639 | // fPrintSizeX = 0; |
---|
| 640 | // fPrintSizeY = 0; |
---|
[941] | 641 | |
---|
[938] | 642 | return true; |
---|
[918] | 643 | } |
---|
| 644 | |
---|
[1039] | 645 | unsigned int G4OpenGLViewer::getWinWidth() { |
---|
| 646 | return fWinSize_x; |
---|
| 647 | } |
---|
| 648 | |
---|
| 649 | unsigned int G4OpenGLViewer::getWinHeight() { |
---|
| 650 | return fWinSize_y; |
---|
| 651 | } |
---|
| 652 | |
---|
| 653 | G4bool G4OpenGLViewer::sizeHasChanged() { |
---|
| 654 | return fSizeHasChanged; |
---|
| 655 | } |
---|
| 656 | |
---|
[1041] | 657 | G4int G4OpenGLViewer::getRealPrintSizeX() { |
---|
| 658 | if (fPrintSizeX == -1) { |
---|
| 659 | return fWinSize_x; |
---|
| 660 | } |
---|
| 661 | GLint dims[2]; |
---|
| 662 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims); |
---|
| 663 | if (fPrintSizeX > dims[0]){ |
---|
| 664 | return dims[0]; |
---|
| 665 | } |
---|
| 666 | if (fPrintSizeX < -1){ |
---|
| 667 | return 0; |
---|
| 668 | } |
---|
[1049] | 669 | #ifdef G4DEBUG_VIS_OGL |
---|
| 670 | printf("G4OpenGLViewer::getRealPrintSizeX :: %d",fPrintSizeX); |
---|
| 671 | #endif |
---|
[1041] | 672 | return fPrintSizeX; |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | G4int G4OpenGLViewer::getRealPrintSizeY() { |
---|
| 676 | if (fPrintSizeY == -1) { |
---|
| 677 | return fWinSize_y; |
---|
| 678 | } |
---|
| 679 | GLint dims[2]; |
---|
| 680 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims); |
---|
| 681 | if (fPrintSizeY > dims[1]){ |
---|
| 682 | return dims[1]; |
---|
| 683 | } |
---|
| 684 | if (fPrintSizeY < -1){ |
---|
| 685 | return 0; |
---|
| 686 | } |
---|
[1049] | 687 | #ifdef G4DEBUG_VIS_OGL |
---|
| 688 | printf("G4OpenGLViewer::getRealPrintSizeY :: %d",fPrintSizeY); |
---|
| 689 | #endif |
---|
[1041] | 690 | return fPrintSizeY; |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | void G4OpenGLViewer::setPrintSize(G4int X, G4int Y) { |
---|
| 694 | fPrintSizeX = X; |
---|
| 695 | fPrintSizeY = Y; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | void G4OpenGLViewer::setPrintFilename(G4String name,G4bool inc) { |
---|
| 699 | if (name != "") { |
---|
| 700 | fPrintFilename = name; |
---|
| 701 | } else { |
---|
| 702 | fPrintFilename = "G4OpenGL"; // by default |
---|
| 703 | } |
---|
| 704 | if (inc) { |
---|
| 705 | fPrintFilenameIndex=0; |
---|
| 706 | } else { |
---|
| 707 | fPrintFilenameIndex=-1; |
---|
| 708 | } |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | std::string G4OpenGLViewer::getRealPrintFilename() { |
---|
[1042] | 712 | std::string temp = fPrintFilename; |
---|
[1041] | 713 | if (fPrintFilenameIndex != -1) { |
---|
[1042] | 714 | temp += std::string("_"); |
---|
| 715 | std::ostringstream os; |
---|
| 716 | os << fPrintFilenameIndex; |
---|
| 717 | std::string nb_str = os.str(); |
---|
| 718 | temp += nb_str; |
---|
[1041] | 719 | } |
---|
| 720 | temp += ".eps"; |
---|
| 721 | return temp; |
---|
| 722 | } |
---|
| 723 | |
---|
[712] | 724 | GLdouble G4OpenGLViewer::getSceneNearWidth() |
---|
| 725 | { |
---|
| 726 | const G4Point3D targetPoint |
---|
| 727 | = fSceneHandler.GetScene()->GetStandardTargetPoint() |
---|
| 728 | + fVP.GetCurrentTargetPoint (); |
---|
| 729 | G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); |
---|
| 730 | if(radius<=0.) radius = 1.; |
---|
| 731 | const G4double cameraDistance = fVP.GetCameraDistance (radius); |
---|
| 732 | const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius); |
---|
| 733 | return 2 * fVP.GetFrontHalfHeight (pnear, radius); |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | GLdouble G4OpenGLViewer::getSceneFarWidth() |
---|
| 737 | { |
---|
| 738 | const G4Point3D targetPoint |
---|
| 739 | = fSceneHandler.GetScene()->GetStandardTargetPoint() |
---|
| 740 | + fVP.GetCurrentTargetPoint (); |
---|
| 741 | G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); |
---|
| 742 | if(radius<=0.) radius = 1.; |
---|
| 743 | const G4double cameraDistance = fVP.GetCameraDistance (radius); |
---|
| 744 | const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius); |
---|
| 745 | const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius); |
---|
| 746 | return 2 * fVP.GetFrontHalfHeight (pfar, radius); |
---|
| 747 | } |
---|
| 748 | |
---|
| 749 | |
---|
| 750 | GLdouble G4OpenGLViewer::getSceneDepth() |
---|
| 751 | { |
---|
| 752 | const G4Point3D targetPoint |
---|
| 753 | = fSceneHandler.GetScene()->GetStandardTargetPoint() |
---|
| 754 | + fVP.GetCurrentTargetPoint (); |
---|
| 755 | G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); |
---|
| 756 | if(radius<=0.) radius = 1.; |
---|
| 757 | const G4double cameraDistance = fVP.GetCameraDistance (radius); |
---|
| 758 | const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius); |
---|
| 759 | return fVP.GetFarDistance (cameraDistance, pnear, radius)- pnear; |
---|
| 760 | } |
---|
| 761 | |
---|
| 762 | |
---|
[593] | 763 | |
---|
[798] | 764 | void G4OpenGLViewer::rotateScene(G4double dx, G4double dy,G4double deltaRotation) |
---|
| 765 | { |
---|
| 766 | |
---|
| 767 | G4Vector3D vp; |
---|
| 768 | G4Vector3D up; |
---|
| 769 | |
---|
| 770 | G4Vector3D xprime; |
---|
| 771 | G4Vector3D yprime; |
---|
| 772 | G4Vector3D zprime; |
---|
| 773 | |
---|
| 774 | G4double delta_alpha; |
---|
| 775 | G4double delta_theta; |
---|
| 776 | |
---|
| 777 | G4Vector3D new_vp; |
---|
| 778 | G4Vector3D new_up; |
---|
| 779 | |
---|
| 780 | G4double cosalpha; |
---|
| 781 | G4double sinalpha; |
---|
| 782 | |
---|
| 783 | G4Vector3D a1; |
---|
| 784 | G4Vector3D a2; |
---|
| 785 | G4Vector3D delta; |
---|
| 786 | G4Vector3D viewPoint; |
---|
| 787 | |
---|
| 788 | |
---|
| 789 | //phi spin stuff here |
---|
| 790 | |
---|
| 791 | vp = fVP.GetViewpointDirection ().unit (); |
---|
| 792 | up = fVP.GetUpVector ().unit (); |
---|
| 793 | |
---|
| 794 | yprime = (up.cross(vp)).unit(); |
---|
| 795 | zprime = (vp.cross(yprime)).unit(); |
---|
| 796 | |
---|
| 797 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 798 | delta_alpha = dy * deltaRotation; |
---|
| 799 | delta_theta = -dx * deltaRotation; |
---|
| 800 | } else { |
---|
| 801 | delta_alpha = -dy * deltaRotation; |
---|
| 802 | delta_theta = dx * deltaRotation; |
---|
| 803 | } |
---|
| 804 | |
---|
| 805 | delta_alpha *= deg; |
---|
| 806 | delta_theta *= deg; |
---|
| 807 | |
---|
| 808 | new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; |
---|
| 809 | |
---|
| 810 | // to avoid z rotation flipping |
---|
| 811 | // to allow more than 360° rotation |
---|
[847] | 812 | |
---|
[801] | 813 | const G4Point3D targetPoint |
---|
| 814 | = fSceneHandler.GetScene()->GetStandardTargetPoint() |
---|
| 815 | + fVP.GetCurrentTargetPoint (); |
---|
| 816 | G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); |
---|
| 817 | if(radius<=0.) radius = 1.; |
---|
| 818 | const G4double cameraDistance = fVP.GetCameraDistance (radius); |
---|
| 819 | const G4Point3D cameraPosition = |
---|
| 820 | targetPoint + cameraDistance * fVP.GetViewpointDirection().unit(); |
---|
| 821 | |
---|
[798] | 822 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 823 | new_up = (new_vp.cross(yprime)).unit(); |
---|
| 824 | if (new_vp.z()*vp.z() <0) { |
---|
| 825 | new_up.set(new_up.x(),-new_up.y(),new_up.z()); |
---|
| 826 | } |
---|
| 827 | } else { |
---|
| 828 | new_up = up; |
---|
| 829 | if (new_vp.z()*vp.z() <0) { |
---|
| 830 | new_up.set(new_up.x(),-new_up.y(),new_up.z()); |
---|
| 831 | } |
---|
| 832 | } |
---|
| 833 | fVP.SetUpVector(new_up); |
---|
| 834 | //////////////// |
---|
| 835 | // Rotates by fixed azimuthal angle delta_theta. |
---|
| 836 | |
---|
| 837 | cosalpha = new_up.dot (new_vp.unit()); |
---|
| 838 | sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); |
---|
| 839 | yprime = (new_up.cross (new_vp.unit())).unit (); |
---|
| 840 | xprime = yprime.cross (new_up); |
---|
| 841 | // Projection of vp on plane perpendicular to up... |
---|
| 842 | a1 = sinalpha * xprime; |
---|
| 843 | // Required new projection... |
---|
| 844 | a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); |
---|
| 845 | // Required Increment vector... |
---|
| 846 | delta = a2 - a1; |
---|
| 847 | // So new viewpoint is... |
---|
| 848 | viewPoint = new_vp.unit() + delta; |
---|
| 849 | |
---|
| 850 | fVP.SetViewAndLights (viewPoint); |
---|
| 851 | } |
---|
| 852 | |
---|
[529] | 853 | #endif |
---|