Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CModel Class Reference

#include <Model.h>

Inheritance diagram for CModel:
Collaboration diagram for CModel:

Classes

struct  Prop
 

Public Member Functions

 CModel (const CSimulation2 &simulation, const CMaterial &material, const CModelDefPtr &modeldef)
 
 ~CModel () override
 
CModelToCModel () override
 Dynamic cast. More...
 
void UpdateTo (float time)
 
const CModelDefPtrGetModelDef ()
 
void SetPlayerID (player_id_t id) override
 
void SetShadingColor (const CColor &color) override
 
const CMaterialGetMaterial ()
 
bool SetAnimation (CSkeletonAnim *anim, bool once=false)
 
CSkeletonAnimGetAnimation () const
 
void CopyAnimationFrom (CModel *source)
 
void SetFlags (int flags)
 
int GetFlags () const
 
void AddFlagsRec (int flags)
 
void RemoveShadowsRec ()
 
void SetTerrainDirty (ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) override
 Called when terrain has changed in the given inclusive bounds. More...
 
void SetEntityVariable (const std::string &name, float value) override
 Called when the entity tries to set some variable to affect the display of this model and/or its child objects. More...
 
void CalcBounds () override
 Overridden to calculate both the world-space and object-space bounds of this model, and stores the result in m_Bounds and m_ObjectBounds, respectively. More...
 
const CBoundingBoxAlignedGetObjectBounds ()
 Returns the object-space bounds for this model, excluding its children. More...
 
const CBoundingBoxAligned GetWorldBoundsRec () override
 Returns world space bounds of this object and all child objects. More...
 
void CalcStaticObjectBounds ()
 Auxiliary method; calculates object space bounds of this model, based solely on vertex positions, and stores the result in m_ObjectBounds. More...
 
void CalcAnimatedObjectBounds (CSkeletonAnimDef *anim, CBoundingBoxAligned &result)
 Auxiliary method; calculate object-space bounds encompassing all vertex positions for given animation, and stores the result in m_ObjectBounds. More...
 
const CBoundingBoxAligned GetObjectSelectionBoundsRec () override
 Reimplemented here since proper models should participate in selection boxes. More...
 
void SetTransform (const CMatrix3D &transform) override
 Set transform of this object. More...
 
bool IsSkinned ()
 Return whether this is a skinned/skeletal model. More...
 
const CMatrix3DGetAnimatedBoneMatrices ()
 
void AddProp (const SPropPoint *point, std::unique_ptr< CModelAbstract > model, CObjectEntry *objectentry, float minHeight=0.f, float maxHeight=0.f, bool selectable=true)
 Add a prop to the model on the given point. More...
 
void AddAmmoProp (const SPropPoint *point, std::unique_ptr< CModelAbstract > model, CObjectEntry *objectentry)
 Add a prop to the model on the given point, and treat it as the ammo prop. More...
 
void ShowAmmoProp ()
 Show the ammo prop (if any), and hide any other props on that prop point. More...
 
void HideAmmoProp ()
 Hide the ammo prop (if any), and show any other props on that prop point. More...
 
CModelAbstractFindFirstAmmoProp ()
 Find the first prop used for ammo, by this model or its own props. More...
 
std::vector< Prop > & GetProps ()
 
const std::vector< Prop > & GetProps () const
 
std::unique_ptr< CModelAbstractClone () const override
 
void ValidatePosition () override
 Ensure that both the transformation and the bone matrices are correct for this model and all its props. More...
 
void InvalidatePosition () override
 Mark this model's position and bone matrices, and all props' positions as invalid. More...
 
- Public Member Functions inherited from CModelAbstract
 CModelAbstract ()
 
virtual ~CModelAbstract ()
 
virtual std::unique_ptr< CModelAbstractClone () const =0
 
virtual CModelDummyToCModelDummy ()
 Dynamic cast. More...
 
virtual CModelToCModel ()
 Dynamic cast. More...
 
virtual CModelDecalToCModelDecal ()
 Dynamic cast. More...
 
virtual CModelParticleEmitterToCModelParticleEmitter ()
 Dynamic cast. More...
 
