port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
#include "stdafx.h"
#include "Bone.h"
#include "IResourceFactory.h"
#include "ITransformationAnimation.h"
Bone::Bone(IEngine& argEngine)
: m_Engine(argEngine)
, m_Parent(NULL)
, m_TransformationAnimation(NULL)
, m_BoneIndex(-1)
, m_LastAnimationTime(-1.0f)
, m_MatrixArray(NULL)
{
}
Bone::~Bone()
{
delete m_MatrixArray;
m_Engine.get_ResourceFactory().DeleteBone(*const_cast<Bone*>(this), true);
}
void Bone::Initialize(const std::wstring& argName, int argIndex, const D3DXVECTOR3& argPoseTranslation, const D3DXVECTOR3& argPoseScale, const D3DXQUATERNION& argPoseRotation)
{
D3DXMatrixTransformation(&m_PoseTransformation, NULL, NULL, &argPoseScale, NULL, &argPoseRotation, &argPoseTranslation);
D3DXMatrixInverse(&m_InvPoseTransformation, NULL, &m_PoseTransformation);
}
const D3DXMATRIX& Bone::GetTransformationAtTime(float argT, const D3DXMATRIX& argRootTransformationMatrix)
{
if (m_TransformationAnimation != NULL)
{
if (argT != m_LastAnimationTime)
{
if (m_Parent != NULL)
{
m_Transformation = (m_TransformationAnimation->GetTransformationAtTime(argT) * m_InvPoseTransformation) * m_Parent->GetTransformationAtTime(argT, argRootTransformationMatrix);
m_Transformation = m_InvPoseTransformation * m_TransformationAnimation->GetTransformationAtTime(argT);
//m_Transformation = m_Transformation * ( * m_InvPoseTransformation);
}
else
m_Transformation = m_TransformationAnimation->GetTransformationAtTime(argT) * m_InvPoseTransformation;
}
}
return m_Transformation;
}
const D3DXMATRIX& Bone::get_PoseTransformation() const
{
return m_PoseTransformation;
}
void Bone::set_Parent(IBone* argParent)
{
if (m_Parent != NULL)
{
std::vector<IBone*>& children = m_Parent->get_ChildBones();
for (unsigned int i = 0; i < children.size(); ++i)
if (children[i] == this)
{
children.erase(children.begin() + i);
break;
}
}
m_Parent = argParent;
if (m_Parent != NULL)
m_Parent->get_ChildBones().push_back(this);
}
IBone* Bone::get_Parent() const
{
return m_Parent;
}
std::vector<IBone*>& Bone::get_ChildBones()
{
return m_Children;
}
std::wstring Bone::get_Name() const
{
return m_Name;
}
int Bone::get_Index() const
{
return m_BoneIndex;
}
void Bone::set_TransformationAnimation(ITransformationAnimation* argTa)
{
m_TransformationAnimation = argTa;
m_LastAnimationTime = -1.0f;
m_Transformation = D3DXMATRIX();
}
ITransformationAnimation* Bone::get_TransformationAnimation() const
{
return m_TransformationAnimation;
}
std::map<int, IBone*>& Bone::get_BoneIndexList()
{
if (m_Parent != NULL)
return m_Parent->get_BoneIndexList();
if (m_BoneIndexList.empty())
this->FillBoneIndexList(this, m_BoneIndexList);
return m_BoneIndexList;
}
D3DXMATRIX* Bone::get_MatrixArray()
{
if (m_MatrixArray == NULL)
{
m_MatrixArraySize = this->get_BoneIndexList().size();
m_MatrixArray = new D3DXMATRIX[m_MatrixArraySize];
}
return m_MatrixArray;
}
unsigned int Bone::get_MatrixArraySize()
{
if (m_MatrixArray == NULL)
this->get_MatrixArray();
return m_MatrixArraySize;
}
void Bone::FillBoneIndexList(IBone* argCurrentBone, std::map<int, IBone*>& argList)
{
argList[argCurrentBone->get_Index()] = argCurrentBone;
for (unsigned int i = 0; i < argCurrentBone->get_ChildBones().size(); ++i)
this->FillBoneIndexList(argCurrentBone->get_ChildBones()[i], argList);
}

