2001-11-27 18:50:04 -07:00
|
|
|
// command.cpp
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001 Chris Laurel <claurel@shatters.net>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
|
2009-10-04 08:12:59 -06:00
|
|
|
#include "command.h"
|
2019-08-12 12:49:33 -06:00
|
|
|
#include <celengine/astro.h>
|
|
|
|
#include <celengine/asterism.h>
|
2002-04-01 23:39:26 -07:00
|
|
|
#include "execution.h"
|
2019-06-18 05:20:01 -06:00
|
|
|
#ifdef USE_GLCONTEXT
|
2019-08-12 12:49:33 -06:00
|
|
|
#include <celengine/glcontext.h>
|
2019-06-18 05:20:01 -06:00
|
|
|
#endif
|
2019-10-14 11:06:06 -06:00
|
|
|
#include <celestia/celestiacore.h>
|
2018-11-12 12:31:22 -07:00
|
|
|
#include <celengine/multitexture.h>
|
2019-10-19 06:38:04 -06:00
|
|
|
#include <celutil/filetype.h>
|
2009-10-04 08:12:59 -06:00
|
|
|
#include <celutil/util.h>
|
2018-10-06 12:46:30 -06:00
|
|
|
#include <celmath/mathlib.h>
|
2009-07-14 21:06:30 -06:00
|
|
|
#include <iostream>
|
2018-09-22 07:13:49 -06:00
|
|
|
#include <utility>
|
|
|
|
#include <algorithm>
|
2018-07-28 12:40:23 -06:00
|
|
|
#include <Eigen/Geometry>
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
using namespace std;
|
2018-07-28 12:40:23 -06:00
|
|
|
using namespace Eigen;
|
2019-05-16 15:51:11 -06:00
|
|
|
using namespace celmath;
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
|
2021-03-03 13:03:41 -07:00
|
|
|
double InstantaneousCommand::getDuration() const
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstantaneousCommand::process(ExecutionEnvironment& env, double /*t*/, double /*dt*/)
|
|
|
|
{
|
|
|
|
process(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
TimedCommand::TimedCommand(double duration) :
|
|
|
|
duration(duration)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
double TimedCommand::getDuration() const
|
|
|
|
{
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
////////////////
|
|
|
|
// Wait command: a no-op with no side effect other than its duration
|
|
|
|
|
|
|
|
CommandWait::CommandWait(double _duration) : TimedCommand(_duration)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
void CommandWait::process(ExecutionEnvironment& /*unused*/, double /*unused*/, double /*unused*/)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Select command: select a body
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandSelect::CommandSelect(string _target) : target(std::move(_target))
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSelect::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection sel = env.getSimulation()->findObjectFromPath(target);
|
|
|
|
env.getSimulation()->setSelection(sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Goto command: go to the selected body
|
|
|
|
|
|
|
|
CommandGoto::CommandGoto(double t,
|
|
|
|
double dist,
|
2021-03-03 13:03:41 -07:00
|
|
|
const Eigen::Vector3f &_up,
|
2008-02-08 14:46:02 -07:00
|
|
|
ObserverFrame::CoordinateSystem _upFrame) :
|
2021-03-03 13:03:41 -07:00
|
|
|
gotoTime(t),
|
|
|
|
distance(dist),
|
|
|
|
up(_up),
|
|
|
|
upFrame(_upFrame)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandGoto::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection sel = env.getSimulation()->getSelection();
|
|
|
|
env.getSimulation()->gotoSelection(gotoTime,
|
2009-07-21 22:53:15 -06:00
|
|
|
sel.radius() * distance,
|
2018-07-28 12:40:23 -06:00
|
|
|
up, upFrame);
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
2006-09-12 08:24:55 -06:00
|
|
|
// GotoLongLat command: go to the selected body and hover over
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
CommandGotoLongLat::CommandGotoLongLat(double t,
|
|
|
|
double dist,
|
|
|
|
float _longitude,
|
|
|
|
float _latitude,
|
2021-03-03 13:03:41 -07:00
|
|
|
const Eigen::Vector3f &_up) :
|
2001-11-27 18:50:04 -07:00
|
|
|
gotoTime(t),
|
|
|
|
distance(dist),
|
|
|
|
longitude(_longitude),
|
|
|
|
latitude(_latitude),
|
|
|
|
up(_up)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandGotoLongLat::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection sel = env.getSimulation()->getSelection();
|
|
|
|
env.getSimulation()->gotoSelectionLongLat(gotoTime,
|
2009-07-21 22:53:15 -06:00
|
|
|
sel.radius() * distance,
|
2001-11-27 18:50:04 -07:00
|
|
|
longitude, latitude,
|
2018-07-28 12:40:23 -06:00
|
|
|
up);
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-01 23:39:26 -07:00
|
|
|
/////////////////////////////
|
|
|
|
// GotoLocation
|
|
|
|
|
|
|
|
CommandGotoLocation::CommandGotoLocation(double t,
|
2018-07-28 12:40:23 -06:00
|
|
|
const Eigen::Vector3d& _translation,
|
|
|
|
const Eigen::Quaterniond& _rotation) :
|
2002-04-01 23:39:26 -07:00
|
|
|
gotoTime(t), translation(_translation), rotation(_rotation)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandGotoLocation::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2018-07-28 12:40:23 -06:00
|
|
|
UniversalCoord toPosition = UniversalCoord::CreateUly(translation);
|
|
|
|
env.getSimulation()->gotoLocation(toPosition, rotation, gotoTime);
|
2002-04-01 23:39:26 -07:00
|
|
|
}
|
|
|
|
|
Addition and overloading of cel script commands to work with cel:// urls.
New function:
** seturl
Arg: url (string)
Takes you to the location of the cel:// url.
Example:
seturl { url
"cel://Follow/Sol/2002-09-01T16:58:51.32378?x=AAAAAMCrktOdILb5/////w&y=CkxgAADEXts7E7HX/////w&z=VcpQAAAAAAAAAMIy/////w&ow=0.090610&ox=-0.494683&oy=0.860207&oz=-0.084397&select=Sol&fov=49.499992&ts=1.000000<d=0&rf=6043&lm=0"}
Overloaded functions:
** time
Arg: utc (string)
Sets the time according to the UTC date string in YYYY-MM-DDTHH:MM:SS.SSSSS
format.
Example:
time { utc "2002-09-01T16:58:51.32378" }
** setposition
Arg: x, y, z (string)
Sets the observer's position to the x, y, z coordinates encoded in Base64.
Example:
setposition {
x "AAAAAMCrktOdILb5/////w"
y "CkxgAADEXts7E7HX/////w"
z "VcpQAAAAAAAAAMIy/////w"
}
** setorientation
Arg: ow, ox, oy, oz (number)
Sets the observer's orientation to (ow, ox, oy, oz).
Example:
setorientation {
ow 0.090610
ox -0.494683
oy 0.860207
oz -0.084397
}
** gotoloc
Arg: time (number), x, y, z (string), ow, ox, oy, oz (number)
Travels to the coodinates (x, y, z) encoded in Base64 and sets the orientation
to (ow, ox, oy, oz) over time seconds.
Example:
gotoloc {
time 2
x "AAAAAMCrktOdILb5/////w"
y "CkxgAADEXts7E7HX/////w"
z "VcpQAAAAAAAAAMIy/////w"
ow 0.090610
ox -0.494683
oy 0.860207
oz -0.084397
}
2003-11-23 13:51:08 -07:00
|
|
|
/////////////////////////////
|
|
|
|
// SetUrl
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandSetUrl::CommandSetUrl(std::string _url) :
|
|
|
|
url(std::move(_url))
|
Addition and overloading of cel script commands to work with cel:// urls.
New function:
** seturl
Arg: url (string)
Takes you to the location of the cel:// url.
Example:
seturl { url
"cel://Follow/Sol/2002-09-01T16:58:51.32378?x=AAAAAMCrktOdILb5/////w&y=CkxgAADEXts7E7HX/////w&z=VcpQAAAAAAAAAMIy/////w&ow=0.090610&ox=-0.494683&oy=0.860207&oz=-0.084397&select=Sol&fov=49.499992&ts=1.000000<d=0&rf=6043&lm=0"}
Overloaded functions:
** time
Arg: utc (string)
Sets the time according to the UTC date string in YYYY-MM-DDTHH:MM:SS.SSSSS
format.
Example:
time { utc "2002-09-01T16:58:51.32378" }
** setposition
Arg: x, y, z (string)
Sets the observer's position to the x, y, z coordinates encoded in Base64.
Example:
setposition {
x "AAAAAMCrktOdILb5/////w"
y "CkxgAADEXts7E7HX/////w"
z "VcpQAAAAAAAAAMIy/////w"
}
** setorientation
Arg: ow, ox, oy, oz (number)
Sets the observer's orientation to (ow, ox, oy, oz).
Example:
setorientation {
ow 0.090610
ox -0.494683
oy 0.860207
oz -0.084397
}
** gotoloc
Arg: time (number), x, y, z (string), ow, ox, oy, oz (number)
Travels to the coodinates (x, y, z) encoded in Base64 and sets the orientation
to (ow, ox, oy, oz) over time seconds.
Example:
gotoloc {
time 2
x "AAAAAMCrktOdILb5/////w"
y "CkxgAADEXts7E7HX/////w"
z "VcpQAAAAAAAAAMIy/////w"
ow 0.090610
ox -0.494683
oy 0.860207
oz -0.084397
}
2003-11-23 13:51:08 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetUrl::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getCelestiaCore()->goToUrl(url);
|
|
|
|
}
|
2002-04-01 23:39:26 -07:00
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Center command: go to the selected body
|
|
|
|
|
|
|
|
CommandCenter::CommandCenter(double t) : centerTime(t)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandCenter::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->centerSelection(centerTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Follow command: follow the selected body
|
|
|
|
|
|
|
|
void CommandFollow::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->follow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Synchronous command: maintain the current position relative to the
|
|
|
|
// surface of the currently selected object.
|
|
|
|
|
|
|
|
void CommandSynchronous::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->geosynchronousFollow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 10:48:40 -07:00
|
|
|
////////////////
|
2006-09-12 08:24:55 -06:00
|
|
|
// Chase command:
|
2002-03-21 10:48:40 -07:00
|
|
|
|
|
|
|
void CommandChase::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->chase();
|
|
|
|
}
|
|
|
|
|
2003-02-21 01:39:10 -07:00
|
|
|
|
|
|
|
////////////////
|
2006-09-12 08:24:55 -06:00
|
|
|
// Track command:
|
2003-02-21 01:39:10 -07:00
|
|
|
|
|
|
|
void CommandTrack::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->setTrackedObject(env.getSimulation()->getSelection());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 10:48:40 -07:00
|
|
|
////////////////
|
|
|
|
// Lock command:
|
|
|
|
|
|
|
|
void CommandLock::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2002-04-01 23:39:26 -07:00
|
|
|
env.getSimulation()->phaseLock();
|
2002-03-21 10:48:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-01 23:39:26 -07:00
|
|
|
|
|
|
|
////////////////
|
2003-06-23 08:41:06 -06:00
|
|
|
// Setframe command
|
2002-04-01 23:39:26 -07:00
|
|
|
|
2008-02-08 14:46:02 -07:00
|
|
|
CommandSetFrame::CommandSetFrame(ObserverFrame::CoordinateSystem _coordSys,
|
2018-09-22 07:13:49 -06:00
|
|
|
string refName,
|
|
|
|
string targetName) :
|
|
|
|
coordSys(_coordSys), refObjectName(std::move(refName)), targetObjectName(std::move(targetName))
|
2002-04-01 23:39:26 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetFrame::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection ref = env.getSimulation()->findObjectFromPath(refObjectName);
|
|
|
|
Selection target;
|
2008-02-08 14:46:02 -07:00
|
|
|
if (coordSys == ObserverFrame::PhaseLock)
|
2002-04-01 23:39:26 -07:00
|
|
|
target = env.getSimulation()->findObjectFromPath(targetObjectName);
|
2008-02-08 14:46:02 -07:00
|
|
|
env.getSimulation()->setFrame(coordSys, ref, target);
|
2002-04-01 23:39:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-23 08:41:06 -06:00
|
|
|
////////////////
|
|
|
|
// SetSurface command: select an alternate surface to show
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandSetSurface::CommandSetSurface(string _surfaceName) :
|
|
|
|
surfaceName(std::move(_surfaceName))
|
2003-06-23 08:41:06 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetSurface::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->getActiveObserver()->setDisplayedSurface(surfaceName);
|
|
|
|
}
|
|
|
|
|
2002-04-01 23:39:26 -07:00
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
////////////////
|
2003-08-01 00:59:33 -06:00
|
|
|
// Cancel command: stop all motion, set the coordinate system to absolute,
|
|
|
|
// and cancel any tracking
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
void CommandCancel::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->cancelMotion();
|
2008-02-08 14:46:02 -07:00
|
|
|
env.getSimulation()->setFrame(ObserverFrame::Universal, Selection());
|
2003-08-01 00:59:33 -06:00
|
|
|
env.getSimulation()->setTrackedObject(Selection());
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Print command: print text to the console
|
|
|
|
|
2002-09-22 03:17:10 -06:00
|
|
|
CommandPrint::CommandPrint(string _text,
|
|
|
|
int horig, int vorig, int hoff, int voff,
|
2021-03-03 13:03:41 -07:00
|
|
|
float _duration) :
|
|
|
|
text(std::move(_text)),
|
|
|
|
hOrigin(horig), vOrigin(vorig),
|
|
|
|
hOffset(hoff), vOffset(voff),
|
|
|
|
duration(_duration)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandPrint::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2002-09-22 03:17:10 -06:00
|
|
|
env.showText(text, hOrigin, vOrigin, hOffset, vOffset, duration);
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Clear screen command: clear the console of all text
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
void CommandClearScreen::process(ExecutionEnvironment& /*unused*/)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-22 16:07:15 -07:00
|
|
|
////////////////
|
|
|
|
// Exit command: quit the program
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
void CommandExit::process(ExecutionEnvironment& /*unused*/)
|
2004-12-22 16:07:15 -07:00
|
|
|
{
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
////////////////
|
|
|
|
// Set time command: set the simulation time
|
|
|
|
|
|
|
|
CommandSetTime::CommandSetTime(double _jd) : jd(_jd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetTime::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->setTime(jd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Set time rate command: set the simulation time rate
|
|
|
|
|
|
|
|
CommandSetTimeRate::CommandSetTimeRate(double _rate) : rate(_rate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetTimeRate::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getSimulation()->setTimeScale(rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Change distance command: change the distance from the selected object
|
|
|
|
|
|
|
|
CommandChangeDistance::CommandChangeDistance(double _duration, double _rate) :
|
|
|
|
TimedCommand(_duration),
|
|
|
|
rate(_rate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
void CommandChangeDistance::process(ExecutionEnvironment& env, double /*unused*/, double dt)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
env.getSimulation()->changeOrbitDistance((float) (rate * dt));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
2018-07-28 12:40:23 -06:00
|
|
|
// Orbit command: rotate about the selected object
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2018-07-28 12:40:23 -06:00
|
|
|
CommandOrbit::CommandOrbit(double _duration, const Eigen::Vector3f& axis, float rate) :
|
2001-11-27 18:50:04 -07:00
|
|
|
TimedCommand(_duration),
|
|
|
|
spin(axis * rate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
void CommandOrbit::process(ExecutionEnvironment& env, double /*unused*/, double dt)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
2018-07-28 12:40:23 -06:00
|
|
|
float v = spin.norm();
|
2001-11-27 18:50:04 -07:00
|
|
|
if (v != 0.0f)
|
|
|
|
{
|
2018-07-28 12:40:23 -06:00
|
|
|
auto q = Quaternionf(AngleAxisf((float) (v * dt), (spin / v).normalized()));
|
|
|
|
env.getSimulation()->orbit(q);
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-28 12:40:23 -06:00
|
|
|
CommandRotate::CommandRotate(double _duration, const Eigen::Vector3f& axis, float rate) :
|
2001-11-27 18:50:04 -07:00
|
|
|
TimedCommand(_duration),
|
|
|
|
spin(axis * rate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
void CommandRotate::process(ExecutionEnvironment& env, double /*unused*/, double dt)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
2018-07-28 12:40:23 -06:00
|
|
|
float v = spin.norm();
|
2001-11-27 18:50:04 -07:00
|
|
|
if (v != 0.0f)
|
|
|
|
{
|
2018-07-28 12:40:23 -06:00
|
|
|
auto q = Quaternionf(AngleAxisf((float) (v * dt), (spin / v).normalized()));
|
|
|
|
env.getSimulation()->rotate(q);
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-28 12:40:23 -06:00
|
|
|
CommandMove::CommandMove(double _duration, const Eigen::Vector3d& _velocity) :
|
2001-11-27 18:50:04 -07:00
|
|
|
TimedCommand(_duration),
|
|
|
|
velocity(_velocity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
void CommandMove::process(ExecutionEnvironment& env, double /*unused*/, double dt)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
2018-07-28 12:40:23 -06:00
|
|
|
Eigen::Vector3d velocityKm = velocity * dt * astro::microLightYearsToKilometers(1.0);
|
2019-03-16 06:36:43 -06:00
|
|
|
env.getSimulation()->setObserverPosition(env.getSimulation()->getObserver().getPosition().offsetKm(velocityKm));
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Set position command: set the position of the camera
|
|
|
|
|
|
|
|
CommandSetPosition::CommandSetPosition(const UniversalCoord& uc) : pos(uc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetPosition::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2002-01-09 16:20:20 -07:00
|
|
|
env.getSimulation()->setObserverPosition(pos);
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Set orientation command: set the orientation of the camera
|
|
|
|
|
2018-07-28 12:40:23 -06:00
|
|
|
CommandSetOrientation::CommandSetOrientation(const Quaternionf& _orientation) :
|
|
|
|
orientation(_orientation)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetOrientation::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2018-07-28 12:40:23 -06:00
|
|
|
env.getSimulation()->setObserverOrientation(orientation);
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
|
|
|
|
2003-01-01 16:57:36 -07:00
|
|
|
////////////////
|
2003-01-03 04:08:44 -07:00
|
|
|
// Look back command: reverse observer orientation
|
2003-01-01 16:57:36 -07:00
|
|
|
|
2003-01-03 04:08:44 -07:00
|
|
|
void CommandLookBack::process(ExecutionEnvironment& env)
|
2003-01-01 16:57:36 -07:00
|
|
|
{
|
|
|
|
env.getSimulation()->reverseObserverOrientation();
|
|
|
|
}
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Set render flags command
|
|
|
|
|
2018-11-13 13:31:07 -07:00
|
|
|
CommandRenderFlags::CommandRenderFlags(uint64_t _setFlags, uint64_t _clearFlags) :
|
2001-11-27 18:50:04 -07:00
|
|
|
setFlags(_setFlags), clearFlags(_clearFlags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandRenderFlags::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Renderer* r = env.getRenderer();
|
2018-09-22 07:13:49 -06:00
|
|
|
if (r != nullptr)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
r->setRenderFlags(r->getRenderFlags() | setFlags);
|
|
|
|
r->setRenderFlags(r->getRenderFlags() & ~clearFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Set labels command
|
|
|
|
|
|
|
|
CommandLabels::CommandLabels(int _setFlags, int _clearFlags) :
|
|
|
|
setFlags(_setFlags), clearFlags(_clearFlags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandLabels::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Renderer* r = env.getRenderer();
|
2018-09-22 07:13:49 -06:00
|
|
|
if (r != nullptr)
|
2001-11-27 18:50:04 -07:00
|
|
|
{
|
|
|
|
r->setLabelMode(r->getLabelMode() | setFlags);
|
|
|
|
r->setLabelMode(r->getLabelMode() & ~clearFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-10 02:17:34 -07:00
|
|
|
//////////////////
|
|
|
|
// Set orbit flags command
|
|
|
|
|
|
|
|
CommandOrbitFlags::CommandOrbitFlags(int _setFlags, int _clearFlags) :
|
|
|
|
setFlags(_setFlags), clearFlags(_clearFlags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandOrbitFlags::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Renderer* r = env.getRenderer();
|
2018-09-22 07:13:49 -06:00
|
|
|
if (r != nullptr)
|
2004-12-10 02:17:34 -07:00
|
|
|
{
|
|
|
|
r->setOrbitMask(r->getOrbitMask() | setFlags);
|
|
|
|
r->setOrbitMask(r->getOrbitMask() & ~clearFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
////////////////
|
|
|
|
// Set limiting magnitude command
|
|
|
|
|
|
|
|
CommandSetVisibilityLimit::CommandSetVisibilityLimit(double mag) :
|
|
|
|
magnitude(mag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetVisibilityLimit::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2004-12-10 02:17:34 -07:00
|
|
|
env.getSimulation()->setFaintestVisible((float) magnitude);
|
2001-11-27 18:50:04 -07:00
|
|
|
}
|
2002-12-11 13:31:08 -07:00
|
|
|
////////////////
|
|
|
|
// Set FaintestAutoMag45deg command
|
|
|
|
|
|
|
|
CommandSetFaintestAutoMag45deg::CommandSetFaintestAutoMag45deg(double mag) :
|
|
|
|
magnitude(mag)
|
|
|
|
{
|
|
|
|
}
|
2002-03-21 10:48:40 -07:00
|
|
|
|
2002-12-11 13:31:08 -07:00
|
|
|
void CommandSetFaintestAutoMag45deg::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Renderer* r = env.getRenderer();
|
2018-09-22 07:13:49 -06:00
|
|
|
if (r != nullptr)
|
2004-12-10 02:17:34 -07:00
|
|
|
r->setFaintestAM45deg((float) magnitude);
|
2002-12-11 13:31:08 -07:00
|
|
|
}
|
2002-03-21 10:48:40 -07:00
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Set ambient light command
|
|
|
|
|
|
|
|
CommandSetAmbientLight::CommandSetAmbientLight(float level) :
|
|
|
|
lightLevel(level)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetAmbientLight::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Renderer* r = env.getRenderer();
|
2018-09-22 07:13:49 -06:00
|
|
|
if (r != nullptr)
|
2002-03-21 10:48:40 -07:00
|
|
|
r->setAmbientLightLevel(lightLevel);
|
|
|
|
}
|
2002-04-01 23:39:26 -07:00
|
|
|
|
2008-09-16 16:05:59 -06:00
|
|
|
////////////////
|
|
|
|
// Set galaxy light gain command
|
|
|
|
|
|
|
|
CommandSetGalaxyLightGain::CommandSetGalaxyLightGain(float gain) :
|
|
|
|
lightGain(gain)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-16 03:19:38 -07:00
|
|
|
void CommandSetGalaxyLightGain::process(ExecutionEnvironment& /* env */)
|
2008-09-16 16:05:59 -06:00
|
|
|
{
|
|
|
|
Galaxy::setLightGain(lightGain);
|
|
|
|
}
|
|
|
|
|
2002-04-01 23:39:26 -07:00
|
|
|
|
2002-04-25 21:49:59 -06:00
|
|
|
////////////////
|
|
|
|
// Set command
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandSet::CommandSet(std::string _name, double _value) :
|
|
|
|
name(std::move(_name)), value(_value)
|
2002-04-25 21:49:59 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSet::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
if (compareIgnoringCase(name, "MinOrbitSize") == 0)
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getRenderer() != nullptr)
|
2002-04-25 21:49:59 -06:00
|
|
|
env.getRenderer()->setMinimumOrbitSize((float) value);
|
|
|
|
}
|
|
|
|
else if (compareIgnoringCase(name, "AmbientLightLevel") == 0)
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getRenderer() != nullptr)
|
2002-04-25 21:49:59 -06:00
|
|
|
env.getRenderer()->setAmbientLightLevel((float) value);
|
|
|
|
}
|
2002-09-02 15:13:41 -06:00
|
|
|
else if (compareIgnoringCase(name, "FOV") == 0)
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getRenderer() != nullptr)
|
2003-02-12 03:35:50 -07:00
|
|
|
env.getSimulation()->getActiveObserver()->setFOV(degToRad((float) value));
|
2002-09-02 15:13:41 -06:00
|
|
|
}
|
2002-09-09 04:16:15 -06:00
|
|
|
else if (compareIgnoringCase(name, "StarDistanceLimit") == 0)
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getRenderer() != nullptr)
|
2002-09-09 04:16:15 -06:00
|
|
|
env.getRenderer()->setDistanceLimit((float) value);
|
|
|
|
}
|
2003-07-20 18:00:49 -06:00
|
|
|
else if (compareIgnoringCase(name, "StarStyle") == 0)
|
|
|
|
{
|
|
|
|
// The cast from double to an enum requires an intermediate cast to int
|
|
|
|
// Probably shouldn't be doing this at all, but other alternatives
|
|
|
|
// are more trouble than they're worth.
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getRenderer() != nullptr)
|
2003-07-20 18:00:49 -06:00
|
|
|
env.getRenderer()->setStarStyle((Renderer::StarStyle) (int) value);
|
|
|
|
}
|
2002-04-25 21:49:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-04 03:40:47 -07:00
|
|
|
////////////////
|
|
|
|
// Mark object command
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandMark::CommandMark(string _target,
|
2021-05-22 01:10:05 -06:00
|
|
|
celestia::MarkerRepresentation _rep,
|
2009-07-19 12:06:00 -06:00
|
|
|
bool _occludable) :
|
2018-09-22 07:13:49 -06:00
|
|
|
target(std::move(_target)),
|
2009-07-19 12:06:00 -06:00
|
|
|
rep(_rep),
|
|
|
|
occludable(_occludable)
|
2003-02-04 03:40:47 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMark::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection sel = env.getSimulation()->findObjectFromPath(target);
|
|
|
|
if (sel.empty())
|
|
|
|
return;
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getSimulation()->getUniverse() != nullptr)
|
2008-05-22 14:30:45 -06:00
|
|
|
{
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2009-07-19 12:06:00 -06:00
|
|
|
env.getSimulation()->getUniverse()->markObject(sel, rep, 1, occludable);
|
2008-05-22 14:30:45 -06:00
|
|
|
}
|
2003-02-04 03:40:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Unmark object command
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandUnmark::CommandUnmark(string _target) :
|
|
|
|
target(std::move(_target))
|
2003-02-04 03:40:47 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandUnmark::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection sel = env.getSimulation()->findObjectFromPath(target);
|
|
|
|
if (sel.empty())
|
|
|
|
return;
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getSimulation()->getUniverse() != nullptr)
|
2003-02-04 03:40:47 -07:00
|
|
|
env.getSimulation()->getUniverse()->unmarkObject(sel, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-02 01:57:38 -06:00
|
|
|
|
2003-07-20 13:41:13 -06:00
|
|
|
///////////////
|
|
|
|
// Unmarkall command - clear all current markers
|
|
|
|
|
|
|
|
void CommandUnmarkAll::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getSimulation()->getUniverse() != nullptr)
|
2003-07-20 13:41:13 -06:00
|
|
|
env.getSimulation()->getUniverse()->unmarkAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-02 01:57:38 -06:00
|
|
|
////////////////
|
|
|
|
// Preload textures command
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandPreloadTextures::CommandPreloadTextures(string _name) :
|
|
|
|
name(std::move(_name))
|
2002-05-02 01:57:38 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandPreloadTextures::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection target = env.getSimulation()->findObjectFromPath(name);
|
2018-09-22 07:13:49 -06:00
|
|
|
if (target.body() == nullptr)
|
2002-05-02 01:57:38 -06:00
|
|
|
return;
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getRenderer() != nullptr)
|
2003-06-25 11:40:24 -06:00
|
|
|
env.getRenderer()->loadTextures(target.body());
|
2002-05-02 01:57:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-22 16:07:15 -07:00
|
|
|
////////////////
|
|
|
|
// Capture command
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandCapture::CommandCapture(std::string _type,
|
|
|
|
std::string _filename) : type(std::move(_type)), filename(std::move(_filename))
|
2004-12-22 16:07:15 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-05-25 10:44:38 -06:00
|
|
|
void CommandCapture::process(ExecutionEnvironment& env)
|
2004-12-22 16:07:15 -07:00
|
|
|
{
|
2019-10-19 06:38:04 -06:00
|
|
|
ContentType _type = Content_Unknown;
|
|
|
|
if (type == "jpeg" || type == "jpg")
|
|
|
|
_type = Content_JPEG;
|
|
|
|
else if (type == "png")
|
|
|
|
_type = Content_PNG;
|
|
|
|
env.getCelestiaCore()->saveScreenShot(filename, _type);
|
2004-12-22 16:07:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-23 15:10:16 -06:00
|
|
|
////////////////
|
|
|
|
// Set texture resolution command
|
|
|
|
|
|
|
|
CommandSetTextureResolution::CommandSetTextureResolution(unsigned int _res) :
|
|
|
|
res(_res)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetTextureResolution::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (env.getRenderer() != nullptr)
|
2009-03-23 15:10:16 -06:00
|
|
|
{
|
|
|
|
env.getRenderer()->setResolution(res);
|
|
|
|
env.getCelestiaCore()->notifyWatchers(CelestiaCore::RenderFlagsChanged);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-22 16:07:15 -07:00
|
|
|
////////////////
|
2018-10-27 10:40:32 -06:00
|
|
|
// Set RenderPath command. Left for compatibility.
|
2004-12-22 16:07:15 -07:00
|
|
|
|
2019-06-18 05:20:01 -06:00
|
|
|
#ifdef USE_GLCONTEXT
|
2004-12-22 16:07:15 -07:00
|
|
|
CommandRenderPath::CommandRenderPath(GLContext::GLRenderPath _path) :
|
|
|
|
path(_path)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-30 12:57:10 -06:00
|
|
|
void CommandRenderPath::process(ExecutionEnvironment& /*env*/)
|
2004-12-22 16:07:15 -07:00
|
|
|
{
|
2018-10-27 10:40:32 -06:00
|
|
|
#if 0
|
2004-12-22 16:07:15 -07:00
|
|
|
GLContext* context = env.getRenderer()->getGLContext();
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
if (context != nullptr)
|
2004-12-22 16:07:15 -07:00
|
|
|
{
|
|
|
|
context->setRenderPath(path);
|
|
|
|
env.getCelestiaCore()->notifyWatchers(CelestiaCore::RenderFlagsChanged);
|
|
|
|
}
|
2018-10-27 10:40:32 -06:00
|
|
|
#endif
|
2004-12-22 16:07:15 -07:00
|
|
|
}
|
2019-06-18 05:20:01 -06:00
|
|
|
#endif
|
2004-12-22 16:07:15 -07:00
|
|
|
|
2002-05-02 01:57:38 -06:00
|
|
|
|
2008-09-16 16:05:59 -06:00
|
|
|
////////////////
|
|
|
|
// SplitView command
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandSplitView::CommandSplitView(unsigned int _view, string _splitType, double _splitPos) :
|
2008-09-16 16:05:59 -06:00
|
|
|
view(_view),
|
2018-09-22 07:13:49 -06:00
|
|
|
splitType(std::move(_splitType)),
|
2008-09-16 16:05:59 -06:00
|
|
|
splitPos(_splitPos)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSplitView::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2019-10-17 13:19:12 -06:00
|
|
|
vector<Observer*> observer_list = env.getCelestiaCore()->getObservers();
|
2008-09-16 16:05:59 -06:00
|
|
|
if (view >= 1 && view <= observer_list.size())
|
|
|
|
{
|
|
|
|
Observer* obs = observer_list[view - 1];
|
2019-10-17 13:19:12 -06:00
|
|
|
View* view = env.getCelestiaCore()->getViewByObserver(obs);
|
2008-09-16 16:05:59 -06:00
|
|
|
View::Type type = (compareIgnoringCase(splitType, "h") == 0) ? View::HorizontalSplit : View::VerticalSplit;
|
|
|
|
env.getCelestiaCore()->splitView(type, view, (float)splitPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// DeleteView command
|
|
|
|
|
|
|
|
CommandDeleteView::CommandDeleteView(unsigned int _view) :
|
|
|
|
view(_view)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandDeleteView::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2019-10-17 13:19:12 -06:00
|
|
|
vector<Observer*> observer_list = env.getCelestiaCore()->getObservers();
|
2008-09-16 16:05:59 -06:00
|
|
|
|
|
|
|
if (view >= 1 && view <= observer_list.size())
|
|
|
|
{
|
|
|
|
Observer* obs = observer_list[view - 1];
|
2019-10-17 13:19:12 -06:00
|
|
|
View* view = env.getCelestiaCore()->getViewByObserver(obs);
|
2008-09-16 16:05:59 -06:00
|
|
|
env.getCelestiaCore()->deleteView(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// SingleView command
|
|
|
|
|
|
|
|
void CommandSingleView::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2019-10-17 13:19:12 -06:00
|
|
|
View* view = env.getCelestiaCore()->getViewByObserver(env.getSimulation()->getActiveObserver());
|
2008-09-16 16:05:59 -06:00
|
|
|
env.getCelestiaCore()->singleView(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// SetActiveView command
|
|
|
|
|
|
|
|
CommandSetActiveView::CommandSetActiveView(unsigned int _view) :
|
|
|
|
view(_view)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetActiveView::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2019-10-17 13:19:12 -06:00
|
|
|
vector<Observer*> observer_list = env.getCelestiaCore()->getObservers();
|
2008-09-16 16:05:59 -06:00
|
|
|
|
|
|
|
if (view >= 1 && view <= observer_list.size())
|
|
|
|
{
|
|
|
|
Observer* obs = observer_list[view - 1];
|
2019-10-17 13:19:12 -06:00
|
|
|
View* view = env.getCelestiaCore()->getViewByObserver(obs);
|
2008-09-16 16:05:59 -06:00
|
|
|
env.getCelestiaCore()->setActiveView(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// SetRadius command
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
CommandSetRadius::CommandSetRadius(string _object, double _radius) :
|
|
|
|
object(std::move(_object)),
|
2008-09-16 16:05:59 -06:00
|
|
|
radius(_radius)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetRadius::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection sel = env.getSimulation()->findObjectFromPath(object);
|
2018-09-22 07:13:49 -06:00
|
|
|
if (sel.body() != nullptr)
|
2008-09-16 16:05:59 -06:00
|
|
|
{
|
|
|
|
Body* body = sel.body();
|
|
|
|
float iradius = body->getRadius();
|
|
|
|
if ((radius > 0))
|
|
|
|
{
|
|
|
|
body->setSemiAxes(body->getSemiAxes() * ((float) radius / iradius));
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
if (body->getRings() != nullptr)
|
2008-09-16 16:05:59 -06:00
|
|
|
{
|
|
|
|
RingSystem rings(0.0f, 0.0f);
|
|
|
|
rings = *body->getRings();
|
|
|
|
float inner = rings.innerRadius;
|
|
|
|
float outer = rings.outerRadius;
|
|
|
|
rings.innerRadius = inner * (float) radius / iradius;
|
|
|
|
rings.outerRadius = outer * (float) radius / iradius;
|
|
|
|
body->setRings(rings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// SetLineColor command
|
|
|
|
|
2021-03-03 13:03:41 -07:00
|
|
|
CommandSetLineColor::CommandSetLineColor(string _item, const Color& _color) :
|
2018-09-22 07:13:49 -06:00
|
|
|
item(std::move(_item)),
|
2008-09-16 16:05:59 -06:00
|
|
|
color(_color)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-10-17 13:19:12 -06:00
|
|
|
void CommandSetLineColor::process(ExecutionEnvironment& env)
|
2008-09-16 16:05:59 -06:00
|
|
|
{
|
2019-10-17 13:19:12 -06:00
|
|
|
auto &LineColorMap = env.getCelestiaCore()->scriptMaps()->LineColorMap;
|
|
|
|
if (LineColorMap.count(item) == 0)
|
2008-09-16 16:05:59 -06:00
|
|
|
{
|
|
|
|
cerr << "Unknown line style: " << item << "\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-17 13:19:12 -06:00
|
|
|
*LineColorMap[item] = color;
|
2008-09-16 16:05:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// SetLabelColor command
|
|
|
|
|
2021-03-03 13:03:41 -07:00
|
|
|
CommandSetLabelColor::CommandSetLabelColor(string _item, const Color& _color) :
|
2018-09-22 07:13:49 -06:00
|
|
|
item(std::move(_item)),
|
2008-09-16 16:05:59 -06:00
|
|
|
color(_color)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-10-17 13:19:12 -06:00
|
|
|
void CommandSetLabelColor::process(ExecutionEnvironment& env)
|
2008-09-16 16:05:59 -06:00
|
|
|
{
|
2019-10-17 13:19:12 -06:00
|
|
|
auto &LabelColorMap = env.getCelestiaCore()->scriptMaps()->LabelColorMap;
|
|
|
|
if (LabelColorMap.count(item) == 0)
|
2008-09-16 16:05:59 -06:00
|
|
|
{
|
|
|
|
cerr << "Unknown label style: " << item << "\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-17 13:19:12 -06:00
|
|
|
*LabelColorMap[item] = color;
|
2008-09-16 16:05:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-01 12:18:35 -07:00
|
|
|
////////////////
|
|
|
|
// SetTextColor command
|
|
|
|
|
2021-03-03 13:03:41 -07:00
|
|
|
CommandSetTextColor::CommandSetTextColor(const Color& _color) :
|
2009-11-01 12:18:35 -07:00
|
|
|
color(_color)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetTextColor::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getCelestiaCore()->setTextColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-01 23:39:26 -07:00
|
|
|
///////////////
|
|
|
|
// Repeat command
|
|
|
|
|
|
|
|
RepeatCommand::RepeatCommand(CommandSequence* _body, int _repeatCount) :
|
|
|
|
body(_body),
|
2018-09-22 07:13:49 -06:00
|
|
|
repeatCount(_repeatCount)
|
2002-04-01 23:39:26 -07:00
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
for (const auto b : *body)
|
2002-04-01 23:39:26 -07:00
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
bodyDuration += b->getDuration();
|
2002-04-01 23:39:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RepeatCommand::~RepeatCommand()
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
|
|
|
|
delete execution;
|
2002-04-01 23:39:26 -07:00
|
|
|
// delete body;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepeatCommand::process(ExecutionEnvironment& env, double t, double dt)
|
|
|
|
{
|
|
|
|
double t0 = t - dt;
|
2018-09-22 07:13:49 -06:00
|
|
|
auto loop0 = (int) (t0 / bodyDuration);
|
|
|
|
auto loop1 = (int) (t / bodyDuration);
|
2002-04-01 23:39:26 -07:00
|
|
|
|
|
|
|
// TODO: This is bogus . . . should not be storing a reference to an
|
|
|
|
// execution environment.
|
2018-09-22 07:13:49 -06:00
|
|
|
if (execution == nullptr)
|
2002-04-01 23:39:26 -07:00
|
|
|
execution = new Execution(*body, env);
|
|
|
|
|
|
|
|
if (loop0 == loop1)
|
|
|
|
{
|
|
|
|
execution->tick(dt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double timeLeft = (loop0 + 1) * bodyDuration - t0;
|
|
|
|
execution->tick(timeLeft);
|
|
|
|
|
|
|
|
for (int i = loop0 + 1; i < loop1; i++)
|
|
|
|
{
|
|
|
|
execution->reset(*body);
|
|
|
|
execution->tick(bodyDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
execution->reset(*body);
|
|
|
|
execution->tick(t - loop1 * bodyDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 16:09:09 -06:00
|
|
|
double RepeatCommand::getDuration() const
|
2002-04-01 23:39:26 -07:00
|
|
|
{
|
|
|
|
return bodyDuration * repeatCount;
|
|
|
|
}
|
2008-02-29 14:43:30 -07:00
|
|
|
|
2017-03-28 14:17:52 -06:00
|
|
|
// ScriptImage command
|
2019-10-08 14:00:19 -06:00
|
|
|
CommandScriptImage::CommandScriptImage(float _duration, float _fadeafter,
|
|
|
|
float _xoffset, float _yoffset,
|
2021-03-03 13:03:41 -07:00
|
|
|
const fs::path &_filename,
|
2019-10-08 14:00:19 -06:00
|
|
|
bool _fitscreen,
|
|
|
|
array<Color,4> &_colors) :
|
2017-03-28 14:17:52 -06:00
|
|
|
duration(_duration),
|
2019-10-08 14:00:19 -06:00
|
|
|
fadeafter(_fadeafter),
|
2017-03-28 14:17:52 -06:00
|
|
|
xoffset(_xoffset),
|
|
|
|
yoffset(_yoffset),
|
2021-03-03 13:03:41 -07:00
|
|
|
filename(_filename),
|
2017-03-28 14:17:52 -06:00
|
|
|
fitscreen(_fitscreen)
|
|
|
|
{
|
2019-10-08 14:00:19 -06:00
|
|
|
copy(_colors.begin(), _colors.end(), colors.begin());
|
2017-03-28 14:17:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandScriptImage::process(ExecutionEnvironment& env)
|
|
|
|
{
|
2019-10-08 14:00:19 -06:00
|
|
|
auto image = unique_ptr<OverlayImage>(new OverlayImage(filename, env.getRenderer()));
|
|
|
|
image->setDuration(duration);
|
|
|
|
image->setFadeAfter(fadeafter);
|
|
|
|
image->setOffset(xoffset, yoffset);
|
|
|
|
image->setColor(colors);
|
|
|
|
image->fitScreen(fitscreen);
|
|
|
|
env.getCelestiaCore()->setScriptImage(std::move(image));
|
2017-03-28 14:17:52 -06:00
|
|
|
}
|
2008-02-29 14:43:30 -07:00
|
|
|
|
2017-03-28 14:17:52 -06:00
|
|
|
// Verbosity command
|
2018-03-11 07:12:58 -06:00
|
|
|
CommandVerbosity::CommandVerbosity(int _level) :
|
2017-03-28 14:17:52 -06:00
|
|
|
level(_level)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandVerbosity::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getCelestiaCore()->setHudDetail(level);
|
|
|
|
}
|
2008-02-29 14:43:30 -07:00
|
|
|
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
///////////////
|
|
|
|
//
|
2008-02-29 14:43:30 -07:00
|
|
|
|
|
|
|
void CommandConstellations::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Universe* u = env.getSimulation()->getUniverse();
|
2021-03-03 13:03:41 -07:00
|
|
|
if (u == nullptr)
|
2018-09-22 07:13:49 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
AsterismList& asterisms = *u->getAsterisms();
|
|
|
|
for (const auto ast : asterisms)
|
2008-02-29 14:43:30 -07:00
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (flags.none)
|
2008-02-29 14:43:30 -07:00
|
|
|
{
|
2021-03-03 13:03:41 -07:00
|
|
|
ast->setActive(false);
|
2018-09-22 07:13:49 -06:00
|
|
|
}
|
|
|
|
else if (flags.all)
|
|
|
|
{
|
2021-03-03 13:03:41 -07:00
|
|
|
ast->setActive(true);
|
2018-09-22 07:13:49 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto name = ast->getName(false);
|
|
|
|
auto it = std::find_if(constellations.begin(), constellations.end(),
|
|
|
|
[&name](Cons& c){ return compareIgnoringCase(c.name, name) == 0; });
|
|
|
|
|
|
|
|
if (it != constellations.end())
|
2021-03-03 13:03:41 -07:00
|
|
|
ast->setActive(it->active);
|
2008-02-29 14:43:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 13:03:41 -07:00
|
|
|
void CommandConstellations::setValues(string_view _cons, bool act)
|
2008-02-29 14:43:30 -07:00
|
|
|
{
|
2018-03-11 07:12:58 -06:00
|
|
|
// ignore all above 99 constellations
|
2018-09-22 07:13:49 -06:00
|
|
|
if (constellations.size() == MAX_CONSTELLATIONS)
|
2018-03-11 07:12:58 -06:00
|
|
|
return;
|
|
|
|
|
2021-03-03 13:03:41 -07:00
|
|
|
string cons(_cons);
|
2018-09-22 07:13:49 -06:00
|
|
|
std::replace(cons.begin(), cons.end(), '_', ' ');
|
2008-02-29 14:43:30 -07:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
auto it = std::find_if(constellations.begin(), constellations.end(),
|
2021-03-03 13:03:41 -07:00
|
|
|
[&cons](Cons& c){ return compareIgnoringCase(c.name, cons) == 0; });
|
2008-02-29 14:43:30 -07:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
if (it != constellations.end())
|
|
|
|
it->active = act;
|
|
|
|
else
|
2021-03-03 13:03:41 -07:00
|
|
|
constellations.emplace_back(cons, act); // If not found then add a new constellation
|
2008-02-29 14:43:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CommandConstellationColor::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Universe* u = env.getSimulation()->getUniverse();
|
2021-03-03 13:03:41 -07:00
|
|
|
if (u == nullptr)
|
2018-09-22 07:13:49 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
AsterismList& asterisms = *u->getAsterisms();
|
|
|
|
for (const auto ast : asterisms)
|
2008-02-29 14:43:30 -07:00
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (flags.none)
|
2008-02-29 14:43:30 -07:00
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
ast->unsetOverrideColor();
|
|
|
|
}
|
|
|
|
else if (flags.all)
|
|
|
|
{
|
|
|
|
ast->setOverrideColor(rgb);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto name = ast->getName(false);
|
|
|
|
auto it = std::find_if(constellations.begin(), constellations.end(),
|
|
|
|
[&name](string& c){ return compareIgnoringCase(c, name) == 0; });
|
|
|
|
|
|
|
|
if (it != constellations.end())
|
2008-02-29 14:43:30 -07:00
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
if (flags.unset)
|
|
|
|
ast->unsetOverrideColor();
|
|
|
|
else
|
|
|
|
ast->setOverrideColor(rgb);
|
2018-03-11 07:12:58 -06:00
|
|
|
}
|
2008-02-29 14:43:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CommandConstellationColor::setColor(float r, float g, float b)
|
|
|
|
{
|
|
|
|
rgb = Color(r, g, b);
|
2018-09-22 07:13:49 -06:00
|
|
|
flags.unset = false;
|
2008-02-29 14:43:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CommandConstellationColor::unsetColor()
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
flags.unset = true;
|
2008-02-29 14:43:30 -07:00
|
|
|
}
|
|
|
|
|
2021-03-03 13:03:41 -07:00
|
|
|
void CommandConstellationColor::setConstellations(string_view _cons)
|
2008-02-29 14:43:30 -07:00
|
|
|
{
|
2018-03-11 07:12:58 -06:00
|
|
|
// ignore all above 99 constellations
|
2018-09-22 07:13:49 -06:00
|
|
|
if (constellations.size() == MAX_CONSTELLATIONS)
|
|
|
|
return;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2021-03-03 13:03:41 -07:00
|
|
|
string cons(_cons);
|
2018-09-22 07:13:49 -06:00
|
|
|
std::replace(cons.begin(), cons.end(), '_', ' ');
|
2008-02-29 14:43:30 -07:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
// If not found then add a new constellation
|
|
|
|
if (std::none_of(constellations.begin(), constellations.end(),
|
|
|
|
[&cons](string& c){ return compareIgnoringCase(c, cons) == 0; }))
|
|
|
|
constellations.push_back(cons);
|
2008-02-29 14:43:30 -07:00
|
|
|
}
|
2018-07-13 09:50:44 -06:00
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// SetWindowBordersVisible command
|
|
|
|
void CommandSetWindowBordersVisible::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
env.getCelestiaCore()->setFramesVisible(visible);
|
|
|
|
}
|
2018-11-12 12:31:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// SetRingsTexture command
|
|
|
|
CommandSetRingsTexture::CommandSetRingsTexture(string _object,
|
|
|
|
string _textureName,
|
|
|
|
string _path) :
|
|
|
|
object(std::move(_object)),
|
|
|
|
textureName(std::move(_textureName)),
|
|
|
|
path(std::move(_path))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandSetRingsTexture::process(ExecutionEnvironment& env)
|
|
|
|
{
|
|
|
|
Selection sel = env.getSimulation()->findObjectFromPath(object);
|
|
|
|
if (sel.body() != nullptr &&
|
|
|
|
sel.body()->getRings() != nullptr &&
|
|
|
|
!textureName.empty())
|
|
|
|
{
|
|
|
|
sel.body()->getRings()->texture = MultiResTexture(textureName, path);
|
|
|
|
}
|
|
|
|
}
|
2018-11-17 10:53:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
2018-11-21 10:02:02 -07:00
|
|
|
// LoadFragment command
|
|
|
|
CommandLoadFragment::CommandLoadFragment(string _type, string _fragment, string _dir) :
|
|
|
|
type(std::move(_type)),
|
|
|
|
fragment(std::move(_fragment)),
|
|
|
|
dir(std::move(_dir))
|
2018-11-17 10:53:36 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:02:02 -07:00
|
|
|
void CommandLoadFragment::process(ExecutionEnvironment& env)
|
2018-11-17 10:53:36 -07:00
|
|
|
{
|
|
|
|
Universe* u = env.getSimulation()->getUniverse();
|
|
|
|
if (u == nullptr)
|
|
|
|
return;
|
2018-11-21 10:02:02 -07:00
|
|
|
|
2018-11-17 10:53:36 -07:00
|
|
|
istringstream in(fragment);
|
2018-11-21 10:02:02 -07:00
|
|
|
if (compareIgnoringCase(type, "ssc") == 0)
|
|
|
|
{
|
|
|
|
LoadSolarSystemObjects(in, *u, dir);
|
|
|
|
}
|
|
|
|
else if (compareIgnoringCase(type, "stc") == 0)
|
|
|
|
{
|
|
|
|
u->getStarCatalog()->load(in, dir);
|
|
|
|
}
|
|
|
|
else if (compareIgnoringCase(type, "dsc") == 0)
|
|
|
|
{
|
|
|
|
u->getDSOCatalog()->load(in, dir);
|
|
|
|
}
|
2018-11-17 10:53:36 -07:00
|
|
|
}
|