static public Vector3d RADecTo3d(double ra, double dec) { return(Vector3d.Create((Math.Cos(ra * RCRA) * Math.Cos(dec * RC) * radius), (Math.Sin(dec * RC) * radius), (Math.Sin(ra * RCRA) * Math.Cos(dec * RC) * radius))); }
static public Vector3d GeoTo3dDoubleRad(double lat, double lng, double radius) { lng -= 180; return(Vector3d.Create(Math.Cos(lng * RC) * Math.Cos(lat * RC) * radius, Math.Sin(lat * RC) * radius, Math.Sin(lng * RC) * Math.Cos(lat * RC) * radius)); }
static public Vector3d GeoTo3dRad(double lat, double lng, double radius) { return(Vector3d.Create(((Math.Cos(lng * RC)) * (Math.Cos(lat * RC)) * radius), ((Math.Sin(lat * RC) * radius)), ((Math.Sin(lng * RC)) * (Math.Cos(lat * RC)) * radius))); }
public void SetupMatricesSolarSystem(bool forStars) { Lighting = Settings.Active.SolarSystemLighting; Space = false; if (SolarSystemTrack != SolarSystemObjects.Custom && SolarSystemTrack != SolarSystemObjects.Undefined) { ViewCamera.ViewTarget = Planets.GetPlanetTargetPoint(SolarSystemTrack, ViewCamera.Lat, ViewCamera.Lng, 0); } RenderTriangle.CullInside = false; double cameraDistance = SolarSystemCameraDistance; Matrix3d trackingMatrix = Matrix3d.Identity; cameraDistance -= 0.000001; bool activeTrackingFrame = false; if (SolarSystemTrack == SolarSystemObjects.Custom && !string.IsNullOrEmpty(TrackingFrame)) { activeTrackingFrame = true; FrameTarget target = LayerManager.GetFrameTarget(this, TrackingFrame); ViewCamera.ViewTarget = target.Target; trackingMatrix = target.Matrix; } else if (!string.IsNullOrEmpty(TrackingFrame)) { TrackingFrame = ""; } Vector3d center = ViewCamera.ViewTarget; //Vector3d lightPosition = -center; double localZoom = ViewCamera.Zoom * 20; Vector3d lookAt = new Vector3d(); Matrix3d viewAdjust = Matrix3d.Identity; viewAdjust.Multiply(Matrix3d.RotationX(((-ViewCamera.Lat) / 180f * Math.PI))); viewAdjust.Multiply(Matrix3d.RotationY(((-ViewCamera.Lng) / 180f * Math.PI))); Matrix3d lookAtAdjust = Matrix3d.Identity; bool dome = false; Vector3d lookUp; if (useSolarSystemTilt && !SandboxMode) { double angle = ViewCamera.Angle; if (cameraDistance > 0.0008) { angle = 0; } else if (cameraDistance > 0.00001) { double val = Math.Min(1.903089987, Util.Log10(cameraDistance) + 5) / 1.903089987; angle = angle * Math.Max(0, 1 - val); } CameraPosition = Vector3d.Create( (Math.Sin(-ViewCamera.Rotation) * Math.Sin(angle) * cameraDistance), (Math.Cos(-ViewCamera.Rotation) * Math.Sin(angle) * cameraDistance), ((Math.Cos(angle) * cameraDistance))); lookUp = Vector3d.Create(Math.Sin(-ViewCamera.Rotation), Math.Cos(-ViewCamera.Rotation), 0.00001f); } else { CameraPosition = Vector3d.Create(0, 0, ((cameraDistance))); lookUp = Vector3d.Create(Math.Sin(-ViewCamera.Rotation), Math.Cos(-ViewCamera.Rotation), 0.0001f); } CameraPosition = viewAdjust.Transform(CameraPosition); cameraOffset = CameraPosition.Copy(); Matrix3d tmp = trackingMatrix.Clone(); tmp.Invert(); cameraOffset = Vector3d.TransformCoordinate(cameraOffset, tmp); lookUp = viewAdjust.Transform(lookUp); // WorldMatrix = Matrix3d.Identity; World = Matrix3d.Identity; WorldBase = World.Clone(); View = Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(trackingMatrix, Matrix3d.LookAtLH(CameraPosition, lookAt, lookUp)), lookAtAdjust); ViewBase = View.Clone(); Vector3d temp = Vector3d.SubtractVectors(lookAt, 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) { nearPlane = cameraDistance * 0.03; //m_nearPlane = Math.Max(m_nearPlane, .000000000030); nearPlane = Math.Max(nearPlane, .00000000001); back = 1900; } else { if (forStars) { back = 900056; back = cameraDistance > 900056 ? cameraDistance * 3 : 900056; nearPlane = .00003f; // m_nearPlane = cameraDistance * 0.03; // back = 9937812653; // back = 21421655730; } else { back = cameraDistance > 1900 ? cameraDistance + 200 : 1900; // m_nearPlane = .0001f; if (Settings.Active.SolarSystemScale < 13) { nearPlane = (float)Math.Min(cameraDistance * 0.03, 0.01); } else { nearPlane = .001f; } } } Projection = Matrix3d.PerspectiveFovLH((fovLocal), (double)Width / (double)Height, nearPlane, back); PerspectiveFov = fovLocal; fovAngle = ((this.ViewCamera.Zoom) / FOVMULT) / Math.PI * 180; fovScale = (fovAngle / Height) * 3600; SetMatrixes(); MakeFrustum(); }
static public Vector3d GeoTo3dDouble(double lat, double lng) { return(Vector3d.Create(Math.Cos(lng * RC) * Math.Cos(lat * RC) * radius, Math.Sin(lat * RC) * radius, Math.Sin(lng * RC) * Math.Cos(lat * RC) * radius)); }
internal void SetupMatricesLand3d() { Lighting = false; Space = false; RenderTriangle.CullInside = false; // For our world matrix, we will just rotate the Earth and Clouds about the y-axis. Matrix3d WorldMatrix = Matrix3d.RotationY(((ViewCamera.Lng - 90f) / 180f * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(((-ViewCamera.Lat) / 180f * Math.PI))); World = WorldMatrix; WorldBase = WorldMatrix.Clone(); viewPoint = Coordinates.GeoTo3d(ViewCamera.Lat, ViewCamera.Lng); double distance = 0; if (backgroundImageset.IsMandelbrot) { distance = (4.0 * (ViewCamera.Zoom / 180)) + 0.00000000000000000000000000000000000000001; } else { distance = (4.0 * (ViewCamera.Zoom / 180)) + 0.000001; } fovAngle = ((this.ViewCamera.Zoom) / FOVMULT) / Math.PI * 180; fovScale = (fovAngle / Height) * 3600; if (gl != null) { targetAltitude = GetScaledAltitudeForLatLong(ViewCamera.Lat, ViewCamera.Lng); double heightNow = 1 + targetAltitude; targetAltitude *= 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; //} } else { targetAltitude = 0; targetHeight = 1; } double rotLocal = ViewCamera.Rotation; CameraPosition = Vector3d.Create( (Math.Sin(rotLocal) * Math.Sin(ViewCamera.Angle) * distance), (Math.Cos(rotLocal) * Math.Sin(ViewCamera.Angle) * distance), (-targetHeight - (Math.Cos(ViewCamera.Angle) * distance))); Vector3d cameraTarget = Vector3d.Create(0.0f, 0.0f, -targetHeight); double camHeight = CameraPosition.Length(); Vector3d lookUp = Vector3d.Create(Math.Sin(rotLocal) * Math.Cos(ViewCamera.Angle), Math.Cos(rotLocal) * Math.Cos(ViewCamera.Angle), Math.Sin(ViewCamera.Angle)); View = Matrix3d.LookAtLH( (CameraPosition), (cameraTarget), lookUp); // * Matrix3d.RotationX(((-config.DomeTilt) / 180 * Math.PI)); ViewBase = View; double back = Math.Sqrt((distance + 1f) * (distance + 1f) - 1); back = Math.Max(.5, back); // back = (float)camDist * 40f; double m_nearPlane = distance * .05f; m_nearPlane = distance * .05f; Projection = Matrix3d.PerspectiveFovLH((Math.PI / 4.0), (double)Width / (double)Height, m_nearPlane, back); SetMatrixes(); MakeFrustum(); }
public void SetupMatricesSpace3d(double canvasWidth, double canvasHeight) { Lighting = false; if (!firstTimeInit) { galacticMatrix = Matrix3d.Identity; // -28.9361739586894, 17.7603329867975 galacticMatrix.Multiply(Matrix3d.RotationY(-(270 - (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)); //galacticMatrix.Transpose(); //galacticMatrix.Invert(); firstTimeInit = true; } Space = true; RenderTriangle.CullInside = true; Matrix3d WorldMatrix = Matrix3d.Identity; if (Settings.Active.GalacticMode) { WorldMatrix.Multiply(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); viewPoint = Coordinates.RADecTo3dAu(gPoint[0] / 15, gPoint[1], 1.0); TargetCamera.Lng = this.RAtoViewLng(gPoint[0] / 15); TargetCamera.Lat = gPoint[1]; ViewCamera.Lat = TargetCamera.Lat; ViewCamera.Lng = TargetCamera.Lng; } else { WorldMatrix.Multiply(Matrix3d.RotationY(-((ViewCamera.Lng - 90)) / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.RotationX(-((ViewCamera.Lat)) / 180.0 * Math.PI)); viewPoint = Coordinates.RADecTo3dAu(RA, Dec, 1.0); } double camLocal = ((ViewCamera.Rotation /*+ 90*/)); fovAngle = ((this.ViewCamera.Zoom) / FOVMULT) / Math.PI * 180; fovScale = (fovAngle / canvasHeight) * 3600; //Settings.Global.LocalHorizonMode = true; // altaz if (Settings.Active.LocalHorizonMode && backgroundImageset.DataSetType == ImageSetType.Sky) { Coordinates zenithAltAz = new Coordinates(0, 0); zenithAltAz.Az = 0; zenithAltAz.Alt = 0; Coordinates zenith = Coordinates.HorizonToEquitorial(zenithAltAz, SpaceTimeController.Location, SpaceTimeController.Now); //Coordinates zenith2 = Coordinates.HorizonToEquitorial(zenithAltAz, Coordinates.FromLatLng(1, 1), SpaceTimeController.Now); //Coordinates zenith3 = Coordinates.HorizonToEquitorial(zenithAltAz, Coordinates.FromLatLng(-1, 1), 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 - Math.PI); 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); ViewCamera.Lat = TargetCamera.Lat = currentRaDec.Dec; ViewCamera.Lng = TargetCamera.Lng = RAtoViewLng(currentRaDec.RA); } World = WorldMatrix; WorldBase = WorldMatrix.Clone(); // altaz double localZoomFactor = ViewCamera.Zoom; double FovAngle = ((localZoomFactor) / FOVMULT) / Math.PI * 180; CameraPosition = Vector3d.Create(0.0, 0.0, 0.0); // This is for distance Calculation. For space everything is the same distance, so camera target is key. View = Matrix3d.LookAtLH(CameraPosition, Vector3d.Create(0.0, 0.0, -1.0), Vector3d.Create(Math.Sin(camLocal), Math.Cos(camLocal), 0.0)); ViewBase = View.Clone(); double m_nearPlane = .1; nearPlane = .1f; Projection = Matrix3d.PerspectiveFovLH((localZoomFactor) / FOVMULT, (double)canvasWidth / (double)canvasHeight, .1, -2.0); SetMatrixes(); MakeFrustum(); }
protected override bool PrepVertexBuffer(RenderContext renderContext, float opacity) { table.Lock(); if (lineList != null) { lineList.Clear(); } if (lineList2d != null) { lineList2d.Clear(); } if (triangleList != null) { triangleList.Clear(); } if (pointList != null) { pointList.Clear(); } if (triangleList2d != null) { triangleList2d.Clear(); } if (lineList == null) { lineList = new LineList(); } if (pointList == null) { pointList = new PointList(renderContext); } lineList.TimeSeries = this.timeSeries; if (lineList2d == null) { lineList2d = new LineList(); lineList2d.DepthBuffered = false; } lineList.TimeSeries = this.timeSeries; if (triangleList == null) { triangleList = new TriangleList(); } if (triangleList2d == null) { triangleList2d = new TriangleList(); triangleList2d.DepthBuffered = false; } positions.Clear(); UInt32 currentIndex = 0; // device.RenderState.FillMode = FillMode.WireFrame; Color colorLocal = Color; // colorLocal.A = (byte)(Color.A * Opacity); // for space 3d double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI; Dictionary <string, bool> selectDomain = new Dictionary <string, bool>(); double mr = 0; // double mr = LayerManager.AllMaps[ReferenceFrame].Frame.MeanRadius; if (mr != 0) { meanRadius = mr; } Vector3d position = new Vector3d(); float pointSize = .0002f; Color pointColor = Colors.White; float pointStartTime = 0; float pointEndTime = 0; foreach (string[] row in table.Rows) { try { bool selected = false; if (geometryColumn > -1 || (this.CoordinatesType == CoordinatesTypes.Spherical && (lngColumn > -1 && latColumn > -1)) || ((this.CoordinatesType == CoordinatesTypes.Rectangular) && (XAxisColumn > -1 && YAxisColumn > -1))) { double Xcoord = 0; double Ycoord = 0; double Zcoord = 0; double alt = 1; double altitude = 0; double distParces = 0; double factor = GetScaleFactor(AltUnit, 1); if (altColumn == -1 || AltType == AltTypes.SeaLevel || bufferIsFlat) { alt = 1; if (astronomical & !bufferIsFlat) { alt = UiTools.AuPerLightYear * 100; } } else { if (AltType == AltTypes.Depth) { factor = -factor; } alt = 0; try { alt = double.Parse(row[altColumn]); } catch { } if (astronomical) { factor = factor / (1000 * UiTools.KilometersPerAu); distParces = (alt * factor) / UiTools.AuPerParsec; altitude = (factor * alt); alt = (factor * alt); } else if (AltType == AltTypes.Distance) { altitude = (factor * alt); alt = (factor * alt / meanRadius); } else { altitude = (factor * alt); alt = 1 + (factor * alt / meanRadius); } } //todo remove hack when alt is fixed //alt = 1; if (CoordinatesType == CoordinatesTypes.Spherical && lngColumn > -1 && latColumn > -1) { //Xcoord = Coordinates.Parse(row[lngColumn]); //Ycoord = Coordinates.Parse(row[latColumn]); Xcoord = double.Parse(row[lngColumn]); Ycoord = double.Parse(row[latColumn]); if (astronomical) { if (RaUnits == RAUnits.Hours) { Xcoord *= 015; } if (bufferIsFlat) { // Xcoord += 180; } } double offset = 0; //todo EGM96Geoid.Height(Ycoord, Xcoord); // if (altitude != 0) { //altitude += offset; //alt += offset / meanRadius; } Vector3d pos = Coordinates.GeoTo3dDoubleRad(Ycoord, Xcoord, alt); if (astronomical && !bufferIsFlat) { pos.RotateX(ecliptic); } position = pos; positions.Add(position); } else if (this.CoordinatesType == CoordinatesTypes.Rectangular) { double xyzScale = GetScaleFactor(CartesianScale, CartesianCustomScale) / meanRadius; if (ZAxisColumn > -1) { Zcoord = double.Parse(row[ZAxisColumn]); } Xcoord = double.Parse(row[XAxisColumn]); Ycoord = double.Parse(row[YAxisColumn]); if (XAxisReverse) { Xcoord = -Xcoord; } if (YAxisReverse) { Ycoord = -Ycoord; } if (ZAxisReverse) { Zcoord = -Zcoord; } position = Vector3d.Create((Xcoord * xyzScale), (Zcoord * xyzScale), (Ycoord * xyzScale)); positions.Add(position); } // SqlGeometry pntGeo = SqlGeometry.Point(Xcoord,Ycoord, 4326); //// SqlGeometry pntGeo = SqlGeometry.Point(new SqlChars(String.Format("Point ({0} {1})", Xcoord,Ycoord).ToCharArray()), 4326); // if (!geo.STContains(pntGeo)) // { // continue; // } switch (ColorMap) { case ColorMaps.Same_For_All: pointColor = colorLocal; break; case ColorMaps.Per_Column_Literal: if (ColorMapColumn > -1) { pointColor = ParseColor(row[ColorMapColumn], colorLocal); } else { pointColor = colorLocal; } break; //case ColorMaps.Group_by_Range: // break; //case ColorMaps.Gradients_by_Range: // break; //case ColorMaps.Group_by_Values: // pointColor = ColorDomainValues[row[ColorMapColumn]].MarkerIndex; // break; default: break; } if (sizeColumn > -1) { switch (pointScaleType) { case PointScaleTypes.Linear: pointSize = Single.Parse(row[sizeColumn]); break; case PointScaleTypes.Log: pointSize = (float)Math.Log(Single.Parse(row[sizeColumn])); break; case PointScaleTypes.Power: { double size = 0; try { pointSize = (float)double.Parse(row[altColumn]); } catch { pointSize = 0; } } break; case PointScaleTypes.StellarMagnitude: { double size = 0; try { size = double.Parse(row[sizeColumn]); if (!bufferIsFlat) { size = size - 5 * ((Util.LogN(distParces, 10) - 1)); pointSize = (float)(120000000 / Math.Pow(1.6, size)); } else { pointSize = (float)(40 / Math.Pow(1.6, size)); } } catch { pointSize = 0; } } break; case PointScaleTypes.Constant: pointSize = 1; break; default: break; } } else { pointSize = (float)1; } if (PlotType == PlotTypes.Point) { pointSize = (float)1; } if (astronomical & !bufferIsFlat) { // lastItem.PointSize *= 1000000000000000000000000000f; } if (startDateColumn > -1) { Date dateTime = new Date(row[startDateColumn]); pointStartTime = (float)(SpaceTimeController.UtcToJulian(dateTime) - SpaceTimeController.UtcToJulian(baseDate)); if (endDateColumn > -1) { dateTime = new Date(row[endDateColumn]); //dateTime = DateTime.Parse(row[endDateColumn]); pointEndTime = (float)(SpaceTimeController.UtcToJulian(dateTime) - SpaceTimeController.UtcToJulian(baseDate)); } else { pointEndTime = pointStartTime; } } pointList.AddPoint(position, pointColor, new Dates(pointStartTime, pointEndTime), pointSize); if (geometryColumn > -1) { ParseGeometry(row[geometryColumn], pointColor, pointColor, altitude, new Dates(pointStartTime, pointEndTime)); } //if (barChartBitmask != 0) //{ // MakeBarChart(device, row, Ycoord, Xcoord, pointSize, factor, Color.FromArgb(lastItem.Color), selected, new Dates(pointStartTime, pointEndTime)); //} currentIndex++; } } catch { } lines = false; } table.Unlock(); dataDirty = false; dirty = false; return(false); }
// This version of DrawEllipse works without a 'head' point public static void DrawEllipse(RenderContext renderContext, double semiMajorAxis, double eccentricity, double eccentricAnomaly, Color color, Matrix3d worldMatrix) { if (ellipseShader == null) { ellipseShader = new EllipseShader(); } if (ellipseWithoutStartPointVertexBuffer == null) { ellipseWithoutStartPointVertexBuffer = CreateEllipseVertexBufferWithoutStartPoint(360); } Matrix3d savedWorld = renderContext.World; renderContext.World = worldMatrix; renderContext.gl.bindBuffer(GL.ARRAY_BUFFER, ellipseWithoutStartPointVertexBuffer.VertexBuffer); renderContext.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null); EllipseShader.Use(renderContext, (float)semiMajorAxis, (float)eccentricity, (float)eccentricAnomaly, color, 1.0f, savedWorld, Vector3d.Create(0.0, 0.0, 0.0)); renderContext.gl.drawArrays(GL.LINE_STRIP, 0, ellipseWithoutStartPointVertexBuffer.Count - 1); renderContext.World = savedWorld; }
static public Vector3d RADecTo3dPointRad(Coordinates point, double radius) { point.Dec = -point.Dec; return(Vector3d.Create((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))); }
static public Vector3d RADecTo3dMat(double ra, double dec, Matrix3d mat) { return(Vector3d.TransformCoordinate(Vector3d.Create((Math.Cos(ra * RCRA) * Math.Cos(dec * RC) * radius), (Math.Sin(dec * RC) * radius), (Math.Sin(ra * RCRA) * Math.Cos(dec * RC) * radius)), mat)); }
static public Vector3d RADecTo3dAu(double ra, double dec, double au) { return(Vector3d.Create((Math.Cos(ra * RCRA) * Math.Cos(dec * RC) * au), (Math.Sin(dec * RC) * au), (Math.Sin(ra * RCRA) * Math.Cos(dec * RC) * au))); }
internal static void Draw(RenderContext renderContext, float opacity, bool astronomical, string referenceFrame, bool nested, bool cosmos) { if (!AllMaps.ContainsKey(referenceFrame)) { return; } LayerMap thisMap = AllMaps[referenceFrame]; if (!thisMap.Enabled || (thisMap.ChildMaps.Count == 0 && thisMap.Layers.Count == 0 && !(thisMap.Frame.ShowAsPoint || thisMap.Frame.ShowOrbitPath))) { return; } if (TourPlayer.Playing) { TourPlayer player = (TourPlayer)WWTControl.Singleton.uiController; if (player != null) { TourDocument tour = player.Tour; if (tour.CurrentTourStop != null) { player.UpdateTweenPosition(-1); tour.CurrentTourStop.UpdateLayerOpacity(); foreach (Guid key in tour.CurrentTourStop.Layers.Keys) { LayerInfo info = tour.CurrentTourStop.Layers[key]; if (LayerList.ContainsKey(info.ID)) { LayerList[info.ID].Opacity = info.FrameOpacity; LayerList[info.ID].SetParams(info.FrameParams); } } } } } Matrix3d matOld = renderContext.World; Matrix3d matOldNonRotating = renderContext.WorldBaseNonRotating; double oldNominalRadius = renderContext.NominalRadius; if (thisMap.Frame.Reference == ReferenceFrames.Custom) { thisMap.ComputeFrame(renderContext); if (thisMap.Frame.ReferenceFrameType != ReferenceFrameTypes.Orbital && thisMap.Frame.ReferenceFrameType != ReferenceFrameTypes.Trajectory) //if (true) { renderContext.World = Matrix3d.MultiplyMatrix(thisMap.Frame.WorldMatrix, renderContext.World); } else { renderContext.World = Matrix3d.MultiplyMatrix(thisMap.Frame.WorldMatrix, renderContext.WorldBaseNonRotating); } renderContext.NominalRadius = thisMap.Frame.MeanRadius; } if (thisMap.Frame.ShowAsPoint) { // todo Draw point planet... // Planets.DrawPointPlanet(renderContext.Device, new Vector3d(0, 0, 0), (float).2, thisMap.Frame.RepresentativeColor, true); } for (int pass = 0; pass < 2; pass++) { foreach (Layer layer in AllMaps[referenceFrame].Layers) { if ((pass == 0 && layer is ImageSetLayer) || (pass == 1 && !(layer is ImageSetLayer))) { if (layer.Enabled) // && astronomical == layer.Astronomical) { double layerStart = SpaceTimeController.UtcToJulian(layer.StartTime); double layerEnd = SpaceTimeController.UtcToJulian(layer.EndTime); double fadeIn = SpaceTimeController.UtcToJulian(layer.StartTime) - ((layer.FadeType == FadeType.FadeIn || layer.FadeType == FadeType.Both) ? (layer.FadeSpan / 864000000) : 0); double fadeOut = SpaceTimeController.UtcToJulian(layer.EndTime) + ((layer.FadeType == FadeType.FadeOut || layer.FadeType == FadeType.Both) ? (layer.FadeSpan / 864000000) : 0); if (SpaceTimeController.JNow > fadeIn && SpaceTimeController.JNow < fadeOut) { float fadeOpacity = 1; if (SpaceTimeController.JNow < layerStart) { fadeOpacity = (float)((SpaceTimeController.JNow - fadeIn) / (layer.FadeSpan / 864000000)); } if (SpaceTimeController.JNow > layerEnd) { fadeOpacity = (float)((fadeOut - SpaceTimeController.JNow) / (layer.FadeSpan / 864000000)); } layer.Astronomical = astronomical; //if (thisMap.Frame.Reference == ReferenceFrames.Sky) //{ // layer.Astronomical = true; //} if (layer is SpreadSheetLayer) { SpreadSheetLayer tsl = layer as SpreadSheetLayer; tsl.Draw(renderContext, opacity * fadeOpacity, cosmos); } else { layer.Draw(renderContext, opacity * fadeOpacity, cosmos); } } } } } } if (nested) { foreach (string key in AllMaps[referenceFrame].ChildMaps.Keys) { LayerMap map = AllMaps[referenceFrame].ChildMaps[key]; if (map.Frame.ShowOrbitPath && Settings.Active.SolarSystemOrbits) { if (map.Frame.ReferenceFrameType == ReferenceFrameTypes.Orbital) { if (map.Frame.Orbit == null) { map.Frame.Orbit = new Orbit(map.Frame.Elements, 360, map.Frame.RepresentativeColor, 1, (float)renderContext.NominalRadius); } Matrix3d matSaved = renderContext.World; renderContext.World = Matrix3d.MultiplyMatrix(thisMap.Frame.WorldMatrix, renderContext.WorldBaseNonRotating); map.Frame.Orbit.Draw3D(renderContext, 1f * .25f, Vector3d.Create(0, 0, 0)); renderContext.World = matSaved; } else if (map.Frame.ReferenceFrameType == ReferenceFrameTypes.Trajectory) { //todo add trajectories back //if (map.Frame.trajectoryLines == null) //{ // map.Frame.trajectoryLines = new LineList(renderContext.Device); // map.Frame.trajectoryLines.ShowFarSide = true; // map.Frame.trajectoryLines.UseNonRotatingFrame = true; // int count = map.Frame.Trajectory.Count - 1; // for (int i = 0; i < count; i++) // { // Vector3d pos1 = map.Frame.Trajectory[i].Position; // Vector3d pos2 = map.Frame.Trajectory[i + 1].Position; // pos1.Multiply(1 / renderContext.NominalRadius); // pos2.Multiply(1 / renderContext.NominalRadius); // map.Frame.trajectoryLines.AddLine(pos1, pos2, map.Frame.RepresentativeColor, new Dates()); // } //} //Matrix3D matSaved = renderContext.World; //renderContext.World = thisMap.Frame.WorldMatrix * renderContext.WorldBaseNonRotating; //map.Frame.trajectoryLines.DrawLines(renderContext, Earth3d.MainWindow.showMinorOrbits.Opacity * .25f); //renderContext.World = matSaved; } } if ((map.Frame.Reference == ReferenceFrames.Custom || map.Frame.Reference == ReferenceFrames.Identity)) { Draw(renderContext, opacity, astronomical, map.Name, nested, cosmos); } } } renderContext.NominalRadius = oldNominalRadius; renderContext.World = matOld; renderContext.WorldBaseNonRotating = matOldNonRotating; }
//private Vector3d GetTragectoryPoint(double jNow, out Vector3d vector) //{ //int min = 0; //int max = Trajectory.Count - 1; //Vector3d point = new Vector3d(); //vector = new Vector3d(); //int current = max / 2; //bool found = false; //while (!found) //{ // if (current < 1) // { // vector = Trajectory[0].Position - Trajectory[1].Position; // return Trajectory[0].Position; // } // if (current == Trajectory.Count - 1) // { // vector = Trajectory[current - 1].Position - Trajectory[current].Position; // return Trajectory[current].Position; // } // if ((Trajectory[current-1].Time <= jNow) && (Trajectory[current].Time > jNow)) // { // double denominator = Trajectory[current].Time -Trajectory[current-1].Time; // double numerator = jNow - Trajectory[current - 1].Time; // double tween = numerator / denominator; // vector = Trajectory[current - 1].Position - Trajectory[current].Position; // point = Vector3d.Lerp(Trajectory[current - 1].Position, Trajectory[current].Position, tween); // return point; // } // if (Trajectory[current].Time < jNow) // { // int next = current + ( max - current + 1) / 2; // min = current; // current = next; // } // else // if (Trajectory[current - 1].Time > jNow) // { // int next = current - ( current - min + 1) / 2; // max = current; // current = next; // } //} //return point; //} private void ComputeOrbital(RenderContext renderContext) { EOE ee = Elements; Vector3d point = ELL.CalculateRectangularJD(SpaceTimeController.JNow, ee); MeanAnomoly = ee.meanAnnomolyOut; Vector3d pointInstantLater = ELL.CalculateRectangular(ee, MeanAnomoly + .001); Vector3d direction = Vector3d.SubtractVectors(point, pointInstantLater); Vector3d up = point.Copy(); 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(Vector3d.Create(0, 0, 0), direction, up); look.Invert(); WorldMatrix = Matrix3d.Identity; WorldMatrix.Translate(Translation); double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius; WorldMatrix.Scale(Vector3d.Create(localScale, localScale, localScale)); //Matrix3d mat = Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(Matrix3d.RotationY(Heading / 180.0 * Math.PI), Matrix3d.RotationX(Pitch / 180.0 * Math.PI)),Matrix3d.RotationZ(Roll / 180.0 * Math.PI)); WorldMatrix.Multiply(Matrix3d.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 = Matrix3d.MultiplyMatrix(look, WorldMatrix); } }