Example #1
0
 public void Render(Context context, SceneState sceneState)
 {
     _pointSize.Value = (float)(8.0 * sceneState.HighResolutionSnapScale);
     
     context.Draw(PrimitiveType.Triangles, 0, 6, _drawState, sceneState);
     context.Draw(PrimitiveType.Points, 6, 1, _drawState, sceneState);
 }
        private void Update(SceneState sceneState)
        {
            Vector3D eye = sceneState.Camera.Eye;

            //
            // Eye change means view matrix changed, so recompute
            // model-view-perspective relative to center.
            //
            if (_eye != eye)
            {
                _eye = eye;

                Matrix4D m = sceneState.ModelViewMatrix;
                Vector4D centerEye = m * new Vector4D(_center, 1.0);
                Matrix4D mv = new Matrix4D(
                    m.Column0Row0, m.Column1Row0, m.Column2Row0, centerEye.X,
                    m.Column0Row1, m.Column1Row1, m.Column2Row1, centerEye.Y,
                    m.Column0Row2, m.Column1Row2, m.Column2Row2, centerEye.Z,
                    m.Column0Row3, m.Column1Row3, m.Column2Row3, m.Column3Row3);

                _modelViewPerspectiveMatrixRelativeToCenter.Value =
                    (sceneState.PerspectiveMatrix * mv).ToMatrix4F();
            }

            _pointSize.Value = (float)(8.0 * sceneState.HighResolutionSnapScale);
        }
        public TerrainRayCasting()
        {
            _window = Device.CreateWindow(800, 600, "Chapter 11:  Terrain Ray Casting");
            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _window.Keyboard.KeyDown += OnKeyDown;
            _sceneState = new SceneState();
            _sceneState.Camera.PerspectiveFarPlaneDistance = 4096;
            _clearState = new ClearState();

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

            TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap(@"ps-e.lg.png"));
            _tile = new RayCastedTerrainTile(terrainTile);
            _tile.HeightExaggeration = 30;

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

            double tileRadius = Math.Max(terrainTile.Resolution.X, terrainTile.Resolution.Y) * 0.5;
            _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere);
            _camera.CenterPoint = new Vector3D(terrainTile.Resolution.X * 0.5, terrainTile.Resolution.Y * 0.5, 0.0);
            _camera.MinimumRotateRate = 1.0;
            _camera.MaximumRotateRate = 1.0;
            _camera.RotateRateRangeAdjustment = 0.0;
            _camera.RotateFactor = 0.0;
            _sceneState.Camera.ZoomToTarget(tileRadius);
            
            ///////////////////////////////////////////////////////////////////

            _hudFont = new Font("Arial", 16);
            _hud = new HeadsUpDisplay();
            _hud.Color = Color.Black;
            UpdateHUD();
        }
