Пример #1
0
        public DepthBufferPrecision()
        {
            _globeShape = Ellipsoid.Wgs84;
            _nearDistance = 1;
            _cubeRootFarDistance = 300;

            _window = Device.CreateWindow(800, 600, "Chapter 6:  Depth Buffer Precision");
            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _window.Keyboard.KeyUp += OnKeyUp;
            _window.Keyboard.KeyDown += OnKeyDown;
            _sceneState = new SceneState();
            _sceneState.DiffuseIntensity = 0.45f;
            _sceneState.SpecularIntensity = 0.05f;
            _sceneState.AmbientIntensity = 0.5f;

            _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape);

            _sceneState.Camera.ZoomToTarget(_globeShape.MaximumRadius);

            ///////////////////////////////////////////////////////////////////

            _globe = new TessellatedGlobe();
            _globe.Shape = _globeShape;
            _globe.NumberOfSlicePartitions = 64;
            _globe.NumberOfStackPartitions = 32;
            _globe.Texture = Device.CreateTexture2D(new Bitmap("world_topo_bathy_200411_3x5400x2700.jpg"), TextureFormat.RedGreenBlue8, false);
            _globe.Textured = true;

            _plane = new Plane(_window.Context);
            _plane.XAxis = 0.6 * _globeShape.MaximumRadius * Vector3D.UnitX;
            _plane.YAxis = 0.6 * _globeShape.MinimumRadius * Vector3D.UnitZ;
            _plane.OutlineWidth = 3;
            _cubeRootPlaneHeight = 100.0;
            UpdatePlaneOrigin();

            _viewportQuad = new ViewportQuad(_window.Context, null);

            _framebuffer = _window.Context.CreateFramebuffer();
            _depthFormatIndex = 1;
            _depthTestLess = true;
            _logarithmicDepthConstant = 1;
            UpdatePlanesAndDepthTests();

            _clearState = new ClearState();

            ///////////////////////////////////////////////////////////////////

            _hudFont = new Font("Arial", 16);
            _hud = new HeadsUpDisplay();
            _hud.Color = Color.Blue;
            UpdateHUD();
        }