virtual const CBoundingBoxAligned GetWorldBoundsRec ()
 Returns world space bounds of this object and all child objects. More...
 
virtual const CBoundingBoxOrientedGetSelectionBox ()
 Returns the world-space selection box of this model. More...
 
virtual void InvalidateBounds ()
 Marks the bounds as invalid. More...
 
void SetCustomSelectionShape (CustomSelectionShape *descriptor)
 Sets a custom selection shape as described by a descriptor. More...
 
virtual const CBoundingBoxAligned GetObjectSelectionBoundsRec ()
 Returns the (object-space) bounds that should be used to construct a selection box for this model and its children. More...
 
virtual void SetTerrainDirty (ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1)=0
 Called when terrain has changed in the given inclusive bounds. More...
 
virtual void SetEntityVariable (const std::string &name, float value)
 Called when the entity tries to set some variable to affect the display of this model and/or its child objects. More...
 
virtual void ValidatePosition ()=0
 Ensure that both the transformation and the bone matrices are correct for this model and all its props. More...
 
virtual void InvalidatePosition ()=0
 Mark this model's position and bone matrices, and all props' positions as invalid. More...
 
virtual void SetPlayerID (player_id_t id)
 
virtual player_id_t GetPlayerID () const
 
virtual void SetShadingColor (const CColor &color)
 
virtual const CColorGetShadingColor () const
 
- Public Member Functions inherited from CRenderableObject
 CRenderableObject ()
 
virtual ~CRenderableObject ()
 
virtual void SetTransform (const CMatrix3D &transform)
 
const CMatrix3DGetTransform () const
 
const CMatrix3DGetInvTransform () const
 
void SetDirty (u32 dirtyflags)
 
virtual void CalcBounds ()=0
 (Re)calculates and stores any bounds or bound-dependent data for this object. More...
 
const CBoundingBoxAlignedGetWorldBounds ()
 Returns the world-space axis-aligned bounds of this object. More...
 
virtual void InvalidateBounds ()
 Marks the bounds as invalid. More...
 
void SetRenderData (CRenderData *renderdata)
 
CRenderDataGetRenderData ()
 Return object renderdata - can be null if renderer hasn't yet created the renderdata. More...
 

Private Member Functions

 NONCOPYABLE (CModel)
 

Private Attributes

const CSimulation2m_Simulation
 
int m_Flags {0}
 
CMaterial m_Material
 
const CModelDefPtr m_pModelDef
 
CBoundingBoxAligned m_ObjectBounds
 
CSkeletonAnimm_Anim = nullptr
 
float m_AnimTime {0.0f}
 
CMatrix3Dm_BoneMatrices {nullptr}
 Current state of all bones on this model; null if associated modeldef isn't skeletal. More...
 
std::vector< Propm_Props
 
const SPropPointm_AmmoPropPoint {nullptr}
 The prop point to which the ammo prop is attached, or NULL if none. More...
 
size_t m_AmmoLoadedProp {0}
 If m_AmmoPropPoint is not NULL, then the index in m_Props of the ammo prop. More...
 

Additional Inherited Members

- Public Attributes inherited from CModelAbstract
CModelAbstractm_Parent
 If non-null, points to the model that we are attached to. More...
 
bool m_PositionValid
 True if both transform and and bone matrices are valid. More...
 
player_id_t m_PlayerID
 
CColor m_ShadingColor
 Modulating color. More...
 
- Protected Member Functions inherited from CModelAbstract
void CalcSelectionBox ()
 
- Protected Member Functions inherited from CRenderableObject
void RecalculateBoundsIfNecessary ()
 Factored out so subclasses don't need to repeat this if they want to add additional getters for bounds-related methods (since they'll have to make sure to recalc the bounds if necessary before they return it). More...
 
- Protected Attributes inherited from CModelAbstract
CBoundingBoxOriented m_SelectionBox
 Selection box for this model. More...
 
bool m_SelectionBoxValid
 Is the current selection box valid? More...
 
