Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Model.cpp
Show All 19 Lines | |||||
#include "Model.h" | #include "Model.h" | ||||
#include "graphics/Decal.h" | #include "graphics/Decal.h" | ||||
#include "graphics/MeshManager.h" | #include "graphics/MeshManager.h" | ||||
#include "graphics/ModelDef.h" | #include "graphics/ModelDef.h" | ||||
#include "graphics/ObjectEntry.h" | #include "graphics/ObjectEntry.h" | ||||
#include "graphics/SkeletonAnim.h" | #include "graphics/SkeletonAnim.h" | ||||
#include "graphics/SkeletonAnimDef.h" | #include "graphics/SkeletonAnimDef.h" | ||||
#include "graphics/Terrain.h" | |||||
#include "graphics/Water.h" | |||||
#include "maths/BoundingBoxAligned.h" | #include "maths/BoundingBoxAligned.h" | ||||
#include "maths/Quaternion.h" | #include "maths/Quaternion.h" | ||||
#include "lib/sysdep/rtl.h" | #include "lib/sysdep/rtl.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/CStrInternStatic.h" | #include "ps/CStrInternStatic.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "renderer/RenderingOptions.h" | #include "renderer/RenderingOptions.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | |||||
#include "simulation2/components/ICmpWaterManager.h" | |||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// Constructor | // Constructor | ||||
CModel::CModel(CSimulation2& simulation) | CModel::CModel(CTerrain& terrain, CWater& water) | ||||
: m_Flags(0), m_Anim(NULL), m_AnimTime(0), m_Simulation(simulation), | : m_Flags(0), m_Anim(NULL), m_AnimTime(0), m_Terrain(terrain), m_Water(water), | ||||
m_BoneMatrices(NULL), m_AmmoPropPoint(NULL), m_AmmoLoadedProp(0) | m_BoneMatrices(NULL), m_AmmoPropPoint(NULL), m_AmmoLoadedProp(0) | ||||
{ | { | ||||
} | } | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// Destructor | // Destructor | ||||
CModel::~CModel() | CModel::~CModel() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | // PROFILE( "generating bone matrices" ); | ||||
// our own position is now valid; now we can safely update our props' positions without fearing | // our own position is now valid; now we can safely update our props' positions without fearing | ||||
// that doing so will cause a revalidation of this model (see recursion above). | // that doing so will cause a revalidation of this model (see recursion above). | ||||
m_PositionValid = true; | m_PositionValid = true; | ||||
CMatrix3D translate; | CMatrix3D translate; | ||||
CVector3D objTranslation = m_Transform.GetTranslation(); | CVector3D objTranslation = m_Transform.GetTranslation(); | ||||
float objectHeight = 0.0f; | float objectHeight = 0.0f; | ||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY); | objectHeight = m_Terrain.GetExactGroundLevel(objTranslation.X, objTranslation.Z); | ||||
if (cmpTerrain) | |||||
objectHeight = cmpTerrain->GetExactGroundLevel(objTranslation.X, objTranslation.Z); | |||||
// Object height is incorrect for floating objects. We use water height instead. | // Object height is incorrect for floating objects. We use water height instead. | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(m_Simulation, SYSTEM_ENTITY); | float waterHeight = m_Water.GetExactWaterHeight(objTranslation.X, objTranslation.Z); | ||||
if (cmpWaterManager) | |||||
{ | |||||
float waterHeight = cmpWaterManager->GetExactWaterLevel(objTranslation.X, objTranslation.Z); | |||||
if (waterHeight >= objectHeight && m_Flags & MODELFLAG_FLOATONWATER) | if (waterHeight >= objectHeight && m_Flags & MODELFLAG_FLOATONWATER) | ||||
objectHeight = waterHeight; | objectHeight = waterHeight; | ||||
} | |||||
// re-position and validate all props | // re-position and validate all props | ||||
for (const Prop& prop : m_Props) | for (const Prop& prop : m_Props) | ||||
{ | { | ||||
CMatrix3D proptransform = prop.m_Point->m_Transform; | CMatrix3D proptransform = prop.m_Point->m_Transform; | ||||
if (prop.m_Point->m_BoneIndex != 0xff) | if (prop.m_Point->m_BoneIndex != 0xff) | ||||
{ | { | ||||
CMatrix3D boneMatrix = m_BoneMatrices[prop.m_Point->m_BoneIndex]; | CMatrix3D boneMatrix = m_BoneMatrices[prop.m_Point->m_BoneIndex]; | ||||
if (!worldSpaceBoneMatrices) | if (!worldSpaceBoneMatrices) | ||||
boneMatrix.Concatenate(GetTransform()); | boneMatrix.Concatenate(GetTransform()); | ||||
proptransform.Concatenate(boneMatrix); | proptransform.Concatenate(boneMatrix); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// not relative to any bone; just apply world-space transformation (i.e. relative to object-space origin) | // not relative to any bone; just apply world-space transformation (i.e. relative to object-space origin) | ||||
proptransform.Concatenate(m_Transform); | proptransform.Concatenate(m_Transform); | ||||
} | } | ||||
// Adjust prop height to terrain level when needed | // Adjust prop height to terrain level when needed | ||||
if (cmpTerrain && (prop.m_MaxHeight != 0.f || prop.m_MinHeight != 0.f)) | if (prop.m_MaxHeight != 0.f || prop.m_MinHeight != 0.f) | ||||
{ | { | ||||
const CVector3D& propTranslation = proptransform.GetTranslation(); | const CVector3D& propTranslation = proptransform.GetTranslation(); | ||||
const float propTerrain = cmpTerrain->GetExactGroundLevel(propTranslation.X, propTranslation.Z); | const float propTerrain = m_Terrain.GetExactGroundLevel(propTranslation.X, propTranslation.Z); | ||||
const float translateHeight = std::min(prop.m_MaxHeight, std::max(prop.m_MinHeight, propTerrain - objectHeight)); | const float translateHeight = std::min(prop.m_MaxHeight, std::max(prop.m_MinHeight, propTerrain - objectHeight)); | ||||
translate.SetTranslation(0.f, translateHeight, 0.f); | translate.SetTranslation(0.f, translateHeight, 0.f); | ||||
proptransform.Concatenate(translate); | proptransform.Concatenate(translate); | ||||
} | } | ||||
prop.m_Model->SetTransform(proptransform); | prop.m_Model->SetTransform(proptransform); | ||||
prop.m_Model->ValidatePosition(); | prop.m_Model->ValidatePosition(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | CModelAbstract* CModel::FindFirstAmmoProp() | ||||
return NULL; | return NULL; | ||||
} | } | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// Clone: return a clone of this model | // Clone: return a clone of this model | ||||
CModelAbstract* CModel::Clone() const | CModelAbstract* CModel::Clone() const | ||||
{ | { | ||||
CModel* clone = new CModel(m_Simulation); | CModel* clone = new CModel(m_Terrain, m_Water); | ||||
clone->m_ObjectBounds = m_ObjectBounds; | clone->m_ObjectBounds = m_ObjectBounds; | ||||
clone->InitModel(m_pModelDef); | clone->InitModel(m_pModelDef); | ||||
clone->SetMaterial(m_Material); | clone->SetMaterial(m_Material); | ||||
clone->SetAnimation(m_Anim); | clone->SetAnimation(m_Anim); | ||||
clone->SetFlags(m_Flags); | clone->SetFlags(m_Flags); | ||||
for (size_t i = 0; i < m_Props.size(); i++) | for (size_t i = 0; i < m_Props.size(); i++) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator