2016-01-29 03:31:54 -08:00
|
|
|
// Copyright © 2008-2016 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 _BODY_H
|
|
|
|
#define _BODY_H
|
|
|
|
|
|
|
|
#include "vector3.h"
|
|
|
|
#include "matrix4x4.h"
|
|
|
|
#include "Object.h"
|
2012-11-12 19:03:39 -08:00
|
|
|
#include "Frame.h"
|
2010-05-22 10:26:25 -07:00
|
|
|
#include "Serializer.h"
|
2013-01-13 21:34:43 -08:00
|
|
|
#include "PropertiedObject.h"
|
2008-06-24 03:17:31 -07:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class ObjMesh;
|
2011-11-17 13:38:06 -08:00
|
|
|
class Space;
|
2012-07-09 06:47:47 -07:00
|
|
|
class Camera;
|
2012-02-21 02:04:06 -08:00
|
|
|
namespace Graphics { class Renderer; }
|
2013-11-06 00:30:46 -08:00
|
|
|
struct CollisionContact;
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2013-01-13 21:34:43 -08:00
|
|
|
class Body: public Object, public PropertiedObject {
|
2008-06-24 03:17:31 -07:00
|
|
|
public:
|
2008-09-18 07:00:12 -07:00
|
|
|
OBJDEF(Body, Object, BODY);
|
2008-06-24 03:17:31 -07:00
|
|
|
Body();
|
2008-07-07 15:19:53 -07:00
|
|
|
virtual ~Body();
|
2015-02-16 15:13:46 -08:00
|
|
|
void ToJson(Json::Value &jsonObj, Space *space);
|
|
|
|
static Body *FromJson(const Json::Value &jsonObj, Space *space);
|
2011-11-17 13:38:06 -08:00
|
|
|
virtual void PostLoadFixup(Space *space) {};
|
2011-02-27 20:46:48 -08:00
|
|
|
|
2012-11-16 17:07:15 -08:00
|
|
|
virtual void SetPosition(const vector3d &p) { m_pos = p; }
|
|
|
|
vector3d GetPosition() const { return m_pos; }
|
|
|
|
virtual void SetOrient(const matrix3x3d &r) { m_orient = r; }
|
|
|
|
const matrix3x3d &GetOrient() const { return m_orient; }
|
2012-09-03 07:54:22 -07:00
|
|
|
virtual void SetVelocity(const vector3d &v) { assert(0); }
|
2009-03-27 05:21:42 -07:00
|
|
|
virtual vector3d GetVelocity() const { return vector3d(0.0); }
|
2012-11-26 15:40:03 -08:00
|
|
|
|
|
|
|
void SetPhysRadius(double r) { m_physRadius = r; }
|
|
|
|
double GetPhysRadius() const { return m_physRadius; }
|
|
|
|
void SetClipRadius(double r) { m_clipRadius = r; }
|
|
|
|
double GetClipRadius() const { return m_clipRadius; }
|
2008-08-17 04:28:25 -07:00
|
|
|
virtual double GetMass() const { assert(0); return 0; }
|
2012-11-12 19:03:39 -08:00
|
|
|
|
2008-07-15 13:47:06 -07:00
|
|
|
// return true if to do collision response and apply damage
|
2009-10-21 08:54:01 -07:00
|
|
|
virtual bool OnCollision(Object *o, Uint32 flags, double relVel) { return false; }
|
2009-11-04 07:06:36 -08:00
|
|
|
// Attacker may be null
|
2013-10-20 07:05:30 -07:00
|
|
|
virtual bool OnDamage(Object *attacker, float kgDamage, const CollisionContact& contactData) { return false; }
|
2011-02-27 20:46:48 -08:00
|
|
|
// Override to clear any pointers you hold to the body
|
2011-11-14 14:09:29 -08:00
|
|
|
virtual void NotifyRemoved(const Body* const removedBody) {}
|
2011-02-27 20:46:48 -08:00
|
|
|
|
2011-03-02 19:05:10 -08:00
|
|
|
// before all bodies have had TimeStepUpdate (their moving step),
|
2009-09-12 10:25:15 -07:00
|
|
|
// StaticUpdate() is called. Good for special collision testing (Projectiles)
|
|
|
|
// as you can't test for collisions if different objects are on different 'steps'
|
|
|
|
virtual void StaticUpdate(const float timeStep) {}
|
2011-03-02 19:05:10 -08:00
|
|
|
virtual void TimeStepUpdate(const float timeStep) {}
|
2012-07-24 22:51:17 -07:00
|
|
|
virtual void Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) = 0;
|
2011-02-27 20:46:48 -08:00
|
|
|
|
|
|
|
virtual void SetFrame(Frame *f) { m_frame = f; }
|
2008-11-14 03:11:51 -08:00
|
|
|
Frame *GetFrame() const { return m_frame; }
|
2012-11-18 10:13:47 -08:00
|
|
|
void SwitchToFrame(Frame *newFrame);
|
2011-02-27 20:46:48 -08:00
|
|
|
void UpdateFrame(); // check for frame switching
|
2012-11-12 19:03:39 -08:00
|
|
|
|
|
|
|
vector3d GetVelocityRelTo(const Body *) const;
|
|
|
|
vector3d GetVelocityRelTo(const Frame *) const;
|
2011-02-27 20:46:48 -08:00
|
|
|
vector3d GetPositionRelTo(const Frame *) const;
|
|
|
|
vector3d GetPositionRelTo(const Body *) const;
|
2012-11-18 10:13:47 -08:00
|
|
|
matrix3x3d GetOrientRelTo(const Frame *) const;
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2011-02-27 20:46:48 -08:00
|
|
|
// Should return pointer in Pi::currentSystem
|
2012-04-17 18:53:53 -07:00
|
|
|
virtual const SystemBody *GetSystemBody() const { return 0; }
|
2011-02-27 20:46:48 -08:00
|
|
|
// for putting on planet surface, oriented +y up
|
|
|
|
void OrientOnSurface(double radius, double latitude, double longitude);
|
|
|
|
|
2013-01-25 00:18:27 -08:00
|
|
|
virtual void SetLabel(const std::string &label);
|
2009-07-02 04:39:14 -07:00
|
|
|
const std::string &GetLabel() const { return m_label; }
|
2012-04-01 10:22:47 -07:00
|
|
|
unsigned int GetFlags() const { return m_flags; }
|
2008-07-07 15:19:53 -07:00
|
|
|
// Only Space::KillBody() should call this method.
|
|
|
|
void MarkDead() { m_dead = true; }
|
2008-11-13 05:46:20 -08:00
|
|
|
bool IsDead() const { return m_dead; }
|
2011-02-27 20:46:48 -08:00
|
|
|
|
2012-07-23 12:03:13 -07:00
|
|
|
// all Bodies are in space... except where they're not (Ships hidden in hyperspace clouds)
|
|
|
|
virtual bool IsInSpace() const { return true; }
|
|
|
|
|
2011-02-27 20:46:48 -08:00
|
|
|
// Interpolated between physics ticks.
|
2012-11-12 19:03:39 -08:00
|
|
|
const matrix3x3d &GetInterpOrient() const { return m_interpOrient; }
|
|
|
|
vector3d GetInterpPosition() const { return m_interpPos; }
|
|
|
|
vector3d GetInterpPositionRelTo(const Frame *relTo) const;
|
|
|
|
vector3d GetInterpPositionRelTo(const Body *relTo) const;
|
|
|
|
matrix3x3d GetInterpOrientRelTo(const Frame *relTo) const;
|
|
|
|
|
|
|
|
// should set m_interpolatedTransform to the smoothly interpolated value
|
|
|
|
// (interpolated by 0 <= alpha <=1) between the previous and current physics tick
|
2012-11-16 17:07:15 -08:00
|
|
|
virtual void UpdateInterpTransform(double alpha) {
|
2012-11-12 19:03:39 -08:00
|
|
|
m_interpOrient = GetOrient();
|
|
|
|
m_interpPos = GetPosition();
|
2010-11-15 16:04:43 -08:00
|
|
|
}
|
2008-06-29 14:46:11 -07:00
|
|
|
|
2011-12-02 08:10:21 -08:00
|
|
|
// where to draw targeting indicators - usually equal to GetInterpolatedPositionRelTo
|
|
|
|
virtual vector3d GetTargetIndicatorPosition(const Frame *relTo) const;
|
|
|
|
|
2009-11-05 06:49:26 -08:00
|
|
|
enum { FLAG_CAN_MOVE_FRAME = (1<<0),
|
2012-11-12 19:03:39 -08:00
|
|
|
FLAG_LABEL_HIDDEN = (1<<1),
|
2012-11-18 10:13:47 -08:00
|
|
|
FLAG_DRAW_LAST = (1<<2) }; // causes the body drawn after other bodies in the z-sort
|
2012-01-18 09:47:59 -08:00
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
protected:
|
2015-02-16 15:13:46 -08:00
|
|
|
virtual void SaveToJson(Json::Value &jsonObj, Space *space);
|
|
|
|
virtual void LoadFromJson(const Json::Value &jsonObj, Space *space);
|
2008-06-24 03:17:31 -07:00
|
|
|
unsigned int m_flags;
|
2010-11-15 16:04:43 -08:00
|
|
|
|
|
|
|
// Interpolated draw orientation-position
|
2012-11-12 19:03:39 -08:00
|
|
|
vector3d m_interpPos;
|
|
|
|
matrix3x3d m_interpOrient;
|
2008-06-24 03:17:31 -07:00
|
|
|
private:
|
2012-11-16 17:07:15 -08:00
|
|
|
vector3d m_pos;
|
|
|
|
matrix3x3d m_orient;
|
|
|
|
Frame *m_frame; // frame of reference
|
2008-06-24 03:17:31 -07:00
|
|
|
std::string m_label;
|
2012-11-16 17:07:15 -08:00
|
|
|
bool m_dead; // Checked in destructor to make sure body has been marked dead.
|
2012-11-26 15:40:03 -08:00
|
|
|
double m_clipRadius;
|
|
|
|
double m_physRadius;
|
2008-06-24 03:17:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _BODY_H */
|