Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/SceneObject.h
- This file was moved from source/graphics/ModelAbstract.h.
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 11 Lines | |||||
#include "graphics/Color.h" | #include "graphics/Color.h" | ||||
#include "graphics/RenderableObject.h" | #include "graphics/RenderableObject.h" | ||||
#include "maths/BoundingBoxOriented.h" | #include "maths/BoundingBoxOriented.h" | ||||
#include "simulation2/helpers/Player.h" | #include "simulation2/helpers/Player.h" | ||||
class CModel; | class CModel; | ||||
class CModelDecal; | class CModelDecal; | ||||
class CModelParticleEmitter; | class CModelParticleEmitter; | ||||
class CUnit; | |||||
/** | /** | ||||
* Abstract base class for graphical objects that are used by units, | * Abstract base class for graphical objects in the scene. | ||||
* or as props attached to other CModelAbstract objects. | |||||
* This includes meshes, terrain decals, and sprites. | * This includes meshes, terrain decals, and sprites. | ||||
* These objects exist in a tree hierarchy. | * These objects exist in a tree hierarchy, | ||||
* and are ultimately owned by a CUnit. | |||||
* Note that CSceneObject currently doesn't keep a reference to its children, | |||||
* since only CModel can actually have children. | |||||
*/ | */ | ||||
class CModelAbstract : public CRenderableObject | class CSceneObject : public CRenderableObject | ||||
{ | { | ||||
NONCOPYABLE(CModelAbstract); | NONCOPYABLE(CSceneObject); | ||||
public: | public: | ||||
/** | /** | ||||
* Describes a custom selection shape to be used for a model's selection box instead of the default | * Describes a custom selection shape to be used for a model's selection box instead of the default | ||||
* recursive bounding boxes. | * recursive bounding boxes. | ||||
*/ | */ | ||||
struct CustomSelectionShape | struct CustomSelectionShape | ||||
{ | { | ||||
enum EType { | enum EType { | ||||
/// The selection shape is determined by an oriented box of custom, user-specified size. | /// The selection shape is determined by an oriented box of custom, user-specified size. | ||||
BOX, | BOX, | ||||
/// The selection shape is determined by a cylinder of custom, user-specified size. | /// The selection shape is determined by a cylinder of custom, user-specified size. | ||||
CYLINDER | CYLINDER | ||||
}; | }; | ||||
EType m_Type; ///< Type of shape. | EType m_Type; ///< Type of shape. | ||||
float m_Size0; ///< Box width if @ref BOX, or radius if @ref CYLINDER | float m_Size0; ///< Box width if @ref BOX, or radius if @ref CYLINDER | ||||
float m_Size1; ///< Box depth if @ref BOX, or radius if @ref CYLINDER | float m_Size1; ///< Box depth if @ref BOX, or radius if @ref CYLINDER | ||||
float m_Height; ///< Box height if @ref BOX, cylinder height if @ref CYLINDER | float m_Height; ///< Box height if @ref BOX, cylinder height if @ref CYLINDER | ||||
}; | }; | ||||
public: | public: | ||||
CModelAbstract() | CSceneObject() | ||||
: m_Parent(NULL), m_PositionValid(false), m_ShadingColor(1, 1, 1, 1), m_PlayerID(INVALID_PLAYER), | : m_Owner(nullptr), m_Parent(nullptr), m_PositionValid(false), | ||||
m_SelectionBoxValid(false), m_CustomSelectionShape(NULL) | m_SelectionBoxValid(false), m_CustomSelectionShape(nullptr) | ||||
{ } | { } | ||||
~CModelAbstract() | ~CSceneObject() | ||||
{ | { | ||||
delete m_CustomSelectionShape; // allocated and set externally by CCmpVisualActor, but our responsibility to clean up | delete m_CustomSelectionShape; // allocated and set externally by CCmpVisualActor, but our responsibility to clean up | ||||
} | } | ||||
virtual CModelAbstract* Clone() const = 0; | void SetParent(CSceneObject* object); | ||||
CSceneObject* GetParent() const; | |||||
virtual void SetOwner(CUnit* owner); | |||||
CUnit* GetOwner() const; | |||||
virtual CSceneObject* Clone() const = 0; | |||||
/// Dynamic cast | /// Dynamic cast | ||||
virtual CModel* ToCModel() { return NULL; } | virtual CModel* ToCModel() { return NULL; } | ||||
/// Dynamic cast | /// Dynamic cast | ||||
virtual CModelDecal* ToCModelDecal() { return NULL; } | virtual CModelDecal* ToCModelDecal() { return NULL; } | ||||
/// Dynamic cast | /// Dynamic cast | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public: | ||||
*/ | */ | ||||
virtual void ValidatePosition() = 0; | virtual void ValidatePosition() = 0; | ||||
/** | /** | ||||
* Mark this model's position and bone matrices, and all props' positions as invalid. | * Mark this model's position and bone matrices, and all props' positions as invalid. | ||||
*/ | */ | ||||
virtual void InvalidatePosition() = 0; | virtual void InvalidatePosition() = 0; | ||||
virtual void SetPlayerID(player_id_t id) { m_PlayerID = id; } | |||||
// get the model's player ID; initial default is INVALID_PLAYER | |||||
virtual player_id_t GetPlayerID() const { return m_PlayerID; } | |||||
virtual void SetShadingColor(const CColor& color) { m_ShadingColor = color; } | |||||
virtual CColor GetShadingColor() const { return m_ShadingColor; } | |||||
protected: | protected: | ||||
void CalcSelectionBox(); | void CalcSelectionBox(); | ||||
public: | public: | ||||
/// If non-null, points to the model that we are attached to. | |||||
CModelAbstract* m_Parent; | |||||
/// True if both transform and and bone matrices are valid. | /// True if both transform and and bone matrices are valid. | ||||
bool m_PositionValid; | bool m_PositionValid; | ||||
player_id_t m_PlayerID; | |||||
/// Modulating color | |||||
CColor m_ShadingColor; | |||||
protected: | protected: | ||||
/// If non-null, points to the model that we are attached to. | |||||
CSceneObject* m_Parent; | |||||
/** | |||||
* Parent CUnit. This is the top-level object to which props and props of props also point to. | |||||
*/ | |||||
CUnit* m_Owner; | |||||
/// Selection box for this model. | /// Selection box for this model. | ||||
CBoundingBoxOriented m_SelectionBox; | CBoundingBoxOriented m_SelectionBox; | ||||
/// Is the current selection box valid? | /// Is the current selection box valid? | ||||
bool m_SelectionBoxValid; | bool m_SelectionBoxValid; | ||||
/// Pointer to a descriptor for a custom-defined selection box shape. If no custom selection box is required, this is NULL | /// Pointer to a descriptor for a custom-defined selection box shape. If no custom selection box is required, this is NULL | ||||
/// and the standard recursive-bounding-box-based selection box is used. Otherwise, a custom selection box described by this | /// and the standard recursive-bounding-box-based selection box is used. Otherwise, a custom selection box described by this | ||||
/// field will be used. | /// field will be used. | ||||
/// @see SetCustomSelectionShape | /// @see SetCustomSelectionShape | ||||
CustomSelectionShape* m_CustomSelectionShape; | CustomSelectionShape* m_CustomSelectionShape; | ||||
}; | }; | ||||
#endif // INCLUDED_MODELABSTRACT | #endif // INCLUDED_MODELABSTRACT |
Wildfire Games · Phabricator