Example #4
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(sceneState);
            Verify.ThrowInvalidOperationIfNull(Texture, "Texture");

            Clean(context);

            if (ShowGlobe)
            {
                Vector3D eye = sceneState.Camera.Eye;
                Vector3F cameraEyeSquared = eye.MultiplyComponents(eye).ToVector3F();

                if (Shade)
                {
                    context.TextureUnits[0].Texture = Texture;
                    context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearClamp;
                    _cameraEyeSquared.Value = cameraEyeSquared;
                    context.Draw(_primitiveType, _drawState, sceneState);
                }
                else
                {
                    _cameraEyeSquaredSolid.Value = cameraEyeSquared;
                    context.Draw(_primitiveType, _drawStateSolid, sceneState);
                }
            }

            if (ShowWireframeBoundingBox)
            {
                _wireframe.Render(context, sceneState);
            }
        }
        private void Update(SceneState sceneState)
        {
            Vector3D eye = sceneState.Camera.Eye;

            if (_eye != eye)
            {
                _eye = eye;

                Matrix4D m = sceneState.ModelViewMatrix;
                Matrix4D mv = new Matrix4D(
                    m.Column0Row0, m.Column1Row0, m.Column2Row0, 0.0,
                    m.Column0Row1, m.Column1Row1, m.Column2Row1, 0.0,
                    m.Column0Row2, m.Column1Row2, m.Column2Row2, 0.0,
                    m.Column0Row3, m.Column1Row3, m.Column2Row3, m.Column3Row3);

                _modelViewPerspectiveMatrixRelativeToEye.Value = 
                    (sceneState.PerspectiveMatrix * mv).ToMatrix4F();

                for (int i = 0; i < _positions.Length; ++i)
                {
                    _positionsRelativeToEye[i] = (_positions[i] - eye).ToVector3F();
                }

                _positionBuffer.CopyFromSystemMemory(_positionsRelativeToEye);
            }

            _pointSize.Value = (float)(8.0 * sceneState.HighResolutionSnapScale);
        }
        public EllipsoidSurfaceNormals()
        {
            _globeShape = new Ellipsoid(1, 1, _semiMinorAxis);

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

            _instructions = new HeadsUpDisplay();
            _instructions.Texture = Device.CreateTexture2D(
                Device.CreateBitmapFromText("Up - Increase semi-minor axis\nDown - Decrease semi-minor axis", 
                    new Font("Arial", 24)),
                TextureFormat.RedGreenBlueAlpha8, false);
            _instructions.Color = Color.Black;

            _clearState = new ClearState();

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

            _sceneState.Camera.Eye = Vector3D.UnitY;
            _sceneState.Camera.ZoomToTarget(2 * _globeShape.MaximumRadius);
        }
Example #7
0
 protected void SetDrawAutomaticUniforms(Context context, DrawState drawState, SceneState sceneState)
 {
     for (int i = 0; i < _drawAutomaticUniforms.Count; ++i)
     {
         _drawAutomaticUniforms[i].Set(context, drawState, sceneState);
     }
 }
Example #8
0
 public static void ThrowIfNull(SceneState sceneState)
 {
     if (sceneState == null)
     {
         throw new ArgumentNullException("sceneState");
     }
 }
Example #9
0
        public GlobeRayCasting()
        {
            Ellipsoid globeShape = Ellipsoid.ScaledWgs84;

            _window = Device.CreateWindow(800, 600, "Chapter 4:  Globe Ray Casting");
            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _sceneState = new SceneState();
            _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape);
            _clearState = new ClearState();

            _window.Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e)
            {
                if (e.Key == KeyboardKey.P)
                {
                    CenterCameraOnPoint();
                }
                else if (e.Key == KeyboardKey.C)
                {
                    CenterCameraOnGlobeCenter();
                }
            };

            Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg");
            _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false);

            _globe = new RayCastedGlobe(_window.Context);
            _globe.Shape = globeShape;
            _globe.Texture = _texture;
            _globe.ShowWireframeBoundingBox = true;

            _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius);
        }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     //
     // viewport.Bottom should really be used but Rectangle goes top to botom, not bottom to top.
     //
     Rectangle viewport = context.Viewport;
     _uniform.Value = new Vector2F(1.0f / (float)viewport.Width, 1.0f / (float)viewport.Height);
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = new Vector4F(
         sceneState.DiffuseIntensity,
         sceneState.SpecularIntensity,
         sceneState.AmbientIntensity,
         sceneState.Shininess);
 }
Example #12
0
        public override void Set(Context context, DrawState drawState, SceneState sceneState)
        {
            //
            // viewport.Bottom should really be used but Rectangle goes top to botom, not bottom to top.
            //
            Rectangle viewport = context.Viewport;

            _uniform.Value = new Vector4F(viewport.Left, viewport.Top, viewport.Width, viewport.Height);
        }
