// Draw an ellipse with the specified semi-major axis and eccentricity. The orbit is drawn over a single period, // fading from full brightness at the given eccentric anomaly. // // In order to match exactly the position at which a planet is drawn, the planet's position at the current time // must be passed as a parameter. positionNow is in the current coordinate system of the render context, not the // translated and rotated system of the orbital plane. public static void DrawEllipse(RenderContext11 renderContext, double semiMajorAxis, double eccentricity, double eccentricAnomaly, Color color, Matrix3d worldMatrix, Vector3d positionNow) { if (ellipseShader == null) { ellipseShader = new EllipseShader11(); } if (ellipseVertexBuffer == null) { ellipseVertexBuffer = CreateEllipseVertexBuffer( 500); } Matrix3d savedWorld = renderContext.World; renderContext.World = worldMatrix; renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineStrip; renderContext.SetVertexBuffer(ellipseVertexBuffer); ellipseShader.UseShader(renderContext, semiMajorAxis, eccentricity, eccentricAnomaly, new SharpDX.Color(color.R, color.G, color.B, color.A), savedWorld, positionNow); renderContext.devContext.Draw(ellipseVertexBuffer.Count, 0); renderContext.World = savedWorld; }
// video private void SetupMatricesVideoOverlay(double localZoomFactor) { if (config.MultiChannelDome1 || config.MultiProjector || DomePreviewPopup.Active) { SetupMatricesVideoOverlayMultiChannel(localZoomFactor); return; } WorldMatrix = Matrix3d.RotationY(-((0 + 90) / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((-0) / 180.0 * Math.PI))); double camLocal = 0; RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; // altaz ViewPoint = Coordinates.RADecTo3d(0, 0, 1.0); FovAngle = ((360) / 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. if (rift) { Matrix3d matRiftView = Matrix3d.Identity; float yaw = 0; float pitch = 0; float roll = 0; eyeRenderPose[0].Orientation.GetEulerAngles(out yaw, out pitch, out roll); matRiftView = Matrix3d.RotationY(yaw) * Matrix3d.RotationX(pitch) * Matrix3d.RotationZ(-roll); RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, new Vector3d(0.0, 0.0, -1.0), new Vector3d(Math.Sin(camLocal), Math.Cos(camLocal), 0.0)) * matRiftView; RenderContext11.ViewBase = RenderContext11.View; } else { RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, new Vector3d(0.0, 0.0, -1.0), new Vector3d(Math.Sin(camLocal), Math.Cos(camLocal), 0.0)); RenderContext11.ViewBase = RenderContext11.View; } m_nearPlane = 0f; if (multiMonClient) { ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)(monitorWidth * MonitorCountX) / (double)(monitorHeight * MonitorCountY), 0, -2.0); } else if (rift) { FovPort fovPort = eyeRenderDesc[0].Fov; RenderContext11.PerspectiveFov = Math.Atan(fovPort.UpTan + fovPort.DownTan); ProjMatrix = new Matrix3d(); var projMat = OVR.MatrixProjection(fovPort, (float)m_nearPlane, (float)back, Projection.None); projMat.Transpose(); ProjMatrix.Matrix11 = projMat; } else if (megaFrameDump) { ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)megaWidth / (double)megaHeight, 0, -2.0); } else { ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, 0, -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; MakeFrustum(); }
private void ComputeMatrix() { matrixComputed = true; matrix = Matrix3d.Identity; matrix.Multiply(Matrix3d.RotationX((((this.rotationField)) / 180f * Math.PI))); matrix.Multiply(Matrix3d.RotationZ(((this.CenterY) / 180f * Math.PI))); matrix.Multiply(Matrix3d.RotationY((((360 - this.CenterX) + 180) / 180f * Math.PI))); }
public static void UseShader(RenderContext11 renderContext, Color color, Matrix3d world, Vector3d positionNow, double timeOffset, double coverageDuration) { TimeOffset = (float)timeOffset; CoverageDuration = (float)coverageDuration; Color = color; PositionNow = positionNow; Matrix matrixWVP = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; matrixWVP.Transpose(); MatWVP = matrixWVP; Matrix positionWVP = (world * renderContext.View * renderContext.Projection).Matrix11; positionWVP.Transpose(); MatPositionWVP = positionWVP; Use(renderContext.devContext); }
public ImageSetHelper(ImageSetType dataSetType, BandPass bandPass) { generic = true; name = "Generic"; sparse = false; this.dataSetType = dataSetType; this.bandPass = bandPass; quadTreeTileMap = ""; url = ""; levels = 0; baseTileDegrees = 0; imageSetID = 0; extension = ""; projection = ProjectionType.Equirectangular; bottomsUp = false; baseLevel = 0; mercator = (projection == ProjectionType.Mercator); centerX = 0; centerY = 0; rotation = 0; //todo add scale thumbnailUrl = ""; matrix = Matrix3d.Identity; matrix.Multiply(Matrix3d.RotationX((((Rotation)) / 180f * Math.PI))); matrix.Multiply(Matrix3d.RotationZ(((CenterY) / 180f * Math.PI))); matrix.Multiply(Matrix3d.RotationY((((360 - CenterX) + 180) / 180f * Math.PI))); Earth3d.AddImageSetToTable(GetHash(), this); }
private void SetupMatricesVideoOverlayDome(bool forStars, RenderTypes renderType) { Vector3d center = viewCamera.ViewTarget; RenderContext11.LightingEnabled = false; double localZoom = ZoomFactor * 20; Vector3d lookAt = new Vector3d(0, 0, -1); FovAngle = ((360) / FOVMULT) / Math.PI * 180; double distance = 1; RenderContext11.CameraPosition = new Vector3d(0, 0, distance); Vector3d lookUp = new Vector3d(Math.Sin(-0), Math.Cos(-0), 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; } WorldMatrix = Matrix3d.RotationY(-((0 + 90) / 180f * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((0) / 180f * Math.PI))); RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; if (rift) { double amount = 0; Matrix3d stereoTranslate = Matrix3d.Translation(renderType == RenderTypes.LeftEye ? amount : -amount, 0, 0); Matrix3d matRiftView = Matrix3d.RotationY(GetHeading()) * Matrix3d.RotationX(GetPitch()) * Matrix3d.RotationZ(-GetRoll()); RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * lookAtAdjust * matRiftView * stereoTranslate; } else { RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * lookAtAdjust; } Vector3d temp = lookAt - RenderContext11.CameraPosition; temp.Normalize(); ViewPoint = temp; m_nearPlane = ((.000000001)); if (rift) { ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, 1.0f, m_nearPlane, -1f); } else { ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, -1f); } 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 (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 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 SetupMatricesLand11(RenderTypes renderType) { WorldMatrix = Matrix3d.RotationY(((this.ViewLong + 90f) / 180f * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180f * Math.PI))); RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; double distance = 0; if (CurrentImageSet.IsMandelbrot) { distance = (4.0 * (ZoomFactor / 180)) + 0.00000000000000000000000000000000000000001; } else { distance = (4.0 * (ZoomFactor / 180)) + 0.000001; } if (Settings.Active.ShowElevationModel) { targetAltitude = GetScaledAltitudeForLatLong(ViewLat, ViewLong); double heightNow = 1 + targetAltitude; targetAltitude *= RenderContext11.NominalRadius; if ((double.IsNaN(heightNow))) { heightNow = 0; } if (targetHeight < heightNow) { targetHeight = (((targetHeight * 2) + heightNow) / 3); } else { targetHeight = (((targetHeight * 9) + heightNow) / 10); } if (double.IsNaN(targetHeight)) { targetHeight = 0; } if (config.MultiChannelDome1 || config.MultiProjector) { targetHeight = heightNow = NetControl.focusAltitude; } } else { targetAltitude = 0; targetHeight = 1; } double rotLocal = CameraRotate; if (!rift) { if (renderType == RenderTypes.RightEye) { rotLocal -= .008; } if (renderType == RenderTypes.LeftEye) { rotLocal += .008; } } RenderContext11.CameraPosition = new Vector3d( (Math.Sin(rotLocal) * Math.Sin(CameraAngle) * distance), (Math.Cos(rotLocal) * Math.Sin(CameraAngle) * distance), (-targetHeight - (Math.Cos(CameraAngle) * distance))); cameraTarget = new Vector3d(0.0f, 0.0f, -targetHeight); double camHeight = RenderContext11.CameraPosition.Length(); if (Tile.GrayscaleStyle) { if (CurrentImageSet.Projection == ProjectionType.Toast && (CurrentImageSet.MeanRadius > 0 && CurrentImageSet.MeanRadius < 4000000)) { int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000))); SkyColor = Color.FromArgb(213 * val / 255, 165 * val / 255, 118 * val / 255); } else if (CurrentImageSet.DataSetType == ImageSetType.Earth) { SkyColor = Color.FromArgb(255, 184, 184, 184); } else { SkyColor = Color.Black; } } else { if (CurrentImageSet.ReferenceFrame == "Mars" && Settings.Active.ShowEarthSky) { int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000))); SkyColor = Color.FromArgb(213 * val / 255, 165 * val / 255, 118 * val / 255); } else if (CurrentImageSet.DataSetType == ImageSetType.Earth && Settings.Active.ShowEarthSky) { int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000))); SkyColor = Color.FromArgb(255, val / 3, val / 3, val); } else { SkyColor = Color.Black; } } if (config.MultiChannelGlobe) { // Move the camera to some fixed distance from the globe RenderContext11.CameraPosition *= 50.0 / RenderContext11.CameraPosition.Length(); // Modify camera position in globe mode Matrix3d globeCameraRotation = Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) * Matrix3d.RotationY((config.Heading / 180 * Math.PI)) * Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI)); RenderContext11.CameraPosition = globeCameraRotation.Transform(RenderContext11.CameraPosition); cameraTarget = globeCameraRotation.Transform(cameraTarget); RenderContext11.View = Matrix3d.LookAtLH( RenderContext11.CameraPosition, cameraTarget, new Vector3d(Math.Sin(rotLocal) * Math.Cos(CameraAngle), Math.Cos(rotLocal) * Math.Cos(CameraAngle), Math.Sin(CameraAngle))); } else 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 = Matrix3d.LookAtLH( RenderContext11.CameraPosition, cameraTarget, new Vector3d(Math.Sin(rotLocal) * Math.Cos(CameraAngle), Math.Cos(rotLocal) * Math.Cos(CameraAngle), Math.Sin(CameraAngle))) * DomeMatrix * matHeadingPitchRoll; RenderContext11.ViewBase = RenderContext11.View; } else { Vector3d lookUp = new Vector3d(Math.Sin(rotLocal) * Math.Cos(CameraAngle), Math.Cos(rotLocal) * Math.Cos(CameraAngle), Math.Sin(CameraAngle)); if (DomePreviewPopup.Active) { Matrix3d matDomePreview = Matrix3d.RotationY((DomePreviewPopup.Az / 180 * Math.PI)) * Matrix3d.RotationX((DomePreviewPopup.Alt / 180 * Math.PI)); RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, cameraTarget, lookUp) * Matrix3d.RotationX(((-config.TotalDomeTilt) / 180 * Math.PI)) * matDomePreview; } else if (rift) { double amount = distance / 100; Matrix3d stereoTranslate = Matrix3d.Translation(renderType == RenderTypes.LeftEye ? amount : -amount, 0, 0); Matrix3d matRiftView = Matrix3d.RotationY(GetHeading()) * Matrix3d.RotationX(GetPitch()) * Matrix3d.RotationZ(-GetRoll()); RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, cameraTarget, lookUp) * Matrix3d.Translation(HeadPosition) * matRiftView * stereoTranslate; } else { RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, cameraTarget, lookUp) * Matrix3d.Translation(HeadPosition); } if (multiMonClient) { RenderContext11.View = RenderContext11.View * Matrix3d.RotationY((config.Heading / 180 * Math.PI)); } RenderContext11.ViewBase = RenderContext11.View; } back = Math.Sqrt((distance + 1f) * (distance + 1f) - 1); back = Math.Max(.5, back); if (Properties.Settings.Default.EarthCutawayView.State) { back = 20; } m_nearPlane = distance * .05f; if (config.MultiChannelGlobe) { m_nearPlane = RenderContext11.CameraPosition.Length() - 2.0; back = m_nearPlane + 4.0; ProjMatrix = Matrix3d.OrthoLH(config.Aspect * 2.0, 2.0, m_nearPlane, back); } else 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) { double fov = (((config.UpFov + config.DownFov) / 2 / 180 * Math.PI)); if (fov == 0) { fov = (Math.PI / 4.0); } m_nearPlane = distance * .05f; ProjMatrix = Matrix3d.PerspectiveFovLH(fov, (monitorWidth * MonitorCountX) / (monitorHeight * MonitorCountY), m_nearPlane, back); } else if (rift) { m_nearPlane = distance * .05f; ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back); RenderContext11.PerspectiveFov = riftFov; } else { m_nearPlane = distance * .05f; ProjMatrix = Matrix3d.PerspectiveFovLH(fovLocal, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back); RenderContext11.PerspectiveFov = fovLocal; } if (multiMonClient && !config.MultiChannelDome1 && !Config.MultiProjector && !Config.MultiChannelGlobe) { 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; colorBlend = 1 / distance; ViewMatrix = RenderContext11.View; MakeFrustum(); }
private void ComputeFixedSherical(RenderContext11 renderContext) { if (ObservingLocation) { Lat = SpaceTimeController.Location.Lat; Lng = SpaceTimeController.Location.Lng; Altitude = SpaceTimeController.Altitude; } WorldMatrix = Matrix3d.Identity; WorldMatrix.Translate(Translation); double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius; WorldMatrix.Scale(new Vector3d(localScale, localScale, localScale)); //WorldMatrix.Scale(new Vector3d(1000, 1000, 1000)); WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI))); WorldMatrix.Multiply(Matrix3d.RotationZ(-90.0 / 180.0 * Math.PI)); if (RotationalPeriod != 0) { double rotationCurrent = (((SpaceTimeController.JNow - this.ZeroRotationDate) / RotationalPeriod) * Math.PI * 2) % (Math.PI * 2); WorldMatrix.Multiply(Matrix3d.RotationX(-rotationCurrent)); } WorldMatrix.Translate(new Vector3d(1 + (Altitude / renderContext.NominalRadius), 0, 0)); WorldMatrix.Multiply(Matrix3d.RotationZ(Lat / 180 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationY(-(Lng) / 180 * Math.PI)); }
private void ComputeFixedRectangular(RenderContext11 renderContext) { WorldMatrix = Matrix3d.Identity; WorldMatrix.Translate(Translation); WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI))); WorldMatrix.Scale(new Vector3d(Scale, Scale, Scale)); WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)(Coordinates.MstFromUTC2(SpaceTimeController.Now, 0) / 180 * Math.PI), (float)0, (float)0)); }
public void ComputeFrame(RenderContext11 renderContext) { if (this.Reference == ReferenceFrames.Sandbox) { WorldMatrix = Matrix3d.Identity; return; } switch (ReferenceFrameType) { case ReferenceFrameTypes.Orbital: ComputeOrbital(renderContext); break; case ReferenceFrameTypes.FixedSherical: ComputeFixedSherical(renderContext); break; case ReferenceFrameTypes.Trajectory: ComputeFrameTrajectory(renderContext); break; case ReferenceFrameTypes.Synodic: ComputeFrameSynodic(renderContext); break; //case ReferenceFrameTypes.FixedRectangular: // ComputeFixedRectangular(renderContext); // break; default: break; } }
private void OffsetObjects(List<PositionNormalTextured> vertList, List<ObjectNode> objects, Matrix3d offsetMat, Vector3 offsetPoint) { foreach (ObjectNode node in objects) { Matrix3d matLoc = node.LocalMat; //offsetMat *; OffsetObjects(vertList, node.Children, matLoc, node.PivotPoint + offsetPoint); foreach (Mesh.Group group in node.DrawGroup) { int end = group.startIndex + group.indexCount; for (int i = group.startIndex; i < end; i++) { PositionNormalTextured vert = vertList[i]; vert.Pos += (node.PivotPoint + offsetPoint); vertList[i] = vert; } } } }
public void ComputeMatrix() { Matrix = Matrix3d.Identity; Matrix = Matrix3d.Multiply(Matrix, Matrix3d.RotationX((float)(((Rotation)) / 180f * Math.PI))); Matrix = Matrix3d.Multiply(Matrix, Matrix3d.RotationZ((float)((LatCenter) / 180f * Math.PI))); Matrix = Matrix3d.Multiply(Matrix, Matrix3d.RotationY((float)(((360 - LngCenter) + 180) / 180f * Math.PI))); }
public static void ComputeFrustum(Matrix3d projection, PlaneD[] frustum) { // Left plane frustum[0].A = projection.M14 + projection.M11; frustum[0].B = projection.M24 + projection.M21; frustum[0].C = projection.M34 + projection.M31; frustum[0].D = projection.M44 + projection.M41; // Right plane frustum[1].A = projection.M14 - projection.M11; frustum[1].B = projection.M24 - projection.M21; frustum[1].C = projection.M34 - projection.M31; frustum[1].D = projection.M44 - projection.M41; // Top plane frustum[2].A = projection.M14 - projection.M12; frustum[2].B = projection.M24 - projection.M22; frustum[2].C = projection.M34 - projection.M32; frustum[2].D = projection.M44 - projection.M42; // Bottom plane frustum[3].A = projection.M14 + projection.M12; frustum[3].B = projection.M24 + projection.M22; frustum[3].C = projection.M34 + projection.M32; frustum[3].D = projection.M44 + projection.M42; // Near plane frustum[4].A = projection.M13; frustum[4].B = projection.M23; frustum[4].C = projection.M33; frustum[4].D = projection.M43; // Far plane frustum[5].A = projection.M14 - projection.M13; frustum[5].B = projection.M24 - projection.M23; frustum[5].C = projection.M34 - projection.M33; frustum[5].D = projection.M44 - projection.M43; // Normalize planes for (int i = 0; i < 6; i++) { frustum[i].Normalize(); } }
public Matrix3d GetMatrix() { if (!MatrixFresh) { double fieldWidth = east - west; double fieldHeight = north - south; Coordinates center = new Coordinates(0, 0); center.Lat = south + fieldHeight / 2; center.Lng = west + fieldWidth / 2; Matrix = Matrix3d.GetMapMatrix(center, fieldWidth, fieldHeight, rotation/180*Math.PI); } return Matrix; }
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(); }
public void MakeFrustum() { Matrix3d viewProjection = (RenderContext11.World * RenderContext11.View * RenderContext11.Projection); inverseWorld = RenderContext11.World; inverseWorld.Invert(); // Left plane frustum[0].A = (float)(viewProjection.M14 + viewProjection.M11); frustum[0].B = (float)(viewProjection.M24 + viewProjection.M21); frustum[0].C = (float)(viewProjection.M34 + viewProjection.M31); frustum[0].D = (float)(viewProjection.M44 + viewProjection.M41); // Right plane frustum[1].A = (float)(viewProjection.M14 - viewProjection.M11); frustum[1].B = (float)(viewProjection.M24 - viewProjection.M21); frustum[1].C = (float)(viewProjection.M34 - viewProjection.M31); frustum[1].D = (float)(viewProjection.M44 - viewProjection.M41); // Top plane frustum[2].A = (float)(viewProjection.M14 - viewProjection.M12); frustum[2].B = (float)(viewProjection.M24 - viewProjection.M22); frustum[2].C = (float)(viewProjection.M34 - viewProjection.M32); frustum[2].D = (float)(viewProjection.M44 - viewProjection.M42); // Bottom plane frustum[3].A = (float)(viewProjection.M14 + viewProjection.M12); frustum[3].B = (float)(viewProjection.M24 + viewProjection.M22); frustum[3].C = (float)(viewProjection.M34 + viewProjection.M32); frustum[3].D = (float)(viewProjection.M44 + viewProjection.M42); // Near plane frustum[4].A = (float)(viewProjection.M13); frustum[4].B = (float)(viewProjection.M23); frustum[4].C = (float)(viewProjection.M33); frustum[4].D = (float)(viewProjection.M43); // Far plane frustum[5].A = (float)(viewProjection.M14 - viewProjection.M13); frustum[5].B = (float)(viewProjection.M24 - viewProjection.M23); frustum[5].C = (float)(viewProjection.M34 - viewProjection.M33); frustum[5].D = (float)(viewProjection.M44 - viewProjection.M43); // Normalize planes for (int i = 0; i < 6; i++) { frustum[i].Normalize(); } RenderContext11.MakeFrustum(); }
private void ComputeFrameSynodic(RenderContext11 renderContext) { // A synodic frame is a rotating frame of reference in which // the x-axis is the direction between the bodies in a two-body // system. The origin is at the secondary body, and +x points // in the direction opposite the primary. The z-axis is in the orbital // plane and normal to x; it points in the direction of the instantaneous // orbital velocity of the secondary. // The origin is offset by then translation. The five libration points in a // two-body system can be approximated by choosing different offsets. For // example, the Sun-Earth L2 point is approximated by using x = 1,500,000 km, y = 0 and z = 0. WorldMatrix = Matrix3d.Identity; double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius; WorldMatrix.Scale(new Vector3d(localScale, localScale, localScale)); WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI))); WorldMatrix.Translate(Translation / 6371.000); // Currently we assume the Sun-Earth system double jd = SpaceTimeController.JNow; double B = CAACoordinateTransformation.DegreesToRadians(CAAEarth.EclipticLatitude(jd)); double L = CAACoordinateTransformation.DegreesToRadians(CAAEarth.EclipticLongitude(jd)); Vector3d eclPos = new Vector3d(Math.Cos(L) * Math.Cos(B), Math.Sin(L) * Math.Cos(B), Math.Sin(B)); // Just approximate the orbital velocity for now Vector3d eclVel = Vector3d.Cross(eclPos, new Vector3d(0.0, 0.0, 1.0)); eclVel.Normalize(); // Convert to WWT's coordinate convention by swapping Y and Z eclPos = new Vector3d(eclPos.X, eclPos.Z, eclPos.Y); eclVel = new Vector3d(eclVel.X, eclVel.Z, eclVel.Y); Vector3d xaxis = eclPos; Vector3d yaxis = Vector3d.Cross(eclVel, eclPos); Vector3d zaxis = eclVel; Matrix3d rotation = new Matrix3d(xaxis.X, yaxis.X, zaxis.X, 0, xaxis.Y, yaxis.Y, zaxis.Y, 0, xaxis.Z, yaxis.Z, zaxis.Z, 0, 0, 0, 0, 1); // Convert from ecliptic to J2000 EME (equatorial) system double earthObliquity = CAACoordinateTransformation.DegreesToRadians(Coordinates.MeanObliquityOfEcliptic(jd)); rotation = rotation * Matrix3d.RotationX(-earthObliquity); WorldMatrix.Multiply(rotation); }
private void SetupMatricesLandDome(RenderTypes renderType) { FovAngle = 60; RenderContext11.LightingEnabled = false; double localZoom = ZoomFactor * 20; double distance = (4.0 * (ZoomFactor / 180)) + 0.000001; Vector3d lookAt = new Vector3d(0.0f, 0.0f, -targetHeight); if (Settings.Active.ShowElevationModel) { double heightNow = 1 + GetScaledAltitudeForLatLong(ViewLat, ViewLong); if (targetHeight < heightNow) { targetHeight = (((targetHeight * 2) + heightNow) / 3); } else { targetHeight = (((targetHeight * 9) + heightNow) / 10); } } else { targetHeight = 1; } double rotLocal = CameraRotate; if (renderType == RenderTypes.RightEye) { rotLocal -= .008; } if (renderType == RenderTypes.LeftEye) { rotLocal += .008; } RenderContext11.CameraPosition = new Vector3d( (Math.Sin(rotLocal) * Math.Sin(CameraAngle) * distance), (Math.Cos(rotLocal) * Math.Sin(CameraAngle) * distance), (-targetHeight - (Math.Cos(CameraAngle) * distance))); Matrix3d lookAtAdjust = Matrix3d.Identity; Vector3d lookUp = new Vector3d(Math.Sin(rotLocal) * Math.Cos(CameraAngle), Math.Cos(rotLocal) * Math.Cos(CameraAngle), Math.Sin(CameraAngle)); Matrix3d cubeMat = Matrix3d.Identity; switch (renderType) { case RenderTypes.DomeUp: cubeMat = Matrix3d.RotationX((Math.PI / 2)); break; case RenderTypes.DomeLeft: cubeMat = Matrix3d.RotationY((Math.PI / 2)); break; case RenderTypes.DomeRight: cubeMat = Matrix3d.RotationY(-(Math.PI / 2)); break; case RenderTypes.DomeFront: break; case RenderTypes.DomeBack: cubeMat = Matrix3d.RotationY((Math.PI)); break; default: break; } double camHeight = RenderContext11.CameraPosition.Length(); if (CurrentImageSet.Projection == ProjectionType.Toast && (CurrentImageSet.MeanRadius > 0 && CurrentImageSet.MeanRadius < 4000000)) { int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000))); SkyColor = Color.FromArgb(213 * val / 255, 165 * val / 255, 118 * val / 255); } else if (CurrentImageSet.DataSetType == ImageSetType.Earth && Settings.Active.ShowEarthSky) { int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000))); SkyColor = Color.FromArgb(255, val / 3, val / 3, val); } else { SkyColor = Color.Black; } WorldMatrix = Matrix3d.RotationY(((this.ViewLong + 90f) / 180f * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180f * Math.PI))); RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; if (config.MultiChannelDome1) { Matrix3d matHeadingPitchRoll = Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) * Matrix3d.RotationX((config.Pitch / 180 * Math.PI)) * Matrix3d.RotationY((config.Heading / 180 * Math.PI)); RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * matHeadingPitchRoll; } else { RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * cubeMat; } Vector3d temp = lookAt - RenderContext11.CameraPosition; temp.Normalize(); ViewPoint = temp; back = Math.Sqrt((distance + 1f) * (distance + 1f) - 1); m_nearPlane = distance * .1f; ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, back); if (config.MultiChannelDome1) { ProjMatrix = Matrix3d.PerspectiveFovLH(((config.UpFov + config.DownFov) / 180 * Math.PI), (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back); } else if (multiMonClient) { ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, back); RenderContext11.PerspectiveFov = (Math.PI / 2.0); } RenderContext11.Projection = ProjMatrix; ViewMatrix = RenderContext11.View; RenderContext11.ViewBase = RenderContext11.View; MakeFrustum(); }
private void ComputeFrameTrajectory(RenderContext11 renderContext) { Vector3d vector = new Vector3d(); Vector3d point = GetTragectoryPoint(SpaceTimeController.JNow, out vector); Vector3d direction = vector; direction.Normalize(); Vector3d up = point; up.Normalize(); direction.Normalize(); double dist = point.Length(); double scaleFactor = 1.0; //scaleFactor = UiTools.KilometersPerAu * 1000; scaleFactor *= 1 / renderContext.NominalRadius; Matrix3d look = Matrix3d.LookAtLH(new Vector3d(0, 0, 0), direction, new Vector3d(0, 1, 0)); look.Invert(); WorldMatrix = Matrix3d.Identity; WorldMatrix.Translate(Translation); double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius; WorldMatrix.Scale(new Vector3d(localScale, localScale, localScale)); WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI))); if (RotationalPeriod != 0) { double rotationCurrent = (((SpaceTimeController.JNow - this.ZeroRotationDate) / RotationalPeriod) * Math.PI * 2) % (Math.PI * 2); WorldMatrix.Multiply(Matrix3d.RotationX(-rotationCurrent)); } point = Vector3d.Scale(point, scaleFactor); WorldMatrix.Translate(point); if (StationKeeping) { WorldMatrix = look * WorldMatrix; } }
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(); }
private void ComputeOrbital(RenderContext11 renderContext) { CAAEllipticalObjectElements ee = Elements; Vector3d point = CAAElliptical.CalculateRectangular(SpaceTimeController.JNow, ee, out MeanAnomoly); Vector3d pointInstantLater = CAAElliptical.CalculateRectangular(ee, MeanAnomoly + .001); Vector3d direction = point - pointInstantLater; direction.Normalize(); Vector3d up = point; up.Normalize(); direction.Normalize(); double dist = point.Length(); double scaleFactor = 1.0; switch (SemiMajorAxisUnits) { case AltUnits.Meters: scaleFactor = 1.0; break; case AltUnits.Feet: scaleFactor = 1.0 / 3.2808399; break; case AltUnits.Inches: scaleFactor = (1.0 / 3.2808399) / 12; break; case AltUnits.Miles: scaleFactor = 1609.344; break; case AltUnits.Kilometers: scaleFactor = 1000; break; case AltUnits.AstronomicalUnits: scaleFactor = UiTools.KilometersPerAu * 1000; break; case AltUnits.LightYears: scaleFactor = UiTools.AuPerLightYear * UiTools.KilometersPerAu * 1000; break; case AltUnits.Parsecs: scaleFactor = UiTools.AuPerParsec * UiTools.KilometersPerAu * 1000; break; case AltUnits.MegaParsecs: scaleFactor = UiTools.AuPerParsec * UiTools.KilometersPerAu * 1000 * 1000000; break; case AltUnits.Custom: scaleFactor = 1; break; default: break; } scaleFactor *= 1 / renderContext.NominalRadius; Matrix3d look = Matrix3d.LookAtLH(new Vector3d(0, 0, 0), direction, up); look.Invert(); WorldMatrix = Matrix3d.Identity; WorldMatrix.Translate(Translation); double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius; WorldMatrix.Scale(new Vector3d(localScale, localScale, localScale)); WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI))); if (RotationalPeriod != 0) { double rotationCurrent = (((SpaceTimeController.JNow - this.ZeroRotationDate) / RotationalPeriod) * Math.PI * 2) % (Math.PI * 2); WorldMatrix.Multiply(Matrix3d.RotationX(-rotationCurrent)); } point = Vector3d.Scale(point, scaleFactor); WorldMatrix.Translate(point); if (StationKeeping) { WorldMatrix = look * WorldMatrix; } }
internal static Vector3d GetFrameTarget(RenderContext11 renderContext, string TrackingFrame, out Matrix3d matOut) { Vector3d targetPoint = Vector3d.Empty; matOut = Matrix3d.Identity; if (!AllMaps.ContainsKey(TrackingFrame)) { return targetPoint; } List<LayerMap> mapList = new List<LayerMap>(); LayerMap current = AllMaps[TrackingFrame]; mapList.Add(current); while (current.Frame.Reference == ReferenceFrames.Custom) { current = current.Parent; mapList.Insert(0, current); } Matrix3d matOld = renderContext.World; Matrix3d matOldNonRotating = renderContext.WorldBaseNonRotating; Matrix3d matOldBase = renderContext.WorldBase; double oldNominalRadius = renderContext.NominalRadius; foreach (LayerMap map in mapList) { if (map.Frame.Reference != ReferenceFrames.Custom && map.Frame.Reference != ReferenceFrames.Sandbox) { Planets.SetupPlanetMatrix(renderContext, (int)Enum.Parse(typeof(SolarSystemObjects), map.Frame.Name), Vector3d.Empty, false); } else { map.ComputeFrame(renderContext); if (map.Frame.useRotatingParentFrame()) { renderContext.World = map.Frame.WorldMatrix * renderContext.World; } else { renderContext.World = map.Frame.WorldMatrix * renderContext.WorldBaseNonRotating; } if (map.Frame.ReferenceFrameType == ReferenceFrameTypes.Synodic) { renderContext.WorldBaseNonRotating = renderContext.World; } renderContext.NominalRadius = map.Frame.MeanRadius; } } targetPoint = renderContext.World.Transform(targetPoint); Vector3d lookAt = renderContext.World.Transform(new Vector3d(0, 0, 1)); Vector3d lookUp = renderContext.World.Transform(new Vector3d(0, 1, 0)) - targetPoint; lookUp.Normalize(); matOut = Matrix3d.LookAtLH(new Vector3d(0, 0, 0), lookAt - targetPoint, lookUp); renderContext.NominalRadius = oldNominalRadius; renderContext.World = matOld; renderContext.WorldBaseNonRotating = matOldNonRotating; renderContext.WorldBase = matOldBase; return targetPoint; }
public void SetupMatricesAltAz() { RenderContext11.World = Matrix3d.Identity; Matrix3d lookAtAdjust = Matrix3d.Identity; Vector3d lookFrom = new Vector3d(0, 0, 0); Vector3d lookAt = new Vector3d(0, 0, 1); Vector3d lookUp = new Vector3d(0, 1, 0); bool dome = false; Matrix3d view; Matrix3d ProjMatrix; switch (CurrentRenderType) { 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; } 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)); view = Matrix3d.LookAtLH(lookFrom, lookAt, lookUp) * matHeadingPitchRoll; } else { if (Settings.DomeView) { view = Matrix3d.LookAtLH(lookFrom, lookAt, lookUp) * lookAtAdjust; } else { if (DomePreviewPopup.Active && !dome) { Matrix3d matDomePreview = Matrix3d.RotationY((DomePreviewPopup.Az / 180 * Math.PI)) * Matrix3d.RotationX((DomePreviewPopup.Alt / 180 * Math.PI)); view = Matrix3d.LookAtLH(lookFrom, lookAt, lookUp) * matDomePreview; } else if (rift) { Matrix3d matRiftView = Matrix3d.RotationY(GetHeading()) * Matrix3d.RotationX(GetPitch()) * Matrix3d.RotationZ(-GetRoll()); view = Matrix3d.LookAtLH(lookFrom, lookAt, lookUp) * matRiftView; } else { view = Matrix3d.LookAtLH(lookFrom, lookAt, lookUp) * DomeMatrix * lookAtAdjust; } if (multiMonClient) { RenderContext11.View = RenderContext11.View * Matrix3d.RotationY((config.Heading / 180 * Math.PI)); } } } Matrix3d viewXform = Matrix3d.Scaling(1, 1, 1); view = viewXform * view; RenderContext11.View = view; double back = 10000; m_nearPlane = .1f; 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) { double fov = (((config.UpFov + config.DownFov) / 2 / 180 * Math.PI)); if (fov == 0) { fov = (Math.PI / 4.0); } ProjMatrix = Matrix3d.PerspectiveFovLH(fov, (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); } else { ProjMatrix = Matrix3d.PerspectiveFovLH(RenderContext11.PerspectiveFov, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back); } 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)); } RenderContext11.Projection = ProjMatrix; }
public void UseShader(RenderContext11 renderContext, double semiMajorAxis, double eccentricity, double eccentricAnomaly, Color color, Matrix3d world, Vector3d positionNow) { SemiMajorAxis = (float)semiMajorAxis; Eccentricity = (float)eccentricity; EccentricAnomaly = (float)eccentricAnomaly; Color = color; PositionNow = positionNow; Matrix matrixWVP = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; matrixWVP.Transpose(); MatWVP = matrixWVP; Matrix positionWVP = (world * renderContext.View * renderContext.Projection).Matrix11; positionWVP.Transpose(); MatPositionWVP = positionWVP; Use(renderContext.devContext); }
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(); }
public void AddGlyphPoints(List<PositionColoredTextured> pointList, SizeF size, RectangleF position, RectangleF uv) { PositionColoredTextured[] points = new PositionColoredTextured[6]; Vector3d left = Vector3d.Cross(center, up); Vector3d right = Vector3d.Cross(up, center); left.Normalize(); right.Normalize(); up.Normalize(); Vector3d upTan = Vector3d.Cross(center, right); upTan.Normalize(); if (alignment == Alignment.Center) { left.Multiply(width - position.Left * 2); right.Multiply(width - ((width * 2) - position.Right * 2)); } else if (alignment == Alignment.Left) { left.Multiply(-position.Left * 2); right.Multiply(position.Right * 2); } Vector3d top = upTan; Vector3d bottom = -upTan; top.Multiply(height-position.Top*2); bottom.Multiply(height-((height*2)-position.Bottom*2)); Vector3d ul = center; ul.Add(top); if (sky) { ul.Add(left); } else { ul.Subtract(left); } Vector3d ur = center; ur.Add(top); if (sky) { ur.Add(right); } else { ur.Subtract(right); } Vector3d ll = center; if (sky) { ll.Add(left); } else { ll.Subtract(left); } ll.Add(bottom); Vector3d lr = center; if (sky) { lr.Add(right); } else { lr.Subtract(right); } lr.Add(bottom); points[0].Pos3d = ul; points[0].Tu = uv.Left; points[0].Tv = uv.Top; points[0].Color = Color; points[2].Tu = uv.Left; points[2].Tv = uv.Bottom; points[2].Pos3d = ll; points[2].Color = Color; points[1].Tu = uv.Right; points[1].Tv = uv.Top; points[1].Pos3d = ur; points[1].Color = Color; points[3].Tu = uv.Right; points[3].Tv = uv.Bottom; points[3].Pos3d = lr; points[3].Color = Color; points[5].Tu = uv.Right; points[5].Tv = uv.Top; points[5].Pos3d = ur; points[5].Color = Color; points[4].Tu = uv.Left; points[4].Tv = uv.Bottom; points[4].Pos3d = ll; points[4].Color = Color; if (Rotation != 0 || Tilt != 0 || Bank != 0) { if (!matInit) { Matrix3d lookAt = Matrix3d.LookAtLH(center, new Vector3d(0, 0, 0), up); Matrix3d lookAtInv = lookAt; lookAtInv.Invert(); rtbMat = lookAt * Matrix3d.RotationZ(-Rotation / 180 * Math.PI) * Matrix3d.RotationX(-Tilt / 180 * Math.PI) * Matrix3d.RotationY(-Bank / 180 * Math.PI) * lookAtInv; //todo make this true after debug matInit = false; } for (int i = 0; i < 6; i++) { Vector3d pos = points[i].Pos3d; pos.TransformCoordinate(rtbMat); points[i].Pos3d = pos; } } pointList.AddRange(points); }
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(); }
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; } }
// video private void SetupMatricesVideoOverlay(double localZoomFactor) { if (config.MultiChannelDome1 || config.MultiProjector || DomePreviewPopup.Active) { SetupMatricesVideoOverlayMultiChannel(localZoomFactor); return; } WorldMatrix = Matrix3d.RotationY(-((0 + 90) / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((-0) / 180.0 * Math.PI))); double camLocal = 0; RenderContext11.World = WorldMatrix; RenderContext11.WorldBase = WorldMatrix; // altaz ViewPoint = Coordinates.RADecTo3d(0, 0, 1.0); FovAngle = ((360) / 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)); RenderContext11.ViewBase = RenderContext11.View; m_nearPlane = 0f; if (multiMonClient) { ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)(monitorWidth * MonitorCountX) / (double)(monitorHeight * MonitorCountY), 0, -2.0); } else if (rift) { ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back); RenderContext11.PerspectiveFov = riftFov; } else { ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, 0, -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)); } if (rift) { if (CurrentRenderType == RenderTypes.LeftEye) { ProjMatrix.M31 += iod; } else { ProjMatrix.M31 -= iod; } } RenderContext11.Projection = ProjMatrix; ViewMatrix = RenderContext11.View; MakeFrustum(); }