[colobot] 38/100: Fix apperance camera position, closes #802 (#880)

Didier Raboud odyx at moszumanska.debian.org
Thu Jun 1 18:10:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 6ec13017ebae1bf5864ee208d44e4ed66b7c48aa
Author: piotrwalkusz1 <piotrwalkusz1 at users.noreply.github.com>
Date:   Mon Jan 2 18:43:19 2017 +0100

    Fix apperance camera position, closes #802 (#880)
---
 src/graphics/engine/engine.cpp     |  5 +++++
 src/graphics/engine/engine.h       |  2 ++
 src/ui/screen/screen_apperance.cpp | 45 ++++++++++++++++++++++++++++++++------
 src/ui/screen/screen_apperance.h   |  3 +++
 4 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 3110cd3..768897f 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -3087,6 +3087,11 @@ const Math::Matrix& CEngine::GetMatView()
     return m_matView;
 }
 
+const Math::Matrix& CEngine::GetMatProj()
+{
+    return m_matProj;
+}
+
 Math::Vector CEngine::GetEyePt()
 {
     return m_eyePt;
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index e1dadf4..834de1e 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -1135,6 +1135,8 @@ public:
 
     //! Returns the view matrix
     const Math::Matrix& GetMatView();
+    //! Returns the projection matrix
+    const Math::Matrix& GetMatProj();
     //! Returns the camera center point
     TEST_VIRTUAL Math::Vector GetEyePt();
     //! Returns the camera target point
diff --git a/src/ui/screen/screen_apperance.cpp b/src/ui/screen/screen_apperance.cpp
index 3e8cdd0..7ca200f 100644
--- a/src/ui/screen/screen_apperance.cpp
+++ b/src/ui/screen/screen_apperance.cpp
@@ -28,6 +28,8 @@
 #include "level/player_profile.h"
 #include "level/robotmain.h"
 
+#include "math/geometry.h"
+
 #include "ui/controls/button.h"
 #include "ui/controls/color.h"
 #include "ui/controls/interface.h"
@@ -331,6 +333,10 @@ bool CScreenApperance::EventProcess(const Event &event)
             break;
         }
 
+        case EVENT_UPDINTERFACE:
+            CameraPerso();
+            break;
+
         case EVENT_INTERFACE_PHEAD:
             m_apperanceTab = 0;
             UpdatePerso();
@@ -617,18 +623,13 @@ void CScreenApperance::UpdatePerso()
 
 void CScreenApperance::CameraPerso()
 {
-    Gfx::CCamera* camera = m_main->GetCamera();
-
-    camera->SetType(Gfx::CAM_TYPE_SCRIPT);
     if ( m_apperanceTab == 0 )
     {
-        camera->SetScriptCamera(Math::Vector(6.0f, 0.0f, 0.0f),
-                                Math::Vector(0.0f, 0.2f, 1.5f));
+        SetCamera(0.325f, -0.15f, 5.0f);
     }
     else
     {
-        camera->SetScriptCamera(Math::Vector(18.0f, 0.0f, 4.5f),
-                                Math::Vector(0.0f, 1.6f, 4.5f));
+        SetCamera(0.325f, 0.3f, 18.0f);
     }
 }
 
@@ -696,4 +697,34 @@ void CScreenApperance::ColorPerso()
     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
diff --git a/src/ui/screen/screen_apperance.h b/src/ui/screen/screen_apperance.h
index 1aa6c8a..b5faf08 100644
--- a/src/ui/screen/screen_apperance.h
+++ b/src/ui/screen/screen_apperance.h
@@ -40,6 +40,9 @@ protected:
     void FixPerso(int rank, int index);
     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:
     int             m_apperanceTab;         // perso: tab selected
     float           m_apperanceAngle;           // perso: angle of presentation

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list