internal void correctCameraPositionForIncludingTextLabels(ViewPort viewport) { _cam.SetViewPort(viewport); _cam.shoot(_cameraMode); _axe.Draw(_cam); Clear(); AxeBox abox = (AxeBox)_axe; BoundingBox3d newBounds = abox.WholeBounds.scale(_scaling); if (_viewmode == Modes.ViewPositionMode.TOP) { float radius = (float)Math.Max(newBounds.xmax - newBounds.xmin, newBounds.ymax - newBounds.ymin); radius += radius * STRETCH_RATIO; _cam.RenderingSphereRadius = radius; } else { _cam.RenderingSphereRadius = (float)newBounds.getRadius(); Coord3d target = newBounds.getCenter(); Coord3d eye = _viewpoint.cartesian().@add(target); _cam.Target = target; _cam.Eye = eye; } }
internal void ApplyViewPort() { //Stretch projection on the whole viewport if (_stretchToFill) { _screenXOffset = _screenLeft; _screenYOffset = 0; GL.Viewport(_screenXOffset, _screenYOffset, _screenWidth, _screenHeight); _lastViewPort = new ViewPort(_screenWidth, _screenHeight, _screenXOffset, _screenYOffset); //Set the projection into the largest square area centered in the window slice } else { _screenSquaredDim = Math.Min(_screenWidth, _screenHeight); _screenXOffset = _screenLeft + _screenWidth / 2 - _screenSquaredDim / 2; _screenYOffset = _screenHeight / 2 - _screenSquaredDim / 2; GL.Viewport(_screenXOffset, _screenYOffset, _screenSquaredDim, _screenSquaredDim); _lastViewPort = new ViewPort(_screenSquaredDim, _screenSquaredDim, _screenXOffset, _screenYOffset); } if (_screenGridDisplayed) { renderSubScreenGrid(); } }
/// <summary> /// Renders all provided Tooltips and Renderer2ds on top of /// the scene. /// /// Due to the behaviour of the Overlay implementation, Java2d /// geometries must be drawn relative to the Chart's /// IScreenCanvas, BUT will then be stretched to fit in the /// Camera's viewport. This bug is very important to consider, since /// the Camera's viewport may not occupy the full IScreenCanvas. /// Indeed, when View is not maximized (like the default behaviour), the /// viewport remains square and centered in the canvas, meaning the Overlay /// won't cover the full canvas area. /// /// In other words, the following piece of code draws a border around the /// View, and not around the complete chart canvas, although queried /// to occupy chart canvas dimensions: /// /// g2d.drawRect(1, 1, chart.getCanvas().getRendererWidth()-2, /// chart.getCanvas().getRendererHeight()-2); /// /// renderOverlay() must be called while the OpenGL2 context for the /// drawable is current, and after the OpenGL2 scene has been rendered. /// </summary> /// <param name="viewport"></param> /// <remarks></remarks> public void RenderOverlay(ViewPort viewport) { // NOT Implemented so far }
public void UpdateCamera(ViewPort viewport, BoundingBox3d boundsScaled, float sceneRadiusScaled) { Coord3d target = _center.multiply(_scaling); Coord3d eye = default(Coord3d); _viewpoint.z = sceneRadiusScaled * 2; // maintain a reasonnable distance to the scene for viewing it switch (_viewmode) { case Modes.ViewPositionMode.FREE: eye = _viewpoint.cartesian().@add(target); break; case Modes.ViewPositionMode.TOP: eye = _viewpoint; eye.x = -PI_div2; // on x eye.y = PI_div2; // on top eye = eye.cartesian().@add(target); break; case Modes.ViewPositionMode.PROFILE: eye = _viewpoint; eye.y = 0; eye = eye.cartesian().@add(target); break; default: throw new Exception("Unsupported viewmode : " + _viewmode); } Coord3d up = default(Coord3d); if (Math.Abs(_viewpoint.y) == PI_div2) { // handle up vector Coord2d direction = new Coord2d(_viewpoint.x, _viewpoint.y).cartesian(); if (_viewpoint.y > 0) { // on top up = new Coord3d(-direction.x, -direction.y, 0); } else { up = new Coord3d(direction.x, direction.y, 0); } // handle "on-top" events if (!_wasOnTopAtLastRendering) { _wasOnTopAtLastRendering = true; fireViewOnTopEvent(true); } } else { // handle up vector up = new Coord3d(0, 0, 1); // handle "on-top" events if (_wasOnTopAtLastRendering) { _wasOnTopAtLastRendering = false; fireViewOnTopEvent(false); } } // Apply camera settings _cam.Target = target; _cam.Up = up; _cam.Eye = eye; // Set rendering volume if (_viewmode == Modes.ViewPositionMode.TOP) { _cam.RenderingSphereRadius = (float)(Math.Max(boundsScaled.xmax - boundsScaled.xmin, boundsScaled.ymax - boundsScaled.ymin) / 2); // correctCameraPositionForIncludingTextLabels(viewport) ' quite experimental ! } else { _cam.RenderingSphereRadius = sceneRadiusScaled; } // Setup camera (i.e. projection matrix) //cam.setViewPort(canvas.getRendererWidth(), // canvas.getRendererHeight(), left, right); _cam.SetViewPort(viewport); _cam.shoot(_cameraMode); }
public void UpdateCamera(ViewPort viewport, BoundingBox3d boundsScaled) { UpdateCamera(viewport, boundsScaled, (float)boundsScaled.getRadius()); }