/// <summary> /// Computes the angle (seen from the center of the sphere) between 2 sets of latitude/longitude values. /// </summary> /// <param name="latA">Latitude of point 1 (decimal degrees)</param> /// <param name="lonA">Longitude of point 1 (decimal degrees)</param> /// <param name="latB">Latitude of point 2 (decimal degrees)</param> /// <param name="lonB">Longitude of point 2 (decimal degrees)</param> /// <returns>Angle in decimal degrees</returns> public static double SphericalDistanceDegrees(double latA, double lonA, double latB, double lonB) { double radLatA = MathEngine.DegreesToRadians(latA); double radLatB = MathEngine.DegreesToRadians(latB); double radLonA = MathEngine.DegreesToRadians(lonA); double radLonB = MathEngine.DegreesToRadians(lonB); return(MathEngine.RadiansToDegrees( Math.Acos(Math.Cos(radLatA) * Math.Cos(radLatB) * Math.Cos(radLonA - radLonB) + Math.Sin(radLatA) * Math.Sin(radLatB)))); }
///<summary> /// Goes to the extent specified by the bounding box for the QTS layer /// or to the lat/lon for icons /// </summary> protected virtual void OnGotoClick(object sender, EventArgs e) { lock (this.ParentList.ChildObjects.SyncRoot) { for (int i = 0; i < this.ParentList.ChildObjects.Count; i++) { RenderableObject ro = (RenderableObject)this.ParentList.ChildObjects[i]; if (ro.Name.Equals(this.name)) { if (ro is QuadTileSet) { QuadTileSet qts = (QuadTileSet)ro; DrawArgs.Camera.SetPosition((qts.North + qts.South) / 2, (qts.East + qts.West) / 2); double perpendicularViewRange = (qts.North - qts.South > qts.East - qts.West ? qts.North - qts.South : qts.East - qts.West); double altitude = qts.LayerRadius * Math.Sin(MathEngine.DegreesToRadians(perpendicularViewRange * 0.5)); DrawArgs.Camera.Altitude = altitude; break; } if (ro is Icon) { Icon ico = (Icon)ro; DrawArgs.Camera.SetPosition(ico.Latitude, ico.Longitude); DrawArgs.Camera.Altitude /= 2; break; } if (ro is ShapeFileLayer) { ShapeFileLayer slayer = (ShapeFileLayer)ro; DrawArgs.Camera.SetPosition((slayer.North + slayer.South) / 2, (slayer.East + slayer.West) / 2); double perpendicularViewRange = (slayer.North - slayer.South > slayer.East - slayer.West ? slayer.North - slayer.South : slayer.East - slayer.West); double altitude = slayer.MaxAltitude; DrawArgs.Camera.Altitude = altitude; break; } } } } }
public override void SetPosition(double lat, double lon, double heading, double _altitude, double tilt, double bank) { if (double.IsNaN(lat)) { lat = this._latitude.Degrees; } if (double.IsNaN(lon)) { lon = this._longitude.Degrees; } if (double.IsNaN(heading)) { heading = this._heading.Degrees; } if (double.IsNaN(bank)) { bank = this._targetBank.Degrees; } this._targetOrientation = Quaternion4d.EulerToQuaternion( MathEngine.DegreesToRadians(lon), MathEngine.DegreesToRadians(lat), MathEngine.DegreesToRadians(heading)); Point3d v = Quaternion4d.QuaternionToEuler(this._targetOrientation); this._targetLatitude.Radians = v.Y; this._targetLongitude.Radians = v.X; this._targetHeading.Radians = v.Z; if (!double.IsNaN(tilt)) { this.Tilt = Angle.FromDegrees(tilt); } if (!double.IsNaN(_altitude)) { this.Altitude = _altitude; } this.Bank = Angle.FromDegrees(bank); }
public override void Render(DrawArgs drawArgs) { if (this.errorMsg != null) { //System.Windows.Forms.MessageBox.Show( errorMsg, "Model failed to load.", MessageBoxButtons.OK, MessageBoxIcon.Error); this.errorMsg = null; this.IsOn = false; this.isInitialized = false; return; } if (!this.IsVisible(drawArgs.WorldCamera)) { // Mesh is not in view, unload it to save memory if (this.isInitialized) this.Dispose(); return; } if (!this.isInitialized) return; //Donot render for other planets if (!drawArgs.CurrentWorld.IsEarth) return; drawArgs.device.SetRenderState(RenderState.CullMode, Cull.None); drawArgs.device.SetRenderState(RenderState.Lighting, true); drawArgs.device.SetRenderState(RenderState.Ambient, 0x808080); drawArgs.device.SetRenderState(RenderState.NormalizeNormals, true); Light lLight = new Light(); lLight.Ambient = Color.FromArgb(255, 255, 255).ToRawColor4();; lLight.Type = LightType.Directional; lLight.Direction = new Vector3(1f, 1f, 1f); // Put the light somewhere up in space lLight.Position = new Vector3((float) this.worldXyz.X * 2f, (float) this.worldXyz.Y * 1f, (float) this.worldXyz.Z * 1.5f); drawArgs.device.SetLight(0, ref lLight); drawArgs.device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Wrap); drawArgs.device.SetSamplerState(0, SamplerState.AddressV,TextureAddress.Wrap); drawArgs.device.SetRenderState(RenderState.AlphaBlendEnable, true); drawArgs.device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture); drawArgs.device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1); Matrix currentWorld = drawArgs.device.GetTransform(TransformState.World); drawArgs.device.SetTransform(TransformState.World, Matrix.RotationX((float)MathEngine.DegreesToRadians(this.RotX))); drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.RotY)); drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.RotZ)); drawArgs.device.SetTransform(TransformState.World *= Matrix.Scaling(this.Scale, this.Scale, this.Scale); // Move the mesh to desired location on earth if (this.IsVertExaggerable) this.vertExaggeration = World.Settings.VerticalExaggeration; else this.vertExaggeration = 1; drawArgs.device.SetTransform(TransformState.World *= Matrix.Translation(0, 0, (float)drawArgs.WorldCamera.WorldRadius + this.Altitude * this.vertExaggeration); drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationY((float)MathEngine.DegreesToRadians(90 - this.Latitude)); drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.Longitude)); drawArgs.device.SetTransform(TransformState.World *= Matrix.Translation( (float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z ); Device device = drawArgs.device; // Draw the mesh with effect if (this.isBumpmapped) this.setupBumpEffect(drawArgs); else this.setupReflectionEffect(drawArgs); //render the effect bool alphastate = device.GetRenderState<bool>(RenderState.AlphaBlendEnable); device.SetRenderState(RenderState.AlphaBlendEnable , true); this.effect.Begin(0); this.effect.BeginPass(0); //drawArgs.device.SetTexture(0, texture); this.m_meshElems[0].mesh.DrawSubset(0); this.effect.EndPass(); this.effect.End(); device.SetRenderState(RenderState.AlphaBlendEnable , alphastate); drawArgs.device.SetTransform(TransformState.World, currentWorld; drawArgs.device.SetRenderState(RenderState.Lighting , false); }
public override void Render(DrawArgs drawArgs) { // Vector3 here = MathEngine.SphericalToCartesian(drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude, this.layerRadius); Matrix currentWorld = drawArgs.device.GetTransform(TransformState.World); drawArgs.device.SetRenderState(RenderState.Lighting, true); drawArgs.device.SetRenderState(RenderState.ZEnable, true); Light lLight = new Light { Diffuse = Color.White.ToRawColor4(), Type = LightType.Point, Range = 100000, Position = new Vector3(this.layerRadius, 0, 0) }; drawArgs.device.SetLight(0, ref lLight); drawArgs.device.SetRenderState(RenderState.CullMode, Cull.None); Matrix lWorldTransform = Matrix.Identity; lWorldTransform = Matrix.Multiply(lWorldTransform, Matrix.Scaling(this.scaleFactor, this.scaleFactor, this.scaleFactor)); lWorldTransform = Matrix.Multiply(lWorldTransform, Matrix.Translation(0, 0, -this.layerRadius)); lWorldTransform = Matrix.Multiply(lWorldTransform, Matrix.RotationY((float)MathEngine.DegreesToRadians(90 - this.lat))); lWorldTransform = Matrix.Multiply(lWorldTransform, Matrix.RotationZ((float)MathEngine.DegreesToRadians(180 + this.lon))); drawArgs.device.SetTransform(TransformState.World, lWorldTransform); drawArgs.device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.Disable); drawArgs.device.SetRenderState(RenderState.NormalizeNormals, true); for (int i = 0; i < this.meshMaterials.Length; i++) { drawArgs.device.Material = this.meshMaterials[i]; this.mesh.DrawSubset(i); } drawArgs.device.SetTransform(TransformState.World, currentWorld); drawArgs.device.SetRenderState(RenderState.CullMode, Cull.Clockwise); drawArgs.device.SetRenderState(RenderState.Lighting, false); }
/// <summary> /// Gets called when user left clicks. /// RenderableObject abstract member (needed) /// Called from UI thread = UI code safe in this function /// </summary> public override bool PerformSelectionAction(DrawArgs drawArgs) { // Note: The following assignment to m is // to match the assignment to // drawArgs.device.SetTransform(TransformState.World in Render(). // Changes to that matrix should be mirrored here // until the assignment is centralized. Matrix m = Matrix.RotationX((float)MathEngine.DegreesToRadians(this.RotX)); m *= Matrix.RotationY((float)MathEngine.DegreesToRadians(this.RotY)); m *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.RotZ)); m *= Matrix.Scaling(this.Scale, this.Scale, this.Scale); if (this.IsVertExaggerable == true) { this.vertExaggeration = World.Settings.VerticalExaggeration; } else { this.vertExaggeration = 1; } m *= Matrix.Translation(0, 0, (float)(drawArgs.WorldCamera.WorldRadius + ((this.currentElevation + this.Altitude) * this.vertExaggeration))); m *= Matrix.RotationY((float)MathEngine.DegreesToRadians(90 - this.Latitude)); m *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.Longitude)); m *= Matrix.Translation( (float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z ); m = Matrix.Invert(m); Vector3 v1 = new Vector3(); v1.X = DrawArgs.LastMousePosition.X; v1.Y = DrawArgs.LastMousePosition.Y; v1.Z = drawArgs.WorldCamera.Viewport.MinDepth; v1.Unproject(drawArgs.WorldCamera.Viewport, drawArgs.WorldCamera.ProjectionMatrix, drawArgs.WorldCamera.ViewMatrix, drawArgs.WorldCamera.WorldMatrix); Vector3 v2 = new Vector3(); v2.X = DrawArgs.LastMousePosition.X; v2.Y = DrawArgs.LastMousePosition.Y; v2.Z = drawArgs.WorldCamera.Viewport.MaxDepth; v2.Unproject(drawArgs.WorldCamera.Viewport, drawArgs.WorldCamera.ProjectionMatrix, drawArgs.WorldCamera.ViewMatrix, drawArgs.WorldCamera.WorldMatrix); v1.TransformCoordinate(m); v2.TransformCoordinate(m); bool sel = false; foreach (MeshElem me in this.m_meshElems) { sel |= (me.mesh.Intersect(v1, v2 - v1)); } if (sel) { } return(sel); }
public override void Render(DrawArgs drawArgs) { if (this.errorMsg != null) { //System.Windows.Forms.MessageBox.Show( errorMsg, "Model failed to load.", MessageBoxButtons.OK, MessageBoxIcon.Error); this.errorMsg = null; this.IsOn = false; this.isInitialized = false; return; } if (!this.IsVisible(drawArgs.WorldCamera)) { // Mesh is not in view, unload it to save memory //if (isInitialized) //Dispose(); return; } if (!this.isInitialized) { this.Update(drawArgs); } // save current state Matrix currentWorld = drawArgs.device.GetTransform(TransformState.World); Cull cullMode = drawArgs.device.GetRenderState <Cull>(RenderState.CullMode); bool lighting = drawArgs.device.GetRenderState <bool>(RenderState.Lighting); int ambientColor = drawArgs.device.GetRenderState <int>(RenderState.Ambient); bool normalizeNormals = drawArgs.device.GetRenderState <bool>(RenderState.NormalizeNormals); drawArgs.device.SetRenderState(RenderState.CullMode, Cull.None); drawArgs.device.SetRenderState(RenderState.Lighting, true); drawArgs.device.SetRenderState(RenderState.Ambient, 0xCCCCCC); // 0x808080); drawArgs.device.SetRenderState(RenderState.NormalizeNormals, true); Light lLight = new Light(); lLight.Diffuse = new RawColor4(1, 1, 1, 1); lLight.Ambient = this.TintColor.ToRawColor4(); lLight.Type = LightType.Directional; lLight.Direction = new Vector3(1f, 1f, 1f); lLight.Position = new Vector3((float)this.worldXyz.X * 2f, (float)this.worldXyz.Y * 1f, (float)this.worldXyz.Z * 1.5f); drawArgs.device.SetLight(0, ref lLight); drawArgs.device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Wrap); drawArgs.device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Wrap); drawArgs.device.SetRenderState(RenderState.AlphaBlendEnable, true); drawArgs.device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture); drawArgs.device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1); // Put the light somewhere up in space Matrix lWorldMatrix = drawArgs.device.GetTransform(TransformState.World); lWorldMatrix = Matrix.Multiply(lWorldMatrix, Matrix.RotationX((float)MathEngine.DegreesToRadians(this.RotX))); lWorldMatrix = Matrix.Multiply(lWorldMatrix, Matrix.RotationY((float)MathEngine.DegreesToRadians(this.RotY))); lWorldMatrix = Matrix.Multiply(lWorldMatrix, Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.RotZ))); lWorldMatrix = Matrix.Multiply(lWorldMatrix, Matrix.Scaling(this.Scale, this.Scale, this.Scale)); // Move the mesh to desired location on earth if (this.IsVertExaggerable == true) { this.vertExaggeration = World.Settings.VerticalExaggeration; } else { this.vertExaggeration = 1; } lWorldMatrix = Matrix.Multiply(lWorldMatrix, Matrix.Translation(0, 0, (float)(drawArgs.WorldCamera.WorldRadius + ((this.currentElevation + this.Altitude) * this.vertExaggeration)))); lWorldMatrix = Matrix.Multiply(lWorldMatrix, Matrix.RotationY((float)MathEngine.DegreesToRadians(90 - this.Latitude))); lWorldMatrix = Matrix.Multiply(lWorldMatrix, Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.Longitude))); lWorldMatrix = Matrix.Multiply(lWorldMatrix, Matrix.Translation((float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z)); drawArgs.device.SetTransform(TransformState.World, lWorldMatrix); foreach (MeshElem me in this.m_meshElems) { try { for (int i = 0; i < me.meshMaterials.Length; i++) { // Set the material and texture for this subset drawArgs.device.Material = me.meshMaterials[i]; drawArgs.device.SetTexture(0, me.meshTextures[i]); // Draw the mesh subset me.mesh.DrawSubset(i); } } catch (Exception) { // Utility.Log.Write(name + caught); } } drawArgs.device.SetTransform(TransformState.World, currentWorld); drawArgs.device.SetRenderState(RenderState.Lighting, lighting); drawArgs.device.SetRenderState(RenderState.CullMode, cullMode); drawArgs.device.SetRenderState(RenderState.Ambient, ambientColor); drawArgs.device.SetRenderState(RenderState.NormalizeNormals, normalizeNormals); }