Fix apperance camera position, closes #802 (#880)

dev-buzzingcars
piotrwalkusz1 2017-01-02 18:43:19 +01:00 committed by krzys_h
parent 9bdd83771e
commit 6ec13017eb
4 changed files with 48 additions and 7 deletions

View File

@ -3087,6 +3087,11 @@ const Math::Matrix& CEngine::GetMatView()
return m_matView; return m_matView;
} }
const Math::Matrix& CEngine::GetMatProj()
{
return m_matProj;
}
Math::Vector CEngine::GetEyePt() Math::Vector CEngine::GetEyePt()
{ {
return m_eyePt; return m_eyePt;

View File

@ -1135,6 +1135,8 @@ public:
//! Returns the view matrix //! Returns the view matrix
const Math::Matrix& GetMatView(); const Math::Matrix& GetMatView();
//! Returns the projection matrix
const Math::Matrix& GetMatProj();
//! Returns the camera center point //! Returns the camera center point
TEST_VIRTUAL Math::Vector GetEyePt(); TEST_VIRTUAL Math::Vector GetEyePt();
//! Returns the camera target point //! Returns the camera target point

View File

@ -28,6 +28,8 @@
#include "level/player_profile.h" #include "level/player_profile.h"
#include "level/robotmain.h" #include "level/robotmain.h"
#include "math/geometry.h"
#include "ui/controls/button.h" #include "ui/controls/button.h"
#include "ui/controls/color.h" #include "ui/controls/color.h"
#include "ui/controls/interface.h" #include "ui/controls/interface.h"
@ -331,6 +333,10 @@ bool CScreenApperance::EventProcess(const Event &event)
break; break;
} }
case EVENT_UPDINTERFACE:
CameraPerso();
break;
case EVENT_INTERFACE_PHEAD: case EVENT_INTERFACE_PHEAD:
m_apperanceTab = 0; m_apperanceTab = 0;
UpdatePerso(); UpdatePerso();
@ -617,18 +623,13 @@ void CScreenApperance::UpdatePerso()
void CScreenApperance::CameraPerso() void CScreenApperance::CameraPerso()
{ {
Gfx::CCamera* camera = m_main->GetCamera();
camera->SetType(Gfx::CAM_TYPE_SCRIPT);
if ( m_apperanceTab == 0 ) if ( m_apperanceTab == 0 )
{ {
camera->SetScriptCamera(Math::Vector(6.0f, 0.0f, 0.0f), SetCamera(0.325f, -0.15f, 5.0f);
Math::Vector(0.0f, 0.2f, 1.5f));
} }
else else
{ {
camera->SetScriptCamera(Math::Vector(18.0f, 0.0f, 4.5f), SetCamera(0.325f, 0.3f, 18.0f);
Math::Vector(0.0f, 1.6f, 4.5f));
} }
} }
@ -696,4 +697,34 @@ void CScreenApperance::ColorPerso()
else apperance.colorBand = color; else apperance.colorBand = color;
} }
void CScreenApperance::SetCamera(float x, float y, float cameraDistance)
{
Gfx::CCamera* camera = m_main->GetCamera();
Gfx::CEngine* engine = Gfx::CEngine::GetInstancePointer();
camera->SetType(Gfx::CAM_TYPE_SCRIPT);
Math::Vector p2D(x, y, cameraDistance);
Math::Vector p3D;
Math::Matrix matView;
Math::Matrix matProj = engine->GetMatProj();
Math::LoadViewMatrix(matView, Math::Vector(0.0f, 0.0f, -cameraDistance),
Math::Vector(0.0f, 0.0f, 0.0f),
Math::Vector(0.0f, 0.0f, 1.0f));
p2D.x = p2D.x * 2.0f - 1.0f; // [0..1] -> [-1..1]
p2D.y = p2D.y * 2.0f - 1.0f;
p3D.x = p2D.x * p2D.z / matProj.Get(1,1);
p3D.y = p2D.y * p2D.z / matProj.Get(2,2);
p3D.z = p2D.z;
p3D = Math::Transform(matView.Inverse(), p3D);
p3D = -p3D;
camera->SetScriptCamera(Math::Vector(cameraDistance, p3D.y, p3D.x),
Math::Vector(0.0f, p3D.y, p3D.x));
}
} // namespace Ui } // namespace Ui

View File

@ -40,6 +40,9 @@ protected:
void FixPerso(int rank, int index); void FixPerso(int rank, int index);
void ColorPerso(); void ColorPerso();
//! Move camera in that way that astronaut's origin is in (x, y) point on window
void SetCamera(float x, float y, float cameraDistance);
protected: protected:
int m_apperanceTab; // perso: tab selected int m_apperanceTab; // perso: tab selected
float m_apperanceAngle; // perso: angle of presentation float m_apperanceAngle; // perso: angle of presentation