2016-03-12 04:58:56 +00:00
|
|
|
#include "CGuiCamera.hpp"
|
|
|
|
#include "CGuiFrame.hpp"
|
2016-03-16 03:37:51 +00:00
|
|
|
#include "Graphics/CGraphics.hpp"
|
2016-12-30 06:37:01 +00:00
|
|
|
#include "CGuiWidgetDrawParms.hpp"
|
2016-03-12 04:58:56 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
CGuiCamera::CGuiCamera(const CGuiWidgetParms& parms,
|
|
|
|
float left, float right,
|
|
|
|
float top, float bottom,
|
|
|
|
float znear, float zfar)
|
2017-04-02 03:03:37 +00:00
|
|
|
: CGuiWidget(parms), xb8_proj(EProjection::Orthographic),
|
|
|
|
xbc_left(left), xc0_right(right),
|
|
|
|
xc4_top(top), xc8_bottom(bottom),
|
|
|
|
xcc_znear(znear), xd0_zfar(zfar)
|
2016-03-16 03:37:51 +00:00
|
|
|
{}
|
2016-03-12 04:58:56 +00:00
|
|
|
|
|
|
|
CGuiCamera::CGuiCamera(const CGuiWidgetParms& parms,
|
|
|
|
float fov, float aspect,
|
|
|
|
float znear, float zfar)
|
2017-04-02 03:03:37 +00:00
|
|
|
: CGuiWidget(parms), xb8_proj(EProjection::Perspective),
|
|
|
|
xbc_fov(fov), xc0_aspect(aspect),
|
|
|
|
xc4_znear(znear), xc8_zfar(zfar)
|
2016-03-16 03:37:51 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
zeus::CVector3f CGuiCamera::ConvertToScreenSpace(const zeus::CVector3f& vec) const
|
|
|
|
{
|
|
|
|
zeus::CVector3f local = RotateTranslateW2O(vec);
|
|
|
|
if (local.isZero())
|
|
|
|
return {-1.f, -1.f, 1.f};
|
|
|
|
|
2017-04-02 03:03:37 +00:00
|
|
|
zeus::CMatrix4f mat = CGraphics::CalculatePerspectiveMatrix(xbc_fov, xc0_aspect,
|
|
|
|
xc4_znear, xc8_zfar,
|
2016-04-03 05:25:34 +00:00
|
|
|
false);
|
2016-03-16 03:37:51 +00:00
|
|
|
return mat.multiplyOneOverW(local);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiCamera::Draw(const CGuiWidgetDrawParms& parms) const
|
2016-03-12 04:58:56 +00:00
|
|
|
{
|
2017-04-02 03:03:37 +00:00
|
|
|
if (xb8_proj == EProjection::Perspective)
|
|
|
|
CGraphics::SetPerspective(xbc_fov, xc0_aspect, xc4_znear, xc8_zfar);
|
2016-03-16 03:37:51 +00:00
|
|
|
else
|
2017-04-02 03:03:37 +00:00
|
|
|
CGraphics::SetOrtho(xbc_left, xc0_right, xc4_top, xc8_bottom, xcc_znear, xd0_zfar);
|
2017-01-30 04:16:20 +00:00
|
|
|
CGraphics::SetViewPointMatrix(GetGuiFrame()->GetAspectTransform() *
|
|
|
|
zeus::CTransform::Translate(parms.x4_cameraOffset) * x34_worldXF);
|
2016-03-16 03:37:51 +00:00
|
|
|
CGuiWidget::Draw(parms);
|
2016-03-12 04:58:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 01:40:12 +00:00
|
|
|
std::shared_ptr<CGuiWidget> CGuiCamera::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp)
|
2016-03-12 04:58:56 +00:00
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
CGuiWidgetParms parms = ReadWidgetHeader(frame, in);
|
2016-06-23 19:40:09 +00:00
|
|
|
EProjection proj = EProjection(in.readUint32Big());
|
2017-01-22 01:40:12 +00:00
|
|
|
std::shared_ptr<CGuiCamera> ret = {};
|
2016-03-12 04:58:56 +00:00
|
|
|
switch (proj)
|
|
|
|
{
|
2016-06-23 19:40:09 +00:00
|
|
|
case EProjection::Perspective:
|
2016-03-12 04:58:56 +00:00
|
|
|
{
|
|
|
|
float fov = in.readFloatBig();
|
|
|
|
float aspect = in.readFloatBig();
|
|
|
|
float znear = in.readFloatBig();
|
|
|
|
float zfar = in.readFloatBig();
|
2017-01-22 01:40:12 +00:00
|
|
|
ret = std::make_shared<CGuiCamera>(parms, fov, aspect, znear, zfar);
|
2016-03-12 04:58:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-23 19:40:09 +00:00
|
|
|
case EProjection::Orthographic:
|
2016-03-12 04:58:56 +00:00
|
|
|
{
|
|
|
|
float left = in.readFloatBig();
|
|
|
|
float right = in.readFloatBig();
|
|
|
|
float top = in.readFloatBig();
|
|
|
|
float bottom = in.readFloatBig();
|
|
|
|
float znear = in.readFloatBig();
|
|
|
|
float zfar = in.readFloatBig();
|
2017-01-22 01:40:12 +00:00
|
|
|
ret = std::make_shared<CGuiCamera>(parms, left, right, top, bottom, znear, zfar);
|
2016-03-12 04:58:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-01-22 01:40:12 +00:00
|
|
|
frame->SetFrameCamera(ret->shared_from_this());
|
|
|
|
ret->ParseBaseInfo(frame, in, parms);
|
2016-03-12 04:58:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|