Added move and rotate commands; converted to use new ExecutionEnvironment class.

This commit is contained in:
Chris Laurel 2001-04-27 07:05:38 +00:00
parent 571178c14a
commit 2b56c48c59
3 changed files with 153 additions and 60 deletions

View file

@ -12,6 +12,7 @@
#include <algorithm>
#include <sstream>
#include "util.h"
#include "mathlib.h"
#include "astro.h"
#include "cmdparser.h"
@ -136,7 +137,9 @@ Command* CommandParser::parseCommand()
{
double t = 1.0;
paramList->getNumber("time", t);
cmd = new CommandGoto(t);
double distance = 5.0;
paramList->getNumber("distance", distance);
cmd = new CommandGoto(t, distance);
}
else if (commandName == "center")
{
@ -192,7 +195,27 @@ Command* CommandParser::parseCommand()
paramList->getVector("axis", axis);
cmd = new CommandOrbit(duration,
Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
(float) rate);
(float) degToRad(rate));
}
else if (commandName == "rotate")
{
double rate = 0.0;
double duration = 1.0;
Vec3d axis;
paramList->getNumber("duration", duration);
paramList->getNumber("rate", rate);
paramList->getVector("axis", axis);
cmd = new CommandRotate(duration,
Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
(float) degToRad(rate));
}
else if (commandName == "move")
{
Vec3d velocity;
double duration;
paramList->getNumber("duration", duration);
paramList->getVector("velocity", velocity);
cmd = new CommandMove(duration, velocity * astro::kilometersToLightYears(1.0));
}
else if (commandName == "setposition")
{
@ -202,6 +225,15 @@ Command* CommandParser::parseCommand()
cmd = new CommandSetPosition(astro::universalPosition(Point3d(offset.x, offset.y, offset.z),
Point3f((float) base.x, (float) base.y, (float) base.z)));
}
else if (commandName == "setorientation")
{
Vec3d axis;
double angle;
paramList->getNumber("angle", angle);
paramList->getVector("axis", axis);
cmd = new CommandSetOrientation(Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
(float) degToRad(angle));
}
else if (commandName == "renderflags")
{
int setFlags = 0;

View file

@ -8,6 +8,7 @@
// of the License, or (at your option) any later version.
#include <iostream>
#include "astro.h"
#include "command.h"
using namespace std;
@ -24,7 +25,7 @@ CommandWait::~CommandWait()
{
}
void CommandWait::process(Simulation* sim, Renderer* renderer, double t, double dt)
void CommandWait::process(ExecutionEnvironment& env, double t, double dt)
{
}
@ -40,10 +41,10 @@ CommandSelect::~CommandSelect()
{
}
void CommandSelect::process(Simulation* sim, Renderer* renderer)
void CommandSelect::process(ExecutionEnvironment& env)
{
Selection sel = sim->findObject(target);
sim->setSelection(sel);
Selection sel = env.getSimulation()->findObject(target);
env.getSimulation()->setSelection(sel);
}
@ -51,7 +52,7 @@ void CommandSelect::process(Simulation* sim, Renderer* renderer)
////////////////
// Goto command: go to the selected body
CommandGoto::CommandGoto(double t) : gotoTime(t)
CommandGoto::CommandGoto(double t, double dist) : gotoTime(t), distance(dist)
{
}
@ -59,9 +60,11 @@ CommandGoto::~CommandGoto()
{
}
void CommandGoto::process(Simulation* sim, Renderer* renderer)
void CommandGoto::process(ExecutionEnvironment& env)
{
sim->gotoSelection(gotoTime);
Selection sel = env.getSimulation()->getSelection();
env.getSimulation()->gotoSelection(gotoTime,
astro::kilometersToLightYears(sel.radius() * distance));
}
@ -77,9 +80,9 @@ CommandCenter::~CommandCenter()
{
}
void CommandCenter::process(Simulation* sim, Renderer* renderer)
void CommandCenter::process(ExecutionEnvironment& env)
{
sim->centerSelection(centerTime);
env.getSimulation()->centerSelection(centerTime);
}
@ -90,9 +93,9 @@ CommandFollow::CommandFollow()
{
}
void CommandFollow::process(Simulation* sim, Renderer* renderer)
void CommandFollow::process(ExecutionEnvironment& env)
{
sim->follow();
env.getSimulation()->follow();
}
@ -103,9 +106,9 @@ CommandCancel::CommandCancel()
{
}
void CommandCancel::process(Simulation* sim, Renderer* renderer)
void CommandCancel::process(ExecutionEnvironment& env)
{
sim->cancelMotion();
env.getSimulation()->cancelMotion();
}
@ -116,8 +119,9 @@ CommandPrint::CommandPrint(string _text) : text(_text)
{
}
void CommandPrint::process(Simulation* sim, Renderer* renderer)
void CommandPrint::process(ExecutionEnvironment& env)
{
env.showText(text);
}
@ -128,7 +132,7 @@ CommandClearScreen::CommandClearScreen()
{
}
void CommandClearScreen::process(Simulation* sim, Renderer* renderer)
void CommandClearScreen::process(ExecutionEnvironment& env)
{
}
@ -140,9 +144,9 @@ CommandSetTime::CommandSetTime(double _jd) : jd(_jd)
{
}
void CommandSetTime::process(Simulation* sim, Renderer* renderer)
void CommandSetTime::process(ExecutionEnvironment& env)
{
sim->setTime(jd);
env.getSimulation()->setTime(jd);
}
@ -154,9 +158,9 @@ CommandSetTimeRate::CommandSetTimeRate(double _rate) : rate(_rate)
{
}
void CommandSetTimeRate::process(Simulation* sim, Renderer* renderer)
void CommandSetTimeRate::process(ExecutionEnvironment& env)
{
sim->setTimeScale(rate);
env.getSimulation()->setTimeScale(rate);
}
@ -169,9 +173,9 @@ CommandChangeDistance::CommandChangeDistance(double _duration, double _rate) :
{
}
void CommandChangeDistance::process(Simulation* sim, Renderer* renderer, double t, double dt)
void CommandChangeDistance::process(ExecutionEnvironment& env, double t, double dt)
{
sim->changeOrbitDistance((float) (rate * dt));
env.getSimulation()->changeOrbitDistance((float) (rate * dt));
}
@ -184,18 +188,49 @@ CommandOrbit::CommandOrbit(double _duration, const Vec3f& axis, float rate) :
{
}
void CommandOrbit::process(Simulation* sim, Renderer* rend, double t, double dt)
void CommandOrbit::process(ExecutionEnvironment& env, double t, double dt)
{
float v = spin.length();
if (v != 0.0f)
{
Quatf q;
q.setAxisAngle(spin / v, (float) (v * dt));
sim->orbit(q);
env.getSimulation()->orbit(q);
}
}
CommandRotate::CommandRotate(double _duration, const Vec3f& axis, float rate) :
TimedCommand(_duration),
spin(axis * rate)
{
}
void CommandRotate::process(ExecutionEnvironment& env, double t, double dt)
{
float v = spin.length();
if (v != 0.0f)
{
Quatf q;
q.setAxisAngle(spin / v, (float) (v * dt));
env.getSimulation()->rotate(q);
}
}
CommandMove::CommandMove(double _duration, const Vec3d& _velocity) :
TimedCommand(_duration),
velocity(_velocity)
{
}
void CommandMove::process(ExecutionEnvironment& env, double t, double dt)
{
Observer obs = env.getSimulation()->getObserver();
obs.setPosition(obs.getPosition() + (velocity * dt));
}
////////////////
// Set position command: set the position of the camera
@ -203,9 +238,9 @@ CommandSetPosition::CommandSetPosition(const UniversalCoord& uc) : pos(uc)
{
}
void CommandSetPosition::process(Simulation* sim, Renderer* renderer)
void CommandSetPosition::process(ExecutionEnvironment& env)
{
sim->getObserver().setPosition(pos);
env.getSimulation()->getObserver().setPosition(pos);
}
@ -217,11 +252,12 @@ CommandSetOrientation::CommandSetOrientation(const Vec3f& _axis, float _angle) :
{
}
void CommandSetOrientation::process(Simulation* sim, Renderer* renderer)
void CommandSetOrientation::process(ExecutionEnvironment& env)
{
Quatf q(1);
q.setAxisAngle(axis, angle);
sim->getObserver().setOrientation(q);
env.getSimulation()->getObserver().setOrientation(q);
// env.getSimulation()->setOrientation(q);
}
@ -233,12 +269,13 @@ CommandRenderFlags::CommandRenderFlags(int _setFlags, int _clearFlags) :
{
}
void CommandRenderFlags::process(Simulation* sim, Renderer* renderer)
void CommandRenderFlags::process(ExecutionEnvironment& env)
{
if (renderer != NULL)
Renderer* r = env.getRenderer();
if (r != NULL)
{
renderer->setRenderFlags(renderer->getRenderFlags() | setFlags);
renderer->setRenderFlags(renderer->getRenderFlags() & ~clearFlags);
r->setRenderFlags(r->getRenderFlags() | setFlags);
r->setRenderFlags(r->getRenderFlags() & ~clearFlags);
}
}
@ -251,11 +288,12 @@ CommandLabels::CommandLabels(int _setFlags, int _clearFlags) :
{
}
void CommandLabels::process(Simulation* sim, Renderer* renderer)
void CommandLabels::process(ExecutionEnvironment& env)
{
if (renderer != NULL)
Renderer* r = env.getRenderer();
if (r != NULL)
{
renderer->setLabelMode(renderer->getLabelMode() | setFlags);
renderer->setLabelMode(renderer->getLabelMode() & ~clearFlags);
r->setLabelMode(r->getLabelMode() | setFlags);
r->setLabelMode(r->getLabelMode() & ~clearFlags);
}
}

View file

@ -11,15 +11,15 @@
#define _COMMAND_H_
#include <iostream>
#include "simulation.h"
#include "render.h"
#include "execenv.h"
class Command
{
public:
Command() {};
virtual ~Command() {};
virtual void process(Simulation* sim, Renderer* renderer, double t, double dt) = 0;
virtual void process(ExecutionEnvironment&, double t, double dt) = 0;
virtual double getDuration() const = 0;
};
@ -32,10 +32,10 @@ class InstantaneousCommand : public Command
InstantaneousCommand() {};
virtual ~InstantaneousCommand() {};
virtual double getDuration() const { return 0.0; };
virtual void process(Simulation* sim, Renderer* renderer) = 0;
void process(Simulation* sim, Renderer* renderer, double t, double dt)
virtual void process(ExecutionEnvironment&) = 0;
void process(ExecutionEnvironment& env, double t, double dt)
{
process(sim, renderer);
process(env);
};
};
@ -57,7 +57,7 @@ class CommandWait : public TimedCommand
public:
CommandWait(double _duration);
~CommandWait();
void process(Simulation* sim, Renderer* renderer, double t, double dt);
void process(ExecutionEnvironment&, double t, double dt);
};
@ -66,7 +66,7 @@ class CommandSelect : public InstantaneousCommand
public:
CommandSelect(std::string _target);
~CommandSelect();
void process(Simulation* sim, Renderer* renderer);
void process(ExecutionEnvironment&);
private:
string target;
@ -76,12 +76,13 @@ class CommandSelect : public InstantaneousCommand
class CommandGoto : public InstantaneousCommand
{
public:
CommandGoto(double t);
CommandGoto(double t, double dist);
~CommandGoto();
void process(Simulation* sim, Renderer* renderer);
void process(ExecutionEnvironment&);
private:
double gotoTime;
double distance;
};
@ -90,7 +91,7 @@ class CommandCenter : public InstantaneousCommand
public:
CommandCenter(double t);
~CommandCenter();
void process(Simulation* sim, Renderer* renderer);
void process(ExecutionEnvironment&);
private:
double centerTime;
@ -101,7 +102,7 @@ class CommandFollow : public InstantaneousCommand
{
public:
CommandFollow();
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
int dummy; // Keep the class from having zero size
@ -112,7 +113,7 @@ class CommandCancel : public InstantaneousCommand
{
public:
CommandCancel();
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
int dummy; // Keep the class from having zero size
@ -123,7 +124,7 @@ class CommandPrint : public InstantaneousCommand
{
public:
CommandPrint(std::string);
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
std::string text;
@ -134,7 +135,7 @@ class CommandClearScreen : public InstantaneousCommand
{
public:
CommandClearScreen();
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
int dummy; // Keep the class from having zero size
@ -145,7 +146,7 @@ class CommandSetTime : public InstantaneousCommand
{
public:
CommandSetTime(double _jd);
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
double jd;
@ -156,7 +157,7 @@ class CommandSetTimeRate : public InstantaneousCommand
{
public:
CommandSetTimeRate(double);
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
double rate;
@ -167,7 +168,7 @@ class CommandChangeDistance : public TimedCommand
{
public:
CommandChangeDistance(double duration, double rate);
void process(Simulation*, Renderer*, double t, double dt);
void process(ExecutionEnvironment&, double t, double dt);
private:
double rate;
@ -178,18 +179,40 @@ class CommandOrbit : public TimedCommand
{
public:
CommandOrbit(double _duration, const Vec3f& axis, float rate);
void process(Simulation*, Renderer*, double t, double dt);
void process(ExecutionEnvironment&, double t, double dt);
private:
Vec3f spin;
};
class CommandRotate : public TimedCommand
{
public:
CommandRotate(double _duration, const Vec3f& axis, float rate);
void process(ExecutionEnvironment&, double t, double dt);
private:
Vec3f spin;
};
class CommandMove : public TimedCommand
{
public:
CommandMove(double _duration, const Vec3d& _velocity);
void process(ExecutionEnvironment&, double t, double dt);
private:
Vec3d velocity;
};
class CommandSetPosition : public InstantaneousCommand
{
public:
CommandSetPosition(const UniversalCoord&);
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
UniversalCoord pos;
@ -200,7 +223,7 @@ class CommandSetOrientation : public InstantaneousCommand
{
public:
CommandSetOrientation(const Vec3f&, float);
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
Vec3f axis;
@ -212,7 +235,7 @@ class CommandRenderFlags : public InstantaneousCommand
{
public:
CommandRenderFlags(int _setFlags, int _clearFlags);
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
int setFlags;
@ -224,7 +247,7 @@ class CommandLabels : public InstantaneousCommand
{
public:
CommandLabels(int _setFlags, int _clearFlags);
void process(Simulation*, Renderer*);
void process(ExecutionEnvironment&);
private:
int setFlags;