// 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 DrawEllipseWithPosition(RenderContext renderContext, double semiMajorAxis, double eccentricity, double eccentricAnomaly, Color color, Matrix3d worldMatrix, Vector3d positionNow) { if (ellipseShader == null) { ellipseShader = new EllipseShader(); } if (ellipseVertexBuffer == null) { ellipseVertexBuffer = CreateEllipseVertexBuffer(500); } Matrix3d savedWorld = renderContext.World; renderContext.World = worldMatrix; renderContext.gl.bindBuffer(GL.ARRAY_BUFFER, ellipseVertexBuffer.VertexBuffer); renderContext.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null); EllipseShader.Use(renderContext, (float)semiMajorAxis, (float)eccentricity, (float)eccentricAnomaly, color, 1.0f, savedWorld, positionNow); renderContext.gl.drawArrays(GL.LINE_STRIP, 0, ellipseVertexBuffer.Count); renderContext.World = savedWorld; }
public static PositionVertexBuffer CreateEllipseVertexBufferWithoutStartPoint(int vertexCount) { PositionVertexBuffer vb = new PositionVertexBuffer(vertexCount); Vector3d[] verts = vb.Lock(); // Setting a non-zero value will prevent the ellipse shader from using the 'head' point verts[0] = Vector3d.Create(1.0e-6f, 0.0f, 0.0f); for (int i = 1; i < vertexCount; ++i) { verts[i] = Vector3d.Create(2.0f * (float)i / (float)vertexCount, 0.0f, 0.0f); } vb.Unlock(); return(vb); }
public static PositionVertexBuffer CreateEllipseVertexBuffer(int vertexCount) { PositionVertexBuffer vb = new PositionVertexBuffer(vertexCount); Vector3d[] verts = vb.Lock(); int index = 0; // Pack extra samples into the front of the orbit to avoid obvious segmentation // when viewed from near the planet or moon. for (int i = 0; i < vertexCount / 2; ++i) { verts[index++] = Vector3d.Create(2.0f * (float)i / (float)vertexCount * 0.05f, 0.0f, 0.0f); } for (int i = 0; i < vertexCount / 2; ++i) { verts[index++] = Vector3d.Create(2.0f * (float)i / (float)vertexCount * 0.95f + 0.05f, 0.0f, 0.0f); } vb.Unlock(); return(vb); }
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(); } } } }