port from perforce
This commit is contained in:
150
aiwaz/Aiwaz/Resources/Bone/Bone.cpp
Normal file
150
aiwaz/Aiwaz/Resources/Bone/Bone.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user