public Vector3d MakePosition(float centerX, float centerY, float offsetX, float offsetY, float angle) { centerX -= 960; centerY -= 558; if (this.Anchor == OverlayAnchor.Screen) { Vector3d point = new Vector3d(centerX + offsetX, centerY + offsetY, 1347); if (domeMatX != 0 || domeMatY != 0 || domeAngle != angle) { domeMatX = centerX; domeMatY = centerY; domeMatrix = Matrix3d.Translation(new Vector3d(-centerX, -centerY, 0)) * Matrix3d.RotationZ((float)(angle / 180 * Math.PI)) * Matrix3d.Translation(new Vector3d(centerX, centerY, 0)); } point.TransformCoordinate(domeMatrix); return point; } else { centerX /=1350; centerY /=1350; Vector3d point = new Vector3d(offsetX, offsetY, 1347); if (domeMatX != centerX || domeMatY != centerY || domeAngle != angle) { domeMatX = centerX; domeMatY = centerY; domeMatrix = Matrix3d.RotationZ((float)(angle/180*Math.PI)) * Matrix3d.RotationX(-centerY) * Matrix3d.RotationY(centerX); } point.TransformCoordinate(domeMatrix); return point; } }
public static void QueueThread() { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false); bool fileOnly = fileOnlyThreadID == Thread.CurrentThread.ManagedThreadId; while (running) { if (queue.Count < 1) { System.Threading.Thread.Sleep(50); } else { System.Threading.Thread.Sleep(1); } double minDistance = 1000000000000000000; bool overlayTile = false; long maxKey = 0; int level = 1000; queueMutex.WaitOne(); foreach (Tile t in queue.Values ) { if (!t.RequestPending ) // && t.InViewFrustum) { Vector3d vectTemp = new Vector3d(t.SphereCenter); vectTemp.TransformCoordinate(Earth3d.WorldMatrix); if (Earth3d.MainWindow.Space) { vectTemp.Subtract(new Vector3d(0.0f, 0.0f, -1.0f)); } else { vectTemp.Subtract(Earth3d.MainWindow.RenderContext11.CameraPosition); } double distTemp = Math.Max(0,vectTemp.Length()-t.SphereRadius); bool thisIsOverlay = (t.Dataset.Projection == ProjectionType.Tangent) || (t.Dataset.Projection == ProjectionType.SkyImage); if (distTemp < minDistance && (!overlayTile || thisIsOverlay)) { Tile test = (Tile)queue[t.Key]; if (!test.FileChecked) { test.FileExists = File.Exists(test.FileName); test.FileChecked = true; if (test.Volitile) { test.FileExists = false; } } if (test.FileExists || (!test.FileExists && !fileOnly)) { minDistance = distTemp; maxKey = t.Key; level = t.Level; overlayTile = thisIsOverlay; } } } } if (maxKey != 0) { Tile workTile = (Tile)queue[maxKey]; workTile.RequestPending = true; TileCache.RequestCount++; queueMutex.ReleaseMutex(); TileCache.GetTileFromWeb(workTile, true); queueMutex.WaitOne(); TileCache.RequestCount--; workTile.RequestPending = false; queue.Remove(workTile.Key); } queueMutex.ReleaseMutex(); } return; }
private void SetupMatricesVideoOverlayMultiChannel(double localZoomFactor) { RenderContext11.LightingEnabled = false; Vector3d lookAt = new Vector3d(-1, 0, 0); RenderContext11.CameraPosition = new Vector3d(0, 0, 0); Vector3d lookUp = new Vector3d(0, 1, 0); Matrix3d lookAtAdjust = Matrix3d.Identity; WorldMatrix = Matrix3d.Identity; RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; lookAt.TransformCoordinate(lookAtAdjust); Matrix3d matHeadingPitchRoll; if (DomePreviewPopup.Active) { matHeadingPitchRoll = Matrix3d.RotationY((DomePreviewPopup.Az / 180 * Math.PI)) * Matrix3d.RotationX((DomePreviewPopup.Alt / 180 * Math.PI)); } else { matHeadingPitchRoll = Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) * Matrix3d.RotationY((config.Heading / 180 * Math.PI)) * Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI)); } RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * matHeadingPitchRoll; m_nearPlane = .000000001; back = 12; double aspect = config.Aspect; double top = m_nearPlane * 2 / ((1 / Math.Tan(config.UpFov / 180 * Math.PI))) / 2; double bottom = m_nearPlane * 2 / -(1 / Math.Tan(config.DownFov / 180 * Math.PI)) / 2; double right = m_nearPlane * 2 / (1 / Math.Tan((config.UpFov + config.DownFov) / 2 / 180 * Math.PI)) * aspect / 2; double left = -right; if (config.MultiChannelDome1) { ProjMatrix = Matrix3d.PerspectiveOffCenterLH( left, right, bottom, top, m_nearPlane, back); } else { RenderContext11.View = RenderContext11.View * config.ViewMatrix; ProjMatrix = Matrix3d.PerspectiveFovLH((75f / 180f) * Math.PI, 1.777778, m_nearPlane, back); } RenderContext11.Projection = ProjMatrix; ViewMatrix = RenderContext11.View; RenderContext11.ViewBase = RenderContext11.View; MakeFrustum(); }
private void SetupMatricesSolarSystem11(bool forStars, RenderTypes renderType) { if (SandboxMode) { if (SolarSystemTrack != SolarSystemObjects.Custom && SolarSystemTrack != SolarSystemObjects.Undefined) { viewCamera.ViewTarget = new Vector3d(); } } else { if (SolarSystemTrack != SolarSystemObjects.Custom && SolarSystemTrack != SolarSystemObjects.Undefined) { viewCamera.ViewTarget = Planets.GetPlanetTargetPoint(SolarSystemTrack, ViewLat, ViewLong, 0); } } double cameraDistance = SolarSystemCameraDistance; Matrix3d trackingMatrix = Matrix3d.Identity; cameraDistance -= 0.000001; bool activeTrackingFrame = false; if (SolarSystemTrack == SolarSystemObjects.Custom && !string.IsNullOrEmpty(TrackingFrame)) { activeTrackingFrame = true; viewCamera.ViewTarget = LayerManager.GetFrameTarget(RenderContext11, TrackingFrame, out trackingMatrix); } else if (!string.IsNullOrEmpty(TrackingFrame)) { TrackingFrame = ""; } Vector3d center = viewCamera.ViewTarget; Vector3d lightPosition = -center; double localZoom = ZoomFactor * 20; Vector3d lookAt = new Vector3d(0, 0, 0); Matrix3d viewAdjust = Matrix3d.Identity; viewAdjust.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180f * Math.PI))); viewAdjust.Multiply(Matrix3d.RotationY(((-this.ViewLong) / 180f * Math.PI))); Matrix3d lookAtAdjust = Matrix3d.Identity; bool dome = false; Vector3d lookUp; if (useSolarSystemTilt && !SandboxMode) { double angle = CameraAngle; if (cameraDistance > 0.0008) { angle = 0; } else if (cameraDistance > 0.00001) { double val = Math.Min(1.903089987, Math.Log(cameraDistance, 10) + 5) / 1.903089987; angle = angle * Math.Max(0, 1 - val); } RenderContext11.CameraPosition = new Vector3d( (Math.Sin(-CameraRotate) * Math.Sin(angle) * cameraDistance), (Math.Cos(-CameraRotate) * Math.Sin(angle) * cameraDistance), ((Math.Cos(angle) * cameraDistance))); lookUp = new Vector3d(Math.Sin(-CameraRotate), Math.Cos(-CameraRotate), 0.00001f); } else { RenderContext11.CameraPosition = new Vector3d(0, 0, ((cameraDistance))); lookUp = new Vector3d(Math.Sin(-CameraRotate), Math.Cos(-CameraRotate), 0.0001f); } RenderContext11.CameraPosition.TransformCoordinate(viewAdjust); cameraOffset = RenderContext11.CameraPosition; cameraOffset.TransformCoordinate(Matrix3d.Invert(trackingMatrix)); lookUp.TransformCoordinate(viewAdjust); switch (renderType) { case RenderTypes.DomeUp: dome = true; lookAtAdjust.Multiply(Matrix3d.RotationX(Math.PI / 2)); break; case RenderTypes.DomeLeft: dome = true; lookAtAdjust.Multiply(Matrix3d.RotationY(Math.PI / 2)); break; case RenderTypes.DomeRight: dome = true; lookAtAdjust.Multiply(Matrix3d.RotationY(-Math.PI / 2)); break; case RenderTypes.DomeFront: dome = true; break; case RenderTypes.DomeBack: lookAtAdjust.Multiply(Matrix3d.RotationY(Math.PI)); dome = true; break; default: break; } WorldMatrix = Matrix3d.Identity; RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = RenderContext11.World; if (config.MultiChannelDome1) { Matrix3d matHeadingPitchRoll = Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) * Matrix3d.RotationY((config.Heading / 180 * Math.PI)) * Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI)); RenderContext11.View = trackingMatrix * Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * matHeadingPitchRoll; } else { if (Settings.DomeView) { RenderContext11.View = trackingMatrix * Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * lookAtAdjust; } else { if (DomePreviewPopup.Active && !dome) { Matrix3d matDomePreview = Matrix3d.RotationY((DomePreviewPopup.Az / 180 * Math.PI)) * Matrix3d.RotationX((DomePreviewPopup.Alt / 180 * Math.PI)); RenderContext11.View = trackingMatrix * Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * matDomePreview; } else if (rift || renderType == RenderTypes.RightEye || renderType == RenderTypes.LeftEye) { double amount = cameraDistance / 100; Matrix3d stereoTranslate = Matrix3d.Translation(renderType == RenderTypes.LeftEye ? amount : -amount, 0, 0); Matrix3d matRiftView = Matrix3d.Identity; if (rift) { matRiftView = Matrix3d.RotationY(GetHeading()) * Matrix3d.RotationX(GetPitch()) * Matrix3d.RotationZ(-GetRoll()); } RenderContext11.View = trackingMatrix * Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * lookAtAdjust * matRiftView * stereoTranslate; } else { RenderContext11.View = trackingMatrix * Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * lookAtAdjust; } if (multiMonClient) { RenderContext11.View = RenderContext11.View * Matrix3d.RotationY((config.Heading / 180 * Math.PI)); } } } RenderContext11.ViewBase = RenderContext11.View; Vector3d temp = lookAt - RenderContext11.CameraPosition; temp.Normalize(); temp = Vector3d.TransformCoordinate(temp, trackingMatrix); temp.Normalize(); ViewPoint = temp; if (activeTrackingFrame) { Vector3d atfCamPos = RenderContext11.CameraPosition; Vector3d atfLookAt = lookAt; Vector3d atfLookUp = lookUp; Matrix3d mat = trackingMatrix; mat.Invert(); atfCamPos.TransformCoordinate(mat); atfLookAt.TransformCoordinate(mat); atfLookUp.TransformCoordinate(mat); atfLookAt.Normalize(); atfLookUp.Normalize(); CustomTrackingParams.Angle = 0; CustomTrackingParams.Rotation = 0; CustomTrackingParams.DomeAlt = viewCamera.DomeAlt; CustomTrackingParams.DomeAz = viewCamera.DomeAz; CustomTrackingParams.TargetReferenceFrame = ""; CustomTrackingParams.ViewTarget = viewCamera.ViewTarget; CustomTrackingParams.Zoom = viewCamera.Zoom; CustomTrackingParams.Target = SolarSystemObjects.Custom; Vector3d atfLook = atfCamPos - atfLookAt; atfLook.Normalize(); Coordinates latlng = Coordinates.CartesianToSpherical2(atfLook); CustomTrackingParams.Lat = latlng.Lat; CustomTrackingParams.Lng = latlng.Lng - 90; Vector3d up = Coordinates.GeoTo3dDouble(latlng.Lat + 90, latlng.Lng - 90); Vector3d left = Vector3d.Cross(atfLook, up); double dotU = Math.Acos(Vector3d.Dot(atfLookUp, up)); double dotL = Math.Acos(Vector3d.Dot(atfLookUp, left)); CustomTrackingParams.Rotation = dotU;// -Math.PI / 2; } double radius = Planets.GetAdjustedPlanetRadius((int)SolarSystemTrack); if (cameraDistance < radius * 2.0 && !forStars) { m_nearPlane = cameraDistance * 0.03; m_nearPlane = Math.Max(m_nearPlane, .00000000001); back = 1900; } else { if (forStars) { back = 900056; back = cameraDistance > 900056 ? cameraDistance * 3 : 900056; m_nearPlane = .00003f; } else { back = cameraDistance > 1900 ? cameraDistance + 200 : 1900; if (Settings.Active.SolarSystemScale < 13) { m_nearPlane = (float)Math.Min(cameraDistance * 0.03, 0.01); } else { m_nearPlane = .001f; } } } if (config.MultiChannelDome1) { double aspect = config.Aspect; double top = m_nearPlane * 2 / ((1 / Math.Tan(config.UpFov / 180 * Math.PI))) / 2; double bottom = m_nearPlane * 2 / -(1 / Math.Tan(config.DownFov / 180 * Math.PI)) / 2; double right = m_nearPlane * 2 / (1 / Math.Tan((config.UpFov + config.DownFov) / 2 / 180 * Math.PI)) * aspect / 2; double left = -right; ProjMatrix = Matrix3d.PerspectiveOffCenterLH( left, right, bottom, top, m_nearPlane, back); } else if (config.MultiProjector) { RenderContext11.View = RenderContext11.View * config.ViewMatrix; ProjMatrix = Matrix3d.PerspectiveFovLH((75f / 180f) * Math.PI, 1.777778, m_nearPlane, back); RenderContext11.ViewBase = RenderContext11.View; } else if (multiMonClient && !dome) { double fov = (((config.UpFov + config.DownFov) / 2 / 180 * Math.PI)); if (fov == 0) { fov = (Math.PI / 4.0); } ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 4.0), (double)(monitorWidth * MonitorCountX) / ((double)monitorHeight * (double)MonitorCountY), m_nearPlane, back); } else if (dome) { ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, back); } else if (rift) { ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back); RenderContext11.PerspectiveFov = riftFov; } else { ProjMatrix = Matrix3d.PerspectiveFovLH((fovLocal), (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back); RenderContext11.PerspectiveFov = fovLocal; } if (multiMonClient && !config.MultiChannelDome1 && !config.MultiProjector) { ProjMatrix.M11 *= MonitorCountX * bezelSpacing; ProjMatrix.M22 *= MonitorCountY * bezelSpacing; ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2); ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2)); } if (rift) { if (renderType == RenderTypes.LeftEye) { ProjMatrix.M31 += iod; } else { ProjMatrix.M31 -= iod; } } RenderContext11.Projection = ProjMatrix; ViewMatrix = RenderContext11.View; RenderContext11.ViewBase = RenderContext11.View; MakeFrustum(); }
private void SetupMatricesSpaceMultiChannel(double localZoomFactor, RenderTypes renderType) { bool faceSouth = false; if ((Settings.Active.LocalHorizonMode && !Settings.Active.GalacticMode) && CurrentImageSet.DataSetType == ImageSetType.Sky) { faceSouth = !Properties.Settings.Default.FaceNorth; Coordinates currentRaDec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(0, 0), SpaceTimeController.Location, SpaceTimeController.Now); alt = 0; az = 0; config.DomeTilt = 0; if (Properties.Settings.Default.DomeTilt != 0) { Properties.Settings.Default.DomeTilt = 0; } TargetLat = ViewLat = currentRaDec.Dec; TargetLong = ViewLong = RAtoViewLng(currentRaDec.RA); } if (SolarSystemTrack != SolarSystemObjects.Custom && SolarSystemTrack != SolarSystemObjects.Undefined) { viewCamera.ViewTarget = Planets.GetPlanetTargetPoint(SolarSystemTrack, ViewLat, ViewLong, 0); } RenderContext11.LightingEnabled = false; double localZoom = ZoomFactor * 20; Vector3d lookAt = new Vector3d(0, 0, -1); FovAngle = ((ZoomFactor/**16*/) / FOVMULT) / Math.PI * 180; // for constellations ViewPoint = Coordinates.RADecTo3d(this.RA, -this.Dec, 1.0); 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; 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) / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180.0 * Math.PI))); } RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; lookAt.TransformCoordinate(lookAtAdjust); Matrix3d matHeadingPitchRoll; if (DomePreviewPopup.Active) { matHeadingPitchRoll = Matrix3d.RotationY((DomePreviewPopup.Az / 180 * Math.PI)) * Matrix3d.RotationX((DomePreviewPopup.Alt / 180 * Math.PI)); } else { matHeadingPitchRoll = Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) * Matrix3d.RotationY((config.Heading / 180 * Math.PI)) * Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI)); } if (rift) { Matrix3d matRiftView = Matrix3d.RotationY(GetHeading()) * Matrix3d.RotationX(GetPitch()) * Matrix3d.RotationZ(-GetRoll()); RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * matRiftView; } else { Matrix3d matNorth = Matrix3d.RotationY(faceSouth ? Math.PI : 0); RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * matNorth * DomeMatrix * matHeadingPitchRoll; } 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; back = 12; double aspect = config.Aspect; double top = m_nearPlane * 2 / ((1 / Math.Tan(config.UpFov / 180 * Math.PI))) / 2; double bottom = m_nearPlane * 2 / -(1 / Math.Tan(config.DownFov / 180 * Math.PI)) / 2; double right = m_nearPlane * 2 / (1 / Math.Tan((config.UpFov + config.DownFov) / 2 / 180 * Math.PI)) * aspect / 2; double left = -right; if (config.MultiChannelDome1) { ProjMatrix = Matrix3d.PerspectiveOffCenterLH( left, right, bottom, top, m_nearPlane, back); } else if (rift) { RenderContext11.View = RenderContext11.View * config.ViewMatrix; ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back); RenderContext11.PerspectiveFov = riftFov; } else { RenderContext11.View = RenderContext11.View * config.ViewMatrix; ProjMatrix = Matrix3d.PerspectiveFovLH((75f / 180f) * Math.PI, 1.777778, m_nearPlane, back); } if (rift) { if (renderType == RenderTypes.LeftEye) { ProjMatrix.M31 += iod; } else { ProjMatrix.M31 -= iod; } } RenderContext11.Projection = ProjMatrix; ViewMatrix = RenderContext11.View; RenderContext11.ViewBase = RenderContext11.View; MakeFrustum(); }