2016-03-10 03:47:37 +00:00
|
|
|
#include "CGuiObject.hpp"
|
2016-03-17 02:18:01 +00:00
|
|
|
#include "CGuiWidgetDrawParms.hpp"
|
2016-03-30 20:44:19 +00:00
|
|
|
#include "Graphics/CTexture.hpp"
|
2016-03-10 03:47:37 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
void CGuiObject::Update(float dt)
|
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
if (x68_child)
|
|
|
|
x68_child->Update(dt);
|
|
|
|
if (x6c_nextSibling)
|
|
|
|
x6c_nextSibling->Update(dt);
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiObject::Draw(const CGuiWidgetDrawParms& parms) const
|
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
if (x68_child)
|
|
|
|
x68_child->Draw(parms);
|
|
|
|
if (x6c_nextSibling)
|
|
|
|
x6c_nextSibling->Draw(parms);
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiObject::MoveInWorld(const zeus::CVector3f& vec)
|
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
if (x64_parent)
|
|
|
|
x64_parent->RotateW2O(vec);
|
2016-04-29 10:08:46 +00:00
|
|
|
x4_localXF.origin += vec;
|
2016-03-10 03:47:37 +00:00
|
|
|
Reorthogonalize();
|
|
|
|
RecalculateTransforms();
|
|
|
|
}
|
|
|
|
|
2016-03-14 00:58:19 +00:00
|
|
|
void CGuiObject::SetLocalPosition(const zeus::CVector3f& pos)
|
|
|
|
{
|
2016-04-29 10:08:46 +00:00
|
|
|
MoveInWorld(pos - x4_localXF.origin);
|
2016-03-14 00:58:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 03:47:37 +00:00
|
|
|
void CGuiObject::RotateReset()
|
|
|
|
{
|
2016-04-29 10:08:46 +00:00
|
|
|
x4_localXF.basis = zeus::CMatrix3f::skIdentityMatrix3f;
|
2016-03-11 00:23:16 +00:00
|
|
|
Reorthogonalize();
|
|
|
|
RecalculateTransforms();
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CVector3f CGuiObject::RotateW2O(const zeus::CVector3f& vec) const
|
|
|
|
{
|
2016-03-11 00:23:16 +00:00
|
|
|
return x34_worldXF.transposeRotate(vec);
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CVector3f CGuiObject::RotateO2P(const zeus::CVector3f& vec) const
|
|
|
|
{
|
2016-03-11 00:23:16 +00:00
|
|
|
return x4_localXF.rotate(vec);
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CVector3f CGuiObject::RotateTranslateW2O(const zeus::CVector3f& vec) const
|
|
|
|
{
|
2016-04-29 10:08:46 +00:00
|
|
|
return x34_worldXF.transposeRotate(vec - x34_worldXF.origin);
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiObject::MultiplyO2P(const zeus::CTransform& xf)
|
|
|
|
{
|
|
|
|
x4_localXF = xf * x4_localXF;
|
|
|
|
Reorthogonalize();
|
|
|
|
RecalculateTransforms();
|
|
|
|
}
|
|
|
|
|
2016-03-11 00:23:16 +00:00
|
|
|
void CGuiObject::AddChildObject(CGuiObject* obj, bool makeWorldLocal, bool atEnd)
|
2016-03-10 03:47:37 +00:00
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
obj->x64_parent = this;
|
2016-03-10 03:47:37 +00:00
|
|
|
|
2017-01-22 01:40:12 +00:00
|
|
|
if (!x68_child)
|
2016-03-10 03:47:37 +00:00
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
x68_child = obj;
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
else if (atEnd)
|
|
|
|
{
|
|
|
|
CGuiObject* prev = nullptr;
|
2017-01-22 01:40:12 +00:00
|
|
|
CGuiObject* cur = x68_child;
|
|
|
|
for (; cur ; cur = cur->x6c_nextSibling) {prev = cur;}
|
2016-03-10 03:47:37 +00:00
|
|
|
if (prev)
|
2017-01-22 01:40:12 +00:00
|
|
|
prev->x6c_nextSibling = obj;
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
obj->x6c_nextSibling = x68_child;
|
|
|
|
x68_child = obj;
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 00:23:16 +00:00
|
|
|
if (makeWorldLocal)
|
2016-03-10 03:47:37 +00:00
|
|
|
{
|
2016-04-29 10:08:46 +00:00
|
|
|
zeus::CVector3f negParentWorld = -x34_worldXF.origin;
|
2016-03-11 00:23:16 +00:00
|
|
|
zeus::CMatrix3f basisMat(
|
2016-04-29 10:08:46 +00:00
|
|
|
x34_worldXF.basis[0] / x34_worldXF.basis[0].magnitude(),
|
|
|
|
x34_worldXF.basis[1] / x34_worldXF.basis[1].magnitude(),
|
|
|
|
x34_worldXF.basis[2] / x34_worldXF.basis[2].magnitude());
|
2016-03-11 00:23:16 +00:00
|
|
|
zeus::CVector3f xfWorld = basisMat * negParentWorld;
|
|
|
|
obj->x4_localXF = zeus::CTransform(basisMat, xfWorld) * obj->x34_worldXF;
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RecalculateTransforms();
|
|
|
|
}
|
|
|
|
|
|
|
|
CGuiObject* CGuiObject::RemoveChildObject(CGuiObject* obj, bool makeWorldLocal)
|
|
|
|
{
|
|
|
|
CGuiObject* prev = nullptr;
|
2017-01-22 01:40:12 +00:00
|
|
|
CGuiObject* cur = x68_child;
|
|
|
|
for (; cur && cur != obj ; cur = cur->x6c_nextSibling) {prev = cur;}
|
2016-03-10 03:47:37 +00:00
|
|
|
if (!cur)
|
|
|
|
return nullptr;
|
|
|
|
if (prev)
|
2017-01-22 01:40:12 +00:00
|
|
|
prev->x6c_nextSibling = cur->x6c_nextSibling;
|
|
|
|
cur->x6c_nextSibling = nullptr;
|
|
|
|
cur->x64_parent = nullptr;
|
2016-03-10 03:47:37 +00:00
|
|
|
|
|
|
|
if (makeWorldLocal)
|
|
|
|
cur->x4_localXF = cur->x34_worldXF;
|
|
|
|
cur->RecalculateTransforms();
|
|
|
|
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiObject::RecalculateTransforms()
|
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
if (x64_parent)
|
|
|
|
x34_worldXF = x64_parent->x34_worldXF * x4_localXF;
|
2016-03-10 03:47:37 +00:00
|
|
|
else
|
|
|
|
x34_worldXF = x4_localXF;
|
|
|
|
|
2017-01-22 01:40:12 +00:00
|
|
|
if (x6c_nextSibling)
|
|
|
|
x6c_nextSibling->RecalculateTransforms();
|
|
|
|
if (x68_child)
|
|
|
|
x68_child->RecalculateTransforms();
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiObject::Reorthogonalize()
|
|
|
|
{
|
|
|
|
static bool Global = false;
|
|
|
|
if (Global)
|
|
|
|
{
|
|
|
|
x4_localXF.orthonormalize();
|
|
|
|
RecalculateTransforms();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiObject::SetO2WTransform(const zeus::CTransform& xf)
|
|
|
|
{
|
|
|
|
x4_localXF = GetParent()->x34_worldXF.inverse() * xf;
|
|
|
|
RecalculateTransforms();
|
|
|
|
}
|
|
|
|
|
2016-12-16 04:35:49 +00:00
|
|
|
void CGuiObject::SetLocalTransform(const zeus::CTransform& xf)
|
|
|
|
{
|
|
|
|
x4_localXF = xf;
|
|
|
|
RecalculateTransforms();
|
|
|
|
}
|
|
|
|
|
2016-03-10 03:47:37 +00:00
|
|
|
}
|