Progress Update #8
Orbit Debug Visualization
Over this past week I have worked on and finished 90% of the orbit visualization. This means drawing paths for where planets will go when you hit play given their mass, velocity and position.
DrawOrbits is the main function for the Orbit Debug actor so let's go through how it works. We start by removing the previous orbits with
Per the comment on line 28, the loop starting on line 29 makes "VirtualBodies" for all celestial bodies in the scene. A virtual body is essentially an ultra stripped down celestial body with only the information it needs for movement.
ClearOrbits()
. This function either calls FlushPersistentDebugLines()
if the orbits were drawn with debug lines or clears the splines if they were created that way. Then lines 5-12 gather all celestial bodies into array Bodies. If we are using splines to make the orbits then lines 14-17 will make a spline for each body. Lines 19-26 then initialize more variables.Per the comment on line 28, the loop starting on line 29 makes "VirtualBodies" for all celestial bodies in the scene. A virtual body is essentially an ultra stripped down celestial body with only the information it needs for movement.
The loop starting on line 42 then does the actual "simulation" of orbits. The simplest way to explain this is to say that it is doing the same calculations as a normal celestial body would do during run-time only that here there is a fixed time-step. This fixed time-step is the reason why if you use this system in its current state it might be a little off where the planets actually go. This problem compounds the more time you spend simulating and is an issue I don't know is fixable.
The final loop starting on line 70 deals with rendering all of the simulation data. If we are using splines then we will convert all of the DrawPoints (which are FVectors) into FSplinePoints and add them to the spline. If we are not using splines then we will simply draw a debug line for each point in DrawPoints.
That's essentially all there is to it. This code was heavily inspired from Sebastian Lague's solar system project in Unity, as much of this function is a translation from C# to Unreal C++.
During this process I learned a few other things:
- SplineMeshComponents cannot have more than a start and an end point.
- SplineComponents (non-mesh) are not meant to be rendered in packaged builds.
- The world is not initialized during the constructor function of an actor but is initialized during the
OnConstruction()
function which can be overridden. - Changing a C++ class' parent is a massive headache.
Comments
Post a Comment