// 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; }
public ToastTools(ToastTools parent, int level, int x, int y) { Parent = parent; X = x; Y = y; Level = level; InitializeGrids(); TopLeft = new Vector3d(Vector3d.Scale(bounds[0, 0].Position, 1)); BottomRight = new Vector3d(Vector3d.Scale(bounds[2, 2].Position, 1)); TopRight = new Vector3d(Vector3d.Scale(bounds[2, 0].Position, 1)); BottomLeft = new Vector3d(Vector3d.Scale(bounds[0, 2].Position, 1)); }
public CameraParameters(double lat, double lng, double zoom, double rotation, double angle, float opactity) { Lat = lat; Lng = lng; Zoom = zoom; Rotation = rotation; Angle = angle; RaDec = false; Opacity = opactity; ViewTarget = new Vector3d(0, 0, 0); Target = SolarSystemObjects.Custom; TargetReferenceFrame = ""; DomeAlt = 0; DomeAz = 0; }
public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread) { if (texture == null) { if (this.texture == null) { if (TextureReady) { texture = BufferPool11.GetTexture(FileName); double aspect = (double)texture.Width / (double)texture.Height; if (aspect < 1.5) { domeMaster = true; } } else { return false; } } iTileBuildCount++; if (vertexBuffer == null) { vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), VertexCount, RenderContext11.PrepDevice); indexBuffer = new IndexBuffer11[4]; OnCreateVertexBuffer(vertexBuffer); sphereRadius = 1; sphereCenter = new Vector3d(0, 0, 0); } } ReadyToRender = true; return true; }
public static void QueueThread() { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false); bool fileOnly = fileOnlyThreadID == Thread.CurrentThread.ManagedThreadId; while (running) { if (queue.Count < 1) { System.Threading.Thread.Sleep(50); } else { System.Threading.Thread.Sleep(1); } double minDistance = 1000000000000000000; bool overlayTile = false; long maxKey = 0; int level = 1000; queueMutex.WaitOne(); foreach (Tile t in queue.Values ) { if (!t.RequestPending ) // && t.InViewFrustum) { Vector3d vectTemp = new Vector3d(t.SphereCenter); vectTemp.TransformCoordinate(Earth3d.WorldMatrix); if (Earth3d.MainWindow.Space) { vectTemp.Subtract(new Vector3d(0.0f, 0.0f, -1.0f)); } else { vectTemp.Subtract(Earth3d.MainWindow.RenderContext11.CameraPosition); } double distTemp = Math.Max(0,vectTemp.Length()-t.SphereRadius); bool thisIsOverlay = (t.Dataset.Projection == ProjectionType.Tangent) || (t.Dataset.Projection == ProjectionType.SkyImage); if (distTemp < minDistance && (!overlayTile || thisIsOverlay)) { Tile test = (Tile)queue[t.Key]; if (!test.FileChecked) { test.FileExists = File.Exists(test.FileName); test.FileChecked = true; if (test.Volitile) { test.FileExists = false; } } if (test.FileExists || (!test.FileExists && !fileOnly)) { minDistance = distTemp; maxKey = t.Key; level = t.Level; overlayTile = thisIsOverlay; } } } } if (maxKey != 0) { Tile workTile = (Tile)queue[maxKey]; workTile.RequestPending = true; TileCache.RequestCount++; queueMutex.ReleaseMutex(); TileCache.GetTileFromWeb(workTile, true); queueMutex.WaitOne(); TileCache.RequestCount--; workTile.RequestPending = false; queue.Remove(workTile.Key); } queueMutex.ReleaseMutex(); } return; }
public override bool PreCreateGeometry(RenderContext11 renderContext) { if (Properties.Settings.Default.Show3dCities) { // Conditionalsupport for 3d Cities based on settings dsm = new DSMTile(); var center = new Vector3d(); double radius = 0; if (dsm != null) { texture = dsm.LoadMeshFile(filename, localCenter, out center, out radius); } if (texture != null) { sphereCenter = center; sphereRadius = radius; return true; } } return false; }
public Text3d(Vector3d center, Vector3d up, string text, float fontsize, double scale) { Text = text; this.up = up; this.center = center; this.scale = scale; if (fontsize < 0) { sky = false; } }
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); }
private bool InsideTriangle(Vector3d pntA, Vector3d pntB, Vector3d pntC, Vector3d pntTest) { if (!IsLeftOfHalfSpace(pntA, pntB, pntTest)) { return false; } if (!IsLeftOfHalfSpace(pntB, pntC, pntTest)) { return false; } if (!IsLeftOfHalfSpace(pntC, pntA, pntTest)) { return false; } return true; }
private void FindCurrentObject() { var loc = Earth3d.MainWindow.RenderWindow.PointToClient(PointToScreen(new Point(300, 88))); IPlace closetPlace = null; var result = new Coordinates(0,0); if (Earth3d.MainWindow.SolarSystemMode) { var pt = loc; Vector3d PickRayOrig; Vector3d PickRayDir; var rect = Earth3d.MainWindow.RenderWindow.ClientRectangle; Earth3d.MainWindow.TransformStarPickPointToWorldSpace(pt, rect.Width, rect.Height, out PickRayOrig, out PickRayDir); var temp = new Vector3d(PickRayOrig); temp.Subtract(Earth3d.MainWindow.viewCamera.ViewTarget); //closetPlace = Grids.FindClosestObject(temp , new Vector3d(PickRayDir)); CallFindClosestObject(temp, new Vector3d(PickRayDir)); } else { // TODO fix this for earth, plantes, panoramas result = Earth3d.MainWindow.GetCoordinatesForScreenPoint(loc.X, loc.Y); var constellation = Earth3d.MainWindow.ConstellationCheck.FindConstellationForPoint(result.RA, result.Dec); //Place[] resultList = ContextSearch.FindClosestMatches(constellation, result.RA, result.Dec, ZoomFactor / 600, 5); closetPlace = ContextSearch.FindClosestMatch(constellation, result.RA, result.Dec, Earth3d.MainWindow.DegreesPerPixel * 80); if (closetPlace == null) { // closetPlace = Grids.FindClosestMatch(constellation, result.RA, result.Dec, Earth3d.MainWindow.DegreesPerPixel * 80); CallFindClosestMatch(constellation, result.RA, result.Dec, Earth3d.MainWindow.DegreesPerPixel * 80); noPlaceDefault = new TourPlace(Language.GetLocalizedText(90, "No Object"), result.Dec, result.RA, Classification.Unidentified, constellation, ImageSetType.Sky, -1); //Earth3d.MainWindow.SetLabelText(null, false); return; } Earth3d.MainWindow.SetLabelText(closetPlace, false); Target = closetPlace; } }
private void CallFindClosestObject(Vector3d orig, Vector3d ray) { if (invokeFindClosestObject == null) { invokeFindClosestObject = Grids.FindClosestObject; } invokeFindClosestObject.BeginInvoke(orig, ray, CallBack, null); }
protected void ComputeBoundingSphere(Tile parent, double altitude) { InitializeGrids(); var pointList = BufferPool11.GetVector3dBuffer(vertexList.Count); var scaleFactor = (1 + (altitude / DemScaleFactor)); if (DemEnabled) { for (var i = 0; i < vertexList.Count; i++) { pointList[i] = Vector3d.Scale(vertexList[i].Position, scaleFactor); } } else { for (var i = 0; i < vertexList.Count; i++) { pointList[i] = vertexList[i].Position; } } TopLeft = new Vector3d(Vector3d.Scale(bounds[0, 0].Position, scaleFactor)); BottomRight = new Vector3d(Vector3d.Scale(bounds[2, 2].Position, scaleFactor)); TopRight = new Vector3d(Vector3d.Scale(bounds[2, 0].Position, scaleFactor)); BottomLeft = new Vector3d(Vector3d.Scale(bounds[0, 2].Position, scaleFactor)); CalcSphere(pointList); BufferPool11.ReturnVector3dBuffer(pointList); if (Level == 5 || Level == 12) { localCenter = sphereCenter; localCenter.Round(); } else if (Level > 5) { localCenter = parent.localCenter; } ReturnBuffers(); }
protected void CalcSphere(Vector3d[] list) { ConvexHull.FindEnclosingSphere(list, out sphereCenter, out sphereRadius); }
public static double LineToPoint(Vector3d l0, Vector3d l1, Vector3d p) { var v = l1 - l0; var w = p - l0; var dist = Vector3d.Cross(w, v).Length() / v.Length(); return dist; }
public static Vector2d GetUVFromInnerPoint(Vector3d ul, Vector3d ur, Vector3d ll, Vector3d lr, Vector3d pnt) { ul.Normalize(); ur.Normalize(); ll.Normalize(); lr.Normalize(); pnt.Normalize(); var dUpper = LineToPoint(ul, ur, pnt); var dLower = LineToPoint(ll, lr, pnt); var dVert = dUpper + dLower; var dRight = LineToPoint(ur, lr, pnt); var dLeft = LineToPoint(ul, ll, pnt); var dHoriz = dRight + dLeft; return new Vector2d( dLeft/dHoriz, dUpper/dVert); }
private void Export_Click(object sender, EventArgs e) { var filename = ""; var saveDialog = new SaveFileDialog(); saveDialog.Filter = "Standard Tessellation Language" + "|*.stl"; saveDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); saveDialog.AddExtension = true; saveDialog.DefaultExt = ".stl"; if (saveDialog.ShowDialog() == DialogResult.OK) { filename = saveDialog.FileName; if (string.IsNullOrEmpty(filename)) { return; } } else { return; } ProgressPopup.Show(this, "Export STL File", "Scanning Elevation Map"); var baseOffset = double.Parse(baseHeight.Text); density = int.Parse(Density.Text); var xRate = Rect.West - Rect.East; var yRate = Rect.North - Rect.South; var latCenter = (Rect.North + Rect.South) / 2; var ratio = Math.Cos(latCenter / 180 * Math.PI); double sizeY = 100; var sizeX = Math.Abs(((xRate * ratio) / yRate) * sizeY); var stepsX = (int)(sizeX * density / 10); var stepsY = (int)(sizeY * density / 10); //Computer relative altitude to latitude scaling for this planet. var radius = Earth3d.MainWindow.RenderContext11.NominalRadius; var altScaleFactor = ((radius * Math.PI * 2) / 360) * (yRate/sizeY); altScaleFactor = 1 / altScaleFactor; xRate /= stepsX; yRate /= stepsY; var points = new Vector3d[stepsX, stepsY]; var altitude = new double[stepsX, stepsY]; double maxAltitude = -10000000; double minAltitude = 100000000; var altScale = double.Parse(AltitudeScale.Text) / 100; var estimatedTotal = stepsX * stepsY; var actualTotal = 0; for (var y = 0; y < stepsY; y++) { for (var x = 0; x < stepsX; x++) { var lat = Rect.North - (yRate * y); var lng = Rect.East + (xRate * x); var alt = Earth3d.MainWindow.GetAltitudeForLatLongNow(lat, lng); altitude[x, y] = alt; maxAltitude = Math.Max(alt, maxAltitude); minAltitude = Math.Min(minAltitude, alt); actualTotal++; } if (!ProgressPopup.SetProgress(((actualTotal * 100) / estimatedTotal), "Scanning Elevation Map")) { ProgressPopup.Done(); return; } } var altRange = maxAltitude - minAltitude; // old altScaleFactor = (10 / altRange) * altScale; altScaleFactor *= altScale; var stepScaleX = sizeX / stepsX; var stepScaleY = sizeY / stepsY; // make the verticies for (var y = 0; y < stepsY; y++) { for (var x = 0; x < stepsX; x++) { altitude[x, y] = ((altitude[x, y] - minAltitude) * altScaleFactor) + baseOffset; points[x, y] = new Vector3d(x * stepScaleX, y * stepScaleY, altitude[x, y]); } } ProgressPopup.SetProgress(0, "Writing File"); if (File.Exists(filename)) { File.Delete(filename); } var fs = File.OpenWrite(filename); var bw = new BinaryWriter(fs); // Write File Header bw.Write(new byte[80]); // x-1*y-1*2 var count = ((stepsX - 1) * (stepsY - 1) + (stepsY - 1) + (stepsY - 1) + (stepsX - 1) + (stepsX - 1) + (stepsX - 1) * (stepsY - 1)) * 2; // Write Triangle Count bw.Write(count); // Loop thru and create triangles for all quads.. var writeCount = 0; for (var y = 0; y < stepsY - 1; y++) { for (var x = 0; x < stepsX - 1; x++) { // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 1 WriteVertex(bw, points[x, y]); WriteVertex(bw, points[x + 1, y]); WriteVertex(bw, points[x + 1, y + 1]); bw.Write((UInt16)(0)); writeCount++; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 2 WriteVertex(bw, points[x, y]); WriteVertex(bw, points[x + 1, y + 1]); WriteVertex(bw, points[x, y + 1]); bw.Write((UInt16)(0)); writeCount++; } } ProgressPopup.SetProgress(35, "Writing File"); var pnt = new Vector3d(); // Make side Skirts for (var y = 0; y < stepsY - 1; y++) { var x = 0; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 1 WriteVertex(bw, points[x, y]); WriteVertex(bw, points[x, y + 1]); pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 2 WriteVertex(bw, points[x, y + 1]); pnt = points[x, y + 1]; pnt.Z = 0; WriteVertex(bw, pnt); pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; } ProgressPopup.SetProgress(45, "Writing File"); for (var y = 0; y < stepsY - 1; y++) { var x = stepsX - 1; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 1 WriteVertex(bw, points[x, y + 1]); WriteVertex(bw, points[x, y]); pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 2 pnt = points[x, y + 1]; pnt.Z = 0; WriteVertex(bw, pnt); WriteVertex(bw, points[x, y + 1]); pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; } ProgressPopup.SetProgress(50, "Writing File"); for (var x = 0; x < stepsX - 1; x++) { var y = 0; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 1 WriteVertex(bw, points[x+ 1, y ]); WriteVertex(bw, points[x, y]); pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 2 pnt = points[x+ 1, y ]; pnt.Z = 0; WriteVertex(bw, pnt); WriteVertex(bw, points[x + 1, y]); pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; } ProgressPopup.SetProgress(55, "Writing File"); for (var x = 0; x < stepsX - 1; x++) { var y = stepsY - 1; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 1 WriteVertex(bw, points[x, y]); WriteVertex(bw, points[x + 1, y]); pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 2 WriteVertex(bw, points[x + 1, y]); pnt = points[x + 1, y]; pnt.Z = 0; WriteVertex(bw, pnt); pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; } ProgressPopup.SetProgress(65, "Writing File"); ProgressPopup.SetProgress(75, "Writing File"); for (var y = 0; y < stepsY - 1; y++) { for (var x = 0; x < stepsX - 1; x++) { // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 1 pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); pnt = points[x + 1, y + 1]; pnt.Z = 0; WriteVertex(bw, pnt); pnt = points[x + 1, y]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; // Write dummy Normal bw.Write(0f); bw.Write(0f); bw.Write(0f); // Vertexes - triangle 2 pnt = points[x, y]; pnt.Z = 0; WriteVertex(bw, pnt); pnt = points[x, y + 1]; pnt.Z = 0; WriteVertex(bw, pnt); pnt = points[x + 1, y + 1]; pnt.Z = 0; WriteVertex(bw, pnt); bw.Write((UInt16)(0)); writeCount++; } } // Make Bottom bw.Close(); ProgressPopup.Done(); }
public static Vector3d MakePosition(float centerX, float centerY, float offsetX, float offsetY, float angle) { Vector3d point = new Vector3d(centerX + offsetX, centerY + offsetY, 1); return point; }
private static bool IsSphereInFrustum(Vector3d sphereCenter, double sphereRadius, PlaneD[] frustum) { Vector4d center4 = new Vector4d(sphereCenter.X, sphereCenter.Y, sphereCenter.Z, 1.0); for (int i = 0; i < 6; i++) { if (frustum[i].Dot(center4) < -sphereRadius) { return false; } } return true; }
private bool IsLeftOfHalfSpace(Vector3d pntA, Vector3d pntB, Vector3d pntTest) { pntA.Normalize(); pntB.Normalize(); Vector3d cross = Vector3d.Cross(pntA, pntB); double dot = Vector3d.Dot(cross, pntTest); return dot > 0; }
// Get the radius in pixels of a sphere with the specified center and radius // The sphere center should be a point in camera space private static double ProjectedSizeInPixels(RenderContext11 renderContext, Vector3d center, double radius) { Matrix3d projection = renderContext.Projection; SharpDX.Direct3D11.Viewport viewport = renderContext.ViewPort; double distance = center.Length(); // Calculate pixelsPerUnit which is the number of pixels covered // by an object 1 AU at the distance of the planet center from // the camera. This calculation works regardless of the projection // type. double viewportHeight = viewport.Height; double p11 = projection.M11; double p34 = projection.M34; double p44 = projection.M44; double w = Math.Abs(p34) * distance + p44; double pixelsPerUnit = (p11 / w) * viewportHeight; return radius * pixelsPerUnit; }
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); }
protected void ComputeBoundingSphereBottomsUp(Tile parent) { var tileDegrees = dataset.BaseTileDegrees / Math.Pow(2, level); var latMin = (-90 + ((y + 1) * tileDegrees)); var latMax = (-90 + (y * tileDegrees)); var lngMin = ((x * tileDegrees) - 180.0); var lngMax = (((x + 1) * tileDegrees) - 180.0); var latCenter = (latMin + latMax) / 2.0; var lngCenter = (lngMin + lngMax) / 2.0; if (level == 12 || level == 19) { var temp = Coordinates.GeoTo3dDouble(latCenter, lngCenter); localCenter = new Vector3d(temp.X, temp.Y, temp.Z); } else if (level > 12) { localCenter = parent.localCenter; } sphereCenter = GeoTo3d(latCenter, lngCenter, false); TopLeft = GeoTo3dWithAltitude(latMin, lngMin, false); BottomRight = GeoTo3dWithAltitude(latMax, lngMax, false); TopRight = GeoTo3dWithAltitude(latMin, lngMax, false); BottomLeft = GeoTo3dWithAltitude(latMax, lngMin, false); var distVect = TopLeft; distVect.Subtract(sphereCenter); sphereRadius = distVect.Length(); tileDegrees = lngMax - lngMin; }
public void AddGlyphPoints(List<PositionTextured> pointList, SizeF size, RectangleF position, RectangleF uv) { PositionTextured[] points = new PositionTextured[6]; Vector3d ul = new Vector3d(position.Left+rect.Left, position.Top+rect.Top, .9f); Vector3d ur = new Vector3d(position.Right+rect.Left, position.Top+rect.Top, .9f); Vector3d ll = new Vector3d(position.Left+rect.Left, position.Bottom+rect.Top, .9f); Vector3d lr = new Vector3d(position.Right+rect.Left, position.Bottom+rect.Top, .9f); points[0].Position = ul; points[0].Tu = uv.Left; points[0].Tv = uv.Top; points[2].Tu = uv.Left; points[2].Tv = uv.Bottom; points[2].Position = ll; points[1].Tu = uv.Right; points[1].Tv = uv.Top; points[1].Position = ur; points[3].Tu = uv.Right; points[3].Tv = uv.Bottom; points[3].Position = lr; points[5].Tu = uv.Right; points[5].Tv = uv.Top; points[5].Position = ur; points[4].Tu = uv.Left; points[4].Tv = uv.Bottom; points[4].Position = ll; pointList.AddRange(points); }
private void InitializeRoute(RenderContext11 renderContext) { triangleList = new TriangleList(); triangleList.Decay = 1000; triangleList.Sky = this.Astronomical; triangleList.TimeSeries = true; triangleList.DepthBuffered = false; triangleList.AutoTime = false; int steps = 500; Vector3d start = Coordinates.GeoTo3dDouble(latStart, lngStart); Vector3d end = Coordinates.GeoTo3dDouble(latEnd, lngEnd); Vector3d dir = end - start; dir.Normalize(); Vector3d startNormal = start; startNormal.Normalize(); Vector3d left = Vector3d.Cross(startNormal, dir); Vector3d right = Vector3d.Cross(dir, startNormal); left.Normalize(); right.Normalize(); left.Multiply(.001*width); right.Multiply(.001 * width); Vector3d lastLeft = new Vector3d(); Vector3d lastRight = new Vector3d(); bool firstTime = true; for (int i = 0; i <= steps; i++) { Vector3d v = Vector3d.Lerp(start, end, i / (float)steps); v.Normalize(); Vector3d cl = v; Vector3d cr = v; cl.Add(left); cr.Add(right); if (!firstTime) { triangleList.AddQuad(lastRight, lastLeft, cr, cl, Color, new Dates(i / (float)steps, 2)); } else { firstTime = false; } lastLeft = cl; lastRight = cr; } }
private void AddSiapStcRow(string stcsColName, VoRow row, bool selected) { var stcs = row[stcsColName].ToString().Replace(" ", " "); var col = Color.FromArgb(120, 255, 255, 255); if (selected) { col = Color.Yellow; } if (stcs.StartsWith("Polygon J2000")) { var parts = stcs.Split(new[] { ' ' }); var len = parts.Length; var index = 0; while (index < len) { if (parts[index] == "Polygon") { index += 2; var lastPoint = new Vector3d(); var firstPoint = new Vector3d(); var start = true; for (var i = index; i < len; i += 2) { if (parts[i] == "Polygon") { start = true; break; } var Xcoord = Coordinates.ParseRA(parts[i], true) * 15 + 180; var Ycoord = Coordinates.ParseDec(parts[i + 1]); var pnt = Coordinates.GeoTo3dDouble(Ycoord, Xcoord); if (!start) { lineList2d.AddLine(lastPoint, pnt, col, new Dates()); } else { firstPoint = pnt; start = false; } lastPoint = pnt; index += 2; } if (len > 4) { lineList2d.AddLine(firstPoint, lastPoint, col, new Dates()); } } } } }
public SkyLabel(RenderContext11 renderContext, double ra, double dec, string text, LabelSytle style, double distance) { RA = ra; Dec = dec; Text = text; Style = style; Distance = distance; if (texture == null) { texture = Texture11.FromBitmap(Resources.circle, 0); } var up = new Vector3d(); var textPos = new Vector3d(); if (Earth3d.MainWindow.SolarSystemMode) { pos = Coordinates.RADecTo3d(ra, -dec, distance); up = Coordinates.RADecTo3d(ra, -dec + 90, distance); pos.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI); pos.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth)); up.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI); up.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth)); } else { pos = Coordinates.RADecTo3d(ra+12, dec, distance); textPos = Coordinates.RADecTo3d(ra + 12, dec + 2, distance); up = Coordinates.RADecTo3d(ra+12, dec + 92, distance); } center = new Vector3(9, 9, 0); textBatch = new Text3dBatch(24); if (style == LabelSytle.Telrad) { // Telrad-style labels are always screen-aligned var t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01); t3.alignment = Text3d.Alignment.Left; textBatch.Add(t3); } else { up.Normalize(); textPos.Normalize(); textBatch.Add(new Text3d(textPos, up, text, 20, .0005)); } }
protected void ComputeBoundingSphere(MercatorTile parent, double altitude) { var tileDegrees = 360 / (Math.Pow(2, level)); latMin = AbsoluteMetersToLatAtZoom(y * 256, level); latMax = AbsoluteMetersToLatAtZoom((y + 1) * 256, level); lngMin = ((x * tileDegrees) - 180.0); lngMax = (((x + 1) * tileDegrees) - 180.0); var latCenter = AbsoluteMetersToLatAtZoom(((y * 2) + 1) * 256, level + 1); var lngCenter = (lngMin + lngMax) / 2.0; if (level == 12 || level == 17 ) { localCenter = Coordinates.GeoTo3dDouble(latCenter, lngCenter); } else if (level > 12) { localCenter = parent.localCenter; } demIndex = 0; if (parent != null && parent.DemData != null) { sphereCenter = GeoTo3dWithAltitude(latCenter, lngCenter, parent.GetAltitudeAtLatLng(latCenter, lngCenter, 1), false); TopLeft = GeoTo3dWithAltitude(latMin, lngMin, parent.GetAltitudeAtLatLng(latMin, lngMin, 1), false); BottomRight = GeoTo3dWithAltitude(latMax, lngMax, parent.GetAltitudeAtLatLng(latMax, lngMax, 1), false); TopRight = GeoTo3dWithAltitude(latMin, lngMax, parent.GetAltitudeAtLatLng(latMin, lngMax, 1), false); BottomLeft = GeoTo3dWithAltitude(latMax, lngMin, parent.GetAltitudeAtLatLng(latMax, lngMin, 1), false); } else { sphereCenter = GeoTo3dWithAltitude(latCenter, lngCenter, altitude, false); TopLeft = GeoTo3dWithAltitude(latMin, lngMin, altitude, false); BottomRight = GeoTo3dWithAltitude(latMax, lngMax, altitude, false); TopRight = GeoTo3dWithAltitude(latMin, lngMax, altitude, false); BottomLeft = GeoTo3dWithAltitude(latMax, lngMin, altitude, false); } center = sphereCenter; if (Y == 0) { TopLeft = new Vector3d(0, 1, 0); TopRight = new Vector3d(0, 1, 0); } if (Y == Math.Pow(2, level) - 1) { BottomRight = new Vector3d(0, -1, 0); BottomLeft = new Vector3d(0, -1, 0); } var distVect1 = TopLeft; distVect1.Subtract(sphereCenter); var distVect2 = BottomRight; distVect2.Subtract(sphereCenter); var distVect3 = TopRight; distVect3.Subtract(sphereCenter); var distVect4 = BottomLeft; distVect4.Subtract(sphereCenter); sphereRadius = Math.Max(Math.Max(distVect1.Length(),distVect2.Length()),Math.Max(distVect3.Length(),distVect4.Length())); tileDegrees = lngMax - lngMin; // if (level > 14) { // this.sphereCenter.Add(localCenter); } }
public SkyLabel(RenderContext11 renderContext, Vector3d point, string text, LabelSytle style) { Text = text; Style = style; if (texture == null) { texture = Texture11.FromBitmap(Resources.circle, 0); } pos = point; center = new Vector3(9, 9, 0); textBatch = new Text3dBatch(80); if (style == LabelSytle.Telrad) { // Telrad-style labels are always screen-aligned var t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01); t3.alignment = Text3d.Alignment.Left; textBatch.Add(t3); } else { // This will produce sky or orbit aligned text textBatch.Add(new Text3d(pos, new Vector3d(0,1,0), text, 20, .01)); } }
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; } }
static void WriteVertex(BinaryWriter bw, Vector3d point) { bw.Write((float)point.X); bw.Write((float)point.Y); bw.Write((float)point.Z); }