forked from mirrors/0ad
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.
This commit is contained in:
@@ -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<CStrW, CCinemaPath>& 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<SplineData>& 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user