2017-01-04 07:11:15 -08:00
|
|
|
// Copyright © 2008-2017 Pioneer Developers. See AUTHORS.txt for details
|
2012-09-15 17:59:15 -07:00
|
|
|
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
|
2012-09-12 04:38:30 -07:00
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
#ifndef _FRAME_H
|
|
|
|
#define _FRAME_H
|
|
|
|
|
|
|
|
#include "libs.h"
|
2010-05-22 10:26:25 -07:00
|
|
|
#include "Serializer.h"
|
2014-02-22 08:54:57 -08:00
|
|
|
#include "IterationProxy.h"
|
2015-02-15 06:27:57 -08:00
|
|
|
#include "json/json.h"
|
2008-06-24 03:17:31 -07:00
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
|
2008-08-17 04:28:25 -07:00
|
|
|
class Body;
|
2008-10-07 08:37:18 -07:00
|
|
|
class CollisionSpace;
|
|
|
|
class Geom;
|
2012-04-17 18:53:53 -07:00
|
|
|
class SystemBody;
|
2016-05-10 06:52:46 -07:00
|
|
|
class SfxManager;
|
2011-11-17 13:08:22 -08:00
|
|
|
class Space;
|
2008-08-17 04:28:25 -07:00
|
|
|
|
2012-11-12 19:03:39 -08:00
|
|
|
// Frame of reference.
|
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
class Frame {
|
|
|
|
public:
|
2014-09-06 15:29:17 -07:00
|
|
|
enum { FLAG_DEFAULT=(0), FLAG_ROTATING=(1<<1), FLAG_HAS_ROT=(1<<2) };
|
2012-11-12 19:03:39 -08:00
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
Frame();
|
|
|
|
Frame(Frame *parent, const char *label);
|
|
|
|
Frame(Frame *parent, const char *label, unsigned int flags);
|
|
|
|
~Frame();
|
2015-02-15 06:27:57 -08:00
|
|
|
static void ToJson(Json::Value &jsonObj, Frame *f, Space *space);
|
2011-11-17 21:02:41 -08:00
|
|
|
static void PostUnserializeFixup(Frame *f, Space *space);
|
2015-02-15 06:27:57 -08:00
|
|
|
static Frame *FromJson(const Json::Value &jsonObj, Space *space, Frame *parent, double at_time);
|
2012-04-01 10:31:16 -07:00
|
|
|
const std::string &GetLabel() const { return m_label; }
|
2008-06-24 03:17:31 -07:00
|
|
|
void SetLabel(const char *label) { m_label = label; }
|
2012-11-12 19:03:39 -08:00
|
|
|
|
|
|
|
void SetPosition(const vector3d &pos) { m_pos = pos; }
|
|
|
|
vector3d GetPosition() const { return m_pos; }
|
2014-01-04 10:08:40 -08:00
|
|
|
void SetInitialOrient(const matrix3x3d &m, double time);
|
|
|
|
void SetOrient(const matrix3x3d &m, double time);
|
2012-11-12 19:03:39 -08:00
|
|
|
const matrix3x3d &GetOrient() const { return m_orient; }
|
|
|
|
const matrix3x3d &GetInterpOrient() const { return m_interpOrient; }
|
2008-08-13 13:22:06 -07:00
|
|
|
void SetVelocity(const vector3d &vel) { m_vel = vel; }
|
2008-08-14 14:34:50 -07:00
|
|
|
vector3d GetVelocity() const { return m_vel; }
|
2012-11-24 18:48:14 -08:00
|
|
|
void SetAngSpeed(const double angspeed) { m_angSpeed = angspeed; }
|
|
|
|
double GetAngSpeed() const { return m_angSpeed; }
|
2008-06-24 03:17:31 -07:00
|
|
|
void SetRadius(double radius) { m_radius = radius; }
|
2011-10-06 14:46:32 -07:00
|
|
|
double GetRadius() const { return m_radius; }
|
2012-11-12 19:03:39 -08:00
|
|
|
bool IsRotFrame() const { return m_flags & FLAG_ROTATING; }
|
|
|
|
bool HasRotFrame() const { return m_flags & FLAG_HAS_ROT; }
|
|
|
|
|
|
|
|
Frame *GetParent() const { return m_parent; }
|
2013-03-29 07:04:07 -07:00
|
|
|
const Frame *GetNonRotFrame() const { return IsRotFrame() ? m_parent : this; }
|
2012-11-18 10:13:47 -08:00
|
|
|
Frame *GetNonRotFrame() { return IsRotFrame() ? m_parent : this; }
|
2013-03-29 07:04:07 -07:00
|
|
|
const Frame *GetRotFrame() const { return HasRotFrame() ? m_children.front() : this; }
|
2012-11-18 10:13:47 -08:00
|
|
|
Frame *GetRotFrame() { return HasRotFrame() ? m_children.front() : this; }
|
|
|
|
|
|
|
|
void SetBodies(SystemBody *s, Body *b) { m_sbody = s; m_astroBody = b; }
|
2012-11-16 17:07:15 -08:00
|
|
|
SystemBody *GetSystemBody() const { return m_sbody; }
|
|
|
|
Body *GetBody() const { return m_astroBody; }
|
2012-11-12 19:03:39 -08:00
|
|
|
|
2012-11-18 10:13:47 -08:00
|
|
|
void AddChild(Frame *f) { m_children.push_back(f); }
|
2012-12-28 18:31:52 -08:00
|
|
|
void RemoveChild(Frame *f);
|
2014-02-22 08:54:57 -08:00
|
|
|
bool HasChildren() const { return !m_children.empty(); }
|
|
|
|
unsigned GetNumChildren() const { return m_children.size(); }
|
|
|
|
IterationProxy<std::vector<Frame*> > GetChildren() { return MakeIterationProxy(m_children); }
|
|
|
|
const IterationProxy<const std::vector<Frame*> > GetChildren() const { return MakeIterationProxy(m_children); }
|
2012-11-18 10:13:47 -08:00
|
|
|
|
2008-10-07 08:37:18 -07:00
|
|
|
void AddGeom(Geom *);
|
|
|
|
void RemoveGeom(Geom *);
|
2009-08-21 10:08:11 -07:00
|
|
|
void AddStaticGeom(Geom *);
|
|
|
|
void RemoveStaticGeom(Geom *);
|
2008-10-10 04:11:12 -07:00
|
|
|
void SetPlanetGeom(double radius, Body *);
|
2008-10-07 08:37:18 -07:00
|
|
|
CollisionSpace *GetCollisionSpace() const { return m_collisionSpace; }
|
2012-11-12 19:03:39 -08:00
|
|
|
|
2011-11-30 02:21:55 -08:00
|
|
|
void UpdateOrbitRails(double time, double timestep);
|
2012-11-12 19:03:39 -08:00
|
|
|
void UpdateInterpTransform(double alpha);
|
|
|
|
void ClearMovement();
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2012-11-12 19:03:39 -08:00
|
|
|
// For an object in a rotating frame, relative to non-rotating frames it
|
|
|
|
// must attain this velocity within rotating frame to be stationary.
|
2012-11-24 18:48:14 -08:00
|
|
|
vector3d GetStasisVelocity(const vector3d &pos) const { return -vector3d(0,m_angSpeed,0).Cross(pos); }
|
2012-11-12 19:03:39 -08:00
|
|
|
|
|
|
|
vector3d GetPositionRelTo(const Frame *relTo) const;
|
|
|
|
vector3d GetVelocityRelTo(const Frame *relTo) const;
|
|
|
|
matrix3x3d GetOrientRelTo(const Frame *relTo) const;
|
|
|
|
|
|
|
|
// Same as above except it does interpolation between
|
|
|
|
// physics ticks so rendering is smooth above physics hz
|
|
|
|
vector3d GetInterpPositionRelTo(const Frame *relTo) const;
|
|
|
|
matrix3x3d GetInterpOrientRelTo(const Frame *relTo) const;
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2012-11-18 10:13:47 -08:00
|
|
|
static void GetFrameTransform(const Frame *fFrom, const Frame *fTo, matrix4x4d &m);
|
|
|
|
|
2016-05-10 06:52:46 -07:00
|
|
|
std::unique_ptr<SfxManager> m_sfx; // the last survivor. actually m_children is pretty grim too.
|
2012-11-18 10:13:47 -08:00
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
private:
|
|
|
|
void Init(Frame *parent, const char *label, unsigned int flags);
|
2012-11-18 10:13:47 -08:00
|
|
|
void UpdateRootRelativeVars();
|
2012-11-12 19:03:39 -08:00
|
|
|
|
|
|
|
Frame *m_parent; // if parent is null then frame position is absolute
|
2012-12-28 18:31:52 -08:00
|
|
|
std::vector<Frame*> m_children; // child frames, first may be rotating
|
2012-11-12 19:03:39 -08:00
|
|
|
SystemBody *m_sbody; // points to SBodies in Pi::current_system
|
|
|
|
Body *m_astroBody; // if frame contains a star or planet or something
|
|
|
|
|
|
|
|
vector3d m_pos;
|
|
|
|
vector3d m_oldPos;
|
|
|
|
vector3d m_interpPos;
|
2014-01-04 10:08:40 -08:00
|
|
|
matrix3x3d m_initialOrient;
|
2012-11-12 19:03:39 -08:00
|
|
|
matrix3x3d m_orient;
|
|
|
|
matrix3x3d m_interpOrient;
|
2008-08-13 13:22:06 -07:00
|
|
|
vector3d m_vel; // note we don't use this to move frame. rather,
|
|
|
|
// orbital rails determine velocity.
|
2012-11-24 18:48:14 -08:00
|
|
|
double m_angSpeed; // this however *is* directly applied (for rotating frames)
|
|
|
|
double m_oldAngDisplacement;
|
2008-06-24 03:17:31 -07:00
|
|
|
std::string m_label;
|
|
|
|
double m_radius;
|
|
|
|
int m_flags;
|
2008-10-07 08:37:18 -07:00
|
|
|
CollisionSpace *m_collisionSpace;
|
2011-05-12 05:31:08 -07:00
|
|
|
|
2012-11-18 10:13:47 -08:00
|
|
|
vector3d m_rootVel; // velocity, position and orient relative to root frame
|
|
|
|
vector3d m_rootPos; // updated by UpdateOrbitRails
|
|
|
|
matrix3x3d m_rootOrient;
|
|
|
|
vector3d m_rootInterpPos; // interp position and orient relative to root frame
|
|
|
|
matrix3x3d m_rootInterpOrient; // updated by UpdateInterpTransform
|
2012-11-12 19:03:39 -08:00
|
|
|
|
2011-05-12 05:31:08 -07:00
|
|
|
int m_astroBodyIndex; // deserialisation
|
2008-06-24 03:17:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _FRAME_H */
|