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(); }
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); }
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(); }
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(); }
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(); }
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 myButton1_Click(object sender, EventArgs e) { _window = Device.CreateWindow(800, 600, "Chapter 13: Clipmap Terrain on a Globe"); _ellipsoid = Ellipsoid.Wgs84; WorldWindTerrainSource terrainSource = new WorldWindTerrainSource(); GMapRestImagery imagery = new GMapRestImagery(); _clipmap = new GlobeClipmapTerrain(_window.Context, terrainSource, imagery, _ellipsoid, 511); _clipmap.HeightExaggeration = 1.0f; 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))); _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); //_globe.GridResolutions = new GridResolutionCollection(gridResolutions); _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; //_flyCamera = new CameraFly(_sceneState.Camera, _window); //_flyCamera.MovementRate = 1200.0; //_flyCamera.InputEnabled = true; _sceneState.Camera.Target = new Vector3D(115, -35, 100.0); _window.Run(30); }
public LinesOnTerrain() { _window = Device.CreateWindow(800, 600, "Research: Lines on Terrain"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _sceneState.Camera.PerspectiveFarPlaneDistance = 4096; _sceneState.Camera.PerspectiveNearPlaneDistance = 10; _instructions = new HeadsUpDisplay(); _instructions.Texture = Device.CreateTexture2D( Device.CreateBitmapFromText( "u - Use silhouette\ns - Show silhouette\n", new Font("Arial", 24)), TextureFormat.RedGreenBlueAlpha8, false); _instructions.Color = Color.LightBlue; /////////////////////////////////////////////////////////////////// TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap(@"ps-e.lg.png")); _tile = new TriangleMeshTerrainTile(_window.Context, terrainTile); _tile.HeightExaggeration = 30.0f; /////////////////////////////////////////////////////////////////// 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); _sceneState.Camera.ZoomToTarget(tileRadius); _sceneState.Camera.Eye = new Vector3D(_xPos, 256, 0); // // Positions // IList<Vector3D> positions = new List<Vector3D>(); double temp = 1.2 * _tile.HeightExaggeration; positions.Add(new Vector3D(0.0, 0.0, -temp)); positions.Add(new Vector3D(0.0, 0.0, temp)); positions.Add(new Vector3D(100.0, 100.0, -temp)); positions.Add(new Vector3D(100.0, 100.0, temp)); positions.Add(new Vector3D(200.0, 100.0, -temp)); positions.Add(new Vector3D(200.0, 100.0, temp)); positions.Add(new Vector3D(256.0, 256.0, -temp)); positions.Add(new Vector3D(256.0, 256.0, temp)); positions.Add(new Vector3D(512.0, 512.0, -temp)); positions.Add(new Vector3D(512.0, 512.0, temp)); // // junk _polylineOnTerrain = new PolylineOnTerrain(); _polylineOnTerrain.Set(_window.Context, positions); _clearState = new ClearState(); // junk string fs = @"#version 330 uniform sampler2D og_texture0; in vec2 fsTextureCoordinates; out vec4 fragmentColor; void main() { if (texture(og_texture0, fsTextureCoordinates).r == 0.0) { fragmentColor = vec4(0.0, 0.0, 0.0, 1.0); } else { discard; } }"; _viewportQuad = new ViewportQuad(_window.Context, fs); }
public VectorData() { Ellipsoid globeShape = Ellipsoid.ScaledWgs84; _window = Device.CreateWindow(800, 600, "Chapter 7: Vector Data"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _window.Keyboard.KeyUp += OnKeyUp; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); Context context = _window.Context; _framebuffer = context.CreateFramebuffer(); _clearBlack = new ClearState(); _clearBlack.Color = Color.Black; _clearWhite = new ClearState(); _clearWhite.Color = Color.White; _quad = new DayNightViewportQuad(context); _globe = new DayNightGlobe(context); _globe.Shape = globeShape; _globe.UseAverageDepth = true; _globe.DayTexture = Device.CreateTexture2D(new Bitmap("NE2_50M_SR_W_4096.jpg"), TextureFormat.RedGreenBlue8, false); _globe.NightTexture = Device.CreateTexture2D(new Bitmap("land_ocean_ice_lights_2048.jpg"), TextureFormat.RedGreenBlue8, false); _countries = new ShapefileRenderer("110m_admin_0_countries.shp", context, globeShape, new ShapefileAppearance() { PolylineWidth = 1.0, PolylineOutlineWidth = 1.0 }); _states = new ShapefileRenderer("110m_admin_1_states_provinces_lines_shp.shp", context, globeShape, new ShapefileAppearance() { PolylineWidth = 1.0, PolylineOutlineWidth = 1.0 }); _rivers = new ShapefileRenderer("50m-rivers-lake-centerlines.shp", context, globeShape, new ShapefileAppearance() { PolylineColor = Color.LightBlue, PolylineOutlineColor = Color.LightBlue, PolylineWidth = 1.0, PolylineOutlineWidth = 0.0 }); _populatedPlaces = new ShapefileRenderer("110m_populated_places_simple.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("032.png") }); _airports = new ShapefileRenderer("airprtx020.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("car-red.png") }); _amtrakStations = new ShapefileRenderer("amtrakx020.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("paper-plane--arrow.png") }); _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Blue; _showVectorData = true; _sceneState.DiffuseIntensity = 0.5f; _sceneState.SpecularIntensity = 0.1f; _sceneState.AmbientIntensity = 0.4f; _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); UpdateHUD(); }