Example #13
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(sceneState);

            _lineWidth.Value = (float)(0.5 * Width * sceneState.HighResolutionSnapScale);

            context.Draw(_primitiveType, _drawState, sceneState);
        }
        private void Update(Context context, SceneState sceneState)
        {
            if (_meshBuffers != null)
            {
                if (_drawState.VertexArray != null)
                {
                    _drawState.VertexArray.Dispose();
                    _drawState.VertexArray = null;
                }

                _drawState.VertexArray = context.CreateVertexArray(_meshBuffers);
                _meshBuffers = null;
            }

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

            int width = (int)Math.Ceiling(Width * sceneState.HighResolutionSnapScale);
            int outlineWidth = (int)Math.Ceiling(OutlineWidth * sceneState.HighResolutionSnapScale);

            int textureWidth = width + outlineWidth + outlineWidth + 2;

            if ((_texture == null) || (_texture.Description.Width != textureWidth))
            {
                int textureResolution = textureWidth * 2;

                float[] texels = new float[textureResolution];

                int k = 3;
                for (int i = 1; i < textureWidth - 1; ++i)
                {
                    texels[k] = 1;                  // Alpha (stored in Green channel)
                    k += 2;
                }

                int j = (outlineWidth + 1) * 2;
                for (int i = 0; i < width; ++i)
                {
                    texels[j] = 1;                  // Fill/Outline (stored in Red channel)
                    j += 2;
                }

                WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream,
                    sizeof(float) * textureResolution);
                pixelBuffer.CopyFromSystemMemory(texels);

                if (_texture != null)
                {
                    _texture.Dispose();
                    _texture = null;
                }

                // TODO:  Why does only Float or HalfFloat work here?
                _texture = Device.CreateTexture2D(new Texture2DDescription(textureWidth, 1, TextureFormat.RedGreen8));
                _texture.CopyFromBuffer(pixelBuffer, ImageFormat.RedGreen, ImageDatatype.Float);
            }
        }
        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();
        }
Example #16
0
        public ClipmapUpdater(Context context, ClipmapLevel[] clipmapLevels)
        {
            ShaderVertexAttributeCollection vertexAttributes = new ShaderVertexAttributeCollection();
            vertexAttributes.Add(new ShaderVertexAttribute("position", VertexLocations.Position, ShaderVertexAttributeType.FloatVector2, 1));

            Mesh unitQuad = RectangleTessellator.Compute(new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0)), 1, 1);
            _unitQuad = context.CreateVertexArray(unitQuad, vertexAttributes, BufferHint.StaticDraw);
            _unitQuadPrimitiveType = unitQuad.PrimitiveType;
            _sceneState = new SceneState();
            _framebuffer = context.CreateFramebuffer();

            _updateShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpdateVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpdateFS.glsl"));
            _updateTexelOutput = _updateShader.FragmentOutputs["texelOutput"];
            _updateDrawState = new DrawState(new RenderState(), _updateShader, _unitQuad);
            _updateDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _updateDrawState.RenderState.DepthTest.Enabled = false;
            _updateDestinationOffset = (Uniform<Vector2F>)_updateShader.Uniforms["u_destinationOffset"];
            _updateUpdateSize = (Uniform<Vector2F>)_updateShader.Uniforms["u_updateSize"];
            _updateSourceOrigin = (Uniform<Vector2F>)_updateShader.Uniforms["u_sourceOrigin"];

            _upsampleShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpsampleVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpsampleFS.glsl"));
            _upsampleTexelOutput = _upsampleShader.FragmentOutputs["texelOutput"];
            _upsampleDrawState = new DrawState(new RenderState(), _upsampleShader, _unitQuad);
            _upsampleDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _upsampleDrawState.RenderState.DepthTest.Enabled = false;
            _upsampleSourceOrigin = (Uniform<Vector2F>)_upsampleShader.Uniforms["u_sourceOrigin"];
            _upsampleUpdateSize = (Uniform<Vector2F>)_upsampleShader.Uniforms["u_updateSize"];
            _upsampleDestinationOffset = (Uniform<Vector2F>)_upsampleShader.Uniforms["u_destinationOffset"];
            _upsampleOneOverTextureSize = (Uniform<Vector2F>)_upsampleShader.Uniforms["u_oneOverTextureSize"];

            _computeNormalsShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapComputeNormalsVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapComputeNormalsFS.glsl"));
            _normalOutput = _computeNormalsShader.FragmentOutputs["normalOutput"];
            _computeNormalsDrawState = new DrawState(new RenderState(), _computeNormalsShader, _unitQuad);
            _computeNormalsDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _computeNormalsDrawState.RenderState.DepthTest.Enabled = false;
            _computeNormalsOrigin = (Uniform<Vector2F>)_computeNormalsShader.Uniforms["u_origin"];
            _computeNormalsUpdateSize = (Uniform<Vector2F>)_computeNormalsShader.Uniforms["u_updateSize"];
            _computeNormalsOneOverHeightMapSize = (Uniform<Vector2F>)_computeNormalsShader.Uniforms["u_oneOverHeightMapSize"];
            _heightExaggeration = (Uniform<float>)_computeNormalsShader.Uniforms["u_heightExaggeration"];
            _postDelta = (Uniform<float>)_computeNormalsShader.Uniforms["u_postDelta"];

            HeightExaggeration = 1.0f;

            ClipmapLevel levelZero = clipmapLevels[0];
            InitializeRequestThreads(context, _terrain, levelZero, levelZero.Terrain);
            InitializeRequestThreads(context, _imagery, levelZero, levelZero.Imagery);
        }
