| 221 | |
| 222 | |
| 223 | void G4OpenGLViewer::SetView () { |
| 224 | // if getting pick infos, should not resize the view. |
| 225 | if (fIsGettingPickInfos) return; |
| 226 | |
| 227 | if (!fSceneHandler.GetScene()) { |
| 228 | return; |
| 229 | } |
| 230 | // Calculates view representation based on extent of object being |
| 231 | // viewed and (initial) viewpoint. (Note: it can change later due |
| 232 | // to user interaction via visualization system's GUI.) |
| 233 | |
| 234 | // Lighting. |
| 235 | GLfloat lightPosition [4]; |
| 236 | lightPosition [0] = fVP.GetActualLightpointDirection().x(); |
| 237 | lightPosition [1] = fVP.GetActualLightpointDirection().y(); |
| 238 | lightPosition [2] = fVP.GetActualLightpointDirection().z(); |
| 239 | lightPosition [3] = 0.; |
| 240 | // Light position is "true" light direction, so must come after gluLookAt. |
| 241 | GLfloat ambient [] = { 0.2f, 0.2f, 0.2f, 1.f}; |
| 242 | GLfloat diffuse [] = { 0.8f, 0.8f, 0.8f, 1.f}; |
| 243 | glEnable (GL_LIGHT0); |
| 244 | glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); |
| 245 | glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); |
| 246 | |
| 247 | G4double ratioX = 1; |
| 248 | G4double ratioY = 1; |
| 249 | if (fWinSize_y > fWinSize_x) { |
| 250 | ratioX = ((G4double)fWinSize_y) / ((G4double)fWinSize_x); |
| 251 | } |
| 252 | if (fWinSize_x > fWinSize_y) { |
| 253 | ratioY = ((G4double)fWinSize_x) / ((G4double)fWinSize_y); |
| 254 | } |
| 255 | |
| 256 | // Get radius of scene, etc. |
| 257 | // Note that this procedure properly takes into account zoom, dolly and pan. |
| 258 | const G4Point3D targetPoint |
| 259 | = fSceneHandler.GetScene()->GetStandardTargetPoint() |
| 260 | + fVP.GetCurrentTargetPoint (); |
| 261 | G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); |
| 262 | if(radius<=0.) radius = 1.; |
| 263 | const G4double cameraDistance = fVP.GetCameraDistance (radius); |
| 264 | const G4Point3D cameraPosition = |
| 265 | targetPoint + cameraDistance * fVP.GetViewpointDirection().unit(); |
| 266 | const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius); |
| 267 | const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius); |
| 268 | const GLdouble right = fVP.GetFrontHalfHeight (pnear, radius) * ratioY; |
| 269 | const GLdouble left = -right; |
| 270 | const GLdouble top = fVP.GetFrontHalfHeight (pnear, radius) * ratioX; |
| 271 | const GLdouble bottom = -top; |
| 272 | |
| 273 | // FIXME |
| 274 | ResizeGLView(); |
| 275 | //SHOULD SetWindowsSizeHint()... |
| 276 | |
| 277 | glMatrixMode (GL_PROJECTION); // set up Frustum. |
| 278 | glLoadIdentity(); |
| 279 | |
| 280 | const G4Vector3D scaleFactor = fVP.GetScaleFactor(); |
no test coverage detected