forked from pioneerspacesim/pioneer
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Frame.h
94 lines (85 loc) · 3.2 KB
/
Frame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef _FRAME_H
#define _FRAME_H
#include "libs.h"
#include "Serializer.h"
#include <string>
#include <list>
class Body;
class CollisionSpace;
class Geom;
class SBody;
class Sfx;
/*
* Frame of reference.
*/
class Frame {
public:
Frame();
Frame(Frame *parent, const char *label);
Frame(Frame *parent, const char *label, unsigned int flags);
~Frame();
static void Serialize(Serializer::Writer &wr, Frame *);
static void PostUnserializeFixup(Frame *f);
static Frame *Unserialize(Serializer::Reader &rd, Frame *parent);
const char *GetLabel() const { return m_label.c_str(); }
void SetLabel(const char *label) { m_label = label; }
void SetPosition(const vector3d &pos) { m_orient.SetTranslate(pos); }
vector3d GetPosition() const { return m_orient.GetTranslate(); }
void SetVelocity(const vector3d &vel) { m_vel = vel; }
vector3d GetVelocity() const { return m_vel; }
void SetAngVelocity(const vector3d &angvel) { m_angVel = angvel; }
vector3d GetAngVelocity() const { return m_angVel; }
vector3d GetStasisVelocityAtPosition(const vector3d &pos) const;
const matrix4x4d &GetTransform() const { return m_orient; }
void SetRotationOnly(const matrix4x4d &m) { for (int i=0; i<12; i++) m_orient[i] = m[i]; }
void SetRadius(double radius) { m_radius = radius; }
void RemoveChild(Frame *f);
void AddGeom(Geom *);
void RemoveGeom(Geom *);
void AddStaticGeom(Geom *);
void RemoveStaticGeom(Geom *);
void SetPlanetGeom(double radius, Body *);
CollisionSpace *GetCollisionSpace() const { return m_collisionSpace; }
void RotateInTimestep(double step);
bool IsRotatingFrame() const { return m_angVel.Length() != 0.0; }
// snoops into parent frames so beware
SBody *GetSBodyFor() const;
Body *GetBodyFor() const;
void UpdateOrbitRails();
void ApplyLeavingTransform(matrix4x4d &m) const;
void ApplyEnteringTransform(matrix4x4d &m) const;
static void GetFrameTransform(const Frame *fFrom, const Frame *fTo, matrix4x4d &m);
static vector3d GetFrameRelativeVelocity(const Frame *fFrom, const Frame *fTo);
/** Same as GetFrameTransform except it does interpolation between
* physics ticks so rendering is smooth above physics hz */
static void GetFrameRenderTransform(const Frame *fFrom, const Frame *fTo, matrix4x4d &m);
void UpdateInterpolatedTransform(double alpha);
void ClearMovement() {
m_oldOrient = m_interpolatedTransform = m_orient;
m_oldAngDisplacement = vector3d(0.0);
}
bool IsLocalPosInFrame(const vector3d &pos) {
return (pos.Length() < m_radius);
}
/* if parent is null then frame position is absolute */
Frame *m_parent;
std::list<Frame*> m_children;
SBody *m_sbody; // points to SBodies in Pi::current_system
Body *m_astroBody; // if frame contains a star or planet or something
Sfx *m_sfx;
enum { TEMP_VIEWING=1 };
private:
void Init(Frame *parent, const char *label, unsigned int flags);
vector3d m_vel; // note we don't use this to move frame. rather,
// orbital rails determine velocity.
vector3d m_angVel; // this however *is* directly applied (for rotating frames)
vector3d m_oldAngDisplacement;
matrix4x4d m_orient;
matrix4x4d m_oldOrient;
matrix4x4d m_interpolatedTransform;
std::string m_label;
double m_radius;
int m_flags;
CollisionSpace *m_collisionSpace;
};
#endif /* _FRAME_H */