CustomSelectionShapem_CustomSelectionShape
 Pointer to a descriptor for a custom-defined selection box shape. More...
 
- Protected Attributes inherited from CRenderableObject
CBoundingBoxAligned m_WorldBounds
 World-space bounds of this object. More...
 
CMatrix3D m_Transform
 
CMatrix3D m_InvTransform
 
CRenderDatam_RenderData
 
bool m_BoundsValid
 Remembers whether any bounds need to be recalculated. More...
 

Constructor & Destructor Documentation

◆ CModel()

CModel::CModel ( const CSimulation2 simulation,
const CMaterial material,
const CModelDefPtr modeldef 
)

◆ ~CModel()

CModel::~CModel ( )
override

Member Function Documentation

◆ AddAmmoProp()

void CModel::AddAmmoProp ( const SPropPoint point,
std::unique_ptr< CModelAbstract model,
CObjectEntry objectentry 
)

Add a prop to the model on the given point, and treat it as the ammo prop.

The prop will be hidden by default.

◆ AddFlagsRec()

void CModel::AddFlagsRec ( int  flags)

◆ AddProp()

void CModel::AddProp ( const SPropPoint point,
std::unique_ptr< CModelAbstract model,
CObjectEntry objectentry,
float  minHeight = 0.f,
float  maxHeight = 0.f,
bool  selectable = true 
)

Add a prop to the model on the given point.

◆ CalcAnimatedObjectBounds()

void CModel::CalcAnimatedObjectBounds ( CSkeletonAnimDef anim,
CBoundingBoxAligned result 
)

Auxiliary method; calculate object-space bounds encompassing all vertex positions for given animation, and stores the result in m_ObjectBounds.

Called by CalcBounds (instead of CalcStaticBounds) if it has been determined that the object-space bounds need to take animations into account.

◆ CalcBounds()

void CModel::CalcBounds ( )
overridevirtual

Overridden to calculate both the world-space and object-space bounds of this model, and stores the result in m_Bounds and m_ObjectBounds, respectively.

Implements CRenderableObject.

◆ CalcStaticObjectBounds()

void CModel::CalcStaticObjectBounds ( )

Auxiliary method; calculates object space bounds of this model, based solely on vertex positions, and stores the result in m_ObjectBounds.

Called by CalcBounds (instead of CalcAnimatedObjectBounds) if it has been determined that the object-space bounds are static.

◆ Clone()

std::unique_ptr< CModelAbstract > CModel::Clone ( ) const
overridevirtual

Implements CModelAbstract.

◆ CopyAnimationFrom()

void CModel::CopyAnimationFrom ( CModel source)

◆ FindFirstAmmoProp()

CModelAbstract * CModel::FindFirstAmmoProp ( )

Find the first prop used for ammo, by this model or its own props.

◆ GetAnimatedBoneMatrices()

const CMatrix3D * CModel::GetAnimatedBoneMatrices ( )
inline

◆ GetAnimation()

CSkeletonAnim * CModel::GetAnimation ( ) const
inline

◆ GetFlags()

int CModel::GetFlags ( ) const
inline

◆ GetMaterial()

const CMaterial & CModel::GetMaterial ( )
inline

◆ GetModelDef()

const CModelDefPtr & CModel::GetModelDef ( )
inline

◆ GetObjectBounds()

const CBoundingBoxAligned & CModel::GetObjectBounds ( )
inline

Returns the object-space bounds for this model, excluding its children.

◆ GetObjectSelectionBoundsRec()

const CBoundingBoxAligned CModel::GetObjectSelectionBoundsRec ( )
overridevirtual

Reimplemented here since proper models should participate in selection boxes.

Reimplemented from CModelAbstract.

◆ GetProps() [1/2]

std::vector< Prop > & CModel::GetProps ( )
inline

◆ GetProps() [2/2]

const std::vector< Prop > & CModel::GetProps ( ) const
inline

◆ GetWorldBoundsRec()

const CBoundingBoxAligned CModel::GetWorldBoundsRec ( )
overridevirtual

Returns world space bounds of this object and all child objects.

Reimplemented from CModelAbstract.

