本文整理汇总了C++中SolarSystem::getPlanets方法的典型用法代码示例。如果您正苦于以下问题:C++ SolarSystem::getPlanets方法的具体用法?C++ SolarSystem::getPlanets怎么用?C++ SolarSystem::getPlanets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolarSystem
的用法示例。
在下文中一共展示了SolarSystem::getPlanets方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectPlanet
// Choose a planet around a star given it's index in the planetary system.
// The planetary system is either the system of the selected object, or the
// nearest planetary system if no object is selected. If index is less than
// zero, pick the star. This function should probably be in celestiacore.cpp.
void Simulation::selectPlanet(int index)
{
if (index < 0)
{
if (selection.getType() == Selection::Type_Body)
{
PlanetarySystem* system = selection.body()->getSystem();
if (system != NULL)
setSelection(system->getStar());
}
}
else
{
const Star* star = NULL;
if (selection.getType() == Selection::Type_Star)
star = selection.star();
else if (selection.getType() == Selection::Type_Body)
star = getSun(selection.body());
SolarSystem* solarSystem = NULL;
if (star != NULL)
solarSystem = universe->getSolarSystem(star);
else
solarSystem = closestSolarSystem;
if (solarSystem != NULL &&
index < solarSystem->getPlanets()->getSystemSize())
{
setSelection(Selection(solarSystem->getPlanets()->getBody(index)));
}
}
}
示例2: LoadSolarSystemObjects
//.........这里部分代码省略.........
string::size_type next = nameList.find(':', startPos);
string::size_type length = string::npos;
if (next != string::npos)
{
length = next - startPos;
++next;
}
names.push_back(nameList.substr(startPos, length));
startPos = next;
}
}
string primaryName = names.front();
BodyType bodyType = UnknownBodyType;
if (itemType == "Body")
bodyType = NormalBody;
else if (itemType == "ReferencePoint")
bodyType = ReferencePoint;
else if (itemType == "SurfaceObject")
bodyType = SurfaceObject;
if (bodyType != UnknownBodyType)
{
//bool orbitsPlanet = false;
if (parent.star() != NULL)
{
SolarSystem* solarSystem = universe.getSolarSystem(parent.star());
if (solarSystem == NULL)
{
// No solar system defined for this star yet, so we need
// to create it.
solarSystem = universe.createSolarSystem(parent.star());
}
parentSystem = solarSystem->getPlanets();
}
else if (parent.body() != NULL)
{
// Parent is a planet or moon
parentSystem = parent.body()->getSatellites();
if (parentSystem == NULL)
{
// If the planet doesn't already have any satellites, we
// have to create a new planetary system for it.
parentSystem = new PlanetarySystem(parent.body());
parent.body()->setSatellites(parentSystem);
}
//orbitsPlanet = true;
}
else
{
errorMessagePrelude(tokenizer);
cerr << _("parent body '") << parentName << _("' of '") << primaryName << _("' not found.") << endl;
}
if (parentSystem != NULL)
{
Body* existingBody = parentSystem->find(primaryName);
if (existingBody)
{
if (disposition == AddObject)
{
errorMessagePrelude(tokenizer);
cerr << _("warning duplicate definition of ") <<
parentName << " " << primaryName << '\n';
}
else if (disposition == ReplaceObject)
示例3: createBody
static bool createBody(ParserContext* ctx, const xmlChar** att)
{
const xmlChar* name = NULL;
const xmlChar* parentName = NULL;
// Get the name and parent attributes
if (att != NULL)
{
for (int i = 0; att[i] != NULL; i += 2)
{
if (matchName(att[i], "name"))
name = att[i + 1];
else if (matchName(att[i], "parent"))
parentName = att[i + 1];
}
}
// Require that both are present
if (name == NULL)
{
return false;
}
else if (parentName == NULL)
{
return false;
}
bool orbitsPlanet = false;
Selection parent = ctx->universe->findPath(reinterpret_cast<const char*>(parentName), NULL, 0);
PlanetarySystem* parentSystem = NULL;
if (parent.star != NULL)
{
SolarSystem* solarSystem = ctx->universe->getSolarSystem(parent.star);
if (solarSystem == NULL)
{
// No solar system defined for this star yet, so we need
// to create it.
solarSystem = ctx->universe->createSolarSystem(parent.star);
}
parentSystem = solarSystem->getPlanets();
}
else if (parent.body != NULL)
{
// Parent is a planet or moon
parentSystem = parent.body->getSatellites();
if (parentSystem == NULL)
{
// If the planet doesn't already have any satellites, we
// have to create a new planetary system for it.
parentSystem = new PlanetarySystem(parent.body);
parent.body->setSatellites(parentSystem);
}
orbitsPlanet = true;
}
else
{
cout << "Parent body '" << parentName << "' of '" << name << "' not found.\n";
return false;
}
if (parentSystem != NULL)
{
ctx->body = new Body(parentSystem);
ctx->body->setName(reinterpret_cast<const char*>(name));
parentSystem->addBody(ctx->body);
return true;
}
return false;
}