View File

@@ -0,0 +1,57 @@
#pragma once
#include "IBone.h"
#include "IEngine.h"
class Bone
: public IBone
{
public:
Bone(IEngine& argEngine);
virtual ~Bone();
virtual void Initialize(const string16& argName, int argIndex, const D3DXVECTOR3& argPoseTranslation, const D3DXVECTOR3& argPoseScale, const D3DXQUATERNION& argPoseRotation);
virtual const D3DXMATRIX& GetTransformationAtTime(float argTime, const D3DXMATRIX& argRootTransformationMatrix);
virtual const D3DXMATRIX& get_PoseTransformation() const;
virtual void set_Parent(IBone* argParent_);
virtual IBone* get_Parent() const;
virtual std::vector<IBone*>& get_ChildBones();
virtual string16 get_Name() const;
virtual int get_Index() const;
virtual void set_TransformationAnimation(ITransformationAnimation* argTransformationAnimation);
virtual ITransformationAnimation* get_TransformationAnimation() const;
virtual std::map<int, IBone*>& get_BoneIndexList();
virtual D3DXMATRIX* get_MatrixArray();
virtual unsigned int get_MatrixArraySize();
private:
void FillBoneIndexList(IBone* argCurrentBone, std::map<int, IBone*>& argList);
private:
IEngine& m_Engine;
string16 m_Name;
int m_BoneIndex;
D3DXMATRIX m_PoseTransformation;
D3DXMATRIX m_InvPoseTransformation;
float m_LastAnimationTime;
D3DXMATRIX m_Transformation;
std::vector<IBone*> m_Children;
IBone* m_Parent;
ITransformationAnimation* m_TransformationAnimation;
std::map<int, IBone*> m_BoneIndexList;
D3DXMATRIX* m_MatrixArray;
unsigned int m_MatrixArraySize;
};

View File

@@ -0,0 +1,118 @@
#include "stdafx.h"
#include "IResourceFactory.h"
#include "BoneController.h"
#include "../ShaderParameterCollection/Types/Types.h"
BoneController::BoneController(IEngine& argEngine)
: ShaderParameterCollection(argEngine)
, m_StartTime(0.0)
, m_LastMatrixArray(NULL)
{
}
BoneController::~BoneController()
{
m_Engine.get_ResourceFactory().DeleteBoneController(*const_cast<BoneController*>(this), true);
}
void BoneController::Initialize(IBone& argRootBone)
{
m_RootBone = &argRootBone;
m_Bones = m_RootBone->get_BoneIndexList();
}
void BoneController::Initialize(const IBoneController& argOther)
{
m_RootBone = &argOther.get_RootBone();
m_Bones = m_RootBone->get_BoneIndexList();
m_CurrentSequence = argOther.get_CurrentSequence();
m_Sequences = argOther.get_Sequences();
this->PlaySequence(m_CurrentSequence);
}
void BoneController::Apply()
{
float lf_Time = 0.0f;
if (!m_CurrentSequence.empty())
lf_Time = get_CurrentTime();
int i = 0;
D3DXMATRIX* lr_MatrixArray_ = m_RootBone->get_MatrixArray();
for (std::map<int, IBone*>::const_iterator lk_Iter = m_Bones.begin(); lk_Iter != m_Bones.end(); ++lk_Iter, ++i)
lr_MatrixArray_[i] = lk_Iter->second->GetTransformationAtTime(lf_Time, D3DXMATRIX());
if (m_LastMatrixArray != lr_MatrixArray_)
{
m_LastMatrixArray = lr_MatrixArray_;
this->SetParameter("BoneMatrix", new Matrix4x4ShaderParameter(m_LastMatrixArray, m_RootBone->get_MatrixArraySize(), ParameterBindType::BindBySemantic));
}
}
void BoneController::RegisterSequence(const string16& argName, float argStart, float argEnd, bool argLoop)
{
Sequence lr_NewSequence;
lr_NewSequence.m_Start = argStart;
lr_NewSequence.m_End = argEnd;
lr_NewSequence.m_Loop = argLoop;
m_Sequences[argName] = lr_NewSequence;
}
void BoneController::PlaySequence(const string16& argName)
{
m_StartTime = m_Engine.get_Timeline().get_DemoTime();
std::map<string16, Sequence >::iterator lk_Iter = m_Sequences.find(argName);
if (lk_Iter != m_Sequences.end())
{
m_CurrentSequenceInfo = lk_Iter->second;
m_CurrentSequence = argName;
}
else
m_CurrentSequence = string16();
}
const string16& BoneController::get_CurrentSequence() const
{
return m_CurrentSequence;
}
float BoneController::get_CurrentTime()
{
float lf_CurrentTime = static_cast<float>(m_Engine.get_Timeline().get_DemoTime() - m_StartTime);
lf_CurrentTime = lf_CurrentTime / (m_CurrentSequenceInfo.m_End - m_CurrentSequenceInfo.m_Start);
lf_CurrentTime = (m_CurrentSequenceInfo.m_End - m_CurrentSequenceInfo.m_Start) * lf_CurrentTime + m_CurrentSequenceInfo.m_Start;
if (lf_CurrentTime >= m_CurrentSequenceInfo.m_End)
{
while (m_CurrentSequenceInfo.m_Loop && lf_CurrentTime >= m_CurrentSequenceInfo.m_End)
{
lf_CurrentTime -= m_CurrentSequenceInfo.m_End;
m_StartTime += m_CurrentSequenceInfo.m_End;
}
if (!m_CurrentSequenceInfo.m_Loop)
lf_CurrentTime = m_CurrentSequenceInfo.m_End;
}
else if (lf_CurrentTime < m_CurrentSequenceInfo.m_Start)
{
while (m_CurrentSequenceInfo.m_Loop && lf_CurrentTime < m_CurrentSequenceInfo.m_Start)
{
lf_CurrentTime += m_CurrentSequenceInfo.m_Start;
m_StartTime -= m_CurrentSequenceInfo.m_Start;
}
if (!m_CurrentSequenceInfo.m_Loop)
lf_CurrentTime = m_CurrentSequenceInfo.m_Start;
}
return lf_CurrentTime;
}

View File

@@ -0,0 +1,51 @@
#pragma once
#include "IBone.h"
#include "IEngine.h"
#include "ITimeLine.h"
#include "IUpdatable.h"
#include "../ShaderParameterCollection/ShaderParameterCollection.h"
class BoneController
: public IBoneController
, public ShaderParameterCollection
, public IUpdatable
{
public:
BoneController(IEngine& argEngine);
virtual ~BoneController();
virtual void Initialize(IBone& argRootBone);
virtual void Initialize(const IBoneController& argOther);
virtual void Apply();
virtual void RegisterSequence(const string16& argName, float argStart, float argEnd, bool argLoop);
virtual void PlaySequence(const string16& argName);
virtual const string16& get_CurrentSequence() const;
virtual const std::map<string16, Sequence >& get_Sequences() const { return m_Sequences; }
virtual IBone& get_RootBone() const { return *m_RootBone; }
// IUpdatable
virtual void Update(bool argForceUpdate) { this->Apply(); }
virtual bool get_WantsUpdate() const { return true; }
protected:
// ICommandUser
virtual string8 get_UserName() const { return "BoneController"; }
private:
float get_CurrentTime();
IBone* m_RootBone;
double m_StartTime;
string16 m_CurrentSequence;
Sequence m_CurrentSequenceInfo;
std::map<string16, Sequence > m_Sequences;
std::map<int, IBone*> m_Bones;
D3DXMATRIX* m_LastMatrixArray;
};