◆ HideAmmoProp()

void CModel::HideAmmoProp ( )

Hide the ammo prop (if any), and show any other props on that prop point.

◆ InvalidatePosition()

void CModel::InvalidatePosition ( )
overridevirtual

Mark this model's position and bone matrices, and all props' positions as invalid.

Implements CModelAbstract.

◆ IsSkinned()

bool CModel::IsSkinned ( )
inline

Return whether this is a skinned/skeletal model.

If it is, Get*BoneMatrices() will return valid non-NULL arrays.

◆ NONCOPYABLE()

CModel::NONCOPYABLE ( CModel  )
private

◆ RemoveShadowsRec()

void CModel::RemoveShadowsRec ( )

◆ SetAnimation()

bool CModel::SetAnimation ( CSkeletonAnim anim,
bool  once = false 
)

◆ SetEntityVariable()

void CModel::SetEntityVariable ( const std::string &  name,
float  value 
)
inlineoverridevirtual

Called when the entity tries to set some variable to affect the display of this model and/or its child objects.

Reimplemented from CModelAbstract.

◆ SetFlags()

void CModel::SetFlags ( int  flags)
inline

◆ SetPlayerID()

void CModel::SetPlayerID ( player_id_t  id)
overridevirtual

Reimplemented from CModelAbstract.

◆ SetShadingColor()

void CModel::SetShadingColor ( const CColor color)
overridevirtual

Reimplemented from CModelAbstract.

◆ SetTerrainDirty()

void CModel::SetTerrainDirty ( ssize_t  i0,
ssize_t  j0,
ssize_t  i1,
ssize_t  j1 
)
inlineoverridevirtual

Called when terrain has changed in the given inclusive bounds.

Might call SetDirty if the change affects this model.

Implements CModelAbstract.

◆ SetTransform()

void CModel::SetTransform ( const CMatrix3D transform)
overridevirtual

Set transform of this object.

Note
In order to ensure that all child props are updated properly, you must call ValidatePosition().

Reimplemented from CRenderableObject.

◆ ShowAmmoProp()

void CModel::ShowAmmoProp ( )

Show the ammo prop (if any), and hide any other props on that prop point.

◆ ToCModel()

CModel * CModel::ToCModel ( )
inlineoverridevirtual

Dynamic cast.

Reimplemented from CModelAbstract.

◆ UpdateTo()

void CModel::UpdateTo ( float  time)

◆ ValidatePosition()

void CModel::ValidatePosition ( )
overridevirtual

Ensure that both the transformation and the bone matrices are correct for this model and all its props.

Implements CModelAbstract.

Member Data Documentation

◆ m_AmmoLoadedProp

size_t CModel::m_AmmoLoadedProp {0}
private

If m_AmmoPropPoint is not NULL, then the index in m_Props of the ammo prop.

◆ m_AmmoPropPoint

const SPropPoint* CModel::m_AmmoPropPoint {nullptr}
private

The prop point to which the ammo prop is attached, or NULL if none.

◆ m_Anim

CSkeletonAnim* CModel::m_Anim = nullptr
private

◆ m_AnimTime

float CModel::m_AnimTime {0.0f}
private

◆ m_BoneMatrices

CMatrix3D* CModel::m_BoneMatrices {nullptr}
private

Current state of all bones on this model; null if associated modeldef isn't skeletal.

Props may attach to these bones by means of the SPropPoint::m_BoneIndex field; in this case their transformation matrix held is relative to the bone transformation (see SPropPoint and CModel::ValidatePosition).

See also
SPropPoint

◆ m_Flags

int CModel::m_Flags {0}
private

◆ m_Material

CMaterial CModel::m_Material
private

◆ m_ObjectBounds

CBoundingBoxAligned CModel::m_ObjectBounds
private

◆ m_pModelDef

const CModelDefPtr CModel::m_pModelDef
private

◆ m_Props

std::vector<Prop> CModel::m_Props
private

◆ m_Simulation

const CSimulation2& CModel::m_Simulation
private

The documentation for this class was generated from the following files: