1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details 2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt 3 4 #ifndef _MODELBODY_H 5 #define _MODELBODY_H 6 7 #include "Body.h" 8 #include "CollMesh.h" 9 #include "FrameId.h" 10 11 class Shields; 12 class Geom; 13 class Camera; 14 15 namespace Graphics { 16 class Renderer; 17 class Light; 18 } // namespace Graphics 19 20 namespace SceneGraph { 21 class Model; 22 class Animation; 23 } // namespace SceneGraph 24 25 class ModelBody : public Body { 26 public: 27 OBJDEF(ModelBody, Body, MODELBODY); 28 ModelBody(); 29 ModelBody(const Json &jsonObj, Space *space); 30 virtual ~ModelBody(); 31 void SetPosition(const vector3d &p) override; 32 void SetOrient(const matrix3x3d &r) override; 33 virtual void SetFrame(FrameId fId) override; 34 // Colliding: geoms are checked against collision space 35 void SetColliding(bool colliding); IsColliding()36 bool IsColliding() const { return m_colliding; } 37 // Static: geoms are static relative to frame 38 void SetStatic(bool isStatic); IsStatic()39 bool IsStatic() const { return m_isStatic; } GetAabb()40 const Aabb &GetAabb() const { return m_collMesh->GetAabb(); } GetModel()41 SceneGraph::Model *GetModel() const { return m_model; } GetCollMesh()42 CollMesh *GetCollMesh() { return m_collMesh.Get(); } GetGeom()43 Geom *GetGeom() const { return m_geom; } 44 45 void SetModel(const char *modelName); 46 47 void RenderModel(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform, const bool setLighting = true); 48 49 virtual void TimeStepUpdate(const float timeStep) override; 50 51 protected: 52 virtual void SaveToJson(Json &jsonObj, Space *space) override; 53 54 void SetLighting(Graphics::Renderer *r, const Camera *camera, std::vector<Graphics::Light> &oldLights, Color &oldAmbient); 55 void ResetLighting(Graphics::Renderer *r, const std::vector<Graphics::Light> &oldLights, const Color &oldAmbient); 56 GetShields()57 Shields *GetShields() const { return m_shields.get(); } 58 59 private: 60 void RebuildCollisionMesh(); 61 void DeleteGeoms(); 62 void AddGeomsToFrame(Frame *); 63 void RemoveGeomsFromFrame(Frame *); 64 void MoveGeoms(const matrix4x4d &, const vector3d &); 65 66 void CalcLighting(double &ambient, double &direct, const Camera *camera); 67 68 bool m_isStatic; 69 bool m_colliding; 70 RefCountedPtr<CollMesh> m_collMesh; 71 Geom *m_geom; //static geom 72 std::string m_modelName; 73 SceneGraph::Model *m_model; 74 std::vector<Geom *> m_dynGeoms; 75 SceneGraph::Animation *m_idleAnimation; 76 std::unique_ptr<Shields> m_shields; 77 }; 78 79 #endif /* _MODELBODY_H */ 80