Some use cases for keeping them separate:
- The application could be a game that has a lot of processing overhead rendering the objects to the screen.
- The application could be research experiment where it is running one or many simultaneous orbital calculations and wants minimal overhead (no graphics rendering).
- The application could be from some third party that does its own visualization / whatnot and just needs a way to have objects move in space.
Rather than maintaining two tables of objects (one in the aero library and one in the host application), the orbital aero library has the one and only list. I'm using a pointer in the Body object in the orbital aero library to point to an Entity object in my host application.
When a Body is created, two objects are created and added to heap memory: the Body object and an Entity object. The aero library creates the Body object; the host application creates the Entity object. To tie the two together, the Body object has a hostData pointer to the Entity object.
Since my application is doing graphics rendering, the Entity object has a pointer to the visual model that will be drawn on the screen. Eventually the Entity object will contain lots of information that should be tied to the Body but has no purpose within the aero library.
(Side note: In previous posts the bodies map table contained the Body object itself rather than a pointer to the memory location of the Body object. That has been changed.)
// Table to hold all the bodies.
map <uint64, BodyModel*> tableBodies;
BodyModel *thisBody = new BodyModel(this, indexCounter);
thisBody->isActive = true;
void *hostData; // Pointer to data structure populated by host software.
this->isVisible = false;
this->bodyObject = newBody;
this->isVisible = true;
Function for Creating a Body in the Orbital Aero App
void addBodyEarth(OrbitalAeroModel &orbitalAero, VisualModel *newVisualModel)
uint64 newBodyIndex = orbitalAero.createBody();
BodyModel *newBody = orbitalAero.getBody(newBodyIndex);
newBody->location_meters = 0.0;
newBody->massBase_kilograms = earthMass_kilograms;
newBody->radius_meters = earthRadius_meters;
newBody->linearVelocity_metersPerSecond = 0.0;
newBody->angularVelocity_radiansPerSecond.psi = 0.0000727220509259;
Entity *newHostBody = new Entity(newBody);
newBody->hostData = newHostBody;
newHostBody->visualModelObject = newVisualModel;
Copyright (c) 2017 Clinton Kam
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.