public PointShapefile( Shapefile shapefile, Context context, Ellipsoid globeShape, ShapefileAppearance appearance) { Verify.ThrowIfNull(shapefile); Verify.ThrowIfNull(context); Verify.ThrowIfNull(globeShape); Verify.ThrowIfNull(appearance); _billboards = new BillboardCollection(context); _billboards.Texture = Device.CreateTexture2D(appearance.Bitmap, TextureFormat.RedGreenBlueAlpha8, false); foreach (Shape shape in shapefile) { if (shape.ShapeType != ShapeType.Point) { throw new NotSupportedException("The type of an individual shape does not match the Shapefile type."); } Vector2D point = ((PointShape)shape).Position; Vector3D position = globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))); Billboard billboard = new Billboard(); billboard.Position = position; _billboards.Add(billboard); } }
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 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(); }
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; // 创建主场景OpenGL状态存储对象 _sceneState = new SceneState(); // 设置主场景照相机类型(固定观察一点的照相机) _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape); // 创建状态(scissor/color/depth/stencil)清除对象 _clearState = new ClearState(); // 创建单色纹理对象(用于对椭球着色) // 因为RayCastedGlobe对象的颜色只能通过其Texture接口设置 _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; // 创建椭球表面采样点billboard显示集合对象 _sampledPoints = new BillboardCollection(_window.Context); // 创建并设置billboard显示纹理为直径8个窗口像素的点 _sampledPoints.Texture = Device.CreateTexture2D(Device.CreateBitmapFromPoint(8), TextureFormat.RedGreenBlueAlpha8, false); // 关闭采样点billboard集合显示对象的深度测试(使其在任何角度都可见) _sampledPoints.DepthTestEnabled = false; // 创建RayCastedGlobe椭球绘制对象并设置纹理 _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 BillboardCollectionTest() { _window = Device.CreateWindow(1, 1); _group = new BillboardCollection(_window.Context); }
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(); }
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; /////////////////////////////////////////////////////////////////// // 计算p点椭球表面坐标 Vector3D p = _globeShape.ToVector3D(new Geodetic3D(0, Trig.ToRadians(45), 0)); // 计算p点地理法线向量 Vector3D deticNormal = _globeShape.GeodeticSurfaceNormal(p); // 计算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); // 创建p点切平面 _tangentPlane = new Plane(_window.Context); _tangentPlane.Origin = p; _tangentPlane.XAxis = east; _tangentPlane.YAxis = north; _tangentPlane.OutlineWidth = 3; }
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; }