예제 #1
0
파일: View.cs 프로젝트: kgfathur/nzy3d-api
        public BoundingBox3d computeScaling()
        {
            //-- Scale the scene's view -------------------
            if (Squared)
            {
                _scaling = Squarify();
            }
            else
            {
                _scaling = (Coord3d)Coord3d.IDENTITY.Clone();
            }
            // Compute the bounds for computing cam distance, clipping planes, etc ...
            if ((_targetBox == null))
            {
                _targetBox = new BoundingBox3d(0, 1, 0, 1, 0, 1);
            }
            BoundingBox3d boundsScaled = new BoundingBox3d();

            boundsScaled.Add(_targetBox.scale(_scaling));
            if (MAINTAIN_ALL_OBJECTS_IN_VIEW)
            {
                boundsScaled.Add(Scene.Graph.Bounds.scale(_scaling));
            }
            return(boundsScaled);
        }
예제 #2
0
        public void drawAxisTickNumericLabel(AxeDirection direction, Camera cam, Color color, Halign hAlign, Valign vAlign, BoundingBox3d ticksTxtBounds, String tickLabel,
                                             Coord3d tickPosition)
        {
            GL.LoadIdentity();
            GL.Scale(_scale.x, _scale.y, _scale.z);

            BoundingBox3d tickBounds = _txt.drawText(cam, tickLabel, tickPosition, hAlign, vAlign, color);

            if (tickBounds != null)
            {
                ticksTxtBounds.Add(tickBounds);
            }
        }
예제 #3
0
 public void drawAxisLabel(Camera cam, AxeDirection direction, Color color, BoundingBox3d ticksTxtBounds, double xlab, double ylab, double zlab, String axeLabel)
 {
     if ((direction == AxeDirection.AxeX && _layout.XAxeLabelDisplayed) ||
         (direction == AxeDirection.AxeY && _layout.YAxeLabelDisplayed) ||
         (direction == AxeDirection.AxeZ && _layout.ZAxeLabelDisplayed))
     {
         Coord3d       labelPosition = new Coord3d(xlab, ylab, zlab);
         BoundingBox3d labelBounds   = _txt.drawText(cam, axeLabel, labelPosition, Halign.CENTER, Valign.CENTER, color);
         if (labelBounds != null)
         {
             ticksTxtBounds.Add(labelBounds);
         }
     }
 }
