- Home /
Lines or curves for a smooth circle in Vectrosity
Hello,
I am wondering what approach for drawing circles would produce the best looking, smooth circles/orbits in Vectrosity? Pretty much similar to the smoothness of the orbits in Kerbal Space Program.
I am currently using multiple line segments (2500) to display a circle, but it seems a bit ... edgy and not looking good when zooming in and out with the camera (3d camera with changing the Z coordinates for zoom in/out, drawing with Draw3dAuto()).
Would it be better if i used multiple curves to draw a circle, would it be smoother and finally would it be more efficient?
I guess my questions is more directed towards Eric, but if anyone else is interested in providing an answer, that would be great :)
Answer by HarvesteR · Jan 29, 2014 at 10:30 PM
The orbits in KSP are drawn as Vectrosity Splines. We take a fixed number of samples from the orbit code, and let the spline interpolate the segments in between.
This works nicely for us, since querying the orbit maths for sample points is much more expensive than interpolating the spline, so we try to keep the number of samples down as much as we can (as low as we can get them without the spline becoming distorted), and the number of subdivisions just high enough to make it look smooth.
Mind though, it's not just about the number of samples, it's about distribution. The more evenly spaced your sample points are, the better the spline will be able to draw smoothly across them.
Also keep in mind that even then, the spline drawing for orbits is one of the most performance intensive operations in KSP, it is a lot of maths, so we do what we can to keep the number of splines on screen as low as possible.
Cheers
Thank you for your reply, Harvester.
I will have quite a lot of orbits (for now its 1 for each spacial body on a solar system, and 1 for the solar system itself). Which makes around ~6 orbits per system, for an average of 100 systems in a game = ~600orbits. I am trying to reduce the visible ones according to the zoom level. At zoomed out level X i remove the spacial bodies orbits and leave only the system orbit.
$$anonymous$$y question after this rambling is do you think this approach would be performance viable and do you have any suggestions on what i can do to optimize around the orbits?
Answer by Eric5h5 · Nov 23, 2013 at 07:22 PM
The more segments, the smoother it will be. You could switch between different circles at different zoom levels, with higher zooms having more segments.
According to this, $$anonymous$$erbal Space Program uses Vectrosity.
Yes, exactly why i knew i was doing something wrong, when my circles were scaling badly :) Obviously im still pretty new to the vectrosity library (just started using it a day or two ago), but its definitely a very powerful tool.