public void AddLine(Vector3d v1, Vector3d v2) { linePoints.Add(v1); linePoints.Add(v2); EmptyLineBuffer(); }
public static Vector2d CartesianToLatLng(Vector3d vector) { double rho = Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z); double longitude = Math.Atan2(vector.Z, vector.X); double latitude = Math.Asin(vector.Y / rho); return Vector2d.Create(longitude * 180 / Math.PI, latitude * 180 / Math.PI); }
public static Coordinates CartesianToSpherical3(Vector3d vector) { double rho = Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z); double longitude = Math.Atan2(vector.Z, vector.X); double latitude = Math.Asin(vector.Y / rho); return new Coordinates(longitude, latitude); }
// ** Begin public void Draw3D(RenderContext renderContext, float opacity, Vector3d centerPoint) { // Device device = renderContext.Device; // double zoom = Earth3d.MainWindow.ZoomFactor; // double distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 15.5) * 90; // //double distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 14) * 30 + 24; // int alpha = Math.Min(255, Math.Max(0, (int)distAlpha)); // if (alpha > 254) // { // return; // } // if (orbitVertexBuffer == null) // { // KeplerShader.MakeVertexShader(device); // InitVertexBuffer(renderContext.Device); // return; // } // //device.DrawUserPrimitives(PrimitiveType.LineList, segments, points); // // Matrix savedWorld = device.Transform.World; // // Matrix offset = Matrix.Translation(-centerPoint.Vector3); // // device.Transform.World = device.Transform.World * offset; // Vector3 cam = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector3; // double M = elements.n * (SpaceTimeController.JNow - elements.T) * 0.01745329251994; // double F = 1; // if (M < 0) // { // F = -1; // } // M = Math.Abs(M) / (2 * Math.PI); // M = (M - (int)(M)) * 2 * Math.PI * F; // KeplerShader.UseShader(device, SpaceTimeController.JNow, cam, opacity, (float)M); // device.RenderState.PointSpriteEnable = true; // device.RenderState.PointScaleEnable = true; // device.RenderState.PointScaleA = 0; // device.RenderState.PointScaleB = 0; // device.RenderState.PointScaleC = 100f; // device.RenderState.ZBufferEnable = true; // device.RenderState.ZBufferWriteEnable = false; // device.SetTexture(0, null); // device.SetStreamSource(0, orbitVertexBuffer, 0); // device.VertexFormat = KeplerVertex.Format; // device.RenderState.CullMode = Cull.None; // device.RenderState.AlphaBlendEnable = true; // device.RenderState.SourceBlend = Microsoft.DirectX.Direct3D.Blend.SourceAlpha; // device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha; // //device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.One; // device.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha; // device.TextureState[0].ColorOperation = TextureOperation.Modulate; // device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; // device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse; // device.TextureState[0].AlphaOperation = TextureOperation.Modulate; // device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; // device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse; // device.TextureState[1].ColorOperation = TextureOperation.SelectArg1; // device.TextureState[1].ColorArgument1 = TextureArgument.Current; // device.TextureState[1].ColorArgument2 = TextureArgument.Constant; // device.TextureState[1].AlphaOperation = TextureOperation.Modulate; // device.TextureState[1].AlphaArgument1 = TextureArgument.Current; // device.TextureState[1].AlphaArgument2 = TextureArgument.Constant; // device.TextureState[2].ColorOperation = TextureOperation.Disable; // device.TextureState[2].AlphaOperation = TextureOperation.Disable; // device.TextureState[1].ConstantColor = Color.FromArgb(255 - alpha, 255 - alpha, 255 - alpha, 255 - alpha); // device.DrawPrimitives(PrimitiveType.LineStrip, 0, segmentCount - 1); // device.VertexShader = null; // device.RenderState.ZBufferWriteEnable = true; // device.RenderState.PointSpriteEnable = false; // device.RenderState.PointScaleEnable = false; // // device.Transform.World = savedWorld; }
public CameraParameters() { Zoom = 360; ViewTarget = new Vector3d(); }
public static void DrawPointPlanet(RenderContext renderContext, Vector3d location, double size, Color color, bool zOrder) { size = Math.Max(2, size); Vector3d center = (Vector3d)location; double rad = size/2; Vector3d screenSpacePnt = renderContext.WVP.Transform(center); if (screenSpacePnt.Z < 0) { return; } if (!zOrder) { if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, (Vector3d)center) < .55) { return; } } if (renderContext.gl != null) { //todo draw in WebGL } else { CanvasContext2D ctx = renderContext.Device; ctx.Save(); //ctx.Alpha = opacity; ctx.BeginPath(); ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true); ctx.LineWidth = 1; ctx.FillStyle = color.ToString(); if (true) { ctx.Fill(); } ctx.Alpha = 1.0; ctx.StrokeStyle = color.ToString(); ctx.Stroke(); ctx.Restore(); } //device.RenderState.Lighting = false; //StarVertex[] vert = new StarVertex[1]; //vert[0] = new StarVertex(location.Vector3, size, color.ToArgb()); //device.RenderState.PointSpriteEnable = true; //device.RenderState.PointScaleEnable = true; //device.RenderState.PointScaleA = 100; //device.RenderState.PointScaleB = 0; //device.RenderState.PointScaleC = 0; //device.RenderState.ZBufferEnable = zOrder; //device.SetTexture(0, Grids.StarProfile); ////device.SetTexture(0, null); //device.VertexFormat = VertexFormats.Position | VertexFormats.PointSize | VertexFormats.Diffuse; //// device.RenderState.CullMode = Cull.None; //device.RenderState.AlphaBlendEnable = true; //device.RenderState.SourceBlend = Microsoft.DirectX.Direct3D.Blend.SourceAlpha; //device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha; //device.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha; //device.TextureState[0].ColorOperation = TextureOperation.Modulate; //device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; //device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse; //device.TextureState[0].AlphaOperation = TextureOperation.Modulate; //device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; //device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse; //device.TextureState[1].ColorOperation = TextureOperation.Modulate; //device.TextureState[1].ColorArgument1 = TextureArgument.Current; //device.TextureState[1].ColorArgument2 = TextureArgument.Constant; //device.TextureState[1].AlphaOperation = TextureOperation.Modulate; //device.TextureState[1].AlphaArgument1 = TextureArgument.Current; //device.TextureState[1].AlphaArgument2 = TextureArgument.Constant; //device.TextureState[1].ConstantColor = Color.FromArgb(255, 255, 255, 255); //device.DrawUserPrimitives(PrimitiveType.PointList, 1, vert); //device.RenderState.PointSpriteEnable = false; //device.RenderState.PointScaleEnable = false; }
public static Vector3d GetPlanet3dLocationJD(SolarSystemObjects target, double jNow) { try { Vector3d result = new Vector3d(); AstroRaDec centerRaDec = AstroCalc.GetPlanet(jNow, 0, 0, 0, -6378149); Vector3d center = (Vector3d)Coordinates.RADecTo3dAu(centerRaDec.RA, centerRaDec.Dec, centerRaDec.Distance); if (target == SolarSystemObjects.Earth) { result = Vector3d.Create(-center.X, -center.Y, -center.Z); } else { AstroRaDec planet = AstroCalc.GetPlanet(jNow, (EO)(int)target, 0, 0, -6378149); result = (Vector3d)Coordinates.RADecTo3dAu(planet.RA, planet.Dec, planet.Distance); result.Subtract(center); } result.RotateX(Coordinates.MeanObliquityOfEcliptic(jNow) * RC); if (Settings.Active.SolarSystemScale != 1) { switch (target) { case SolarSystemObjects.Moon: { Vector3d parent = (Vector3d)GetPlanet3dLocationJD(SolarSystemObjects.Earth, jNow); // Parent Centric result.Subtract(parent); result.Multiply(Settings.Active.SolarSystemScale / 2); result.Add(parent); } break; case SolarSystemObjects.Io: case SolarSystemObjects.Europa: case SolarSystemObjects.Ganymede: case SolarSystemObjects.Callisto: { Vector3d parent = (Vector3d)GetPlanet3dLocationJD(SolarSystemObjects.Jupiter, jNow); // Parent Centric result.Subtract(parent); result.Multiply(Settings.Active.SolarSystemScale); result.Add(parent); } break; default: break; } } return (Vector3d)result; } catch { return Vector3d.Create(0, 0, 0); } }
public void AddTriangle(Vector3d v1, Vector3d v2, Vector3d v3, Color color, Dates date) { trianglePoints.Add(v1); trianglePoints.Add(v2); trianglePoints.Add(v3); triangleColors.Add(color); triangleDates.Add(date); EmptyTriangleBuffer(); }
public void AddLine(Vector3d v1, Vector3d v2, Color color, Dates date) { linePoints.Add(v1); linePoints.Add(v2); lineColors.Add(color); lineDates.Add(date); EmptyLineBuffer(); }
public static TimeSeriesPointVertex Create(Vector3d position, float size, float time, Color color) { TimeSeriesPointVertex tmp = new TimeSeriesPointVertex(); tmp.Position = position; tmp.PointSize = size; tmp.Tu = time; tmp.Tv = 0; tmp.color = color; return tmp; }
public void AddSubdividedTriangles(Vector3d v1, Vector3d v2, Vector3d v3, Color color, Dates date, int subdivisions) { subdivisions--; if (subdivisions < 0) { AddTriangle(v1, v2, v3, color, date); } else { Vector3d v12; Vector3d v23; Vector3d v31; v12 = Vector3d.MidPointByLength(v1, v2); v23 = Vector3d.MidPointByLength(v2, v3); v31 = Vector3d.MidPointByLength(v3, v1); // Add 1st AddSubdividedTriangles(v1, v12, v31, color, date, subdivisions); // Add 2nd AddSubdividedTriangles(v12, v23, v31, color, date, subdivisions); // Add 3rd AddSubdividedTriangles(v12, v2, v23, color, date, subdivisions); // Add 4th AddSubdividedTriangles(v23, v3, v31, color, date, subdivisions); } }
public static TimeSeriesLineVertex Create(Vector3d position, Vector3d normal, float time, Color color) { TimeSeriesLineVertex temp = new TimeSeriesLineVertex(); temp.Position = position; temp.Normal = normal; temp.Tu = time; temp.Tv = 0; temp.color = color; return temp; }
void InitLineBuffer(RenderContext renderContext) { if (renderContext.gl != null) { if (lineBuffers.Count == 0) { int count = linePoints.Count; PositionVertexBuffer lineBuffer = null; Vector3d[] linePointList = null; localCenter = new Vector3d(); if (DepthBuffered) { // compute the local center.. foreach (Vector3d point in linePoints) { localCenter.Add(point); } localCenter.X /= count; localCenter.Y /= count; localCenter.Z /= count; } int countLeft = count; int index = 0; int counter = 0; Vector3d temp; foreach (Vector3d point in linePoints) { if (counter >= 100000 || linePointList == null) { if (lineBuffer != null) { lineBuffer.Unlock(); } int thisCount = Math.Min(100000, countLeft); countLeft -= thisCount; lineBuffer = new PositionVertexBuffer(thisCount); linePointList = (Vector3d[])lineBuffer.Lock(); // Lock the buffer (which will return our structs) lineBuffers.Add(lineBuffer); lineBufferCounts.Add(thisCount); counter = 0; } if (UseLocalCenters) { temp = Vector3d.SubtractVectors(point, localCenter); linePointList[counter] = temp; } else { linePointList[counter] = point; } index++; counter++; } if (lineBuffer != null) { lineBuffer.Unlock(); } } } }
public void DrawLines(RenderContext renderContext, float opacity, Color color) { if (linePoints.Count < 2) { return; } InitLineBuffer(renderContext); int count = linePoints.Count; if (renderContext.gl == null) { Vector3d viewPoint = Vector3d.TransformCoordinate(renderContext.ViewPoint, ViewTransform); CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.StrokeStyle = color.ToString(); ctx.LineWidth = 2; ctx.Alpha = .25; Vector3d firstPoint = new Vector3d(); Vector3d secondPoint = new Vector3d(); for (int i = 0; i < count; i += 2) { firstPoint = renderContext.WVP.Transform(linePoints[i]); secondPoint = renderContext.WVP.Transform(linePoints[i + 1]); if (Vector3d.Dot(linePoints[i], viewPoint) > .60) { ctx.BeginPath(); ctx.MoveTo(firstPoint.X, firstPoint.Y); ctx.LineTo(secondPoint.X, secondPoint.Y); ctx.Stroke(); } } ctx.Restore(); } else { foreach (PositionVertexBuffer lineBuffer in lineBuffers) { SimpleLineShader.Use(renderContext, lineBuffer.VertexBuffer, color); renderContext.gl.drawArrays(GL.LINES, 0, lineBuffer.Count); } } }
private static void DrawSingleOrbit(RenderContext renderContext, Color eclipticColor, int id, Vector3d centerPoint, double startAngle, Vector3d planetNow, float opacity) { if (opacity < .01) { return; } if (renderContext.gl == null) { int count = orbitalSampleRate; bool planetDropped = false; Vector3d viewPoint = renderContext.ViewPoint; CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.StrokeStyle = eclipticColor.ToString(); ctx.LineWidth = 2; ctx.Alpha = 1; Vector3d point = new Vector3d(); Vector3d pointTest = new Vector3d(); Vector3d lastPoint = new Vector3d(); bool firstPoint = true; Matrix3d translate = Matrix3d.Translation(Vector3d.Negate(centerPoint)); Matrix3d mat = Matrix3d.MultiplyMatrix(translate, renderContext.WVP); Matrix3d matWV = Matrix3d.MultiplyMatrix(translate, renderContext.WV); for (int i = 0; i < count; i ++) { Vector3d pnt = orbits[id][i]; double angle = (Math.Atan2(orbits[id][i].Z, orbits[id][i].X) + Math.PI * 2 - startAngle) % (Math.PI * 2); int alpha = (int)((angle) / (Math.PI * 2) * 255); double alphaD = (double)alpha / 255.0; if (alpha < 2 && !planetDropped) { pnt = planetNow; alphaD = 1.0; } pointTest = matWV.Transform(pnt); point = mat.Transform(pnt); if (pointTest.Z > 0) { if (firstPoint) { firstPoint = false; } else { // if (Vector3d.Dot(pnt, viewPoint) > .60) { ctx.BeginPath(); ctx.Alpha = alphaD * opacity; ctx.MoveTo(lastPoint.X, lastPoint.Y); ctx.LineTo(point.X, point.Y); ctx.Stroke(); } } } lastPoint = point; } ctx.Restore(); } else { //todo add webgl method of drawing } }
//private bool LoadDemData() //{ // DemData = (float[])(object)demFile; // //todo get dem from parent // return true; //} protected void CalcSphere() { Vector3d[] corners = new Vector3d[4]; corners[0] = TopLeft; corners[1] = BottomRight; corners[2] = TopRight; corners[3] = BottomLeft; SphereHull result = ConvexHull.FindEnclosingSphere(corners); sphereCenter = result.Center; sphereRadius = result.Radius; }
public static bool DrawPlanets3D(RenderContext renderContext, float opacity, Vector3d centerPoint) { InitPlanetResources(renderContext); double distss = UiTools.SolarSystemToMeters(renderContext.SolarSystemCameraDistance); float moonFade = (float)Math.Min(1, Math.Max(Util.Log10(distss) - 7.3, 0)); float fade = (float)Math.Min(1, Math.Max(Util.Log10(distss) - 8.6, 0)); if (Settings.Active.SolarSystemOrbits && fade > 0) { for (int ii = 1; ii < 10; ii++) { int id = ii; if (ii == 9) { id = 19; } double angle = Math.Atan2(planet3dLocations[id].Z, planet3dLocations[id].X); DrawSingleOrbit(renderContext, planetColors[id], id, centerPoint, angle, planet3dLocations[id], fade); } } drawOrder.Clear(); Vector3d camera = renderContext.CameraPosition.Copy(); for (int planetId = 0; planetId < 14; planetId++) { if (!planetLocations[planetId].Eclipsed) { Vector3d distVector = Vector3d.SubtractVectors(camera,Vector3d.SubtractVectors(planet3dLocations[planetId],centerPoint)); if (!drawOrder.ContainsKey(distVector.Length())) { drawOrder[distVector.Length()] = planetId; } } } Vector3d distVectorEarth = Vector3d.SubtractVectors(camera, Vector3d.SubtractVectors(planet3dLocations[(int)SolarSystemObjects.Earth], centerPoint)); if (!drawOrder.ContainsKey(distVectorEarth.Length())) { drawOrder[distVectorEarth.Length()] = (int)SolarSystemObjects.Earth; } //for (int planetId = 0; planetId < 14; planetId++) //{ // if (!planetLocations[planetId].Eclipsed) // { // DrawPlanet3d( renderContext, planetId, centerPoint); // } //} // DrawPlanet3d(renderContext, (int)SolarSystemObjects.Earth, centerPoint); foreach (double key in drawOrder.Keys) { int planetId = drawOrder[key]; DrawPlanet3d(renderContext, planetId, centerPoint); } return true; }
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; }
public static void DrawSaturnsRings(RenderContext renderContext, bool front, double distance) { if (RingsTriangleLists[0] == null) { ringImage = (ImageElement)Document.CreateElement("img"); CrossDomainImage xdomimg = (CrossDomainImage)(object)ringImage; //texture.AddEventListener("load", delegate(ElementEvent e) //{ // texReady = true; // Downloading = false; // errored = false; // ReadyToRender = texReady && (DemReady || !demTile); // RequestPending = false; // TileCache.RemoveFromQueue(this.Key, true); // MakeTexture(); //}, false); //texture.AddEventListener("error", delegate(ElementEvent e) //{ // Downloading = false; // ReadyToRender = false; // errored = true; // RequestPending = false; // TileCache.RemoveFromQueue(this.Key, true); //}, false); xdomimg.crossOrigin = "anonymous"; ringImage.Src = "/webclient/images/saturnringsshadow.png"; RingsTriangleLists[0] = new List<RenderTriangle>(); RingsTriangleLists[1] = new List<RenderTriangle>(); double ringSize = 2.25; Vector3d TopLeft = Vector3d.Create(-ringSize, 0, -ringSize); Vector3d TopRight = Vector3d.Create(ringSize, 0, -ringSize); Vector3d BottomLeft = Vector3d.Create(-ringSize, 0, ringSize); Vector3d BottomRight = Vector3d.Create(ringSize, 0, ringSize); Vector3d center = Vector3d.Create(0, 0, 0); Vector3d leftCenter = Vector3d.Create(-ringSize, 0, 0); Vector3d topCenter = Vector3d.Create(0, 0, -ringSize); Vector3d bottomCenter = Vector3d.Create(0, 0, ringSize); Vector3d rightCenter = Vector3d.Create(ringSize, 0, 0); int level = 6; //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(TopLeft, 0, 0, 1024, 1024), PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), ringImage, level)); //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, 0.5, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), ringImage, level)); //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), PositionTexture.CreatePosSize(TopRight, 1, 0, 1024, 1024), ringImage, level)); //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), ringImage, level)); //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), ringImage, level)); //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(BottomLeft, 0, 1, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), ringImage, level)); //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(BottomRight, 1, 1, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), ringImage, level)); //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), PositionTexture.CreatePosSize(BottomRight, 1, 1, 1024, 1024), ringImage, level)); List<PositionTexture> vertexList; vertexList = new List<PositionTexture>(); int Width = 1024; int Height = 1024; vertexList.Add(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height)); vertexList.Add(PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height)); vertexList.Add(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height)); vertexList.Add(PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height)); List<Triangle> childTriangleList = new List<Triangle>(); //if (dataset.BottomsUp) //{ // childTriangleList.Add(Triangle.Create(0, 1, 2)); // childTriangleList.Add(Triangle.Create(2, 1, 3)); //} //else { childTriangleList.Add(Triangle.Create(0, 2, 1)); childTriangleList.Add(Triangle.Create(2, 3, 1)); } int count = 5; while (count-- > 1) { List<Triangle> newList = new List<Triangle>(); foreach (Triangle tri in childTriangleList) { tri.SubDivideNoNormalize(newList, vertexList); } childTriangleList = newList; } double miter = .6 / (Width / 256); foreach (Triangle tri in childTriangleList) { PositionTexture p1 = vertexList[tri.A]; PositionTexture p2 = vertexList[tri.B]; PositionTexture p3 = vertexList[tri.C]; RingsTriangleLists[0].Add(RenderTriangle.CreateWithMiter(p1, p2, p3, ringImage, level, miter)); } } if (renderContext.gl == null) { Vector3d cam = renderContext.CameraPosition; Vector3d test = new Vector3d(); //Matrix3d wv = renderContext.WV; Matrix3d worldLocal = Matrix3d.MultiplyMatrix(Matrix3d.RotationY(Math.Atan2(renderContext.SunPosition.X, renderContext.SunPosition.Z)), renderContext.WorldBaseNonRotating); Matrix3d wv = Matrix3d.MultiplyMatrix(worldLocal, renderContext.View); Matrix3d wvp = Matrix3d.MultiplyMatrix(wv, renderContext.Projection); double Width = renderContext.Width; double Height = renderContext.Height; wvp.Scale(Vector3d.Create(Width / 2, -Height / 2, 1)); wvp.Translate(Vector3d.Create(Width / 2, Height / 2, 0)); double td = 0; // RenderTriangle.CullInside = !RenderTriangle.CullInside; for (int i = 0; i < 2; i++) { foreach (RenderTriangle tri in RingsTriangleLists[0]) { //test = Vector3d.SubtractVectors(wv.Transform(tri.A.Position), cam); test = wv.Transform(tri.A.Position); td = test.Length(); bool draw = td > distance; if (front) { draw = !draw; } if (draw) { tri.Opacity = 1; tri.Draw(renderContext.Device, wvp); } } RenderTriangle.CullInside = !RenderTriangle.CullInside; } } else { //todo port rings to web gl //renderContext.gl.enableVertexAttribArray(renderContext.vertLoc); //renderContext.gl.enableVertexAttribArray(renderContext.textureLoc); //renderContext.gl.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer); //renderContext.gl.vertexAttribPointer(renderContext.vertLoc, 3, GL.FLOAT, false, 20, 0); ////renderContext.gl.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer); //renderContext.gl.vertexAttribPointer(renderContext.textureLoc, 2, GL.FLOAT, false, 20, 12); //renderContext.gl.activeTexture(GL.TEXTURE0); //renderContext.gl.bindTexture(GL.TEXTURE_2D, texture2d); ////if (tileX == TileTargetX && tileY == TileTargetY && Level == TileTargetLevel) ////{ //// renderContext.gl.bindTexture(GL.TEXTURE_2D, null); ////} //renderContext.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, GetIndexBuffer(part, accomidation)); //renderContext.gl.drawElements(GL.TRIANGLES, TriangleCount * 3, GL.UNSIGNED_SHORT, 0); } }
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; }
public Vector3d TransformPickPointToWorldSpace(Vector2d ptCursor, double backBufferWidth, double backBufferHeight) { Vector3d vPickRayOrig; Vector3d vPickRayDir; Vector3d v = new Vector3d(); v.X = (((2.0f * ptCursor.X) / backBufferWidth) - 1) / (RenderContext.Projection.M11);// / (backBufferWidth / 2)); v.Y = (((2.0f * ptCursor.Y) / backBufferHeight) - 1) / (RenderContext.Projection.M22);// / (backBufferHeight / 2)); v.Z = 1.0f; Matrix3d m = Matrix3d.MultiplyMatrix(RenderContext.View, RenderContext.World); m.Invert(); vPickRayDir = new Vector3d(); vPickRayOrig = new Vector3d(); // Transform the screen space pick ray into 3D space vPickRayDir.X = v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31; vPickRayDir.Y = v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32; vPickRayDir.Z = v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33; vPickRayDir.Normalize(); return vPickRayDir; }
private void InitializeRoute(RenderContext 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 = Vector3d.SubtractVectors(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(); // v.Multiply(1.1); 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; } }
bool CheckBackface(Vector3d a, Vector3d b, Vector3d c) { Vector3d ab = Vector3d.SubtractVectors(a, b); Vector3d ac = Vector3d.SubtractVectors(a, c); Vector3d cp = Vector3d.Cross(ab, ac); cp.Normalize(); return cp.Z >= 0; }
public static void UpdateOrbits(int planetCenter) { try { //if (!downloadedPlanets) //{ // Wtml.GetWtmlFile("", PlanetsReady); //} obliquity = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) * RC; if (planetCenter != lastPlanetCenterID) { orbits = null; } lastPlanetCenterID = planetCenter; if (orbits == null) { if (planetCenter < 0) { eclipticTilt = Matrix3d.Identity; } else { eclipticTilt = Matrix3d.Identity; eclipticTilt = Matrix3d.RotationX((float)obliquity); } if (planetOrbitalYears == null) { planetOrbitalYears = new double[20]; planetOrbitalYears[0] = 1; planetOrbitalYears[1] = .241; planetOrbitalYears[2] = .615; planetOrbitalYears[3] = 1.881; planetOrbitalYears[4] = 11.87; planetOrbitalYears[5] = 29.45; planetOrbitalYears[6] = 84.07; planetOrbitalYears[7] = 164.9; planetOrbitalYears[8] = 248.1; planetOrbitalYears[9] = 27.3 / 365.25; planetOrbitalYears[10] = 16.6890184 / 365.25; planetOrbitalYears[11] = 3.551181 / 365.25; planetOrbitalYears[12] = 7.15455296 / 365.25; planetOrbitalYears[13] = 16.6890184 / 365.25; planetOrbitalYears[19] = 1; } if (!ReadOrbits()) { orbits = new Vector3d[20][]; for (int i = 1; i < 20; i++) { orbits[i] = new Vector3d[orbitalSampleRate]; if (i < 9 || i == 19) { for (int j = 0; j < orbitalSampleRate; j++) { int centerId = planetCenter; double now = jNow + ((planetOrbitalYears[i] * 365.25 / (orbitalSampleRate)) * (double)(j - (orbitalSampleRate / 2))); Vector3d center = new Vector3d(); if (i == (int)SolarSystemObjects.Moon) { centerId = -1; } else if (i > 9 && i < 14) { centerId = (int)SolarSystemObjects.Jupiter; } if (centerId > -1) { AstroRaDec centerRaDec = AstroCalc.GetPlanet(now, (EO)centerId, 0, 0, -6378149); center = Coordinates.RADecTo3dAu(centerRaDec.RA, centerRaDec.Dec, centerRaDec.Distance); } if (i != 19) { AstroRaDec planetRaDec = AstroCalc.GetPlanet(now, (EO)i, 0, 0, -6378149); // todo move to double precition for less trucation orbits[i][ j] = (Vector3d)Coordinates.RADecTo3dAu(planetRaDec.RA, planetRaDec.Dec, planetRaDec.Distance); orbits[i][j].Subtract( (Vector3d)center); } else { orbits[i][j] = Vector3d.Create(-center.X, -center.Y, -center.Z); } // todo is the tilt right? //if (i != (int)SolarSystemObjects.Moon && !((i > 9 && i < 14))) { orbits[i][j].RotateX(obliquity); } } orbits[i][ orbitalSampleRate - 1] = orbits[i][0]; } } DumpOrbitsFile(); } } } finally { // OrbitsMutex.ReleaseMutex(); } }
//public Text3d() //{ //} public Text3d(Vector3d center, Vector3d up, string text, float fontsize, double scale) { Text = text; this.up = up; this.center = center; this.scale = scale; this.top = Vector3d.AddVectors(center,Vector3d.Scale(up, scale)); if (fontsize < 0) { sky = false; } }
public static void UpdatePlanetLocations(bool threeDee) { jNow = SpaceTimeController.JNow; if (threeDee) { UpdateOrbits(0); } if (planetDiameters == null) { planetDiameters = new double[20]; planetDiameters[0] = 0.009291568; planetDiameters[1] = 0.0000325794793734425; planetDiameters[2] = 0.0000808669220531394; planetDiameters[3] = 0.0000453785605596396; planetDiameters[4] = 0.000954501; planetDiameters[5] = 0.000802173; planetDiameters[6] = 0.000339564; planetDiameters[7] = 0.000324825; planetDiameters[8] = 0.0000152007379777805; planetDiameters[9] = 0.0000232084653538149; planetDiameters[10] = 0.0000243519298386342; planetDiameters[11] = 0.0000208692629580609; planetDiameters[12] = 0.0000351742670356556; planetDiameters[13] = 0.0000322263666626559; planetDiameters[14] = 0.0000243519298386342; planetDiameters[15] = 0.0000208692629580609; planetDiameters[16] = 0.0000351742670356556; planetDiameters[17] = 0.0000322263666626559; planetDiameters[18] = 0.009291568 * 2; planetDiameters[19] = 0.00008556264121178090; } if (planetColors == null) { Color lightYellow = Color.FromArgb(255, 255, 255, 221); Color orangeRed = Color.FromArgb(255, 255, 68, 00); planetColors = new Color[20]; planetColors[0] = Colors.Yellow; planetColors[1] = Colors.White; planetColors[2] = lightYellow; planetColors[3] = orangeRed; planetColors[4] = Color.FromArgb(255, 255, 165, 00); planetColors[5] = Color.FromArgb(255, 184, 134, 11); planetColors[6] = Color.FromArgb(255, 173, 216, 230); planetColors[7] = Colors.Blue; planetColors[8] = Colors.White; planetColors[9] = Colors.White; planetColors[10] = Colors.White; planetColors[11] = Colors.White; planetColors[12] = Colors.White; planetColors[13] = Colors.White; planetColors[14] = Colors.Black; planetColors[15] = Colors.Black; planetColors[16] = Colors.Black; planetColors[17] = Colors.Black; planetColors[18] = Colors.White; planetColors[19] = Color.FromArgb(255, 173, 216, 230); } if (planetTilts == null) { planetTilts = new double[20]; planetTilts[0] = 0.0; planetTilts[1] = 0.01; planetTilts[2] = 177.4; planetTilts[3] = 25.19; planetTilts[4] = 3.13; planetTilts[5] = 26.73; planetTilts[6] = 97.77; planetTilts[7] = 28.32; planetTilts[8] = 119.61; planetTilts[9] = 23.439; planetTilts[10] = 2.21; planetTilts[11] = 0; planetTilts[12] = -0.33; planetTilts[13] = 0; planetTilts[14] = 0; planetTilts[15] = 0; planetTilts[16] = 0; planetTilts[17] = 0; planetTilts[18] = 0; planetTilts[19] = 23.5; } planetTilts[19] = obliquity / RC; if (planetRotationPeriod == null) { planetRotationPeriod = new double[20]; planetRotationPeriod[0] = 25.37995; planetRotationPeriod[1] = 58.6462; planetRotationPeriod[2] = -243.0187; planetRotationPeriod[3] = 1.02595675; planetRotationPeriod[4] = 0.41007; planetRotationPeriod[5] = 0.426; planetRotationPeriod[6] = -0.71833; planetRotationPeriod[7] = 0.67125; planetRotationPeriod[8] = -6.38718; planetRotationPeriod[9] = 27.3; planetRotationPeriod[10] = 1.769137786; planetRotationPeriod[11] = 3.551; planetRotationPeriod[12] = 7.155; planetRotationPeriod[13] = 16.69; planetRotationPeriod[14] = 0; planetRotationPeriod[15] = 0; planetRotationPeriod[16] = 0; planetRotationPeriod[17] = 0; planetRotationPeriod[18] = 0; planetRotationPeriod[19] = .99726968; } if (planetScales == null) { planetScales = new double[20]; } if (planet3dLocations == null) { planet3dLocations = new Vector3d[20]; } if (Settings.Active.ActualPlanetScale) { planetScales[0] = .5f; planetScales[1] = .25f; planetScales[2] = .25f; planetScales[3] = .25f; planetScales[4] = .25f; planetScales[5] = .5f; planetScales[6] = .25f; planetScales[7] = .25f; planetScales[8] = .25f; planetScales[9] = .25f; planetScales[10] = .25f; planetScales[11] = .25f; planetScales[12] = .25f; planetScales[13] = .25f; planetScales[14] = .25f; planetScales[15] = .25f; planetScales[16] = .25f; planetScales[17] = .25f; planetScales[18] = .5f; planetScales[19] = .25f; } else { for (int i = 0; i < 20; i++) { if (i < 10) { planetScales[i] = .25f; } else { planetScales[i] = .1f; } } // Make Sun and Saturn bigger planetScales[0] = .5f; planetScales[5] = .5f; planetScales[18] = .5f; } planetDrawOrder = new Dictionary<double, int>(); planetLocations = new AstroRaDec[20]; Vector3d center = new Vector3d(); int planetCenter = 0; if (planetCenter > -1) { AstroRaDec centerRaDec = AstroCalc.GetPlanet(jNow, (EO)planetCenter, threeDee ? 0 : SpaceTimeController.Location.Lat, threeDee ? 0 : SpaceTimeController.Location.Lng, threeDee ? -6378149 : SpaceTimeController.Altitude); center = (Vector3d)Coordinates.RADecTo3dAu(centerRaDec.RA, centerRaDec.Dec, centerRaDec.Distance); } planet3dLocations[19] = Vector3d.Create(-center.X, -center.Y, -center.Z); planet3dLocations[19].RotateX(obliquity); for (int i = 0; i < 18; i++) { planetLocations[i] = AstroCalc.GetPlanet(jNow, (EO)i, threeDee ? 0 : SpaceTimeController.Location.Lat, threeDee ? 0 : SpaceTimeController.Location.Lng, threeDee ? -6378149 : SpaceTimeController.Altitude); planet3dLocations[i] = (Vector3d)Coordinates.RADecTo3dAu(planetLocations[i].RA, planetLocations[i].Dec, planetLocations[i].Distance); //planet3dLocations[i] = new Vector3d(planet3dLocations[i].X - center.X, // planet3dLocations[i].Y - center.Y, // planet3dLocations[i].Z - center.Z); planet3dLocations[i].Subtract(center); planet3dLocations[i].RotateX(obliquity); if (Settings.Active.ActualPlanetScale) { planetScales[i] = (2 * Math.Atan(.5 * (planetDiameters[i] / planetLocations[i].Distance))) / Math.PI * 180; //if (i == 5 || i == 0) //{ // planetScales[i] *= 2; //} //if ((i > 9 && i != 18) && Properties.Settings.Default.ShowMoonsAsPointSource) // Jupiters moons should be bigger //{ // planetScales[i] *= 2; //} } if (Settings.Active.SolarSystemScale != 1) { SolarSystemObjects id = (SolarSystemObjects)i; switch (id) { case SolarSystemObjects.Moon: { Vector3d parent = (planet3dLocations[(int)SolarSystemObjects.Earth]); // Parent Centric planet3dLocations[i].Subtract(parent); planet3dLocations[i].Multiply(Settings.Active.SolarSystemScale / 2); planet3dLocations[i].Add(parent); } break; case SolarSystemObjects.Io: case SolarSystemObjects.Europa: case SolarSystemObjects.Ganymede: case SolarSystemObjects.Callisto: { Vector3d parent = (planet3dLocations[(int)SolarSystemObjects.Jupiter]); // Parent Centric planet3dLocations[i].Subtract(parent); planet3dLocations[i].Multiply(Settings.Active.SolarSystemScale); planet3dLocations[i].Add(parent); } break; default: break; } } double finalDistance = -planetLocations[i].Distance; while (planetDrawOrder.ContainsKey(finalDistance)) { finalDistance += 0.0000000001; } planetDrawOrder[finalDistance] = i; } planetLocations[18] = planetLocations[0]; planetScales[18] = planetScales[0]*2; planetScales[5] = planetScales[5]*2; lastUpdate = SpaceTimeController.Now; }
public static Coordinates CartesianToSpherical(Vector3d vector) { double ascention; double declination; double radius = Math.Sqrt((double)vector.X * (double)vector.X + (double)vector.Y * (double)vector.Y + (double)vector.Z * (double)vector.Z); double XZ = Math.Sqrt((double)vector.X * (double)vector.X + (double)vector.Z * (double)vector.Z); declination = Math.Asin((double)vector.Y / radius); if (0 < vector.X) { ascention = Math.Asin((double)vector.Z / XZ); } else if (0 > vector.X) { ascention = Math.PI - Math.Asin((double)vector.Z / XZ); } else { ascention = 0; } return new Coordinates(ascention, declination); }
// private static Matrix bias = Matrix.Scaling(new Vector3(.5f, .5f, .5f)) * Matrix.Translation(new Vector3(.5f, .5f, .5f)); private static void DrawPlanet3d(RenderContext renderContext, int planetID, Vector3d centerPoint) { if (planetID == (int)SolarSystemObjects.Sun) { // device.RenderState.Lighting = false; } else { // device.RenderState.Lighting = Settings.Active.SolarSystemLighting; } double radius = GetAdjustedPlanetRadius(planetID); double rotationCurrent = 0; if (planetID == (int)SolarSystemObjects.Earth) { rotationCurrent = Coordinates.MstFromUTC2(SpaceTimeController.Now, 0) / 180.0 * Math.PI; } else { rotationCurrent = (((jNow - 2451545.0) / planetRotationPeriod[planetID]) * Math.PI * 2) % (Math.PI * 2); } //Matrix3d matOldWV = renderContext.WV.Clone(); Matrix3d matOld = renderContext.World; Matrix3d matOldBase = renderContext.WorldBase; Matrix3d matOldNonRotating = renderContext.WorldBaseNonRotating; Matrix3d matLocal = renderContext.World.Clone(); Matrix3d matLocalNR = renderContext.World.Clone(); Vector3d translation = Vector3d.SubtractVectors(planet3dLocations[planetID], centerPoint); matLocal.Scale(Vector3d.Create(radius, radius, radius)); matLocal.Multiply(Matrix3d.RotationY((double)-rotationCurrent)); matLocal.Multiply(Matrix3d.RotationX((double)(planetTilts[planetID] * RC))); matLocal.Multiply(Matrix3d.Translation(translation)); matLocalNR.Scale(Vector3d.Create(radius, radius, radius)); matLocalNR.Multiply(Matrix3d.RotationX((double)(planetTilts[planetID] * RC))); matLocalNR.Multiply(Matrix3d.Translation(translation)); renderContext.World = matLocal; renderContext.WorldBase = matLocal.Clone(); renderContext.WorldBaseNonRotating = matLocalNR; renderContext.MakeFrustum(); float planetWidth = 1; if (planetID == (int)SolarSystemObjects.Saturn) { planetWidth = 3; } if (IsPlanetInFrustum(renderContext,planetWidth)) { //Matrix3d matOld2 = renderContext.World.Clone(); //Matrix3d matOldBase2 = renderContext.WorldBase.Clone(); //Matrix3d matOldNonRotating2 = renderContext.WorldBaseNonRotating; Vector3d sun = planet3dLocations[0].Copy(); Vector3d planet = planet3dLocations[planetID].Copy(); sun = matOld.Transform(sun); planet = matOld.Transform(planet); Vector3d sunPosition = Vector3d.SubtractVectors(sun, planet); sunPosition.Normalize(); renderContext.SunPosition = sunPosition; Vector3d loc = Vector3d.SubtractVectors(planet3dLocations[planetID], centerPoint); loc.Subtract(renderContext.CameraPosition); double dist = loc.Length(); double sizeIndexParam = (2 * Math.Atan(.5 * (radius / dist))) / Math.PI * 180; int sizeIndex = 0; if (sizeIndexParam > 10.5) { sizeIndex = 0; } else if (sizeIndexParam > 3.9) { sizeIndex = 1; } else if (sizeIndexParam > .72) { sizeIndex = 2; } else if (sizeIndexParam > 0.05) { sizeIndex = 3; } else { sizeIndex = 4; } //ShadowStuff if (planetID == (int)SolarSystemObjects.Earth && sizeIndex < 2) { float width = Settings.Active.SolarSystemScale * .00001f; //todo add shadows centerPoint = SetupShadow(device, centerPoint, width, SolarSystemObjects.Moon); } //ShadowStuff end if (sizeIndex < 3) { bool oldLighting = renderContext.Lighting; //double planetDistance = Vector3d.SubtractVectors(planet3dLocations[planetID], renderContext.CameraPosition).Length(); if (planetID == 5) { renderContext.Lighting = false; // DRAW BACK HALF OF RINGS DrawSaturnsRings(renderContext, false, dist); renderContext.Lighting = oldLighting; //if (Settings.Active.SolarSystemLighting) //{ // SetupRingShadow(device, centerPoint, SolarSystemObjects.Saturn, rotationCurrent); //} // todo saturns rings DrawRings(device); } if (planetID == 0) { renderContext.Lighting = false; } DrawSphere(renderContext, planetID); if (planetID == 5) { renderContext.Lighting = false; DrawSaturnsRings(renderContext, true, dist); // DRAW FRONT HALF OF RINGS //if (Settings.Active.SolarSystemLighting) //{ // SetupRingShadow(device, centerPoint, SolarSystemObjects.Saturn, rotationCurrent); //} // todo saturns rings DrawRings(device); } renderContext.Lighting = oldLighting; } else { if (planetID == 0) { DrawPointPlanet(renderContext, new Vector3d(), (double)(10 * planetDiameters[planetID]), planetColors[planetID], true); } else if (planetID < (int)SolarSystemObjects.Moon || planetID == (int)SolarSystemObjects.Earth) { double size = (800 * planetDiameters[planetID]); DrawPointPlanet(renderContext, new Vector3d(), (double)Math.Max(.05, Math.Min(.1f, size)), planetColors[planetID], true); } else if (sizeIndexParam > .002) { double size = (800 * planetDiameters[planetID]); DrawPointPlanet(renderContext, new Vector3d(), (double)Math.Max(.05, Math.Min(.1f, size)), planetColors[planetID], true); } } //renderContext.World = matOld2; //renderContext.WorldBase = matOldBase2; //renderContext.WorldBaseNonRotating = matOldNonRotating2; } renderContext.World = matOld; renderContext.WorldBase = matOldBase; renderContext.WorldBaseNonRotating = matOldNonRotating; }
public static Vector2d CartesianToSphericalSky(Vector3d vector) { double rho = Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z); double ra = Math.Atan2(vector.Z, vector.X); double dec = Math.Asin(-vector.Y / rho); return Vector2d.Create(ra / Math.PI * 12, dec / Math.PI * 180); }
public void AddPoint(Vector3d v1, Color color, Dates date, float size) { points.Add(v1); colors.Add(color.Clone()); dates.Add(date); sizes.Add(size); EmptyPointBuffer(); }