public virtual void ComputeAbsoluteMatrices() { m_absoluteWorldMatrix = Matrix.Identity; float aspectRatio = (float)viewPort.Width / viewPort.Height; float zNear = (float)Math.Max(this._altitude - TerrainElevationUnderCamera, minimumAltitude) * 0.1f; double distToCenterOfPlanet = (this._altitude + this.WorldRadius); double tangentalDistance = Math.Sqrt(distToCenterOfPlanet * distToCenterOfPlanet - _worldRadius * _worldRadius); if (tangentalDistance < 1000000 || double.IsNaN(tangentalDistance)) { tangentalDistance = 1000000; } m_absoluteProjectionMatrix = Matrix.PerspectiveFovRH((float)_fov.Radians, aspectRatio, zNear, (float)tangentalDistance); m_absoluteViewMatrix = Matrix.LookAtRH( MathEngine.SphericalToCartesian( _latitude.Degrees, _longitude.Degrees, WorldRadius + curCameraElevation), Vector3.Empty, new Vector3(0, 0, 1)); m_absoluteViewMatrix *= Matrix.RotationYawPitchRoll( (float)-(_swivel.Radians + _headSwivel.Radians), (float)-(_tilt.Radians + _headTilt.Radians), (float)this._heading.Radians); //m_absoluteViewMatrix *= Matrix.Translation(0, 0, (float)(-this._distance + curCameraElevation)); m_absoluteViewMatrix *= Matrix.Translation(0, 0, (float)(-(this._distance + _headZoom))); m_absoluteViewMatrix *= Matrix.RotationZ((float)this._bank.Radians); }
public override bool PerformSelectionAction(DrawArgs drawArgs) { Vector3 surfacePos = MathEngine.SphericalToCartesian(m_latitude, m_longitude, World.EquatorialRadius); Vector3 rc = new Vector3( (float)drawArgs.WorldCamera.ReferenceCenter.X, (float)drawArgs.WorldCamera.ReferenceCenter.Y, (float)drawArgs.WorldCamera.ReferenceCenter.Z ); Vector3 projectedPoint = drawArgs.WorldCamera.Project(surfacePos - rc); int mouseBuffer = 15; if (projectedPoint.X > DrawArgs.LastMousePosition.X - mouseBuffer && projectedPoint.X < DrawArgs.LastMousePosition.X + mouseBuffer && projectedPoint.Y > DrawArgs.LastMousePosition.Y - mouseBuffer && projectedPoint.Y < DrawArgs.LastMousePosition.Y + mouseBuffer) { if (OnMouseUpEvent != null) { OnMouseUpEvent(this, new System.Windows.Forms.MouseEventArgs(System.Windows.Forms.MouseButtons.Left, 1, DrawArgs.LastMousePosition.X, DrawArgs.LastMousePosition.Y, 0)); } return(true); } return(false); }
public override void Initialize(DrawArgs drawArgs) { FileInfo boundaryFileInfo = new FileInfo(this._boundaryFilePath); if (!boundaryFileInfo.Exists) { this.isInitialized = true; return; } using (FileStream boundaryFileStream = boundaryFileInfo.OpenRead()) using (BinaryReader boundaryFileReader = new BinaryReader(boundaryFileStream, System.Text.Encoding.ASCII)) { int numBoundaries = boundaryFileReader.ReadInt32(); int count = boundaryFileReader.ReadInt32(); this.vertices = new CustomVertex.PositionColored[count]; for (int i = 0; i < count; i++) { double lat = boundaryFileReader.ReadDouble(); double lon = boundaryFileReader.ReadDouble(); Vector3 v = MathEngine.SphericalToCartesian((float)lat, (float)lon, (float)(this._parentWorld.EquatorialRadius + this._distanceAboveSurface)); this.vertices[i].X = v.X; this.vertices[i].Y = v.Y; this.vertices[i].Z = v.Z; this.vertices[i].Color = this._color; } } this.isInitialized = true; }
private void UpdateTexturedVertices() { m_texturedVertices = new CustomVertex.PositionColoredTextured[m_points.Length * 2]; float textureCoordIncrement = 1.0f / (float)(m_points.Length - 1); m_verticalExaggeration = World.Settings.VerticalExaggeration; Color vertexColor = Color.FromArgb(Opacity, m_color.R, m_color.G, m_color.B); for (int i = 0; i < m_points.Length; i++) { Vector3 xyzVertex = MathEngine.SphericalToCartesian(m_points[i].Y, m_points[i].X, m_verticalExaggeration * (m_points[i].Z + m_distanceAboveSurface) + World.EquatorialRadius); m_texturedVertices[2 * i].X = xyzVertex.X; m_texturedVertices[2 * i].Y = xyzVertex.Y; m_texturedVertices[2 * i].Z = xyzVertex.Z; m_texturedVertices[2 * i].Color = vertexColor.ToArgb(); m_texturedVertices[2 * i].Tu = i * textureCoordIncrement; m_texturedVertices[2 * i].Tv = 1.0f; xyzVertex = MathEngine.SphericalToCartesian(m_points[i].Y, m_points[i].X, m_verticalExaggeration * (m_points[i].Z + m_distanceAboveSurface + (ExtrudeUpwards ? m_extrudeHeight : -1.0 * m_extrudeHeight)) + World.EquatorialRadius); m_texturedVertices[2 * i + 1].X = xyzVertex.X; m_texturedVertices[2 * i + 1].Y = xyzVertex.Y; m_texturedVertices[2 * i + 1].Z = xyzVertex.Z; m_texturedVertices[2 * i + 1].Color = vertexColor.ToArgb(); m_texturedVertices[2 * i + 1].Tu = i * textureCoordIncrement; m_texturedVertices[2 * i + 1].Tv = 0.0f; } }
public virtual void ComputeAbsoluteMatrices() { m_absoluteWorldMatrix = Matrix.Identity; float aspectRatio = (float)viewPort.Width / viewPort.Height; float zNear = (float)this._altitude * 0.1f; double distToCenterOfPlanet = (this._altitude + this.WorldRadius); double tangentalDistance = Math.Sqrt(distToCenterOfPlanet * distToCenterOfPlanet - _worldRadius * _worldRadius); m_absoluteProjectionMatrix = Matrix.PerspectiveFovRH((float)_fov.Radians, aspectRatio, zNear, (float)tangentalDistance); m_absoluteViewMatrix = Matrix.LookAtRH( MathEngine.SphericalToCartesian( _latitude.Degrees, _longitude.Degrees, WorldRadius), Vector3.Empty, new Vector3(0, 0, 1)); m_absoluteViewMatrix *= Matrix.RotationYawPitchRoll( 0, (float)-_tilt.Radians, (float)this._heading.Radians); m_absoluteViewMatrix *= Matrix.Translation(0, 0, (float)(-this._distance - curCameraElevation)); m_absoluteViewMatrix *= Matrix.RotationZ((float)this._bank.Radians); }
public override void Update(DrawArgs drawArgs) { if (drawArgs.WorldCamera.ViewMatrix != lastView && drawArgs.CurrentWorld.TerrainAccessor != null && drawArgs.WorldCamera.Altitude < 300000) { double samplesPerDegree = 50.0 / drawArgs.WorldCamera.ViewRange.Degrees; double elevation = drawArgs.CurrentWorld.TerrainAccessor.GetElevationAt(m_latitude, m_longitude, samplesPerDegree); double altitude = World.Settings.VerticalExaggeration * Altitude + World.Settings.VerticalExaggeration * elevation; Position = MathEngine.SphericalToCartesian(m_latitude, m_longitude, altitude + drawArgs.WorldCamera.WorldRadius); lastView = drawArgs.WorldCamera.ViewMatrix; } if (overlays != null) { for (int i = 0; i < overlays.Count; i++) { ScreenOverlay curOverlay = (ScreenOverlay)overlays[i]; if (curOverlay != null) { curOverlay.Update(drawArgs); } } } }
private void UpdateOutlineVertices() { Color outlineColor = Color.FromArgb(Opacity, m_outlineColor.R, m_outlineColor.G, m_outlineColor.B); m_outlineTopVertices = new CustomVertex.PositionColored[m_points.Length]; m_outlineBottomVertices = new CustomVertex.PositionColored[m_points.Length]; if (m_extrudeHeight > 0) { m_outlineSideVertices = new CustomVertex.PositionColored[m_points.Length * 2]; } for (int i = 0; i < m_points.Length; i++) { Vector3 xyzVertex = MathEngine.SphericalToCartesian(m_points[i].Y, m_points[i].X, m_verticalExaggeration * (m_points[i].Z + m_distanceAboveSurface) + World.EquatorialRadius); m_outlineTopVertices[i].X = xyzVertex.X; m_outlineTopVertices[i].Y = xyzVertex.Y; m_outlineTopVertices[i].Z = xyzVertex.Z; m_outlineTopVertices[i].Color = outlineColor.ToArgb(); if (m_extrudeHeight > 0) { m_outlineSideVertices[2 * i] = m_outlineTopVertices[i]; xyzVertex = MathEngine.SphericalToCartesian(m_points[i].Y, m_points[i].X, m_verticalExaggeration * (m_points[i].Z + m_distanceAboveSurface + (ExtrudeUpwards ? m_extrudeHeight : -1.0 * m_extrudeHeight)) + World.EquatorialRadius); m_outlineBottomVertices[i].X = xyzVertex.X; m_outlineBottomVertices[i].Y = xyzVertex.Y; m_outlineBottomVertices[i].Z = xyzVertex.Z; m_outlineBottomVertices[i].Color = outlineColor.ToArgb(); m_outlineSideVertices[2 * i + 1] = m_outlineBottomVertices[i]; } } }
private void UpdateColoredVertices() { m_vertices = new CustomVertex.PositionColored[(m_extrudeHeight > 0 ? m_points.Length * 2 : m_points.Length)]; Color vertexColor = Color.FromArgb(Opacity, m_color.R, m_color.G, m_color.B); for (int i = 0; i < m_points.Length; i++) { Vector3 xyzVertex = MathEngine.SphericalToCartesian(m_points[i].Y, m_points[i].X, m_verticalExaggeration * (m_points[i].Z + m_distanceAboveSurface) + World.EquatorialRadius); if (m_extrudeHeight > 0) { m_vertices[2 * i].X = xyzVertex.X; m_vertices[2 * i].Y = xyzVertex.Y; m_vertices[2 * i].Z = xyzVertex.Z; m_vertices[2 * i].Color = vertexColor.ToArgb(); xyzVertex = MathEngine.SphericalToCartesian(m_points[i].Y, m_points[i].X, m_verticalExaggeration * (m_points[i].Z + m_distanceAboveSurface + (ExtrudeUpwards ? m_extrudeHeight : -1.0 * m_extrudeHeight)) + World.EquatorialRadius); m_vertices[2 * i + 1].X = xyzVertex.X; m_vertices[2 * i + 1].Y = xyzVertex.Y; m_vertices[2 * i + 1].Z = xyzVertex.Z; m_vertices[2 * i + 1].Color = vertexColor.ToArgb(); } else { m_vertices[i].X = xyzVertex.X; m_vertices[i].Y = xyzVertex.Y; m_vertices[i].Z = xyzVertex.Z; m_vertices[i].Color = vertexColor.ToArgb(); } } }
/// <summary> /// Calculates the segments of the measure curve /// </summary> public void Calculate(World world, bool useTerrain) { Angle angularDistance = World.ApproxAngularDistance( startLatitude, startLongitude, endLatitude, endLongitude ); Linear = angularDistance.Radians * world.EquatorialRadius; int samples = (int)(angularDistance.Radians*30); // 1 point for every 2 degrees. if(samples<2) samples = 2; LinearTrackLine = new CustomVertex.PositionColored[samples]; for(int i=0;i<LinearTrackLine.Length;i++) LinearTrackLine[i].Color = World.Settings.MeasureLineLinearColorXml;; Angle lat,lon=Angle.Zero; for(int i=0; i<samples; i++) { float t = (float)i / (samples-1); World.IntermediateGCPoint(t, startLatitude, startLongitude, endLatitude, endLongitude, angularDistance, out lat, out lon ); double elevation = 0; if(useTerrain) elevation = world.TerrainAccessor.GetElevationAt(lat.Degrees,lon.Degrees,1024); Vector3 subSegmentXyz = MathEngine.SphericalToCartesian(lat, lon, world.EquatorialRadius + elevation * World.Settings.VerticalExaggeration ); LinearTrackLine[i].X = subSegmentXyz.X; LinearTrackLine[i].Y = subSegmentXyz.Y; LinearTrackLine[i].Z = subSegmentXyz.Z; } WorldXyzMid = world.IntermediateGCPoint(0.5f, startLatitude, startLongitude, endLatitude, endLongitude, angularDistance ); }
protected void UpdatePosition(DrawArgs drawArgs) { // compute the ground point double elevation = drawArgs.WorldCamera.WorldRadius; if ((m_globals.WorldWindow.CurrentWorld.TerrainAccessor != null) && (drawArgs.WorldCamera.Altitude < 300000)) { float distanceToIcon = Vector3.Length(this.Position - drawArgs.WorldCamera.Position); // if we're close get high detail otherwise get the general elevation if (distanceToIcon < 300000) { elevation += m_globals.WorldWindow.CurrentWorld.TerrainAccessor.GetElevationAt( Latitude, Longitude, 100.0) * World.Settings.VerticalExaggeration; } else { elevation += m_globals.WorldWindow.CurrentWorld.TerrainAccessor.GetElevationAt( Latitude, Longitude) * World.Settings.VerticalExaggeration; } } Position = MathEngine.SphericalToCartesian(Latitude, Longitude, Altitude + elevation); if (m_drawGroundStick) { m_groundPoint = MathEngine.SphericalToCartesian(Latitude, Longitude, elevation); } m_isUpdated = true; }
//TODO: Improve rendering code to segment spherical coordinates //which are too far apart to follow curvature public Vector3[] BuildSegment(Angle startLatitude, Angle startLongitude, Angle endLatitude, Angle endLongitude, float heightAboveSurface) { //check how far the point being added is from the last point Angle angularDistance = World.ApproxAngularDistance( startLatitude, startLongitude, endLatitude, endLongitude); Vector3[] newPoints = null; if (angularDistance.Degrees >= 2.0) { int samples = (int)(angularDistance.Radians * 30); // 1 point for every 2 degrees. if (samples < 2) { samples = 2; } Angle lat, lon = Angle.Zero; newPoints = new Vector3[samples]; for (int i = 0; i < samples; i++) { float t = (float)i / (samples - 1); World.IntermediateGCPoint(t, startLatitude, startLongitude, endLatitude, endLongitude, angularDistance, out lat, out lon); newPoints[i] = MathEngine.SphericalToCartesian(lat, lon, this._parentWorld.EquatorialRadius + this.verticalExaggeration * heightAboveSurface); } } return(newPoints); }
public bool WasClicked(DrawArgs drawArgs) { int halfIconWidth = (int)(0.3f * this.iconSize); int halfIconHeight = (int)(0.3f * this.iconSize); Vector3 projectedPoint = MathEngine.SphericalToCartesian(0.5f * (this.north + this.south), 0.5f * (this.west + this.east), this.layerRadius); if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(projectedPoint)) { return(false); } projectedPoint.Project(drawArgs.Device.Viewport, drawArgs.Device.Transform.Projection, drawArgs.Device.Transform.View, drawArgs.Device.Transform.World); int top = (int)projectedPoint.Y - halfIconHeight; int bottom = (int)projectedPoint.Y + halfIconHeight; int left = (int)projectedPoint.X - halfIconWidth; int right = (int)projectedPoint.X + halfIconWidth; try { if (DrawArgs.LastMousePosition.X < right && DrawArgs.LastMousePosition.X > left && DrawArgs.LastMousePosition.Y > top && DrawArgs.LastMousePosition.Y < bottom) { return(true); } else { return(false); } } catch { } return(false); }
/// <summary> /// Draws a tropic line at specified latitude with specified label /// </summary> /// <param name="latitude">Latitude in degrees</param> void RenderTropicLine(DrawArgs drawArgs, float latitude, string label) { int vertexIndex = 0; Vector3 referenceCenter = new Vector3( (float)drawArgs.WorldCamera.ReferenceCenter.X, (float)drawArgs.WorldCamera.ReferenceCenter.Y, (float)drawArgs.WorldCamera.ReferenceCenter.Z); for (float longitude = MinVisibleLongitude; longitude <= MaxVisibleLongitude; longitude = longitude + LongitudeInterval) { Vector3 pointXyz = MathEngine.SphericalToCartesian(latitude, longitude, radius); lineVertices[vertexIndex].X = pointXyz.X; lineVertices[vertexIndex].Y = pointXyz.Y; lineVertices[vertexIndex].Z = pointXyz.Z; lineVertices[vertexIndex].Color = World.Settings.tropicLinesColor; vertexIndex++; } drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, LongitudePointCount - 1, lineVertices); Vector3 t1 = MathEngine.SphericalToCartesian(Angle.FromDegrees(latitude), drawArgs.WorldCamera.Longitude - drawArgs.WorldCamera.TrueViewRange * 0.3f * 0.5f, radius); if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(t1)) { t1 = drawArgs.WorldCamera.Project(t1 - referenceCenter); drawArgs.defaultDrawingFont.DrawText(null, label, new System.Drawing.Rectangle((int)t1.X, (int)t1.Y, drawArgs.screenWidth, drawArgs.screenHeight), DrawTextFormat.NoClip, World.Settings.tropicLinesColor); } }
/// <summary> /// Determine if the object is visible /// </summary> bool IsVisible(WorldWind.Camera.CameraBase camera) { if (worldXyz == Vector3.Empty) { worldXyz = MathEngine.SphericalToCartesian(Latitude, Longitude, camera.WorldRadius); } return(camera.ViewFrustum.ContainsPoint(worldXyz)); }
private bool IsInViewFrustum(CameraBase camera, MyChart c) { if (c.Position == Vector3.Empty) { c.Position = MathEngine.SphericalToCartesian(c.Latitude, c.Longitude, camera.WorldRadius); } return(camera.ViewFrustum.ContainsPoint(c.Position)); }
/// <summary> /// determine whether this chart item is in visuble. /// </summary> /// <param name="camera"></param> /// <returns></returns> private bool IsInViewFrustum(CameraBase camera) { if (base.Position == Vector3.Empty) { base.position = MathEngine.SphericalToCartesian(this.latitude, this.longitude, camera.WorldRadius); } return(camera.ViewFrustum.ContainsPoint(base.Position)); }
/// <summary> /// Builds the image's mesh /// </summary> protected virtual void CreateMesh() { int upperBound = meshPointCount - 1; float scaleFactor = (float)1 / upperBound; double latrange = Math.Abs(maxLat - minLat); double lonrange; if (minLon < maxLon) { lonrange = maxLon - minLon; } else { lonrange = 360.0f + maxLon - minLon; } int opacityColor = Color.FromArgb(this.m_opacity, 0, 0, 0).ToArgb(); vertices = new CustomVertex.PositionColoredTextured[meshPointCount * meshPointCount]; for (int i = 0; i < meshPointCount; i++) { for (int j = 0; j < meshPointCount; j++) { double height = 0; if (this._terrainAccessor != null) { height = this.verticalExaggeration * this._terrainAccessor.GetElevationAt((double)maxLat - scaleFactor * latrange * i, (double)minLon + scaleFactor * lonrange * j, (double)upperBound / latrange); } Vector3 pos = MathEngine.SphericalToCartesian(maxLat - scaleFactor * latrange * i, minLon + scaleFactor * lonrange * j, layerRadius + height); vertices[i * meshPointCount + j].X = pos.X; vertices[i * meshPointCount + j].Y = pos.Y; vertices[i * meshPointCount + j].Z = pos.Z; vertices[i * meshPointCount + j].Tu = j * scaleFactor; vertices[i * meshPointCount + j].Tv = i * scaleFactor; vertices[i * meshPointCount + j].Color = opacityColor; } } indices = new short[2 * upperBound * upperBound * 3]; for (int i = 0; i < upperBound; i++) { for (int j = 0; j < upperBound; j++) { indices[(2 * 3 * i * upperBound) + 6 * j] = (short)(i * meshPointCount + j); indices[(2 * 3 * i * upperBound) + 6 * j + 1] = (short)((i + 1) * meshPointCount + j); indices[(2 * 3 * i * upperBound) + 6 * j + 2] = (short)(i * meshPointCount + j + 1); indices[(2 * 3 * i * upperBound) + 6 * j + 3] = (short)(i * meshPointCount + j + 1); indices[(2 * 3 * i * upperBound) + 6 * j + 4] = (short)((i + 1) * meshPointCount + j); indices[(2 * 3 * i * upperBound) + 6 * j + 5] = (short)((i + 1) * meshPointCount + j + 1); } } }
public Layer3D(string name, float latitude, float longitude, float layerRadius, float scaleFactor, string meshFilePath, Quaternion orientation) : base(name, MathEngine.SphericalToCartesian(latitude, longitude, layerRadius), orientation) { }
public override void Initialize(DrawArgs drawArgs) { double samplesPerDegree = 50.0 / (drawArgs.WorldCamera.ViewRange.Degrees); double elevation = drawArgs.CurrentWorld.TerrainAccessor.GetElevationAt(m_latitude, m_longitude, samplesPerDegree); double altitude = (World.Settings.VerticalExaggeration * Altitude + World.Settings.VerticalExaggeration * elevation); Position = MathEngine.SphericalToCartesian(m_latitude, m_longitude, altitude + drawArgs.WorldCamera.WorldRadius); m_positionD = MathEngine.SphericalToCartesianD(Angle.FromDegrees(m_latitude), Angle.FromDegrees(m_longitude), altitude + drawArgs.WorldCamera.WorldRadius); Inited = true; }
public CustomVertex.PositionColored Point3d2PositionColored(Point3d point, Color color) { CustomVertex.PositionColored pc = new CustomVertex.PositionColored(); pc.Color = color.ToArgb(); Vector3 vec = MathEngine.SphericalToCartesian(point.Y, point.X, World.EquatorialRadius + point.Z * World.Settings.VerticalExaggeration); pc.X = vec.X; pc.Y = vec.Y; pc.Z = vec.Z; return(pc); }
/// <summary> /// 更新 /// </summary> /// <param name="drawArgs"></param> public override void Update(DrawArgs drawArgs) { if (drawArgs.WorldCamera.ViewMatrix != lastView && drawArgs.CurrentWorld.TerrainAccessor != null && drawArgs.WorldCamera.Altitude < 300000) { double samplesPerDegree = 50.0 / drawArgs.WorldCamera.ViewRange.Degrees; double elevation = drawArgs.CurrentWorld.TerrainAccessor.GetElevationAt(m_latitude, m_longitude, samplesPerDegree); double altitude = World.Settings.VerticalExaggeration * Altitude + World.Settings.VerticalExaggeration * elevation; Position = MathEngine.SphericalToCartesian(m_latitude, m_longitude, altitude + drawArgs.WorldCamera.WorldRadius); lastView = drawArgs.WorldCamera.ViewMatrix; } }
void UpdateCorners() { if (minLon > maxLon) { double tmp = minLon; minLon = maxLon; maxLon = tmp; } if (minLat > maxLat) { double tmp = minLat; minLat = maxLat; maxLat = tmp; } //MessageBox.Show(meshPointCount.ToString()); float theHeightUL = this._terrainAccessor.GetElevationAt(maxLat, minLon, meshPointCount); float theHeightUR = this._terrainAccessor.GetElevationAt(maxLat, maxLon, meshPointCount); float theHeightLL = this._terrainAccessor.GetElevationAt(minLat, minLon, meshPointCount); float theHeightLR = this._terrainAccessor.GetElevationAt(minLat, maxLon, meshPointCount); if (theHeightUL < 0.0) { theHeightUL = 0.0f; } if (theHeightUR < 0.0) { theHeightUR = 0.0f; } if (theHeightLL < 0.0) { theHeightLL = 0.0f; } if (theHeightLR < 0.0) { theHeightLR = 0.0f; } //MessageBox.Show(verticalExaggeration.ToString()); ul = MathEngine.SphericalToCartesian(maxLat, minLon, layerRadius + (theHeightUL * verticalExaggeration)); ur = MathEngine.SphericalToCartesian(maxLat, maxLon, layerRadius + (theHeightUR * verticalExaggeration)); ll = MathEngine.SphericalToCartesian(minLat, minLon, layerRadius + (theHeightLL * verticalExaggeration)); lr = MathEngine.SphericalToCartesian(minLat, maxLon, layerRadius + (theHeightLR * verticalExaggeration)); //MessageBox.Show(ul.Z.ToString()); //MessageBox.Show(layerRadius.ToString()); //MessageBox.Show(ImageOverlayList.ParentApplication.WorldWindow.CurrentWorld.EquatorialRadius.ToString()); //MessageBox.Show(ll.Z.ToString()); //MessageBox.Show(ImageOverlayList.ParentApplication.WorldWindow.CurrentWorld.TerrainAccessor.GetElevationAt(minLat,minLon).ToString()); }
private void Update() { double altitude; // Altitude is ASL altitude = (World.Settings.VerticalExaggeration * Alt) + DrawArgs.Camera.WorldRadius; Position = MathEngine.SphericalToCartesian(Lat, Lon, altitude); m_positionD = MathEngine.SphericalToCartesianD( Angle.FromDegrees(Lat), Angle.FromDegrees(Lon), altitude); }
/// <summary> /// Initializes a new instance of the <see cref= "T:Qrst.BoundingSphere"/> class /// from a set of lat/lon values (degrees) /// 根据经纬度的值(以°为单位)初始化一个“BoundingBox”的新实例 /// </summary> /// <param name="south"></param> /// <param name="north"></param> /// <param name="west"></param> /// <param name="east"></param> /// <param name="radius1"></param> /// <param name="radius2"></param> public BoundingBox(float south, float north, float west, float east, float radius1, float radius2) { float scale = radius2 / radius1; this.corners = new Vector3[8]; this.corners[0] = MathEngine.SphericalToCartesian(south, west, radius1); this.corners[1] = Vector3.Scale(this.corners[0], scale); this.corners[2] = MathEngine.SphericalToCartesian(south, east, radius1); this.corners[3] = Vector3.Scale(this.corners[2], scale); this.corners[4] = MathEngine.SphericalToCartesian(north, west, radius1); this.corners[5] = Vector3.Scale(this.corners[4], scale); this.corners[6] = MathEngine.SphericalToCartesian(north, east, radius1); this.corners[7] = Vector3.Scale(this.corners[6], scale); }
protected virtual void RenderProgress(DrawArgs drawArgs) { drawArgs.device.Transform.World = Matrix.Translation( (float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z ); device.RenderState.ZBufferEnable = false; double centerLat = 0.5 * (maxLat + minLat); double centerLon = 0.5 * (maxLon + minLon); Vector3 v = MathEngine.SphericalToCartesian(centerLat, centerLon, this.layerRadius); if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(v) && MathEngine.SphericalDistanceDegrees(centerLat, centerLon, drawArgs.WorldCamera.Latitude.Degrees, drawArgs.WorldCamera.Longitude.Degrees) < 2 * drawArgs.WorldCamera.ViewRange.Degrees ) { v.Project(drawArgs.device.Viewport, drawArgs.device.Transform.Projection, drawArgs.device.Transform.View, drawArgs.device.Transform.World); MenuUtils.DrawBox((int)v.X, (int)v.Y, 200, 40, 0.0f, progressBarBackColor, drawArgs.device); Vector2[] boxOutline = new Vector2[5]; boxOutline[0].X = (int)v.X; boxOutline[0].Y = (int)v.Y; boxOutline[1].X = (int)v.X + 200; boxOutline[1].Y = (int)v.Y; boxOutline[2].X = (int)v.X + 200; boxOutline[2].Y = (int)v.Y + 40; boxOutline[3].X = (int)v.X; boxOutline[3].Y = (int)v.Y + 40; boxOutline[4].X = (int)v.X; boxOutline[4].Y = (int)v.Y; MenuUtils.DrawLine(boxOutline, progressBarOutlineColor, drawArgs.device); drawArgs.defaultDrawingFont.DrawText(null, "Downloading Remote Image...", new System.Drawing.Rectangle((int)v.X + 5, (int)v.Y + 5, 200, 50), DrawTextFormat.NoClip, textColor); DrawProgressBar(drawArgs, v.X + 100, v.Y + 30, 180, 10, World.Settings.downloadProgressColor); } device.RenderState.ZBufferEnable = true; drawArgs.device.Transform.World = drawArgs.WorldCamera.WorldMatrix; }
/// <summary> /// Determine if the object is visible /// </summary> protected bool IsVisible(MFW3D.Camera.CameraBase camera) { if (IsVertExaggerable == true) { vertExaggeration = World.Settings.VerticalExaggeration; } else { vertExaggeration = 1; } //if (worldXyz == Vector3.Empty) worldXyz = MathEngine.SphericalToCartesian(Latitude, Longitude, World.EquatorialRadius + ((currentElevation + Altitude) * vertExaggeration)); return(camera.ViewFrustum.ContainsPoint(worldXyz)); }
public void Load(DrawArgs drawArgs) { this.linePoints = new CustomVertex.PositionColored[0]; if (this.terrainFileName == null) { this.isInitialized = true; return; } FileInfo inFile = new FileInfo(this.terrainFileName); if (!inFile.Exists) { this.isInitialized = true; return; } using (FileStream fs = new FileStream(inFile.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] buffer = new byte[inFile.Length]; int bytesRead = fs.Read(buffer, 0, (int)inFile.Length); using (MemoryStream ms = new MemoryStream(buffer)) using (BinaryReader br = new BinaryReader(ms, System.Text.Encoding.ASCII)) { int numCoords = br.ReadInt32(); this.sphericalCoordinates = new Vector3[numCoords]; for (int i = 0; i < numCoords; i++) { this.sphericalCoordinates[i].X = br.ReadSingle(); this.sphericalCoordinates[i].Y = br.ReadSingle(); } this.linePoints = new CustomVertex.PositionColored[numCoords]; for (int i = 0; i < numCoords; i++) { Vector3 v = MathEngine.SphericalToCartesian(this.sphericalCoordinates[i].X, this.sphericalCoordinates[i].Y, this._parentWorld.EquatorialRadius + World.Settings.VerticalExaggeration * this.heightAboveSurface); this.linePoints[i].X = v.X; this.linePoints[i].Y = v.Y; this.linePoints[i].Z = v.Z; this.linePoints[i].Color = this.lineColor; } } } this.isLoaded = true; }
public override void Render(DrawArgs drawArgs) { if (!isOn) { return; } if (!IsInitialized) { Initialize(drawArgs); } if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(MathEngine.SphericalToCartesian(m_latitude, m_longitude, drawArgs.CurrentWorld.EquatorialRadius))) { return; } try { //计算文字的范围 Rectangle textRect = drawArgs.DefaultDrawingFont.MeasureString(null, name, DrawTextFormat.None, 0); //计算标注的的位置 Vector3 translationVector = new Vector3( (float)(m_positionD.X - drawArgs.WorldCamera.ReferenceCenter.X), (float)(m_positionD.Y - drawArgs.WorldCamera.ReferenceCenter.Y), (float)(m_positionD.Z - drawArgs.WorldCamera.ReferenceCenter.Z)); Vector3 projectedPoint = drawArgs.WorldCamera.Project(translationVector); double distanceToAnnotation = Vector3.Length(this.Position - drawArgs.WorldCamera.Position); if (distanceToAnnotation > MaximumDisplayDistance * 3 / 4) { return; } if (distanceToAnnotation < MinimumDisplayDistance) { return; } Rectangle rectAnnotation = new Rectangle( (int)projectedPoint.X - (labelWidth >> 1), (int)(projectedPoint.Y - (drawArgs.DefaultDrawingFont.Description.Height >> 1)), labelWidth, drawArgs.ScreenHeight); drawArgs.DefaultDrawingFont.DrawText(null, name, rectAnnotation, DrawTextFormat.Center, is3DMapMode ? m_textColorAtMapMode : m_textColorAtImageMode); } catch (Exception ex) { //throw new Exception(ex.ToString()); } }
/// <summary> /// Intermediate points on a great circle /// In previous sections we have found intermediate points on a great circle given either /// the crossing latitude or longitude. Here we find points (lat,lon) a given fraction of the /// distance (d) between them. Suppose the starting point is (lat1,lon1) and the final point /// (lat2,lon2) and we want the point a fraction f along the great circle route. f=0 is /// point 1. f=1 is point 2. The two points cannot be antipodal ( i.e. lat1+lat2=0 and /// abs(lon1-lon2)=pi) because then the route is undefined. /// </summary> /// <param name="f">Fraction of the distance for intermediate point (0..1)</param> public Vector3 IntermediateGCPoint(float f, Angle lat1, Angle lon1, Angle lat2, Angle lon2, Angle d) { double sind = Math.Sin(d.Radians); double cosLat1 = Math.Cos(lat1.Radians); double cosLat2 = Math.Cos(lat2.Radians); double A = Math.Sin((1 - f) * d.Radians) / sind; double B = Math.Sin(f * d.Radians) / sind; double x = A * cosLat1 * Math.Cos(lon1.Radians) + B * cosLat2 * Math.Cos(lon2.Radians); double y = A * cosLat1 * Math.Sin(lon1.Radians) + B * cosLat2 * Math.Sin(lon2.Radians); double z = A * Math.Sin(lat1.Radians) + B * Math.Sin(lat2.Radians); Angle lat = Angle.FromRadians(Math.Atan2(z, Math.Sqrt(x * x + y * y))); Angle lon = Angle.FromRadians(Math.Atan2(y, x)); Vector3 v = MathEngine.SphericalToCartesian(lat, lon, m_EquatorialRadius); return(v); }
/// <summary> /// /// </summary> /// <param name="drawArgs"></param> public override void Initialize(DrawArgs drawArgs) { if (!this.IsInViewFrustum(drawArgs.WorldCamera)) { return; } this.CreateMesh(drawArgs.Device); this.chartMaterial = new Material(); base.RenderPriority = RenderPriority.Custom; if (base.position == Vector3.Empty) { base.position = MathEngine.SphericalToCartesian(this.latitude, this.longitude, drawArgs.WorldCamera.WorldRadius + this.elevation + this.distanceAboveSurface); } base.IsSelectable = true; base.Inited = true; }