Jump to content

Mark a landing spot on a celestial body


Recommended Posts

Hello,

I try to mark a certain landing spot on a celestial body. I use OpenGL quads for that for now, but unfortunately this is slow. So I would like to change that, but I don't know how.

My current code:


public static void drawLandingArea (CelestialBody body, double minLatitude, double maxLatitude,
double minLongitude, double maxLongitude,
Color c, double rotation = 0)
{
double dlat = (maxLatitude - minLatitude) / 10.0;
double dlog = (maxLongitude - minLongitude) / 10.0;

List<Vector3d[]> quads = new List<Vector3d[]> ();

for (double lat = minLatitude; lat + dlat < maxLatitude; lat += dlat) {
for (double log = minLongitude; log + dlog < maxLongitude; log += dlog) {
Vector3d up1 = body.GetSurfaceNVector (lat, log);
Vector3d center1 = body.position + body.Radius * up1;

Vector3d up2 = body.GetSurfaceNVector (lat, log + dlog);
Vector3d center2 = body.position + body.Radius * up2;

Vector3d up3 = body.GetSurfaceNVector (lat + dlat, log + dlog);
Vector3d center3 = body.position + body.Radius * up3;

Vector3d up4 = body.GetSurfaceNVector (lat + dlat, log);
Vector3d center4 = body.position + body.Radius * up4;

if (!IsOccluded (center1, body)) { // this function makes sure that the quad is visible
quads.Add (new Vector3d[] { center1, center2, center3, center4});
}
}
}

GLQuadMap (quads, c);
}

public static void GLQuadMap (List<Vector3d[]> list, Color c)
{
GL.PushMatrix ();
material.SetPass (0);
GL.LoadOrtho ();
GL.Begin (GL.QUADS);
GL.Color (c);
foreach(Vector3d[] vertices in list) {
GLVertexMap (vertices[0]);
GLVertexMap (vertices[1]);
GLVertexMap (vertices[2]);
GLVertexMap (vertices[3]);
}
GL.End ();
GL.PopMatrix ();
}

public static void GLVertexMap (Vector3d worldPosition)
{
Vector3 screenPoint = PlanetariumCamera.Camera.WorldToScreenPoint (ScaledSpace.LocalToScaledSpace(worldPosition));
GL.Vertex3 (screenPoint.x / Camera.main.pixelWidth, screenPoint.y / Camera.main.pixelHeight, 0);
}

The result is basically what I want:

46HrI9L.png

But as I said, it is slow. So I would like to try the Unity way and create a game object with a mesh. But actually, I have *no* clue how to do that. *Any* advice is appreciated.

nobody44

Link to comment
Share on other sites

gl quads should be as fast as anything in game if done right... try using a vertex buffer instead of uploading the vertices to the gpu each frame, also cache the divisions by screen dimensions and multiply by the same constant. you can evaluate it once per frame instead of for every vertex. can you use a static fixed array in memory instead of the expensive list? have you tried using a triangle list instead? how about a triangle strip using pairs of degenerate triangles to connect the quads?

this all means nothing if you are drawing, e.g. 4 quads though.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...