bool IUiController.MouseDown(object sender, MouseEventArgs e) { var width = Rect.East - Rect.West; var height = Rect.North - Rect.South; var range = Math.Max(width / 40, height / 40); var cursor = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y); if (cursor.Distance(Coordinates.FromLatLng(Rect.North, Rect.West)) < range) { dragCorner = DragCorners.NW; drag = true; } if (cursor.Distance(Coordinates.FromLatLng(Rect.North, (Rect.West + Rect.East) / 2)) < range) { dragCorner = DragCorners.N; drag = true; } if (cursor.Distance(Coordinates.FromLatLng(Rect.North, Rect.East)) < range) { dragCorner = DragCorners.NE; drag = true; } if (cursor.Distance(Coordinates.FromLatLng((Rect.North + Rect.South) / 2, Rect.West)) < range) { dragCorner = DragCorners.W; drag = true; } if (cursor.Distance(Coordinates.FromLatLng((Rect.North + Rect.South) / 2, (Rect.West + Rect.East) / 2)) < range) { dragCorner = DragCorners.C; drag = true; } if (cursor.Distance(Coordinates.FromLatLng((Rect.North + Rect.South) / 2, Rect.East)) < range) { dragCorner = DragCorners.E; drag = true; } if (cursor.Distance(Coordinates.FromLatLng(Rect.South, Rect.West)) < range) { dragCorner = DragCorners.SW; drag = true; } if (cursor.Distance(Coordinates.FromLatLng(Rect.South, (Rect.West + Rect.East) / 2)) < range) { dragCorner = DragCorners.S; drag = true; } if (cursor.Distance(Coordinates.FromLatLng(Rect.South, Rect.East)) < range) { dragCorner = DragCorners.SE; drag = true; } if (drag) { mouseDown = cursor; } return drag; }
public bool MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (Earth3d.MainWindow.StudyImageset == null) { mouseDown = false; return false; } Tile root = TileCache.GetTile(0, 0, 0, Earth3d.MainWindow.StudyImageset, null); if (root == null) { mouseDown = false; return false; } if (e.Button == MouseButtons.Right && (root is SkyImageTile)) { anchored = !anchored; popup.SetPivotMode(anchored); if (anchored) { anchoredPoint1 = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y); TourPlace place = new TourPlace("", anchoredPoint1.Dec, anchoredPoint1.RA, Classification.Unidentified, "UMA", ImageSetType.Sky, -1); Earth3d.MainWindow.SetLabelText(place, false); if (root is TangentTile) { TangentTile tile = (TangentTile)root; Vector3d vector = tile.TransformPoint(12, 12); vector = Coordinates.GeoTo3dDouble(anchoredPoint1.Lat, anchoredPoint1.Lng); double x; double y; tile.UnTransformPoint(vector, out x, out y); } else if (root is SkyImageTile) { SkyImageTile tile = (SkyImageTile)root; anchorPoint1 = tile.GetImagePixel(anchoredPoint1); } } mouseDown = true; return true; } else if (e.Button == MouseButtons.Left) { dragging = true; pntDown = e.Location; if (anchored) { if (root is TangentTile) { startRotation = Earth3d.MainWindow.StudyImageset.Rotation; startCenterX = Earth3d.MainWindow.StudyImageset.OffsetX; startCenterY = Earth3d.MainWindow.StudyImageset.OffsetY; startScale = Earth3d.MainWindow.StudyImageset.BaseTileDegrees; Coordinates downPoint = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y); startLength = anchoredPoint1.Distance(downPoint); startAngle = anchoredPoint1.Angle(downPoint) / RC; } else if (root is SkyImageTile) { SkyImageTile tile = (SkyImageTile)root; anchoredPoint2 = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y); anchorPoint2 = tile.GetImagePixel(anchoredPoint2); } } mouseDown = true; return true; } else { mouseDown = false; return false; } }
internal static IPlace FindClosest(Coordinates target, float distance, bool astronomical, string referenceLayer) { IPlace closestPlace = null; if (referenceLayer == null) { return closestPlace; } if (AllMaps.ContainsKey(referenceLayer)) { float currentDistance = distance; foreach (Layer layer in AllMaps[referenceLayer].Layers) { if (layer.Enabled && astronomical == layer.Astronomical) { closestPlace = layer.FindClosest(target, distance, closestPlace, astronomical); } } if (closestPlace != null && master != null) { master.ShowPlace(closestPlace); } } return closestPlace; }
public bool PointInboundingBox( Coordinates target, double[] bbox) { if (bbox[0] > bbox[2]) { if (bbox[0] > target.Lng && bbox[1] < target.Lat && bbox[2] < target.Lng && bbox[3] > target.Lat) { return true; } if (bbox[0] - 360 > target.Lng && bbox[1] < target.Lat && bbox[2] - 360 < target.Lng && bbox[3] > target.Lat) { return true; } } else { if (bbox[0] < target.Lng && bbox[1] < target.Lat && bbox[2] > target.Lng && bbox[3] > target.Lat) { return true; } if (bbox[0] - 360 < target.Lng && bbox[1] < target.Lat && bbox[2] - 360 > target.Lng && bbox[3] > target.Lat) { return true; } } return false; }
private void SetupMatricesSpace11(double localZoomFactor, RenderTypes renderType) { if (config.MultiChannelDome1 || config.MultiProjector || DomePreviewPopup.Active || rift) { SetupMatricesSpaceMultiChannel(localZoomFactor, renderType); return; } if ((Settings.Active.GalacticMode && !Settings.Active.LocalHorizonMode) && CurrentImageSet.DataSetType == ImageSetType.Sky) { // Show in galactic coordinates if (!galMatInit) { galacticMatrix = Matrix3d.Identity; galacticMatrix.Multiply(Matrix3d.RotationY(-(90 - (17.7603329867975 * 15)) / 180.0 * Math.PI)); galacticMatrix.Multiply(Matrix3d.RotationX(-((-28.9361739586894)) / 180.0 * Math.PI)); galacticMatrix.Multiply(Matrix3d.RotationZ(((31.422052860102041270114993238783) - 90) / 180.0 * Math.PI)); galMatInit = true; } WorldMatrix = galacticMatrix; WorldMatrix.Multiply(Matrix3d.RotationY(((az)) / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(-((alt)) / 180.0 * Math.PI)); double[] gPoint = Coordinates.GalactictoJ2000(az, alt); this.RA = gPoint[0] / 15; this.Dec = gPoint[1]; viewCamera.Lat = targetViewCamera.Lat; viewCamera.Lng = targetViewCamera.Lng; } else { // Show in Ecliptic WorldMatrix = Matrix3d.RotationY(-((this.ViewLong + 90.0) / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180.0 * Math.PI))); } double camLocal = CameraRotate; // altaz if ((Settings.Active.LocalHorizonMode && !Settings.Active.GalacticMode) && CurrentImageSet.DataSetType == ImageSetType.Sky) { Coordinates zenithAltAz = new Coordinates(0, 0); zenithAltAz.Az = 0; zenithAltAz.Alt = 0; if (!config.Master) { alt = 0; az = 0; config.DomeTilt = 0; if (Properties.Settings.Default.DomeTilt != 0) { Properties.Settings.Default.DomeTilt = 0; } } Coordinates zenith = Coordinates.HorizonToEquitorial(zenithAltAz, SpaceTimeController.Location, SpaceTimeController.Now); double raPart = -((zenith.RA - 6) / 24.0 * (Math.PI * 2)); double decPart = -(((zenith.Dec)) / 360.0 * (Math.PI * 2)); string raText = Coordinates.FormatDMS(zenith.RA); WorldMatrix = Matrix3d.RotationY(-raPart); WorldMatrix.Multiply(Matrix3d.RotationX(decPart)); if (SpaceTimeController.Location.Lat < 0) { WorldMatrix.Multiply(Matrix3d.RotationY(((az) / 180.0 * Math.PI))); WorldMatrix.Multiply(Matrix3d.RotationX(((alt) / 180.0 * Math.PI))); camLocal += Math.PI; } else { WorldMatrix.Multiply(Matrix3d.RotationY(((-az) / 180.0 * Math.PI))); WorldMatrix.Multiply(Matrix3d.RotationX(((-alt) / 180.0 * Math.PI))); } Coordinates currentRaDec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(alt, az), SpaceTimeController.Location, SpaceTimeController.Now); TargetLat = ViewLat = currentRaDec.Dec; TargetLong = ViewLong = RAtoViewLng(currentRaDec.RA); } RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; // altaz ViewPoint = Coordinates.RADecTo3d(this.RA, -this.Dec, 1.0); double distance = (4.0 * (localZoomFactor / 180)) + 0.000001; FovAngle = ((localZoomFactor/**16*/) / FOVMULT) / Math.PI * 180; RenderContext11.CameraPosition = new Vector3d(0.0, 0.0, 0.0); // This is for distance Calculation. For space everything is the same distance, so camera target is key. RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, new Vector3d(0.0, 0.0, -1.0), new Vector3d(Math.Sin(camLocal), Math.Cos(camLocal), 0.0)); if (config.MultiChannelGlobe) { Matrix3d globeCameraRotation = Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) * Matrix3d.RotationY((config.Heading / 180 * Math.PI)) * Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI)); RenderContext11.View = RenderContext11.View * globeCameraRotation; } if (multiMonClient) { RenderContext11.View = RenderContext11.View * Matrix3d.RotationY((config.Heading / 180 * Math.PI)); } RenderContext11.ViewBase = RenderContext11.View; m_nearPlane = 0f; if (multiMonClient) { ProjMatrix = Matrix3d.PerspectiveFovLH((localZoomFactor/**16*/) / FOVMULT, (double)(monitorWidth * MonitorCountX) / (double)(monitorHeight * MonitorCountY), .1, -2.0); } else { ProjMatrix = Matrix3d.PerspectiveFovLH((localZoomFactor/**16*/) / FOVMULT, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, .1, -2.0); } RenderContext11.PerspectiveFov = (localZoomFactor) / FOVMULT; if (multiMonClient) { ProjMatrix.M11 *= MonitorCountX * bezelSpacing; ProjMatrix.M22 *= MonitorCountY * bezelSpacing; ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2); ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2)); } if (config.MultiChannelGlobe) { ProjMatrix = Matrix3d.OrthoLH(config.Aspect * 2.0, 2.0, 0.0, 2.0); } RenderContext11.Projection = ProjMatrix; ViewMatrix = RenderContext11.View; MakeFrustum(); }
private void RenderFrame(RenderTargetTexture targetTexture, DepthBuffer depthBuffer, RenderTypes renderType) { CurrentRenderType = renderType; bool offscreenRender = targetTexture != null; Tile.deepestLevel = 0; try { if (offscreenRender) { RenderContext11.SetOffscreenRenderTargets(targetTexture, depthBuffer); } else { RenderContext11.SetDisplayRenderTargets(); } //Clear the backbuffer to a black color RenderContext11.ClearRenderTarget(new SharpDX.Color(SkyColor.R, SkyColor.G, SkyColor.B, SkyColor.A)); RenderContext11.RenderType = CurrentImageSet.DataSetType; RenderContext11.BlendMode = BlendMode.Alpha; if (CurrentImageSet.DataSetType == ImageSetType.Sandbox) { // Start Sandbox mode RenderContext11.SunPosition = LayerManager.GetPrimarySandboxLight(); RenderContext11.SunlightColor = LayerManager.GetPrimarySandboxLightColor(); RenderContext11.ReflectedLightColor = Color.Black; RenderContext11.HemisphereLightColor = Color.Black; SkyColor = Color.Black; if ((int)SolarSystemTrack < (int)SolarSystemObjects.Custom) { double radius = Planets.GetAdjustedPlanetRadius((int)SolarSystemTrack); double distance = SolarSystemCameraDistance; double camAngle = fovLocal; double distrad = distance / (radius * Math.Tan(.5 * camAngle)); if (distrad < 1) { planetFovWidth = Math.Asin(distrad); } else { planetFovWidth = Math.PI; } } else { planetFovWidth = Math.PI; } SetupMatricesSolarSystem11(false, renderType); Matrix3d matLocal = RenderContext11.World; matLocal.Multiply(Matrix3d.Translation(-viewCamera.ViewTarget)); RenderContext11.World = matLocal; RenderContext11.WorldBase = RenderContext11.World; RenderContext11.WorldBaseNonRotating = RenderContext11.World; RenderContext11.NominalRadius = 1; Earth3d.MainWindow.MakeFrustum(); double zoom = Earth3d.MainWindow.ZoomFactor; LayerManager.Draw(RenderContext11, 1.0f, false, "Sandbox", true, false); if ((SolarSystemMode) && label != null && !TourPlayer.Playing) { label.Draw(RenderContext11, true); } RenderContext11.setRasterizerState(TriangleCullMode.Off); // end Sandbox Mode } else if (CurrentImageSet.DataSetType == ImageSetType.SolarSystem) { { SkyColor = Color.Black; if ((int)SolarSystemTrack < (int)SolarSystemObjects.Custom) { double radius = Planets.GetAdjustedPlanetRadius((int)SolarSystemTrack); double distance = SolarSystemCameraDistance; double camAngle = fovLocal; double distrad = distance / (radius * Math.Tan(.5 * camAngle)); if (distrad < 1) { planetFovWidth = Math.Asin(distrad); } else { planetFovWidth = Math.PI; } } else { planetFovWidth = Math.PI; } if (trackingObject == null) { trackingObject = Search.FindCatalogObjectExact("Sun"); } SetupMatricesSolarSystem11(true, renderType); float skyOpacity = 1.0f - Planets.CalculateSkyBrightnessFactor(RenderContext11.View, viewCamera.ViewTarget); if (float.IsNaN(skyOpacity)) { skyOpacity = 0f; } double zoom = Earth3d.MainWindow.ZoomFactor; float milkyWayBlend = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 8.4)) / 4.2); float milkyWayBlendIn = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 17.9)) / 2.3); if (Properties.Settings.Default.SolarSystemMilkyWay.State) { if (milkyWayBlend < 1) // Solar System mode Milky Way background { if (milkyWayBackground == null) { milkyWayBackground = GetImagesetByName("Digitized Sky Survey (Color)"); } if (milkyWayBackground != null) { float c = ((1 - milkyWayBlend)) / 4; Matrix3d matOldMW = RenderContext11.World; Matrix3d matLocalMW = RenderContext11.World; matLocalMW.Multiply(Matrix3d.Scaling(100000, 100000, 100000)); matLocalMW.Multiply(Matrix3d.RotationX(-23.5 / 180 * Math.PI)); matLocalMW.Multiply(Matrix3d.RotationY(Math.PI)); matLocalMW.Multiply(Matrix3d.Translation(cameraOffset)); RenderContext11.World = matLocalMW; RenderContext11.WorldBase = matLocalMW; Earth3d.MainWindow.MakeFrustum(); RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White); RenderContext11.DepthStencilMode = DepthStencilMode.Off; DrawTiledSphere(milkyWayBackground, c * Properties.Settings.Default.SolarSystemMilkyWay.Opacity, Color.FromArgb(255, 255, 255, 255)); RenderContext11.World = matOldMW; RenderContext11.WorldBase = matOldMW; RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } } } // CMB float cmbBlend = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 33)) / 2.3); double cmbLog = Math.Log(zoom); if (Properties.Settings.Default.SolarSystemCMB.State) { if (cmbBlend > 0) // Solar System mode Milky Way background { if (cmbBackground == null) { cmbBackground = GetImagesetByName("Planck CMB"); } if (cmbBackground != null) { float c = ((cmbBlend)) / 16; Matrix3d matOldMW = RenderContext11.World; Matrix3d matLocalMW = RenderContext11.World; matLocalMW.Multiply(Matrix3d.Scaling(2.9090248982E+15, 2.9090248982E+15, 2.9090248982E+15)); matLocalMW.Multiply(Matrix3d.RotationX(-23.5 / 180 * Math.PI)); matLocalMW.Multiply(Matrix3d.RotationY(Math.PI)); RenderContext11.World = matLocalMW; RenderContext11.WorldBase = matLocalMW; Earth3d.MainWindow.MakeFrustum(); RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White); RenderContext11.DepthStencilMode = DepthStencilMode.Off; DrawTiledSphere(cmbBackground, c * Properties.Settings.Default.SolarSystemCMB.Opacity, Color.FromArgb(255, 255, 255, 255)); RenderContext11.World = matOldMW; RenderContext11.WorldBase = matOldMW; RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } } } { Matrix3d matOld = RenderContext11.World; Matrix3d matLocal = RenderContext11.World; matLocal.Multiply(Matrix3d.Translation(viewCamera.ViewTarget)); RenderContext11.World = matLocal; Earth3d.MainWindow.MakeFrustum(); if (Properties.Settings.Default.SolarSystemCosmos.State) { RenderContext11.DepthStencilMode = DepthStencilMode.Off; Grids.DrawCosmos3D(RenderContext11, Properties.Settings.Default.SolarSystemCosmos.Opacity * skyOpacity); RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } if (true) { RenderContext11.DepthStencilMode = DepthStencilMode.Off; Grids.DrawCustomCosmos3D(RenderContext11, skyOpacity); RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } if (Properties.Settings.Default.SolarSystemMilkyWay.State && milkyWayBlendIn > 0) { Grids.DrawGalaxy3D(RenderContext11, Properties.Settings.Default.SolarSystemMilkyWay.Opacity * skyOpacity * milkyWayBlendIn); } if (Properties.Settings.Default.SolarSystemStars.State) { Grids.DrawStars3D(RenderContext11, Properties.Settings.Default.SolarSystemStars.Opacity * skyOpacity); } LayerManager.Draw(RenderContext11, 1.0f, true, "Sky", true, false); RenderContext11.World = matOld; Earth3d.MainWindow.MakeFrustum(); } if (SolarSystemCameraDistance < 15000) { SetupMatricesSolarSystem11(false, renderType); if (Properties.Settings.Default.SolarSystemMinorPlanets.State) { MinorPlanets.DrawMPC3D(RenderContext11, Properties.Settings.Default.SolarSystemMinorPlanets.Opacity, viewCamera.ViewTarget); } Planets.DrawPlanets3D(RenderContext11, Properties.Settings.Default.SolarSystemPlanets.Opacity, viewCamera.ViewTarget); } double p = Math.Log(zoom); double d = (180 / SolarSystemCameraDistance) * 100; float sunAtDistance = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 7.5)) / 3); if (sunAtDistance > 0 && Settings.Active.SolarSystemPlanets) { Planets.DrawPointPlanet(RenderContext11, new Vector3d(0, 0, 0), (float)d * sunAtDistance, Color.FromArgb(192, 191, 128), false, 1); } if ((SolarSystemMode) && label != null && !TourPlayer.Playing) { label.Draw(RenderContext11, true); } } RenderContext11.setRasterizerState(TriangleCullMode.Off); } else { if (CurrentImageSet.DataSetType == ImageSetType.Panorama || CurrentImageSet.DataSetType == ImageSetType.Sky) { SkyColor = Color.Black; if ((int)renderType < 5) { SetupMatricesSpaceDome(false, renderType); } else { SetupMatricesSpace11(ZoomFactor, renderType); } RenderContext11.DepthStencilMode = DepthStencilMode.Off; } else { if (Settings.DomeView) { SetupMatricesLandDome(renderType); } else { SetupMatricesLand11(renderType); } RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } ComputeViewParameters(CurrentImageSet); // Update Context pane CurrentViewCorners = new Coordinates[] { GetCoordinatesForScreenPoint(0, 0), GetCoordinatesForScreenPoint(ViewWidth, 0), GetCoordinatesForScreenPoint(ViewWidth, renderWindow.ClientRectangle.Height), GetCoordinatesForScreenPoint(0, renderWindow.ClientRectangle.Height) }; Coordinates temp = GetCoordinatesForScreenPoint(ViewWidth / 2, renderWindow.ClientRectangle.Height / 2); if (contextPanel != null && ((int)renderType > 4 || renderType == RenderTypes.DomeFront)) { contextPanel.SetViewRect(CurrentViewCorners); } UpdateKmlViewInfo(); if (KmlMarkers != null) { KmlMarkers.ClearGroundOverlays(); } string referenceFrame = GetCurrentReferenceFrame(); if (PlanetLike || Space) { LayerManager.PreDraw(RenderContext11, 1.0f, Space, referenceFrame, true); } if (Properties.Settings.Default.EarthCutawayView.State && !Space && CurrentImageSet.DataSetType == ImageSetType.Earth) { Grids.DrawEarthStructure(RenderContext11, 1f); } RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White); if (KmlMarkers != null) { KmlMarkers.SetupGroundOverlays(RenderContext11); } if (PlanetLike) { RenderContext11.setRasterizerState(TriangleCullMode.Off); } // Call DrawTiledSphere instead of PaintLayerFull, because PaintLayerFull // will reset ground layer state DrawTiledSphere(CurrentImageSet, 1.0f, Color.White); if (imageStackVisible) { foreach (ImageSet set in ImageStackList) { PaintLayerFull11(set, StudyOpacity); } } if (studyImageset != null) { if (studyImageset.DataSetType != CurrentImageSet.DataSetType) { StudyImageset = null; } else { PaintLayerFull11(studyImageset, StudyOpacity); } } if (previewImageset != null && PreviewBlend.State) { if (previewImageset.DataSetType != CurrentImageSet.DataSetType) { previewImageset = null; } else { PaintLayerFull11(previewImageset, PreviewBlend.Opacity * 100.0f); } } else { PreviewBlend.State = false; previewImageset = null; } if (Space && (CurrentImageSet.Name == "Plotted Sky")) { Grids.DrawStars(RenderContext11, 1f); } if (Space && Properties.Settings.Default.ShowSolarSystem.State) { Planets.DrawPlanets(RenderContext11, Properties.Settings.Default.ShowSolarSystem.Opacity); } if (PlanetLike || Space) { if (!Space) { //todo fix this for other planets.. double angle = Coordinates.MstFromUTC2(SpaceTimeController.Now, 0) / 180.0 * Math.PI; RenderContext11.WorldBaseNonRotating = Matrix3d.RotationY(angle) * RenderContext11.WorldBase; RenderContext11.NominalRadius = CurrentImageSet.MeanRadius; } else { RenderContext11.WorldBaseNonRotating = RenderContext11.World; RenderContext11.NominalRadius = CurrentImageSet.MeanRadius; RenderContext11.DepthStencilMode = DepthStencilMode.Off; } LayerManager.Draw(RenderContext11, 1.0f, Space, referenceFrame, true, Space); } if (Space && !hemisphereView && Settings.Active.LocalHorizonMode && !Settings.DomeView && !ProjectorServer) { Grids.DrawHorizon(RenderContext11, 1f); } if (Settings.Active.ShowClouds && !Space && CurrentImageSet.DataSetType == ImageSetType.Earth) { DrawClouds(); } // Draw Field of view indicator if (Settings.Active.ShowFieldOfView) { fovBlend.TargetState = true; } else { fovBlend.TargetState = false; } if (fovBlend.State) { if (fov != null && Space) { fov.Draw3D(RenderContext11, fovBlend.Opacity, RA, Dec); } } if (label != null && !TourPlayer.Playing) { label.Draw(RenderContext11, PlanetLike); } if (ShowKmlMarkers && KmlMarkers != null) { KmlMarkers.DrawLabels(RenderContext11); } // End Planet & space } if (uiController != null) { { uiController.Render(this); } } if (videoOverlay != null) { if ((int)renderType < 5) { SetupMatricesVideoOverlayDome(false, renderType); } else { SetupMatricesVideoOverlay(ZoomFactor); } DepthStencilMode mode = RenderContext11.DepthStencilMode = DepthStencilMode.Off; PaintLayerFull11(videoOverlay, 100f); RenderContext11.DepthStencilMode = mode; } if (measuringDrag && measureLines != null) { measureLines.DrawLines(RenderContext11, 1.0f, Color.Yellow); } if (Properties.Settings.Default.ShowCrosshairs && !TourPlayer.Playing && renderType == RenderTypes.Normal) { float aspect = RenderContext11.ViewPort.Height / RenderContext11.ViewPort.Width; crossHairPoints[0].X = .01f * aspect; crossHairPoints[1].X = -.01f * aspect; crossHairPoints[0].Y = 0; crossHairPoints[1].Y = 0; crossHairPoints[0].Z = .9f; crossHairPoints[1].Z = .9f; crossHairPoints[0].W = 1f; crossHairPoints[1].W = 1f; crossHairPoints[0].Color = Color.White; crossHairPoints[1].Color = Color.White; crossHairPoints[2].X = 0; crossHairPoints[3].X = 0; crossHairPoints[2].Y = -.01f; crossHairPoints[3].Y = .01f; crossHairPoints[2].Z = .9f; crossHairPoints[3].Z = .9f; crossHairPoints[2].W = 1f; crossHairPoints[3].W = 1f; crossHairPoints[2].Color = Color.White; crossHairPoints[3].Color = Color.White; Sprite2d.DrawLines(RenderContext11, crossHairPoints, 4, SharpDX.Matrix.OrthoLH(1f, 1f, 1, -1), false); } if (Properties.Settings.Default.ShowTouchControls && (!TourPlayer.Playing || mover == null) && ( renderType == RenderTypes.Normal || renderType == RenderTypes.LeftEye || renderType == RenderTypes.RightEye) && !rift ) { DrawTouchControls(); } DrawKinectUI(); SetupMatricesAltAz(); Reticle.DrawAll(RenderContext11); } catch (Exception e) { if (Earth3d.Logging) { Earth3d.WriteLogMessage("RenderFrame: Exception"); } if (offscreenRender) { throw e; } } finally { if (offscreenRender) { RenderContext11.SetDisplayRenderTargets(); } } PresentFrame11(offscreenRender); }
public static Vector3d RADecTo3dDouble(Coordinates point, double radius) { point.Dec = -point.Dec; return new Vector3d((Math.Cos(point.RA * RCRA) * Math.Cos(point.Dec * RC) * radius), (Math.Sin(point.Dec * RC) * radius), (Math.Sin(point.RA * RCRA) * Math.Cos(point.Dec * RC) * radius)); }
private void renderWindow_MouseDown(object sender, MouseEventArgs e) { this.Focus(); if (uiController != null) { if (uiController.MouseDown(sender, new MouseEventArgs(e.Button, e.Clicks, e.X + Properties.Settings.Default.ScreenHitTestOffsetX, e.Y + Properties.Settings.Default.ScreenHitTestOffsetY, e.Delta))) { return; } } if (Control.ModifierKeys == (Keys.Control | Keys.Alt | Keys.Shift)) { // Contrast code here contrastMode = true; return; } contrastMode = false; if (ProcessTouchControls(e)) { return; } if (e.Button == MouseButtons.Left) { if (CurrentImageSet != null && CurrentImageSet.ReferenceFrame == null) { switch (CurrentImageSet.DataSetType) { case ImageSetType.Earth: CurrentImageSet.ReferenceFrame = "Earth"; break; case ImageSetType.Planet: break; case ImageSetType.Sky: CurrentImageSet.ReferenceFrame = "Sky"; break; case ImageSetType.Panorama: CurrentImageSet.ReferenceFrame = "Panorama"; break; case ImageSetType.SolarSystem: CurrentImageSet.ReferenceFrame = SolarSystemTrack.ToString(); break; default: break; } } if (CurrentImageSet != null) { if (LayerManager.ClickCheckScreenSpace(new Point(e.X, e.Y), CurrentImageSet.ReferenceFrame)) { return; } } } if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle) { if (Control.ModifierKeys == Keys.Alt || Control.ModifierKeys == Keys.Control || e.Button == MouseButtons.Middle) { spinning = true; angle = true; } else if (Control.ModifierKeys == Keys.Shift || measuring) { if (Space) { measuringDrag = true; measureEnd = measureStart = GetCoordinatesForScreenPoint(e.X, e.Y); if (measureLines != null) { measureLines.Clear(); } } } else { dragging = true; } moved = false; this.mouseDownX = e.X; this.mouseDownY = e.Y; } }
public static Coordinates EquitorialToHorizon4(Coordinates equitorial, Coordinates location, DateTime utc) { var lon = location.Lng; var hour = utc.Hour + utc.Minute / 60.00 + utc.Second / 3600.0; var day = utc.Day + hour / 24.0; var fullDays = Math.Floor(day); var month = utc.Month; var year = utc.Year; if (month < 3) { year--; month += 12; } double gr; if (year + month / 100 + fullDays / 10000 >= 1582.1015) { gr = 2 - Math.Floor(year / 100.0) + Math.Floor(Math.Floor(year / 100.0) / 4); } else { gr = 0; } var julianDay = Math.Floor(365.25 * year) + Math.Floor(30.6001 * (month + 1)) + fullDays + 1720994.5 + gr; var julianDay2 = julianDay + hour / 24; var t = (julianDay - 2415020) / 36525; var ss = 6.6460656 + 2400.051 * t + 0.00002581 * t * t; var st = (ss / 24 - Math.Floor(ss / 24)) * 24; var gsth = Math.Floor(st); var gstm = Math.Floor((st - Math.Floor(st)) * 60); var gsts = ((st - Math.Floor(st)) * 60 - gstm) * 60; var sa = st + (day - Math.Floor(day)) * 24 * 1.002737908; sa = sa + (lon/15); if (sa < 0) { sa +=24; } if (sa > 24) { sa-=24; } var tsh = Math.Floor(sa); var tsm = Math.Floor((sa - Math.Floor(sa)) * 60); var tss = ((sa - Math.Floor(sa)) * 60 - tsm) * 60; return new Coordinates(0,0); }
public static Coordinates HorizonToEquitorial(Coordinates altAz, Coordinates location, DateTime utc) { var hourAngle = MstFromUTC2(utc, location.Lng);// -(equitorial.RA * 15); double haLocal; double declination; AltAzToRaDec(altAz.Alt * RC, altAz.Az * RC, out haLocal, out declination, location.Lat * RC); var ha = (haLocal / RC); hourAngle += ha; if (hourAngle < 0) { hourAngle += 360.00; } if (hourAngle > 360) { hourAngle -= 360; } return FromRaDec(hourAngle / 15, declination / RC); }
public static Coordinates EquitorialToHorizon(Coordinates equitorial, Coordinates location, DateTime utc) { var hourAngle = MstFromUTC2(utc, location.Lng) - (equitorial.RA * 15); if (hourAngle < 0) { hourAngle += 360.00; } var ha = hourAngle * RC; var dec = equitorial.Dec * RC; var lat = (location.Lat) * RC; var sinAlt = Math.Sin(dec) * Math.Sin(lat) + Math.Cos(dec) * Math.Cos(lat) * Math.Cos(ha); var altitude = Math.Asin(sinAlt); var cosAzimith = (Math.Sin(dec) - Math.Sin(altitude)*Math.Sin(lat))/(Math.Cos(altitude)*Math.Cos(lat)); var azimuth = Math.Acos(cosAzimith); var altAz = new Coordinates(azimuth,altitude); if (Math.Sin(ha) > 0) { altAz.Az = (360 - altAz.Az); } return altAz; }
public double Distance3d(Coordinates pointB) { var pnt1 = GeoTo3dDouble(pointB.Lat, pointB.Lng); var pnt2 = GeoTo3dDouble(Lat, Lng); var pntDiff = pnt1 - pnt2; return pntDiff.Length() / RC; }
public override bool Draw(RenderContext11 renderContext, float opacity, bool flat) { if (bufferIsFlat != flat) { CleanUp(); bufferIsFlat = flat; } if (!CleanAndReady) { PrepVertexBuffer(opacity); } Matrix3d oldWorld = renderContext.World; if (astronomical && !bufferIsFlat) { double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI; renderContext.World = Matrix3d.RotationX(ecliptic) * renderContext.World; } if (triangleList2d != null) { triangleList2d.Decay = decay; triangleList2d.Sky = this.Astronomical; triangleList2d.TimeSeries = timeSeries; triangleList2d.Draw(renderContext, opacity * Opacity, TerraViewer.TriangleList.CullMode.CounterClockwise); } if (triangleList != null) { triangleList.Decay = decay; triangleList.Sky = this.Astronomical; triangleList.TimeSeries = timeSeries; triangleList.Draw(renderContext, opacity * Opacity, TerraViewer.TriangleList.CullMode.CounterClockwise); } if (lineList != null) { lineList.Sky = this.Astronomical; lineList.Decay = decay; lineList.TimeSeries = timeSeries; lineList.DrawLines(renderContext, opacity * Opacity); } if (lineList2d != null) { lineList2d.Sky = !this.Astronomical; lineList2d.Decay = decay; lineList2d.TimeSeries = timeSeries; lineList2d.ShowFarSide = ShowFarSide; lineList2d.DrawLines(renderContext, opacity * Opacity); } if (textBatch != null) { DepthStencilMode mode = renderContext.DepthStencilMode; renderContext.DepthStencilMode = DepthStencilMode.Off; textBatch.Draw(renderContext, 1, Color.White); renderContext.DepthStencilMode = mode; } if (astronomical && !bufferIsFlat) { renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite; } else { renderContext.DepthStencilMode = DepthStencilMode.Off; } DateTime baseDate = new DateTime(2010, 1, 1, 12, 00, 00); renderContext.setRasterizerState(TriangleCullMode.Off); Vector3 cam = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector311; float adjustedScale = scaleFactor; if (flat && astronomical && (markerScale == MarkerScales.World)) { adjustedScale = (float)(scaleFactor / (Earth3d.MainWindow.ZoomFactor / 360)); } Matrix matrixWVP = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; matrixWVP.Transpose(); switch (plotType) { default: case PlotTypes.Gaussian: renderContext.BlendMode = BlendMode.Additive; renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Grids.StarProfile.ResourceView); break; case PlotTypes.Circle: renderContext.BlendMode = BlendMode.Alpha; renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, CircleTexture.ResourceView); break; case PlotTypes.Point: renderContext.BlendMode = BlendMode.Alpha; renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, PointTexture.ResourceView); break; case PlotTypes.Square: renderContext.BlendMode = BlendMode.Alpha; renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, SquareTexture.ResourceView); break; case PlotTypes.Target1: renderContext.BlendMode = BlendMode.Alpha; renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Target1Texture.ResourceView); break; case PlotTypes.Target2: renderContext.BlendMode = BlendMode.Alpha; renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Target2Texture.ResourceView); break; case PlotTypes.PushPin: renderContext.BlendMode = BlendMode.Alpha; renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, PushPin.GetPushPinTexture(markerIndex).ResourceView); break; } columnChartsActivate.TargetState = plotType == PlotTypes.Column; if (shapeFileVertex != null) { if (plotType == PlotTypes.Column && !RenderContext11.Downlevel) // column chart mode { columnChartsActivate.TargetState = true; renderContext.BlendMode = BlendMode.Alpha; renderContext.setRasterizerState(TriangleCullMode.CullClockwise); renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, null); renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite; TimeSeriesColumnChartShader11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1); TimeSeriesColumnChartShader11.Constants.JNow = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate)); TimeSeriesColumnChartShader11.Constants.Decay = timeSeries ? decay : 0f; TimeSeriesColumnChartShader11.Constants.Scale = (float)(adjustedScale); TimeSeriesColumnChartShader11.Constants.Sky = astronomical ? -1 : 1; TimeSeriesColumnChartShader11.Constants.Opacity = opacity * this.Opacity; TimeSeriesColumnChartShader11.Constants.ShowFarSide = ShowFarSide ? 1f : 0f; TimeSeriesColumnChartShader11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f); TimeSeriesColumnChartShader11.Constants.WorldViewProjection = matrixWVP; TimeSeriesColumnChartShader11.ViewportScale = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height); TimeSeriesColumnChartShader11.Use(renderContext.devContext); } else if (plotType == PlotTypes.Cylinder && !RenderContext11.Downlevel) { renderContext.BlendMode = BlendMode.Alpha; renderContext.setRasterizerState(TriangleCullMode.CullClockwise); renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, null); renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite; TimeSeriesColumnChartShaderNGon11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1); TimeSeriesColumnChartShaderNGon11.Constants.JNow = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate)); TimeSeriesColumnChartShaderNGon11.Constants.Decay = timeSeries ? decay : 0f; TimeSeriesColumnChartShaderNGon11.Constants.Scale = (float)(adjustedScale); TimeSeriesColumnChartShaderNGon11.Constants.Sky = astronomical ? -1 : 1; TimeSeriesColumnChartShaderNGon11.Constants.Opacity = opacity * this.Opacity; TimeSeriesColumnChartShaderNGon11.Constants.ShowFarSide = ShowFarSide ? 1f : 0f; TimeSeriesColumnChartShaderNGon11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f); TimeSeriesColumnChartShaderNGon11.Constants.WorldViewProjection = matrixWVP; TimeSeriesColumnChartShaderNGon11.ViewportScale = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height); TimeSeriesColumnChartShaderNGon11.Use(renderContext.devContext); } else { TimeSeriesPointSpriteShader11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1); double jBase = SpaceTimeController.UtcToJulian(baseDate); TimeSeriesPointSpriteShader11.Constants.JNow = (float)(SpaceTimeController.JNow - jBase); TimeSeriesPointSpriteShader11.Constants.Decay = timeSeries ? decay : 0f; TimeSeriesPointSpriteShader11.Constants.Scale = ((markerScale == MarkerScales.World) ? ((float)adjustedScale) : (-(float)adjustedScale)); TimeSeriesPointSpriteShader11.Constants.Sky = astronomical ? -1 : 1; TimeSeriesPointSpriteShader11.Constants.Opacity = opacity * this.Opacity; TimeSeriesPointSpriteShader11.Constants.ShowFarSide = ShowFarSide ? 1f : 0f; TimeSeriesPointSpriteShader11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f); TimeSeriesPointSpriteShader11.Constants.WorldViewProjection = matrixWVP; TimeSeriesPointSpriteShader11.ViewportScale = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height); TimeSeriesPointSpriteShader11.PointScaleFactors = new SharpDX.Vector3(0.0f, 0.0f, 10.0f); if (shapeFileVertex.Downlevel) { DownlevelTimeSeriesPointSpriteShader.Use(renderContext.devContext, shapeFileVertex.Instanced); } else { TimeSeriesPointSpriteShader11.Use(renderContext.devContext); } } shapeFileVertex.Draw(renderContext, shapeFileVertex.Count, null, 1.0f); } renderContext.Device.ImmediateContext.GeometryShader.Set(null); renderContext.BlendMode = BlendMode.Alpha; renderContext.World = oldWorld; return(true); }
public override IPlace FindClosest(Coordinates target, float distance, IPlace closestPlace, bool astronomical) { return base.FindClosest(target, distance, closestPlace, astronomical); }
public static Vector2d RaDecToTan(Coordinates center, Coordinates point) { return RaDecToTan(new Vector2d(center.RA, center.Dec), new Vector2d(point.RA, point.Dec)); }
public override bool Draw(RenderContext11 renderContext, float opacity, bool flat) { if (shapefile == null) { return(false); } if (shapeFileVertex == null) { List <Vector3> vertList = new List <Vector3>(); List <UInt32> indexList = new List <UInt32>(); UInt32 firstItemIndex = 0; Vector3 lastItem = new Vector3(); bool firstItem = true; bool north = true; double offsetX = 0; double offsetY = 0; double centralMeridian = 0; double mapScale = 0; double standardParallel = 70; if (shapefile.Projection == ShapeFile.Projections.PolarStereo) { north = shapefile.FileHeader.ProjectionInfo.Name.ToLower().Contains("north"); standardParallel = shapefile.FileHeader.ProjectionInfo.GetParameter("standard_parallel_1"); centralMeridian = shapefile.FileHeader.ProjectionInfo.GetParameter("central_meridian"); mapScale = shapefile.FileHeader.ProjectionInfo.GetParameter("scale_factor"); offsetY = shapefile.FileHeader.ProjectionInfo.GetParameter("false_easting"); offsetX = shapefile.FileHeader.ProjectionInfo.GetParameter("false_northing"); } UInt32 currentIndex = 0; Color color = Color; int count = 360; for (int i = 0; i < shapefile.Shapes.Count; i++) { if (shapefile.Shapes[i].GetType() == typeof(Polygon)) { Polygon p = (Polygon)shapefile.Shapes[i]; for (int z = 0; z < p.Rings.Length; z++) { count = (p.Rings[z].Points.Length); // content from DBF DataRow dr = p.Rings[z].Attributes; for (int k = 0; k < p.Rings[z].Points.Length; k++) { // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used. double Xcoord = p.Rings[z].Points[k].X; double Ycoord = p.Rings[z].Points[k].Y; if (shapefile.Projection == ShapeFile.Projections.Geo) { lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord); } else if (shapefile.Projection == ShapeFile.Projections.PolarStereo) { lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3; } if (k == 0) { firstItemIndex = currentIndex; firstItem = true; } vertList.Add(lastItem); if (firstItem) { firstItem = false; } else { indexList.Add(currentIndex); currentIndex++; indexList.Add(currentIndex); } } indexList.Add(currentIndex); indexList.Add(firstItemIndex); currentIndex++; } } else if (shapefile.Shapes[i].GetType() == typeof(PolygonZ)) { PolygonZ p = (PolygonZ)shapefile.Shapes[i]; for (int z = 0; z < p.Rings.Length; z++) { count = (p.Rings[z].Points.Length); // content from DBF DataRow dr = p.Rings[z].Attributes; for (int k = 0; k < p.Rings[z].Points.Length; k++) { // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used. double Xcoord = p.Rings[z].Points[k].X; double Ycoord = p.Rings[z].Points[k].Y; if (shapefile.Projection == ShapeFile.Projections.Geo) { lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord); } else if (shapefile.Projection == ShapeFile.Projections.PolarStereo) { lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3; } if (k == 0) { firstItemIndex = currentIndex; firstItem = true; } vertList.Add(lastItem); if (firstItem) { firstItem = false; } else { indexList.Add(currentIndex); currentIndex++; indexList.Add(currentIndex); } } indexList.Add(currentIndex); indexList.Add(firstItemIndex); currentIndex++; } } else if (shapefile.Shapes[i].GetType() == typeof(PolyLine)) { PolyLine p = (PolyLine)shapefile.Shapes[i]; for (int z = 0; z < p.Lines.Length; z++) { count = (p.Lines[z].Points.Length); firstItem = true; for (int k = 0; k < p.Lines[z].Points.Length; k++) { // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used. double Xcoord = p.Lines[z].Points[k].X; double Ycoord = p.Lines[z].Points[k].Y; if (shapefile.Projection == ShapeFile.Projections.Geo) { lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord); } else if (shapefile.Projection == ShapeFile.Projections.PolarStereo) { lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3; } if (k == 0) { firstItemIndex = currentIndex; firstItem = true; } vertList.Add(lastItem); if (firstItem) { firstItem = false; } else { indexList.Add(currentIndex); currentIndex++; indexList.Add(currentIndex); } } currentIndex++; } } else if (shapefile.Shapes[i].GetType() == typeof(PolyLineZ)) { PolyLineZ p = (PolyLineZ)shapefile.Shapes[i]; for (int z = 0; z < p.Lines.Length; z++) { count = (p.Lines[z].Points.Length); Vector3[] points = new Vector3[(count)]; firstItem = true; for (int k = 0; k < p.Lines[z].Points.Length; k++) { // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used. double Xcoord = p.Lines[z].Points[k].X; double Ycoord = p.Lines[z].Points[k].Y; if (shapefile.Projection == ShapeFile.Projections.Geo) { lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord); } else if (shapefile.Projection == ShapeFile.Projections.PolarStereo) { lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3; } if (k == 0) { firstItemIndex = currentIndex; firstItem = true; } vertList.Add(lastItem); if (firstItem) { firstItem = false; } else { indexList.Add(currentIndex); currentIndex++; indexList.Add(currentIndex); } } currentIndex++; } } else if (shapefile.Shapes[i].GetType() == typeof(ShapefileTools.Point)) { ShapefileTools.Point p = (ShapefileTools.Point)shapefile.Shapes[i]; // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used. double Xcoord = p.X; double Ycoord = p.Y; if (shapefile.Projection == ShapeFile.Projections.Geo) { lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord); } else if (shapefile.Projection == ShapeFile.Projections.PolarStereo) { lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3; } vertList.Add(lastItem); currentIndex++; lines = false; } } shapeVertexCount = vertList.Count; shapeFileVertex = new PositionVertexBuffer11(vertList.Count, RenderContext11.PrepDevice); Vector3[] verts = (Vector3[])shapeFileVertex.Lock(0, 0); // Lock the buffer (which will return our structs) int indexer = 0; foreach (Vector3 vert in vertList) { verts[indexer++] = vert; } shapeFileVertex.Unlock(); shapeIndexCount = indexList.Count; if (lines) { if (indexList.Count > 65500) { isLongIndex = true; shapeFileIndex = new IndexBuffer11(typeof(UInt32), indexList.Count, RenderContext11.PrepDevice); } else { isLongIndex = false; shapeFileIndex = new IndexBuffer11(typeof(short), indexList.Count, RenderContext11.PrepDevice); } if (isLongIndex) { indexer = 0; UInt32[] indexes = (UInt32[])shapeFileIndex.Lock(); foreach (UInt32 indexVal in indexList) { indexes[indexer++] = indexVal; } shapeFileIndex.Unlock(); } else { indexer = 0; short[] indexes = (short[])shapeFileIndex.Lock(); foreach (UInt32 indexVal in indexList) { indexes[indexer++] = (short)indexVal; } shapeFileIndex.Unlock(); } } } renderContext.DepthStencilMode = DepthStencilMode.Off; renderContext.BlendMode = BlendMode.Alpha; SimpleLineShader11.Color = Color.FromArgb((int)(opacity * 255), Color); SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; mat.Transpose(); SimpleLineShader11.WVPMatrix = mat; SimpleLineShader11.CameraPosition = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector3; SimpleLineShader11.ShowFarSide = false; SimpleLineShader11.Sky = false; renderContext.SetVertexBuffer(shapeFileVertex); SimpleLineShader11.Use(renderContext.devContext); if (lines) { renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineList; renderContext.SetIndexBuffer(shapeFileIndex); renderContext.devContext.DrawIndexed(shapeFileIndex.Count, 0, 0); } else { renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList; renderContext.devContext.Draw(shapeVertexCount, 0); } renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList; return(true); }
public static Vector2d TanToRaDec(Coordinates center, Vector2d point) { return TanToRaDec(new Vector2d(center.RA, center.Dec), point); }
private void renderWindow_MouseMove(object sender, MouseEventArgs e) { if (contrastMode) { contrast = (1 - (e.Y / (float)ClientSize.Height)); brightness = e.X / (float)ClientSize.Width; return; } if (activeTouch != TouchControls.None) { if (activeTouch == TouchControls.TrackBall) { moveVector = new PointF(touchTrackBallCenter.X - (e.X + Properties.Settings.Default.ScreenHitTestOffsetX), touchTrackBallCenter.Y - (e.Y + Properties.Settings.Default.ScreenHitTestOffsetY)); } if (activeTouch == TouchControls.PanTrack) { Vector2d panTrack = TouchToScreen(this.panTracker); Vector2d mv = new Vector2d(panTrack.X - (e.X + Properties.Settings.Default.ScreenHitTestOffsetX), panTrack.Y - (e.Y + Properties.Settings.Default.ScreenHitTestOffsetY)); if (mv.Length > 50) { mv.Normalize(); mv.Scale(50); } moveVector = new PointF((float)mv.X, (float)mv.Y); } if (activeTouch == TouchControls.ZoomTrack) { Vector2d zoomTrack = TouchToScreen(this.zoomTracker); double zoomDrag = zoomTrack.X - (e.X + Properties.Settings.Default.ScreenHitTestOffsetX); if (Math.Abs(zoomDrag) > 54) { ZoomVector = 54 * Math.Sign(zoomDrag); } else { ZoomVector = (float)zoomDrag; } } if (activeTouch == TouchControls.OrbitTrack) { Vector2d orbitTrack = TouchToScreen(this.orbitTracker); double orbitDrag = orbitTrack.X - (e.X + Properties.Settings.Default.ScreenHitTestOffsetX); if (Math.Abs(orbitDrag) > 70) { OrbitVector = 70 * Math.Sign(orbitDrag); } else { OrbitVector = (float)orbitDrag; } } return; } if (uiController != null) { if (uiController.MouseMove(sender, new MouseEventArgs(e.Button, e.Clicks, e.X + Properties.Settings.Default.ScreenHitTestOffsetX, e.Y + Properties.Settings.Default.ScreenHitTestOffsetY, e.Delta))) { return; } } moved = true; if (lastMousePosition == e.Location) { return; } else { mouseMoved = true; lastMouseMove = DateTime.Now; if (!CursorVisible && !ProjectorServer) { Cursor.Show(); CursorVisible = true; } } if (measuringDrag) { measureEnd = GetCoordinatesForScreenPoint(e.X, e.Y); if (measureLines == null) { measureLines = new SimpleLineList11(); measureLines.DepthBuffered = false; } measureLines.Clear(); measureLines.AddLine(Coordinates.RADecTo3d(measureStart.RA + 12, measureStart.Dec, 1), Coordinates.RADecTo3d(measureEnd.RA + 12, measureEnd.Dec, 1)); double angularSperation = CAAAngularSeparation.Separation(measureStart.RA, measureStart.Dec, measureEnd.RA, measureEnd.Dec); TourPlace pl = new TourPlace(Language.GetLocalizedText(977, "Seperation: ") + Coordinates.FormatDMS(angularSperation), measureEnd.Dec, measureEnd.RA, Classification.Star, Constellations.Containment.FindConstellationForPoint(measureEnd.RA, measureEnd.Dec), ImageSetType.Sky, -1); SetLabelText(pl, true); } else if (Space && Settings.Active.GalacticMode) { if (dragging) { Tracking = false; MoveView(-(e.X - this.mouseDownX), (e.Y - this.mouseDownY), true); if (!Properties.Settings.Default.SmoothPan) { az = targetAz; alt = targetAlt; double[] gPoint = Coordinates.GalactictoJ2000(az, alt); TargetLat = ViewLat = gPoint[1]; TargetLong = ViewLong = RAtoViewLng(gPoint[0] / 15); NotifyMoveComplete(); } this.mouseDownX = e.X; this.mouseDownY = e.Y; } else if (spinning || angle) { CameraRotateTarget = (CameraRotateTarget + (((double)(e.X - this.mouseDownX)) / 1000 * Math.PI)); CameraAngleTarget = (CameraAngleTarget + (((double)(e.Y - this.mouseDownY)) / 1000 * Math.PI)); if (CameraAngleTarget < TiltMin) { CameraAngleTarget = TiltMin; } if (CameraAngleTarget > 0) { CameraAngleTarget = 0; } if (!Properties.Settings.Default.SmoothPan) { CameraRotate = CameraRotateTarget; CameraAngle = CameraAngleTarget; } this.mouseDownX = e.X; this.mouseDownY = e.Y; } else { mouseMoved = true; lastMouseMove = DateTime.Now; } } else if (Space && Settings.Active.LocalHorizonMode) { if (dragging) { if (!SolarSystemMode) { Tracking = false; } MoveView(-(e.X - this.mouseDownX), (e.Y - this.mouseDownY), true); if (!Properties.Settings.Default.SmoothPan) { az = targetAz; alt = targetAlt; Coordinates currentRaDec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(alt, az), SpaceTimeController.Location, SpaceTimeController.Now); TargetLat = ViewLat = currentRaDec.Dec; TargetLong = ViewLong = RAtoViewLng(currentRaDec.RA); NotifyMoveComplete(); } this.mouseDownX = e.X; this.mouseDownY = e.Y; } else { mouseMoved = true; lastMouseMove = DateTime.Now; } } else { if (dragging) { if (!SolarSystemMode) { Tracking = false; } MoveView(-(e.X - this.mouseDownX), (e.Y - this.mouseDownY), true); if (!Properties.Settings.Default.SmoothPan) { ViewLat = TargetLat; ViewLong = TargetLong; NotifyMoveComplete(); } this.mouseDownX = e.X; this.mouseDownY = e.Y; } else if (spinning || angle) { CameraRotateTarget = (CameraRotateTarget + (((double)(e.X - this.mouseDownX)) / 1000 * Math.PI)); CameraAngleTarget = (CameraAngleTarget + (((double)(e.Y - this.mouseDownY)) / 1000 * Math.PI)); if (CameraAngleTarget < TiltMin) { CameraAngleTarget = TiltMin; } if (CameraAngleTarget > 0) { CameraAngleTarget = 0; } if (!Properties.Settings.Default.SmoothPan) { CameraRotate = CameraRotateTarget; CameraAngle = CameraAngleTarget; } this.mouseDownX = e.X; this.mouseDownY = e.Y; } else { mouseMoved = true; lastMouseMove = DateTime.Now; } } lastMousePosition = e.Location; }
public Vector2d GetImagePixel(Coordinates sky) { var result = new Vector2d(); //Vector3 tangent = GeoTo3dWithAltitude(sky.Lat, sky.Lng); var tangent = Coordinates.RADecTo3d(sky.RA + 12, sky.Dec, 1); var mat = dataset.Matrix; mat.Invert(); tangent = Vector3d.TransformCoordinate(tangent, mat); var imagePoint = Coordinates.CartesianToSpherical(tangent); result.X = (float)((imagePoint.Lng / ScaleX) + PixelCenterX); result.Y = (float)((imagePoint.Lat / -ScaleY) + PixelCenterY); return result; }
private void SetupMatricesSpaceDome(bool forStars, RenderTypes renderType) { if (SolarSystemTrack != SolarSystemObjects.Custom && SolarSystemTrack != SolarSystemObjects.Undefined) { viewCamera.ViewTarget = Planets.GetPlanetTargetPoint(SolarSystemTrack, ViewLat, ViewLong, 0); } double camLocal = CameraRotate; if ((Settings.Active.LocalHorizonMode && !Settings.Active.GalacticMode) && CurrentImageSet.DataSetType == ImageSetType.Sky) { if (Properties.Settings.Default.ShowHorizon != false) { Properties.Settings.Default.ShowHorizon = false; } Coordinates zenithAltAz = new Coordinates(0, 0); zenithAltAz.Az = 0; zenithAltAz.Alt = 0; ZoomFactor = TargetZoom = ZoomMax; alt = 0; az = 0; Coordinates zenith = Coordinates.HorizonToEquitorial(zenithAltAz, SpaceTimeController.Location, SpaceTimeController.Now); double raPart = -((zenith.RA - 6) / 24.0 * (Math.PI * 2)); double decPart = -(((zenith.Dec)) / 360.0 * (Math.PI * 2)); string raText = Coordinates.FormatDMS(zenith.RA); WorldMatrix = Matrix3d.RotationY(-raPart); WorldMatrix.Multiply(Matrix3d.RotationX(decPart)); if (SpaceTimeController.Location.Lat < 0) { WorldMatrix.Multiply(Matrix3d.RotationY(((az) / 180.0 * Math.PI))); WorldMatrix.Multiply(Matrix3d.RotationX(((alt) / 180.0 * Math.PI))); camLocal += Math.PI; } else { WorldMatrix.Multiply(Matrix3d.RotationY(((-az) / 180.0 * Math.PI))); WorldMatrix.Multiply(Matrix3d.RotationX(((-alt) / 180.0 * Math.PI))); } Coordinates currentRaDec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(alt, az), SpaceTimeController.Location, SpaceTimeController.Now); TargetLat = ViewLat = currentRaDec.Dec; TargetLong = ViewLong = RAtoViewLng(currentRaDec.RA); } Vector3d center = viewCamera.ViewTarget; RenderContext11.LightingEnabled = false; double localZoom = ZoomFactor * 20; Vector3d lookAt = new Vector3d(0, 0, -1); FovAngle = ((ZoomFactor/**16*/) / FOVMULT) / Math.PI * 180; double distance = (Math.Min(1, (.5 * (ZoomFactor / 180)))) - 1 + 0.0001; RenderContext11.CameraPosition = new Vector3d(0, 0, distance); Vector3d lookUp = new Vector3d(Math.Sin(-CameraRotate), Math.Cos(-CameraRotate), 0.0001f); Matrix3d lookAtAdjust = Matrix3d.Identity; switch (renderType) { case RenderTypes.DomeUp: lookAtAdjust.Multiply(Matrix3d.RotationX(Math.PI / 2)); break; case RenderTypes.DomeLeft: lookAtAdjust.Multiply(Matrix3d.RotationY(Math.PI / 2)); break; case RenderTypes.DomeRight: lookAtAdjust.Multiply(Matrix3d.RotationY(-Math.PI / 2)); break; case RenderTypes.DomeFront: break; case RenderTypes.DomeBack: lookAtAdjust.Multiply(Matrix3d.RotationY(Math.PI)); break; default: break; } if ((Settings.Active.GalacticMode && !Settings.Active.LocalHorizonMode) && CurrentImageSet.DataSetType == ImageSetType.Sky) { if (!galMatInit) { galacticMatrix = Matrix3d.Identity; galacticMatrix.Multiply(Matrix3d.RotationY(-(90 - (17.7603329867975 * 15)) / 180.0 * Math.PI)); galacticMatrix.Multiply(Matrix3d.RotationX(-((-28.9361739586894)) / 180.0 * Math.PI)); galacticMatrix.Multiply(Matrix3d.RotationZ(((31.422052860102041270114993238783) - 90) / 180.0 * Math.PI)); galMatInit = true; } WorldMatrix = galacticMatrix; WorldMatrix.Multiply(Matrix3d.RotationY(((az)) / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(-((alt)) / 180.0 * Math.PI)); double[] gPoint = Coordinates.GalactictoJ2000(az, alt); this.RA = gPoint[0] / 15; this.Dec = gPoint[1]; targetViewCamera.Lat = viewCamera.Lat; targetViewCamera.Lng = viewCamera.Lng; } else { // Show in Ecliptic WorldMatrix = Matrix3d.RotationY(-((this.ViewLong + 90.0) / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180.0 * Math.PI))); } RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; if (Settings.Active.LocalHorizonMode) { Matrix3d matNorth = Matrix3d.RotationY(Properties.Settings.Default.FaceNorth ? 0 : Math.PI); RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * matNorth * DomeAngleMatrix * lookAtAdjust; } else { RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * lookAtAdjust; } Vector3d temp = lookAt - RenderContext11.CameraPosition; temp.Normalize(); ViewPoint = temp; // Set the near clip plane close enough that the sky dome isn't clipped double cameraZ = (Math.Min(1, (.5 * (ZoomFactor / 180)))) - 1 + 0.0001; m_nearPlane = (float)(1.0 + cameraZ) * 0.5f; ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, -1f); RenderContext11.PerspectiveFov = (Math.PI / 2.0); if (multiMonClient) { ProjMatrix.M11 *= MonitorCountX * bezelSpacing; ProjMatrix.M22 *= MonitorCountY * bezelSpacing; ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2); ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2)); } RenderContext11.Projection = ProjMatrix; ViewMatrix = RenderContext11.View; RenderContext11.ViewBase = RenderContext11.View; MakeFrustum(); }
public virtual IPlace FindClosest(Coordinates target, float distance, IPlace closestPlace, bool astronomical) { return closestPlace; }
private void FindCurrentObject() { var loc = Earth3d.MainWindow.RenderWindow.PointToClient(PointToScreen(new Point(300, 88))); IPlace closetPlace = null; var result = new Coordinates(0,0); if (Earth3d.MainWindow.SolarSystemMode) { var pt = loc; Vector3d PickRayOrig; Vector3d PickRayDir; var rect = Earth3d.MainWindow.RenderWindow.ClientRectangle; Earth3d.MainWindow.TransformStarPickPointToWorldSpace(pt, rect.Width, rect.Height, out PickRayOrig, out PickRayDir); var temp = new Vector3d(PickRayOrig); temp.Subtract(Earth3d.MainWindow.viewCamera.ViewTarget); //closetPlace = Grids.FindClosestObject(temp , new Vector3d(PickRayDir)); CallFindClosestObject(temp, new Vector3d(PickRayDir)); } else { // TODO fix this for earth, plantes, panoramas result = Earth3d.MainWindow.GetCoordinatesForScreenPoint(loc.X, loc.Y); var constellation = Earth3d.MainWindow.ConstellationCheck.FindConstellationForPoint(result.RA, result.Dec); //Place[] resultList = ContextSearch.FindClosestMatches(constellation, result.RA, result.Dec, ZoomFactor / 600, 5); closetPlace = ContextSearch.FindClosestMatch(constellation, result.RA, result.Dec, Earth3d.MainWindow.DegreesPerPixel * 80); if (closetPlace == null) { // closetPlace = Grids.FindClosestMatch(constellation, result.RA, result.Dec, Earth3d.MainWindow.DegreesPerPixel * 80); CallFindClosestMatch(constellation, result.RA, result.Dec, Earth3d.MainWindow.DegreesPerPixel * 80); noPlaceDefault = new TourPlace(Language.GetLocalizedText(90, "No Object"), result.Dec, result.RA, Classification.Unidentified, constellation, ImageSetType.Sky, -1); //Earth3d.MainWindow.SetLabelText(null, false); return; } Earth3d.MainWindow.SetLabelText(closetPlace, false); Target = closetPlace; } }
public void SetViewRect(Coordinates[] corners) { if (corners.Length != 4) { return; } bool change = false; if (this.corners != null) { for (int i = 0; i < 4; i++) { if (this.corners[i] != corners[i]) { change = true; break; } } } else { change = true; } if (!change) { return; } if (Settings.Active.LocalHorizonMode) { cornersAltAz = new Coordinates[4]; for (int i = 0; i < 4; i++) { this.cornersAltAz[i] = Coordinates.EquitorialToHorizon(corners[i], SpaceTimeController.Location, SpaceTimeController.Now); } } this.corners = corners; RefreshHint(); }
public override IPlace FindClosest(Coordinates target, float distance, IPlace closestPlace, bool astronomical) { var pointFound = false; var pointIndex = -1; var target3d = Coordinates.GeoTo3dDouble(target.Lat, target.Lng, 1); for (var i = 0; i < shapefile.Shapes.Count; i++) { if (shapefile.Shapes[i] is ComplexShape) { var p = (ComplexShape)shapefile.Shapes[i]; if (PointInboundingBox(target, p.BoundingBox)) { if (p.Attributes != null && p.Attributes.ItemArray.GetLength(0) > 0) { var nameCol = GetNameColumn(); if (nameCol == -1) { nameCol = 0; } var place = new TourPlace(p.Attributes.ItemArray[nameCol].ToString(), (p.BoundingBox[1] + p.BoundingBox[3]) / 2, (p.BoundingBox[0] + p.BoundingBox[2]) / 2, Classification.Unidentified, "", ImageSetType.Earth, -1); var rowData = new Dictionary<string, string>(); for (var r = 0; r < p.Attributes.ItemArray.GetLength(0); r++) { rowData.Add(p.Attributes.Table.Columns[r].ColumnName, p.Attributes.ItemArray[r].ToString()); } place.Tag = rowData; return place; } return closestPlace; } } else if (shapefile.Shapes[i].GetType() == typeof(Point)) { var p = (Point)shapefile.Shapes[i]; var point = Coordinates.GeoTo3dDouble(p.Y, p.X, 1); var dist = target3d - point; if (dist.Length() < distance) { pointFound = true; pointIndex = i; distance = (float)dist.Length(); } } } if (pointFound) { var p = (Point)shapefile.Shapes[pointIndex]; if (p.Attributes.ItemArray.GetLength(0) > 0) { var place = new TourPlace(p.Attributes.ItemArray[0].ToString(), p.Y, p.X, Classification.Unidentified, "", ImageSetType.Earth, -1); var rowData = new Dictionary<string, string>(); for (var r = 0; r < p.Attributes.ItemArray.GetLength(0); r++) { rowData.Add(p.Attributes.Table.Columns[r].ColumnName, p.Attributes.ItemArray[r].ToString()); } place.Tag = rowData; return place; } } return closestPlace; }
public Coordinates GetCoordinatesForScreenPoint(int x, int y) { Coordinates result = new Coordinates(0, 0); Rectangle rect = renderWindow.ClientRectangle; Vector3d PickRayOrig; Vector3d PickRayDir; Point pt = new Point(x, y); TransformPickPointToWorldSpace(pt, rect.Width, rect.Height, out PickRayOrig, out PickRayDir); if (Space) { result = Coordinates.CartesianToSpherical(PickRayDir); } else if (PlanetLike) { bool inThere = SphereIntersectRay(PickRayOrig, PickRayDir, out result); } return result; }
bool IUiController.MouseMove(object sender, MouseEventArgs e) { if (drag) { var cursor = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y); switch (dragCorner) { case DragCorners.NW: Rect.North = cursor.Lat; Rect.West = cursor.Lng; break; case DragCorners.N: Rect.North = cursor.Lat; break; case DragCorners.NE: Rect.North = cursor.Lat; Rect.East = cursor.Lng; break; case DragCorners.W: Rect.West = cursor.Lng; break; case DragCorners.C: Rect.North -= (mouseDown.Lat - cursor.Lat); Rect.West -= (mouseDown.Lng - cursor.Lng); Rect.South -= (mouseDown.Lat - cursor.Lat); Rect.East -= (mouseDown.Lng - cursor.Lng); break; case DragCorners.E: Rect.East = cursor.Lng; break; case DragCorners.SW: Rect.South = cursor.Lat; Rect.West = cursor.Lng; break; case DragCorners.S: Rect.South = cursor.Lat; break; case DragCorners.SE: Rect.South = cursor.Lat; Rect.East = cursor.Lng; break; default: break; } mouseDown = cursor; UpdateTextBoxes(); UpdateLines(); return true; } else { var wnd = (Control)sender; var width = Rect.East - Rect.West; var height = Rect.North - Rect.South; var range = Math.Max(width / 40, height / 40); var cursor = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y); var dragCorner = DragCorners.None; if (cursor.Distance(Coordinates.FromLatLng(Rect.North, Rect.West)) < range) { dragCorner = DragCorners.NW; } if (cursor.Distance(Coordinates.FromLatLng(Rect.North, (Rect.West + Rect.East) / 2)) < range) { dragCorner = DragCorners.N; } if (cursor.Distance(Coordinates.FromLatLng(Rect.North, Rect.East)) < range) { dragCorner = DragCorners.NE; } if (cursor.Distance(Coordinates.FromLatLng((Rect.North + Rect.South) / 2, Rect.West)) < range) { dragCorner = DragCorners.W; } if (cursor.Distance(Coordinates.FromLatLng((Rect.North + Rect.South) / 2, (Rect.West + Rect.East) / 2)) < range) { dragCorner = DragCorners.C; } if (cursor.Distance(Coordinates.FromLatLng((Rect.North + Rect.South) / 2, Rect.East)) < range) { dragCorner = DragCorners.E; } if (cursor.Distance(Coordinates.FromLatLng(Rect.South, Rect.West)) < range) { dragCorner = DragCorners.SW; } if (cursor.Distance(Coordinates.FromLatLng(Rect.South, (Rect.West + Rect.East) / 2)) < range) { dragCorner = DragCorners.S; } if (cursor.Distance(Coordinates.FromLatLng(Rect.South, Rect.East)) < range) { dragCorner = DragCorners.SE; } switch (dragCorner) { case DragCorners.SE: case DragCorners.NW: wnd.Cursor = Cursors.SizeNWSE; break; case DragCorners.N: case DragCorners.S: wnd.Cursor = Cursors.SizeNS; break; case DragCorners.W: case DragCorners.E: wnd.Cursor = Cursors.SizeWE; break; case DragCorners.C: wnd.Cursor = Cursors.Hand; break; case DragCorners.SW: case DragCorners.NE: wnd.Cursor = Cursors.SizeNESW; break; default: wnd.Cursor = Cursors.Default; break; } } return false; }
public Coordinates GetCoordinatesForReticle(int id) { Coordinates result = new Coordinates(0, 0); Vector3d PickRayOrig; Vector3d PickRayDir; if (!Reticle.Reticles.ContainsKey(id)) { return result; } Reticle ret = Reticle.Reticles[id]; Vector3d pick = Coordinates.RADecTo3d(ret.Az / 15 - 6, ret.Alt, 1); double distance = (Math.Min(1, (.5 * (ZoomFactor / 180)))) - 1 + 0.0001; PickRayOrig = new Vector3d(0, 0, distance); Matrix3d mat = WorldMatrix * Matrix3d.RotationX(((config.TotalDomeTilt) / 180 * Math.PI)); Matrix3d mat2 = WorldMatrix * Matrix3d.RotationZ(((config.TotalDomeTilt) / 180 * Math.PI)); mat.Invert(); mat2.Invert(); mat.MultiplyVector(ref pick); mat2.MultiplyVector(ref PickRayOrig); PickRayDir = pick; SphereIntersectRay(PickRayOrig.Vector3, PickRayDir.Vector3, out result); return result; }
public override IPlace FindClosest(Coordinates target, float distance, IPlace defaultPlace, bool astronomical) { var searchPoint = Coordinates.GeoTo3dDouble(target.Lat, target.Lng); //searchPoint = -searchPoint; Vector3d dist; if (defaultPlace != null) { var testPoint = Coordinates.RADecTo3d(defaultPlace.RA, -defaultPlace.Dec, -1.0); dist = searchPoint - testPoint; distance = (float)dist.Length(); } var closestItem = -1; var index = 0; foreach (var point in positions) { dist = searchPoint - new Vector3d(point); if (dist.Length() < distance) { distance = (float)dist.Length(); closestItem = index; } index++; } if (closestItem == -1) { return defaultPlace; } var pnt = Coordinates.CartesianToSpherical2(positions[closestItem]); var name = table.Rows[closestItem].ColumnData[nameColumn].ToString(); if (nameColumn == startDateColumn || nameColumn == endDateColumn) { name = SpreadSheetLayer.ParseDate(name).ToString("u"); } if (String.IsNullOrEmpty(name)) { name = string.Format("RA={0}, Dec={1}", Coordinates.FormatHMS(pnt.RA), Coordinates.FormatDMS(pnt.Dec)); } var place = new TourPlace(name, pnt.Lat, pnt.RA, Classification.Unidentified, "", ImageSetType.Sky, -1); var rowData = new Dictionary<string, string>(); for (var i = 0; i < table.Columns.Count; i++) { var colValue = table.Rows[closestItem][i].ToString(); if (i == startDateColumn || i == endDateColumn) { colValue = SpreadSheetLayer.ParseDate(colValue).ToString("u"); } if (!rowData.ContainsKey(table.Column[i].Name) && !string.IsNullOrEmpty(table.Column[i].Name)) { rowData.Add(table.Column[i].Name, colValue); } else { rowData.Add("Column" + i, colValue); } } place.Tag = rowData; if (Viewer != null) { Viewer.LabelClicked(closestItem); } return place; }
public void GotoReticlePoint(int id) { Coordinates result = new Coordinates(0, 0); Vector3d PickRayOrig; Vector3d PickRayDir; if (!Reticle.Reticles.ContainsKey(id)) { return; } Reticle ret = Reticle.Reticles[id]; Vector3d pick = Coordinates.RADecTo3d(ret.Az / 15 - 6, ret.Alt, 1); double distance = (Math.Min(1, (.5 * (ZoomFactor / 180)))) - 1 + 0.0001; PickRayOrig = new Vector3d(0, -distance, 0); Matrix3d mat = WorldMatrix * Matrix3d.RotationX(((config.TotalDomeTilt) / 180 * Math.PI)); mat.Invert(); mat.MultiplyVector(ref pick); mat.MultiplyVector(ref PickRayOrig); PickRayDir = pick; Vector3d temp = new Vector3d(PickRayOrig); temp.Subtract(Earth3d.MainWindow.viewCamera.ViewTarget); IPlace closetPlace = Grids.FindClosestObject(temp, new Vector3d(PickRayDir)); if (closetPlace != null) { GotoTarget(closetPlace, false, false, true); } }
public void SetViewRect(Coordinates[] corners) { if (corners.Length != 4) { return; } var change = false; if (cornersLast != null) { for (var i = 0; i < 4; i++) { if (cornersLast[i] != corners[i]) { change = true; break; } } } else { change = true; } if (!change) { return; } cornersLast = corners; contextAreaChanged = true; overview.SetViewRect(corners); SkyBall.SetViewRect(corners); }
public bool SphereIntersectRay(SharpDX.Vector3 pickRayOrig, SharpDX.Vector3 pickRayDir, out Coordinates pointCoordinate) { pointCoordinate = new Coordinates(0, 0); float r = 1; //Compute A, B and C coefficients float a = SharpDX.Vector3.Dot(pickRayDir, pickRayDir); float b = 2 * SharpDX.Vector3.Dot(pickRayDir, pickRayOrig); float c = SharpDX.Vector3.Dot(pickRayOrig, pickRayOrig) - (r * r); //Find discriminant float disc = b * b - 4 * a * c; // if discriminant is negative there are no real roots, so return // false as ray misses sphere if (disc < 0) { return false; } // compute q as described above float distSqrt = (float)Math.Sqrt(disc); float q; if (b < 0) { q = (-b - distSqrt) / 2.0f; } else { q = (-b + distSqrt) / 2.0f; } // compute t0 and t1 float t0 = q / a; float t1 = c / q; // make sure t0 is smaller than t1 if (t0 > t1) { // if t0 is bigger than t1 swap them around float temp = t0; t0 = t1; t1 = temp; } // if t1 is less than zero, the object is in the ray's negative direction // and consequently the ray misses the sphere if (t1 < 0) { return false; } float t = 0; // if t0 is less than zero, the intersection point is at t1 if (t0 < 0) { t = t1; } // else the intersection point is at t0 else { t = t0; } SharpDX.Vector3 point = pickRayDir * t; point = pickRayOrig + point; pointCoordinate = Coordinates.CartesianToSpherical2(point); return true; }
public static IPlace[] FindConteallationObjects(string constellationID, Coordinates[] corners, Classification type) { if (!constellationObjects.ContainsKey(constellationID)) { return null; } if (corners != null) { var minRa = Math.Min(corners[0].RA, Math.Min(corners[1].RA, Math.Min(corners[2].RA, corners[3].RA))); var maxRa = Math.Max(corners[0].RA, Math.Max(corners[1].RA, Math.Max(corners[2].RA, corners[3].RA))); var minDec = Math.Min(corners[0].Dec, Math.Min(corners[1].Dec, Math.Min(corners[2].Dec, corners[3].Dec))); var maxDec = Math.Max(corners[0].Dec, Math.Max(corners[1].Dec, Math.Max(corners[2].Dec, corners[3].Dec))); bool wrap = Math.Abs(maxRa - minRa) > 12; var results = new List<IPlace>(); foreach (var place in constellationObjects[constellationID]) { //TODO Need Serious fixing of RA dec range validation... if ((type & place.Classification) != 0) { if (!wrap) { if (place.RA > minRa && place.RA < maxRa && place.Dec > minDec && place.Dec < maxDec) { if (place.IsTour) { results.Insert(0, place); } else { results.Add(place); } } } else { if ((place.RA < minRa || place.RA > maxRa) && place.Dec > minDec && place.Dec < maxDec) { if (place.IsTour) { results.Insert(0, place); } else { results.Add(place); } } } } } return results.ToArray(); } else { var results = new List<IPlace>(); foreach (var place in constellationObjects[constellationID]) { if ((type & place.Classification) != 0) { if (place.IsTour) { results.Insert(0, place); } else { results.Add(place); } } } return results.ToArray(); } }
public override IPlace FindClosest(Coordinates target, float distance, IPlace closestPlace, bool astronomical) { bool pointFound = false; int pointIndex = -1; Vector3d target3d = Coordinates.GeoTo3dDouble(target.Lat, target.Lng, 1); for (int i = 0; i < shapefile.Shapes.Count; i++) { if (shapefile.Shapes[i] is ComplexShape) { ComplexShape p = (ComplexShape)shapefile.Shapes[i]; if (PointInboundingBox(target, p.BoundingBox)) { if (p.Attributes != null && p.Attributes.ItemArray.GetLength(0) > 0) { int nameCol = GetNameColumn(); if (nameCol == -1) { nameCol = 0; } TourPlace place = new TourPlace(p.Attributes.ItemArray[nameCol].ToString(), (p.BoundingBox[1] + p.BoundingBox[3]) / 2, (p.BoundingBox[0] + p.BoundingBox[2]) / 2, Classification.Unidentified, "", ImageSetType.Earth, -1); Dictionary <String, String> rowData = new Dictionary <string, string>(); for (int r = 0; r < p.Attributes.ItemArray.GetLength(0); r++) { rowData.Add(p.Attributes.Table.Columns[r].ColumnName, p.Attributes.ItemArray[r].ToString()); } place.Tag = rowData; return(place); } return(closestPlace); } } else if (shapefile.Shapes[i].GetType() == typeof(ShapefileTools.Point)) { ShapefileTools.Point p = (ShapefileTools.Point)shapefile.Shapes[i]; Vector3d point = Coordinates.GeoTo3dDouble(p.Y, p.X, 1); Vector3d dist = target3d - point; if (dist.Length() < distance) { pointFound = true; pointIndex = i; distance = (float)dist.Length(); } } } if (pointFound) { ShapefileTools.Point p = (ShapefileTools.Point)shapefile.Shapes[pointIndex]; if (p.Attributes.ItemArray.GetLength(0) > 0) { TourPlace place = new TourPlace(p.Attributes.ItemArray[0].ToString(), p.Y, p.X, Classification.Unidentified, "", ImageSetType.Earth, -1); Dictionary <String, String> rowData = new Dictionary <string, string>(); for (int r = 0; r < p.Attributes.ItemArray.GetLength(0); r++) { rowData.Add(p.Attributes.Table.Columns[r].ColumnName, p.Attributes.ItemArray[r].ToString()); } place.Tag = rowData; return(place); } } return(closestPlace); }