Example #17
0
        public HighResolutionSnap(GraphicsWindow window, SceneState sceneState)
        {
            _window     = window;
            _sceneState = sceneState;

            window.Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e)
            {
                if (e.Key == KeyboardKey.Space)
                {
                    Enable(true);
                }
            };
        }
Example #18
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowInvalidOperationIfNull(Texture, "Texture");

            _geometry.Update(context, _drawState.ShaderProgram);

            context.TextureUnits[0].Texture = Texture;
            context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearClamp;
            _drawState.VertexArray = _geometry.VertexArray;

            context.Draw(PrimitiveType.TriangleStrip, _drawState, sceneState);
        }
        public HighResolutionSnap(GraphicsWindow window, SceneState sceneState)
        {
            _window = window;
            _sceneState = sceneState;

            window.Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e)
            {
                if (e.Key == KeyboardKey.Space)
                {
                    Enable(true);
                }
            };
        }
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(sceneState);

            if (_drawState.ShaderProgram != null)
            {
                double fillDistance = Width * 0.5 * sceneState.HighResolutionSnapScale;
                _fillDistance.Value = (float)(fillDistance);
                _outlineDistance.Value = (float)(fillDistance + (OutlineWidth * sceneState.HighResolutionSnapScale));

                context.Draw(_primitiveType, _drawState, sceneState);
            }
        }
Example #21
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowInvalidOperationIfNull(Texture, "Texture");

            Update(context);

            if (_drawState.VertexArray != null)
            {
                context.TextureUnits[0].Texture = Texture;
                context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearClamp;
                context.Draw(PrimitiveType.Points, _drawState, sceneState);
            }
        }
Example #22
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(sceneState);

            if (Show)
            {
                if (_drawState.ShaderProgram != null)
                {
                    _fillDistance.Value = (float)(Width * 0.5 * sceneState.HighResolutionSnapScale);

                    context.Draw(_primitiveType, _drawState, sceneState);
                }
            }
        }
Example #23
0
        public Multithreading()
        {
            Ellipsoid globeShape = Ellipsoid.ScaledWgs84;

            _workerWindow = Device.CreateWindow(1, 1);
            _window = Device.CreateWindow(800, 600, "Chapter 10:  Multithreading");
            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _sceneState = new SceneState();
            _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape);
            _clearState = new ClearState();

            Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg");
            _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false);

            _globe = new RayCastedGlobe(_window.Context);
            _globe.Shape = globeShape;
            _globe.Texture = _texture;
            _globe.UseAverageDepth = true;

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

            _doneQueue.MessageReceived += ProcessNewShapefile;

            _requestQueue.MessageReceived += new ShapefileWorker(_workerWindow.Context, globeShape, _doneQueue).Process;

            // 2ND_EDITION:  Draw order
            _requestQueue.Post(new ShapefileRequest("110m_admin_0_countries.shp", 
                new ShapefileAppearance()));
            _requestQueue.Post(new ShapefileRequest("110m_admin_1_states_provinces_lines_shp.shp", 
                new ShapefileAppearance()));
            _requestQueue.Post(new ShapefileRequest("airprtx020.shp", 
                new ShapefileAppearance() { Bitmap = new Bitmap("paper-plane--arrow.png") }));
            _requestQueue.Post(new ShapefileRequest("amtrakx020.shp", 
                new ShapefileAppearance() { Bitmap = new Bitmap("car-red.png") }));
            _requestQueue.Post(new ShapefileRequest("110m_populated_places_simple.shp", 
                new ShapefileAppearance() { Bitmap = new Bitmap("032.png") }));

