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-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)
|
2016-03-16 03:37:51 +00:00
|
|
|
: CGuiWidget(parms),
|
|
|
|
xfc_left(left), x100_right(right),
|
|
|
|
x104_top(top), x108_bottom(bottom),
|
|
|
|
x10c_znear(znear), x110_zfar(zfar)
|
|
|
|
{}
|
2016-03-12 04:58:56 +00:00
|
|
|
|
|
|
|
CGuiCamera::CGuiCamera(const CGuiWidgetParms& parms,
|
|
|
|
float fov, float aspect,
|
|
|
|
float znear, float zfar)
|
2016-03-16 03:37:51 +00:00
|
|
|
: CGuiWidget(parms),
|
|
|
|
xfc_fov(fov), x100_aspect(aspect),
|
|
|
|
x104_znear(znear), x108_zfar(zfar)
|
|
|
|
{}
|
|
|
|
|
|
|
|
zeus::CVector3f CGuiCamera::ConvertToScreenSpace(const zeus::CVector3f& vec) const
|
|
|
|
{
|
|
|
|
zeus::CVector3f local = RotateTranslateW2O(vec);
|
|
|
|
if (local.isZero())
|
|
|
|
return {-1.f, -1.f, 1.f};
|
|
|
|
|
|
|
|
zeus::CMatrix4f mat = CGraphics::CalculatePerspectiveMatrix(xfc_fov, x100_aspect,
|
2016-04-03 05:25:34 +00:00
|
|
|
x104_znear, x108_zfar,
|
|
|
|
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
|
|
|
{
|
2016-06-23 19:40:09 +00:00
|
|
|
if (xf8_proj == EProjection::Perspective)
|
2016-03-16 03:37:51 +00:00
|
|
|
CGraphics::SetPerspective(xfc_fov, x100_aspect, x104_znear, x108_zfar);
|
|
|
|
else
|
|
|
|
CGraphics::SetOrtho(xfc_left, x100_right, x104_top, x108_bottom, x10c_znear, x110_zfar);
|
|
|
|
CGraphics::SetViewPointMatrix(x34_worldXF);
|
|
|
|
CGuiWidget::Draw(parms);
|
2016-03-12 04:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CGuiCamera* CGuiCamera::Create(CGuiFrame* frame, CInputStream& in, bool flag)
|
|
|
|
{
|
|
|
|
CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag);
|
2016-06-23 19:40:09 +00:00
|
|
|
EProjection proj = EProjection(in.readUint32Big());
|
2016-03-12 04:58:56 +00:00
|
|
|
CGuiCamera* ret = nullptr;
|
|
|
|
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();
|
|
|
|
ret = new CGuiCamera(parms, fov, aspect, znear, zfar);
|
|
|
|
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();
|
|
|
|
ret = new CGuiCamera(parms, left, right, top, bottom, znear, zfar);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame->SetFrameCamera(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|