예제 #4
0
        public void Draw(Rendering.View.Camera camera)
        {
            // Set scaling
            GL.LoadIdentity();
            GL.Scale(_scale.x, _scale.y, _scale.z);
            // Set culling
            GL.Enable(EnableCap.CullFace);
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Front);
            // Draw cube in feedback buffer for computing hidden quads
            _quadIsHidden = getHiddenQuads(camera);
            // Plain part of quad making the surrounding box
            if (_layout.FaceDisplayed)
            {
                Color quadcolor = _layout.QuadColor;
                GL.PolygonMode(MaterialFace.Back, PolygonMode.Fill);
                GL.Color4(quadcolor.r, quadcolor.g, quadcolor.b, quadcolor.a);
                GL.LineWidth(1);
                GL.Enable(EnableCap.PolygonOffsetFill);
                GL.PolygonOffset(1, 1);
                // handle stippling
                drawCube(OpenTK.Graphics.RenderingMode.Render);
                GL.Disable(EnableCap.PolygonOffsetFill);
            }
            // Edge part of quads making the surrounding box
            Color gridcolor = _layout.GridColor;

            GL.PolygonMode(MaterialFace.Back, PolygonMode.Line);
            GL.Color4(gridcolor.r, gridcolor.g, gridcolor.b, gridcolor.a);
            GL.LineWidth(1);
            drawCube(OpenTK.Graphics.RenderingMode.Render);
            // Draw grids on non hidden quads
            GL.PolygonMode(MaterialFace.Back, PolygonMode.Line);
            GL.Color4(gridcolor.r, gridcolor.g, gridcolor.b, gridcolor.a);
            GL.LineWidth(1);
            GL.LineStipple(1, 0xaaaa);
            GL.Enable(EnableCap.LineStipple);
            for (int quad = 0; quad <= 5; quad++)
            {
                if ((!_quadIsHidden[quad]))
                {
                    drawGridOnQuad(quad);
                }
            }
            GL.Disable(EnableCap.LineStipple);
            // Draw ticks on the closest axes
            _wholeBounds.reset();
            _wholeBounds.Add(_boxBounds);
            //gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
            // Display x axis ticks
            if ((_xrange > 0 & _layout.XTickLabelDisplayed))
            {
                // If we are on top, we make direct axe placement
                if ((((_view != null) && _view.ViewMode == nzy3D.Plot3D.Rendering.View.Modes.ViewPositionMode.TOP)))
                {
                    BoundingBox3d bbox = drawTicks(camera, 1, AxeDirection.AxeX, _layout.XTickColor, Halign.LEFT, Valign.TOP);
                    // setup tick labels for X on the bottom
                    _wholeBounds.Add(bbox);
                }
                else
                {
                    // otherwise computed placement
                    int xselect = findClosestXaxe(camera);
                    if ((xselect >= 0))
                    {
                        BoundingBox3d bbox = drawTicks(camera, xselect, AxeDirection.AxeX, _layout.XTickColor);
                        _wholeBounds.Add(bbox);
                    }
                    else
                    {
                        //System.err.println("no x axe selected: " + Arrays.toString(quadIsHidden));
                        // HACK: handles "on top" view, when all face of cube are drawn, which forbid to select an axe automatically
                        BoundingBox3d bbox = drawTicks(camera, 2, AxeDirection.AxeX, _layout.XTickColor, Halign.CENTER, Valign.TOP);
                        _wholeBounds.Add(bbox);
                    }
                }
            }
            // Display y axis ticks
            if ((_yrange > 0 & _layout.YTickLabelDisplayed))
            {
                if ((((_view != null)) && _view.ViewMode == nzy3D.Plot3D.Rendering.View.Modes.ViewPositionMode.TOP))
                {
                    BoundingBox3d bbox = drawTicks(camera, 2, AxeDirection.AxeY, _layout.YTickColor, Halign.LEFT, Valign.GROUND);
                    // setup tick labels for Y on the left
                    _wholeBounds.Add(bbox);
                }
                else
                {
                    int yselect = findClosestYaxe(camera);
                    if ((yselect >= 0))
                    {
                        BoundingBox3d bbox = drawTicks(camera, yselect, AxeDirection.AxeY, _layout.YTickColor);
                        _wholeBounds.Add(bbox);
                    }
                    else
                    {
                        //System.err.println("no y axe selected: " + Arrays.toString(quadIsHidden));
                        // HACK: handles "on top" view, when all face of cube are drawn, which forbid to select an axe automatically
                        BoundingBox3d bbox = drawTicks(camera, 1, AxeDirection.AxeY, _layout.YTickColor, Halign.RIGHT, Valign.GROUND);
                        _wholeBounds.Add(bbox);
                    }
                }
            }
            // Display z axis ticks
            if ((_zrange > 0 & _layout.ZTickLabelDisplayed))
            {
                if ((((_view != null)) && _view.ViewMode == nzy3D.Plot3D.Rendering.View.Modes.ViewPositionMode.TOP))
                {
                }
                else
                {
                    int zselect = findClosestZaxe(camera);
                    if ((zselect >= 0))
                    {
                        BoundingBox3d bbox = drawTicks(camera, zselect, AxeDirection.AxeZ, _layout.ZTickColor);
                        _wholeBounds.Add(bbox);
                    }
                }
            }
            // Unset culling
            GL.Disable(EnableCap.CullFace);
        }