#if SINGLE_THREADED
            _requestQueue.ProcessQueue();
#else
            _requestQueue.StartInAnotherThread();
#endif

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

            _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius);
        }
Example #24
0
        public Jitter()
        {
            _window = Device.CreateWindow(800, 600, "Chapter 5:  Jitter");
            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _window.Keyboard.KeyUp += OnKeyUp;
            _sceneState = new SceneState();
            _clearState = new ClearState();

            _hudFont = new Font("Arial", 16);
            _hud = new HeadsUpDisplay();
            _hud.Color = Color.Black;

            CreateCamera();
            CreateAlgorithm();
        }
Example #25
0
        private void RenderPoint(string vs)
        {
            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
                    using (ShaderProgram sp = Device.CreateShaderProgram(vs, ShaderSources.PassThroughFragmentShader()))
                        using (VertexArray va = TestUtility.CreateVertexArray(window.Context, sp.VertexAttributes["position"].Location))
                        {
                            SceneState sceneState = new SceneState();
                            sceneState.Camera.Eye    = 2 * Vector3D.UnitX;
                            sceneState.Camera.Target = Vector3D.Zero;
                            sceneState.Camera.Up     = Vector3D.UnitZ;

                            window.Context.Framebuffer = framebuffer;
                            window.Context.Draw(PrimitiveType.Points, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), sceneState);
                            TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);
                        }
        }
        public ClipmapTerrainOnGlobe()
        {
            _window = Device.CreateWindow(800, 600, "Chapter 13:  Clipmap Terrain on a Globe");

            _ellipsoid = Ellipsoid.Wgs84;

            WorldWindTerrainSource terrainSource = new WorldWindTerrainSource();
            EsriRestImagery imagery = new EsriRestImagery();
            _clipmap = new GlobeClipmapTerrain(_window.Context, terrainSource, imagery, _ellipsoid, 511);
            _clipmap.HeightExaggeration = 1.0f;

            _sceneState = new SceneState();
            _sceneState.DiffuseIntensity = 0.90f;
            _sceneState.SpecularIntensity = 0.05f;
            _sceneState.AmbientIntensity = 0.05f;
            _sceneState.Camera.FieldOfViewY = Math.PI / 3.0;

            _clearState = new ClearState();
            _clearState.Color = Color.White;

            _sceneState.Camera.PerspectiveNearPlaneDistance = 0.000001 * _ellipsoid.MaximumRadius;
            _sceneState.Camera.PerspectiveFarPlaneDistance = 10.0 * _ellipsoid.MaximumRadius;
            _sceneState.SunPosition = new Vector3D(200000, 300000, 200000) * _ellipsoid.MaximumRadius;

             _lookCamera = new CameraLookAtPoint(_sceneState.Camera, _window, _ellipsoid);
             _lookCamera.Range = 1.5 * _ellipsoid.MaximumRadius;

             _globe = new RayCastedGlobe(_window.Context);
             _globe.Shape = _ellipsoid;
             Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg");
             _globe.Texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false);

             _clearDepth = new ClearState();
             _clearDepth.Buffers = ClearBuffers.DepthBuffer | ClearBuffers.StencilBuffer;

            _window.Keyboard.KeyDown += OnKeyDown;

            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _window.PreRenderFrame += OnPreRenderFrame;

            _hudFont = new Font("Arial", 16);
            _hud = new HeadsUpDisplay();
            _hud.Color = Color.Blue;
            UpdateHUD();
        }
Example #27
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);

            Clean(context);

            if (_textured.Value)
            {
                Verify.ThrowInvalidOperationIfNull(Texture, "Texture");
                context.TextureUnits[0].Texture = Texture;
                context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearClamp;
            }

            _drawState.RenderState.RasterizationMode = Wireframe ? RasterizationMode.Line : RasterizationMode.Fill;

            context.Draw(_primitiveType, _drawState, sceneState);
        }
