From 2f02fb4535dd6fbe50eecf7dba68e2d0ea89c497 Mon Sep 17 00:00:00 2001 From: elexis Date: Sun, 9 Apr 2017 17:21:01 +0000 Subject: [PATCH] Move OpenGL CinemaPath rendering code to the CinemaManager, so that the remaining simulation data can be moved to the simulation directory. Add height indicator so that we can actually estimate the location of the paths in atlas. Differential Revision: https://code.wildfiregames.com/D306 Patch By: Vladislav This was SVN commit r19394. --- source/graphics/CinemaManager.cpp | 102 +++++++++++++++++++++++++++++- source/graphics/CinemaManager.h | 4 ++ source/graphics/CinemaPath.cpp | 96 ---------------------------- source/graphics/CinemaPath.h | 4 -- 4 files changed, 105 insertions(+), 101 deletions(-) diff --git a/source/graphics/CinemaManager.cpp b/source/graphics/CinemaManager.cpp index 561c0d7074..98c355f6b9 100644 --- a/source/graphics/CinemaManager.cpp +++ b/source/graphics/CinemaManager.cpp @@ -39,6 +39,7 @@ #include "ps/Game.h" #include "ps/GameSetup/Config.h" #include "ps/Hotkey.h" +#include "ps/World.h" #include "simulation2/components/ICmpCinemaManager.h" #include "simulation2/components/ICmpOverlayRenderer.h" #include "simulation2/components/ICmpRangeManager.h" @@ -111,7 +112,106 @@ void CCinemaManager::DrawPaths() const return; for (const std::pair& p : cmpCinemaManager->GetPaths()) - p.second.Draw(); + { + DrawSpline(p.second, CColor(0.2f, 0.2f, 1.f, 0.9f), 100, true); + DrawNodes(p.second, CColor(0.5f, 1.0f, 0.f, 1.0f)); + + if (p.second.GetTargetSpline().GetAllNodes().empty()) + continue; + + DrawSpline(p.second.GetTargetSpline(), CColor(1.0f, 0.2f, 0.2f, 0.9f), 100, true); + DrawNodes(p.second.GetTargetSpline(), CColor(1.0f, 0.5f, 0.f, 1.0f)); + } +} + +void CCinemaManager::DrawSpline(const RNSpline& spline, const CColor& splineColor, int smoothness, bool lines) const +{ + if (spline.GetAllNodes().size() < 2) + return; + if (spline.GetAllNodes().size() == 2 && lines) + smoothness = 2; + + float start = spline.MaxDistance.ToFloat() / smoothness; + float time = 0; + +#if CONFIG2_GLES + #warning TODO : implement CCinemaPath on GLES +#else + + glEnable(GL_BLEND); + glColor4f(splineColor.r, splineColor.g, splineColor.b, splineColor.a); + if (lines) + { + glLineWidth(1.8f); + glEnable(GL_LINE_SMOOTH); + glBegin(GL_LINE_STRIP); + for (int i = 0; i <= smoothness; ++i) + { + time = start * i / spline.MaxDistance.ToFloat(); + CVector3D tmp = spline.GetPosition(time); + glVertex3f(tmp.X, tmp.Y, tmp.Z); + } + glEnd(); + + // Height indicaor + if (g_Game && g_Game->GetWorld() && g_Game->GetWorld()->GetTerrain()) + { + glLineWidth(1.1f); + glBegin(GL_LINES); + for (int i = 0; i <= smoothness; ++i) + { + time = start * i / spline.MaxDistance.ToFloat(); + CVector3D tmp = spline.GetPosition(time); + float groundY = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(tmp.X, tmp.Z); + glVertex3f(tmp.X, tmp.Y, tmp.Z); + glVertex3f(tmp.X, groundY, tmp.Z); + } + glEnd(); + } + + glDisable(GL_LINE_SMOOTH); + glLineWidth(1.0f); + } + else + { + smoothness /= 2; + start = spline.MaxDistance.ToFloat() / smoothness; + glEnable(GL_POINT_SMOOTH); + glPointSize(3.0f); + glBegin(GL_POINTS); + for (int i = 0; i <= smoothness; ++i) + { + time = start * i / spline.MaxDistance.ToFloat(); + CVector3D tmp = spline.GetPosition(time); + glVertex3f(tmp.X, tmp.Y, tmp.Z); + } + glEnd(); + glPointSize(1.0f); + glDisable(GL_POINT_SMOOTH); + } + glDisable(GL_BLEND); + +#endif +} + +void CCinemaManager::DrawNodes(const RNSpline& spline, const CColor& nodeColor) const +{ +#if CONFIG2_GLES + #warning TODO : implement CCinemaPath on GLES +#else + + glEnable(GL_POINT_SMOOTH); + glPointSize(5.0f); + glColor4f(nodeColor.r, nodeColor.g, nodeColor.b, nodeColor.a); + glBegin(GL_POINTS); + + for (const SplineData& node : spline.GetAllNodes()) + glVertex3f(node.Position.X.ToFloat(), node.Position.Y.ToFloat(), node.Position.Z.ToFloat()); + + glEnd(); + glPointSize(1.0f); + glDisable(GL_POINT_SMOOTH); +#endif } void CCinemaManager::DrawBars() const diff --git a/source/graphics/CinemaManager.h b/source/graphics/CinemaManager.h index 17f7158225..087c12c9d5 100644 --- a/source/graphics/CinemaManager.h +++ b/source/graphics/CinemaManager.h @@ -26,6 +26,7 @@ #include "graphics/CinemaPath.h" #include "ps/CStr.h" +#include "ps/Shapes.h" /** * Class for in game playing of cinematics. Should only be instantiated in CGameView. @@ -42,6 +43,9 @@ public: void Render() const; void DrawBars() const; void DrawPaths() const; + void DrawSpline(const RNSpline& spline, const CColor& splineColor, int smoothness, bool lines) const; + void DrawNodes(const RNSpline& spline, const CColor& nodesColor) const; + void UpdateSessionVisibility() const; void UpdateSilhouettesVisibility() const; diff --git a/source/graphics/CinemaPath.cpp b/source/graphics/CinemaPath.cpp index ede97600f8..02d63c0fcf 100644 --- a/source/graphics/CinemaPath.cpp +++ b/source/graphics/CinemaPath.cpp @@ -84,102 +84,6 @@ CCinemaPath::CCinemaPath(const CCinemaData& data, const TNSpline& spline, const } } -void CCinemaPath::Draw() const -{ - DrawSpline(*this, CVector4D(0.2f, 0.2f, 1.f, 0.5f), 100, true); - DrawNodes(*this, CVector4D(0.5f, 1.0f, 0.f, 0.5f)); - - if (!m_LookAtTarget) - return; - - DrawSpline(m_TargetSpline, CVector4D(1.0f, 0.2f, 0.2f, 0.5f), 100, true); - DrawNodes(m_TargetSpline, CVector4D(1.0f, 0.5f, 0.f, 0.5f)); -} - -void CCinemaPath::DrawSpline(const RNSpline& spline, const CVector4D& RGBA, int smoothness, bool lines) const -{ - if (spline.NodeCount < 2 || DistModePtr == NULL) - return; - if (spline.NodeCount == 2 && lines) - smoothness = 2; - - float start = spline.MaxDistance.ToFloat() / smoothness; - float time = 0; - -#if CONFIG2_GLES - #warning TODO: do something about CCinemaPath on GLES -#else - - glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W); - if (lines) - { - glLineWidth(1.8f); - glEnable(GL_LINE_SMOOTH); - glBegin(GL_LINE_STRIP); - - for (int i = 0; i <= smoothness; ++i) - { - // Find distorted time - time = start*i / spline.MaxDistance.ToFloat(); - CVector3D tmp = spline.GetPosition(time); - glVertex3f(tmp.X, tmp.Y, tmp.Z); - } - glEnd(); - glDisable(GL_LINE_SMOOTH); - glLineWidth(1.0f); - } - else - { - smoothness /= 2; - start = spline.MaxDistance.ToFloat() / smoothness; - glEnable(GL_POINT_SMOOTH); - glPointSize(3.0f); - glBegin(GL_POINTS); - - for (int i = 0; i <= smoothness; ++i) - { - // Find distorted time - time = (this->*DistModePtr)(start*i / spline.MaxDistance.ToFloat()); - CVector3D tmp = spline.GetPosition(time); - glVertex3f(tmp.X, tmp.Y, tmp.Z); - } - glColor3f(1.0f, 1.0f, 0.0f); // yellow - - for (size_t i = 0; i < spline.GetAllNodes().size(); ++i) - glVertex3f( - spline.GetAllNodes()[i].Position.X.ToFloat(), - spline.GetAllNodes()[i].Position.Y.ToFloat(), - spline.GetAllNodes()[i].Position.Z.ToFloat() - ); - - glEnd(); - glPointSize(1.0f); - glDisable(GL_POINT_SMOOTH); - } - -#endif -} - -void CCinemaPath::DrawNodes(const RNSpline& spline, const CVector4D& RGBA) const -{ -#if CONFIG2_GLES - #warning TODO : do something about CCinemaPath on GLES -#else - glEnable(GL_POINT_SMOOTH); - glPointSize(5.0f); - - glColor4f(RGBA.X, RGBA.Y, RGBA.Z, RGBA.W); - glBegin(GL_POINTS); - const std::vector& nodes = spline.GetAllNodes(); - for (size_t i = 0; i < nodes.size(); ++i) - glVertex3f(nodes[i].Position.X.ToFloat(), nodes[i].Position.Y.ToFloat(), nodes[i].Position.Z.ToFloat()); - glEnd(); - - glPointSize(1.0f); - glDisable(GL_POINT_SMOOTH); -#endif -} - CVector3D CCinemaPath::GetNodePosition(const int index) const { return Node[index].Position; diff --git a/source/graphics/CinemaPath.h b/source/graphics/CinemaPath.h index 7fcbacd19e..68f641ee62 100644 --- a/source/graphics/CinemaPath.h +++ b/source/graphics/CinemaPath.h @@ -83,10 +83,6 @@ public: public: - void Draw() const; - void DrawSpline(const RNSpline& spline, const CVector4D& RGBA, int smoothness, bool lines) const; - void DrawNodes(const RNSpline& spline, const CVector4D& RGBA) const; - CVector3D GetNodePosition(const int index) const; fixed GetNodeDuration(const int index) const; fixed GetDuration() const;