Пример #2
0
        public Curves()
        {
            _semiMinorAxis = Ellipsoid.ScaledWgs84.Radii.Z;
            SetShape();

            _window = Device.CreateWindow(800, 600, "Chapter 2:  Curves");
            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _window.Keyboard.KeyDown += OnKeyDown;
            _sceneState = new SceneState();
            _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape);

            _clearState = new ClearState();

            _texture = Device.CreateTexture2D(new Texture2DDescription(1, 1, TextureFormat.RedGreenBlue8));
            WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream, 3);
            pixelBuffer.CopyFromSystemMemory(new byte[] { 0, 255, 127 });
            _texture.CopyFromBuffer(pixelBuffer, ImageFormat.RedGreenBlue, ImageDatatype.UnsignedByte, 1);

            _instructions = new HeadsUpDisplay();
            _instructions.Color = Color.Black;
            
            _sampledPoints = new BillboardCollection(_window.Context);
            _sampledPoints.Texture = Device.CreateTexture2D(Device.CreateBitmapFromPoint(8), TextureFormat.RedGreenBlueAlpha8, false);
            _sampledPoints.DepthTestEnabled = false;
            
            _ellipsoid = new RayCastedGlobe(_window.Context);
            _ellipsoid.Texture = _texture;

            _polyline = new Polyline();
            _polyline.Width = 3;
            _polyline.DepthTestEnabled = false;

            _plane = new Plane(_window.Context);
            _plane.Origin = Vector3D.Zero;
            _plane.OutlineWidth = 3;

            CreateScene();
            
            ///////////////////////////////////////////////////////////////////

            _sceneState.Camera.Eye = Vector3D.UnitY;
            _sceneState.Camera.ZoomToTarget(2 * _globeShape.MaximumRadius);
        }
        private void CreateScene()
        {
            DisposeScene();

            _ellipsoid = new TessellatedGlobe();
            _ellipsoid.Shape = _globeShape;
            _ellipsoid.NumberOfSlicePartitions = 64;
            _ellipsoid.NumberOfStackPartitions = 32;

            ///////////////////////////////////////////////////////////////////

            Mesh mesh = GeographicGridEllipsoidTessellator.Compute(_globeShape,
                64, 32, GeographicGridEllipsoidVertexAttributes.Position);

            _wireframe = new Wireframe(_window.Context, mesh);
            _wireframe.Width = 2;

            ///////////////////////////////////////////////////////////////////

            _axes = new Axes();
            _axes.Length = 1.5;
            _axes.Width = 3;

            ///////////////////////////////////////////////////////////////////

            Vector3D p = _globeShape.ToVector3D(new Geodetic3D(0, Trig.ToRadians(45), 0));
            Vector3D deticNormal = _globeShape.GeodeticSurfaceNormal(p);
            Vector3D centricNormal = Ellipsoid.CentricSurfaceNormal(p);

            double normalLength = _globeShape.MaximumRadius;
            Vector3D pDetic = p + (normalLength * deticNormal);
            Vector3D pCentric = p + (normalLength * centricNormal);

            VertexAttributeFloatVector3 positionAttribute = new VertexAttributeFloatVector3("position", 4);
            positionAttribute.Values.Add(p.ToVector3F());
            positionAttribute.Values.Add(pDetic.ToVector3F());
            positionAttribute.Values.Add(p.ToVector3F());
            positionAttribute.Values.Add(pCentric.ToVector3F());

            VertexAttributeRGBA colorAttribute = new VertexAttributeRGBA("color", 4);
            colorAttribute.AddColor(Color.DarkGreen);
            colorAttribute.AddColor(Color.DarkGreen);
            colorAttribute.AddColor(Color.DarkCyan);
            colorAttribute.AddColor(Color.DarkCyan);

            Mesh polyline = new Mesh();
            polyline.PrimitiveType = PrimitiveType.Lines;
            polyline.Attributes.Add(positionAttribute);
            polyline.Attributes.Add(colorAttribute);

            _normals = new Polyline();
            _normals.Set(_window.Context, polyline);
            _normals.Width = 3;

            ///////////////////////////////////////////////////////////////////
            Font font = new Font("Arial", 24);
            IList<Bitmap> labelBitmaps = new List<Bitmap>(2);
            labelBitmaps.Add(Device.CreateBitmapFromText("Geodetic", font));
            labelBitmaps.Add(Device.CreateBitmapFromText("Geocentric", font));
            font.Dispose();

            TextureAtlas atlas = new TextureAtlas(labelBitmaps);

            _labels = new BillboardCollection(_window.Context, 2);
            _labels.Texture = Device.CreateTexture2D(atlas.Bitmap, TextureFormat.RedGreenBlueAlpha8, false);
            _labels.Add(new Billboard()
            {
                Position = pDetic,
                TextureCoordinates = atlas.TextureCoordinates[0],
                Color = Color.DarkGreen,
                HorizontalOrigin = HorizontalOrigin.Right,
                VerticalOrigin = VerticalOrigin.Bottom
            });
            _labels.Add(new Billboard()
            {
                Position = pCentric,
                TextureCoordinates = atlas.TextureCoordinates[1],
                Color = Color.DarkCyan,
                HorizontalOrigin = HorizontalOrigin.Right,
                VerticalOrigin = VerticalOrigin.Bottom
            });

            atlas.Dispose();

            ///////////////////////////////////////////////////////////////////
            Vector3D east = Vector3D.UnitZ.Cross(deticNormal);
            Vector3D north = deticNormal.Cross(east);

            _tangentPlane = new Plane(_window.Context);
            _tangentPlane.Origin = p;
            _tangentPlane.XAxis = east;
            _tangentPlane.YAxis = north;
            _tangentPlane.OutlineWidth = 3;
        }