Example #28
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);
        }
        public override void Set(Context context, DrawState drawState, SceneState sceneState)
        {
            Camera camera       = sceneState.Camera;
            double theta        = camera.FieldOfViewX * 0.5;
            double phi          = camera.FieldOfViewY * 0.5;
            double nearDistance = camera.PerspectiveNearPlaneDistance;

            //
            // Coordinate system for the near plane:  origin is at center, x and y
            // span [-1, 1] just like noramlized device coordinates.
            //
            Vector3D origin = camera.Eye + (nearDistance * camera.Forward);    // Project eye onto near plane
            Vector3D xAxis  = camera.Right * (nearDistance * Math.Tan(theta)); // Rescale right to near plane
            Vector3D yAxis  = camera.Up * (nearDistance * Math.Tan(phi));      // Rescale up to near plane

            _uniform.Value = new Matrix4D(
                xAxis.X, yAxis.X, 0.0, origin.X,
                xAxis.Y, yAxis.Y, 0.0, origin.Y,
                xAxis.Z, yAxis.Z, 0.0, origin.Z,
                0.0, 0.0, 0.0, 1.0).ToMatrix4F();
        }
        public override void Set(Context context, DrawState drawState, SceneState sceneState)
        {
            Camera camera = sceneState.Camera;
            double theta = camera.FieldOfViewX * 0.5;
            double phi = camera.FieldOfViewY * 0.5;
            double nearDistance = camera.PerspectiveNearPlaneDistance;

            //
            // Coordinate system for the near plane:  origin is at center, x and y
            // span [-1, 1] just like noramlized device coordinates.
            //
            Vector3D origin = camera.Eye + (nearDistance * camera.Forward);    // Project eye onto near plane
            Vector3D xAxis = camera.Right * (nearDistance * Math.Tan(theta));  // Rescale right to near plane
            Vector3D yAxis = camera.Up * (nearDistance * Math.Tan(phi));       // Rescale up to near plane

            _uniform.Value = new Matrix4D(
                    xAxis.X, yAxis.X, 0.0, origin.X,
                    xAxis.Y, yAxis.Y, 0.0, origin.Y,
                    xAxis.Z, yAxis.Z, 0.0, origin.Z,
                    0.0,     0.0,     0.0, 1.0).ToMatrix4F();
        }
Example #31
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ViewMatrix.ToMatrix4F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ModelViewOrthographicMatrix.ToMatrix4F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.Camera.EyeHigh;
 }
Example #34
0
        private void Update(SceneState sceneState)
        {
            Vector3D eye = sceneState.Camera.Eye;

            if (_eye != eye)
            {
                _eye = eye;

                Vector3F eyeHigh;
                Vector3F eyeLow;
                Vector3DToTwoVector3F(eye, out eyeHigh, out eyeLow);
                _cameraEyeHigh.Value = eyeHigh;
                _cameraEyeLow.Value = eyeLow;

                Matrix4D m = sceneState.ModelViewMatrix;
                Matrix4D mv = new Matrix4D(
                    m.Column0Row0, m.Column1Row0, m.Column2Row0, 0.0,
                    m.Column0Row1, m.Column1Row1, m.Column2Row1, 0.0,
                    m.Column0Row2, m.Column1Row2, m.Column2Row2, 0.0,
                    m.Column0Row3, m.Column1Row3, m.Column2Row3, m.Column3Row3);

                _modelViewPerspectiveMatrixRelativeToEye.Value =
                    (sceneState.PerspectiveMatrix * mv).ToMatrix4F();
            }

            _pointSize.Value = (float)(8.0 * sceneState.HighResolutionSnapScale);
        }
Example #35
0
 protected void SetDrawAutomaticUniforms(Context context, DrawState drawState, SceneState sceneState)
 {
     for (int i = 0; i < _drawAutomaticUniforms.Count; ++i)
     {
         _drawAutomaticUniforms[i].Set(context, drawState, sceneState);
     }
 }
Example #36
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = Matrix42 <float> .DoubleToFloat(sceneState.ModelZToClipCoordinates);
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = (float)sceneState.Camera.Height(Ellipsoid.Wgs84);
 }
Example #38
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = (float)(Math.Tan(0.5 * sceneState.Camera.FieldOfViewY) * 2.0 / context.Viewport.Height);
 }
Example #39
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ModelViewPerspectiveMatrixRelativeToEye.ToMatrix4F();
 }
Example #40
0
 public abstract void Draw(PrimitiveType primitiveType, int offset, int count, DrawState drawState, SceneState sceneState);
Example #41
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.Camera.Eye.ToVector3F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.CameraLightPosition.ToVector3F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ComputeViewportTransformationMatrix(context.Viewport,
                                                                     drawState.RenderState.DepthRange.Near, drawState.RenderState.DepthRange.Far).ToMatrix4F();
 }
        public LatitudeLongitudeGrid()
        {
            Ellipsoid globeShape = Ellipsoid.Wgs84;
            _window = Device.CreateWindow(800, 600, "Chapter 4:  Latitude Longitude Grid");
            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _sceneState = new SceneState();
            _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape);
            _clearState = new ClearState();

            _sceneState.Camera.PerspectiveNearPlaneDistance = 0.01 * globeShape.MaximumRadius;
            _sceneState.Camera.PerspectiveFarPlaneDistance = 10.0 * globeShape.MaximumRadius;
            _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius);

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

            IList<GridResolution> gridResolutions = new List<GridResolution>();
            gridResolutions.Add(new GridResolution(
                new Interval(0, 1000000, IntervalEndpoint.Closed, IntervalEndpoint.Open),
                new Vector2D(0.005, 0.005)));
            gridResolutions.Add(new GridResolution(
                new Interval(1000000, 2000000, IntervalEndpoint.Closed, IntervalEndpoint.Open),
                new Vector2D(0.01, 0.01)));
            gridResolutions.Add(new GridResolution(
                new Interval(2000000, 20000000, IntervalEndpoint.Closed, IntervalEndpoint.Open),
                new Vector2D(0.05, 0.05)));
            gridResolutions.Add(new GridResolution(
                new Interval(20000000, double.MaxValue, IntervalEndpoint.Closed, IntervalEndpoint.Open),
                new Vector2D(0.1, 0.1)));

            _globe = new LatitudeLongitudeGridGlobe(_window.Context);
            _globe.Texture = Device.CreateTexture2D(new Bitmap("NE2_50M_SR_W_4096.jpg"), TextureFormat.RedGreenBlue8, false);
            _globe.Shape = globeShape;
            _globe.GridResolutions = new GridResolutionCollection(gridResolutions);

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

            Vector3D vancouver = globeShape.ToVector3D(new Geodetic3D(Trig.ToRadians(-123.06), Trig.ToRadians(49.13), 0));

            TextureAtlas atlas = new TextureAtlas(new Bitmap[]
            {
                new Bitmap("building.png"),
                Device.CreateBitmapFromText("Vancouver", new Font("Arial", 24))
            });

            _vancouverLabel = new BillboardCollection(_window.Context);
            _vancouverLabel.Texture = Device.CreateTexture2D(atlas.Bitmap, TextureFormat.RedGreenBlueAlpha8, false);
            _vancouverLabel.DepthTestEnabled = false;
            _vancouverLabel.Add(new Billboard()
            {
                Position = vancouver,
                TextureCoordinates = atlas.TextureCoordinates[0]
            });
            _vancouverLabel.Add(new Billboard()
            {
                Position = vancouver,
                TextureCoordinates = atlas.TextureCoordinates[1],
                HorizontalOrigin = HorizontalOrigin.Left
            });

            atlas.Dispose();
        }
Example #45
0
 public abstract void Draw(PrimitiveType primitiveType, DrawState drawState, SceneState sceneState);
Example #46
0
        public void Render(Context context, SceneState sceneState)
        {
            Update(sceneState);

            context.Draw(PrimitiveType.Triangles, 0, 6, _drawState, sceneState);
            context.Draw(PrimitiveType.Points, 6, 1, _drawState, sceneState);
        }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = SceneState.ComputeViewportOrthographicMatrix(context.Viewport).ToMatrix4F();
 }