Render trace colors in the code instead of using texture

master
krzys-h 2015-08-18 22:09:33 +02:00
parent b086c52b14
commit 371621ced4
6 changed files with 118 additions and 177 deletions

2
data

@ -1 +1 @@
Subproject commit 06ad8a0d365033e86e5716273bd17e46d94ca7bc
Subproject commit 2ee08c5397658bbebe5d1593472fdd67a7b2778c

View File

@ -597,18 +597,17 @@ int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim
void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2,
const Math::Vector &p3, const Math::Vector &p4,
ParticleType type)
TraceColor color)
{
int max = MAXWHEELTRACE;
int i = m_wheelTraceIndex++;
if (m_wheelTraceIndex > max) m_wheelTraceIndex = 0;
m_wheelTrace[i].type = type;
m_wheelTrace[i].color = color;
m_wheelTrace[i].pos[0] = p1; // ul
m_wheelTrace[i].pos[1] = p2; // dl
m_wheelTrace[i].pos[2] = p3; // ur
m_wheelTrace[i].pos[3] = p4; // dr
m_wheelTrace[i].startTime = m_absTime;
if (m_terrain == nullptr)
m_terrain = m_main->GetTerrain();
@ -3310,139 +3309,58 @@ void CParticle::DrawParticleWheel(int i)
float dist = Math::DistanceProjected(m_engine->GetEyePt(), m_wheelTrace[i].pos[0]);
if (dist > 300.0f) return;
Math::Vector pos[4];
pos[0] = m_wheelTrace[i].pos[0];
pos[1] = m_wheelTrace[i].pos[1];
pos[2] = m_wheelTrace[i].pos[2];
pos[3] = m_wheelTrace[i].pos[3];
if (m_wheelTrace[i].color == TraceColor::BlackArrow || m_wheelTrace[i].color == TraceColor::RedArrow)
{
m_engine->SetTexture("textures/effect03.png");
m_engine->SetState(ENG_RSTATE_ALPHA);
Math::Point ts;
Math::Vector pos[4];
pos[0] = m_wheelTrace[i].pos[0];
pos[1] = m_wheelTrace[i].pos[1];
pos[2] = m_wheelTrace[i].pos[2];
pos[3] = m_wheelTrace[i].pos[3];
if (m_wheelTrace[i].type == PARTITRACE0) // white ground track?
{
ts.x = 8.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE1) // black ground track?
{
ts.x = 0.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE2) // gray ground track?
{
ts.x = 0.0f/256.0f;
ts.y = 232.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE3) // light gray ground track?
{
ts.x = 8.0f/256.0f;
ts.y = 232.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE4) // red ground track?
{
ts.x = 32.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE5) // pink ground track?
{
ts.x = 40.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE6) // violet ground track?
{
ts.x = 32.0f/256.0f;
ts.y = 232.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE7) // orange ground track?
{
ts.x = 40.0f/256.0f;
ts.y = 232.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE8) // yellow ground track?
{
ts.x = 16.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE9) // beige ground track?
{
ts.x = 24.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE10) // brown ground track?
{
ts.x = 16.0f/256.0f;
ts.y = 232.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE11) // skin ground track?
{
ts.x = 24.0f/256.0f;
ts.y = 232.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE12) // green ground track?
{
ts.x = 48.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE13) // light green ground track?
{
ts.x = 56.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE14) // blue ground track?
{
ts.x = 48.0f/256.0f;
ts.y = 232.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE15) // light blue ground track?
{
ts.x = 56.0f/256.0f;
ts.y = 232.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE16) // black arrow ground track?
{
ts.x = 160.0f/256.0f;
ts.y = 224.0f/256.0f;
}
else if (m_wheelTrace[i].type == PARTITRACE17) // red arrow ground track?
{
ts.x = 176.0f/256.0f;
ts.y = 224.0f/256.0f;
Math::Vector n(0.0f, 1.0f, 0.0f);
Math::Point ts(160.0f/256.0f, 224.0f/256.0f);
Math::Point ti(ts.x+16.0f/256.0f, ts.y+16.0f/256.0f);
float dp = (1.0f/256.0f)/2.0f;
ts.x = ts.x+dp;
ts.y = ts.y+dp;
ti.x = ti.x-dp;
ti.y = ti.y-dp;
Vertex vertex[4];
vertex[0] = Vertex(pos[0], n, Math::Point(ts.x, ts.y));
vertex[1] = Vertex(pos[1], n, Math::Point(ti.x, ts.y));
vertex[2] = Vertex(pos[2], n, Math::Point(ts.x, ti.y));
vertex[3] = Vertex(pos[3], n, Math::Point(ti.x, ti.y));
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4, TraceColorColor(m_wheelTrace[i].color));
m_engine->AddStatisticTriangle(2);
m_engine->SetState(ENG_RSTATE_OPAQUE_COLOR);
}
else
{
return;
Math::Vector pos[4];
pos[0] = m_wheelTrace[i].pos[0];
pos[1] = m_wheelTrace[i].pos[1];
pos[2] = m_wheelTrace[i].pos[2];
pos[3] = m_wheelTrace[i].pos[3];
Math::Vector n(0.0f, 1.0f, 0.0f);
Vertex vertex[4];
vertex[0] = Vertex(pos[0], n);
vertex[1] = Vertex(pos[1], n);
vertex[2] = Vertex(pos[2], n);
vertex[3] = Vertex(pos[3], n);
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4, TraceColorColor(m_wheelTrace[i].color));
m_engine->AddStatisticTriangle(2);
}
Math::Point ti;
if ( m_wheelTrace[i].type == PARTITRACE16 ||
m_wheelTrace[i].type == PARTITRACE17 )
{
ti.x = ts.x+16.0f/256.0f;
ti.y = ts.y+16.0f/256.0f;
}
else
{
ti.x = ts.x+8.0f/256.0f;
ti.y = ts.y+8.0f/256.0f;
}
float dp = (1.0f/256.0f)/2.0f;
ts.x = ts.x+dp;
ts.y = ts.y+dp;
ti.x = ti.x-dp;
ti.y = ti.y-dp;
Math::Vector n(0.0f, 1.0f, 0.0f);
Vertex vertex[4];
vertex[0] = Vertex(pos[0], n, Math::Point(ts.x, ts.y));
vertex[1] = Vertex(pos[1], n, Math::Point(ti.x, ts.y));
vertex[2] = Vertex(pos[2], n, Math::Point(ts.x, ti.y));
vertex[3] = Vertex(pos[3], n, Math::Point(ti.x, ti.y));
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
m_engine->AddStatisticTriangle(2);
}
void CParticle::DrawParticle(int sheet)
@ -3475,8 +3393,7 @@ void CParticle::DrawParticle(int sheet)
// Draw tire marks.
if (m_wheelTraceTotal > 0 && sheet == SH_WORLD)
{
m_engine->SetTexture("textures/effect03.png");
m_engine->SetState(ENG_RSTATE_ALPHA);
m_engine->SetState(ENG_RSTATE_OPAQUE_COLOR);
Math::Matrix matrix;
matrix.LoadIdentity();
m_device->SetTransform(TRANSFORM_WORLD, matrix);

View File

@ -27,6 +27,8 @@
#include "graphics/engine/engine.h"
#include "object/interface/trace_drawing_object.h"
#include "sound/sound_type.h"
@ -150,24 +152,6 @@ enum ParticleType
PARTIEXPLOG1 = 122, //! < ball explosion 1
PARTIEXPLOG2 = 123, //! < ball explosion 2
PARTIBASE = 124, //! < gases of spaceship
PARTITRACE0 = 140, //! < trace
PARTITRACE1 = 141, //! < trace
PARTITRACE2 = 142, //! < trace
PARTITRACE3 = 143, //! < trace
PARTITRACE4 = 144, //! < trace
PARTITRACE5 = 145, //! < trace
PARTITRACE6 = 146, //! < trace
PARTITRACE7 = 147, //! < trace
PARTITRACE8 = 148, //! < trace
PARTITRACE9 = 149, //! < trace
PARTITRACE10 = 150, //! < trace
PARTITRACE11 = 151, //! < trace
PARTITRACE12 = 152, //! < trace
PARTITRACE13 = 153, //! < trace
PARTITRACE14 = 154, //! < trace
PARTITRACE15 = 155, //! < trace
PARTITRACE16 = 156, //! < trace
PARTITRACE17 = 157, //! < trace
};
enum ParticlePhase
@ -225,9 +209,8 @@ struct Track
struct WheelTrace
{
ParticleType type = {}; // type PARTI*
Math::Vector pos[4]; // rectangle positions
float startTime = 0.0f; // beginning of life
TraceColor color = {};
Math::Vector pos[4];
};
@ -277,7 +260,7 @@ public:
//! Creates a tire mark
void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3,
const Math::Vector &p4, ParticleType type);
const Math::Vector &p4, TraceColor color);
//! Removes all particles of a given type
void DeleteParticle(ParticleType type);

View File

@ -19,28 +19,63 @@
#include "object/interface/trace_drawing_object.h"
#include "graphics/core/color.h"
#include <cassert>
std::string TraceColorName(TraceColor color)
{
switch(color)
{
case TraceColor::White: return "White"; break;
case TraceColor::Black: return "Black"; break;
case TraceColor::Gray: return "Gray"; break;
case TraceColor::LightGray: return "LightGray"; break;
case TraceColor::Red: return "Red"; break;
case TraceColor::Pink: return "Pink"; break;
case TraceColor::Purple: return "Purple"; break;
case TraceColor::Orange: return "Orange"; break;
case TraceColor::Yellow: return "Yellow"; break;
case TraceColor::Beige: return "Beige"; break;
case TraceColor::Brown: return "Brown"; break;
case TraceColor::Skin: return "Skin"; break;
case TraceColor::Green: return "Green"; break;
case TraceColor::LightGreen: return "LightGreen"; break;
case TraceColor::Blue: return "Blue"; break;
case TraceColor::LightBlue: return "LightBlue"; break;
case TraceColor::RedArrow: return "RedArrow"; break;
case TraceColor::BlackArrow: return "BlackArrow"; break;
default: return ""; break;
case TraceColor::White: return "White";
case TraceColor::Black: return "Black";
case TraceColor::Gray: return "Gray";
case TraceColor::LightGray: return "LightGray";
case TraceColor::Red: return "Red";
case TraceColor::Pink: return "Pink";
case TraceColor::Purple: return "Purple";
case TraceColor::Orange: return "Orange";
case TraceColor::Yellow: return "Yellow";
case TraceColor::Beige: return "Beige";
case TraceColor::Brown: return "Brown";
case TraceColor::Skin: return "Skin";
case TraceColor::Green: return "Green";
case TraceColor::LightGreen: return "LightGreen";
case TraceColor::Blue: return "Blue";
case TraceColor::LightBlue: return "LightBlue";
case TraceColor::RedArrow: return "RedArrow";
case TraceColor::BlackArrow: return "BlackArrow";
default:
assert(false);
return "";
}
}
Gfx::Color TraceColorColor(TraceColor color)
{
switch(color)
{
case TraceColor::White: return Gfx::Color(1.000f, 1.000f, 1.000f, 1.0f);
case TraceColor::Black: return Gfx::Color(0.000f, 0.000f, 0.000f, 1.0f);
case TraceColor::Gray: return Gfx::Color(0.549f, 0.549f, 0.549f, 1.0f);
case TraceColor::LightGray: return Gfx::Color(0.753f, 0.753f, 0.753f, 1.0f);
case TraceColor::Red: return Gfx::Color(1.000f, 0.000f, 0.000f, 1.0f);
case TraceColor::Pink: return Gfx::Color(1.000f, 0.627f, 0.753f, 1.0f);
case TraceColor::Purple: return Gfx::Color(0.878f, 0.000f, 0.753f, 1.0f);
case TraceColor::Orange: return Gfx::Color(1.000f, 0.627f, 0.000f, 1.0f);
case TraceColor::Yellow: return Gfx::Color(1.000f, 1.000f, 0.000f, 1.0f);
case TraceColor::Beige: return Gfx::Color(0.878f, 0.753f, 0.000f, 1.0f);
case TraceColor::Brown: return Gfx::Color(0.627f, 0.361f, 0.000f, 1.0f);
case TraceColor::Skin: return Gfx::Color(0.961f, 0.839f, 0.714f, 1.0f);
case TraceColor::Green: return Gfx::Color(0.000f, 0.627f, 0.000f, 1.0f);
case TraceColor::LightGreen: return Gfx::Color(0.000f, 1.000f, 0.000f, 1.0f);
case TraceColor::Blue: return Gfx::Color(0.000f, 0.000f, 0.753f, 1.0f);
case TraceColor::LightBlue: return Gfx::Color(0.000f, 0.871f, 1.000f, 1.0f);
case TraceColor::BlackArrow: return TraceColorColor(TraceColor::Black);
case TraceColor::RedArrow: return TraceColorColor(TraceColor::Red); //TODO: We could probably have all the colors available as arrows now
default:
assert(false);
return Gfx::Color();
}
}

View File

@ -23,6 +23,11 @@
#include <string>
namespace Gfx
{
struct Color;
}
enum class TraceColor
{
Default = -1,
@ -49,6 +54,8 @@ enum class TraceColor
};
//! Convert TraceColor to a std::string
std::string TraceColorName(TraceColor c);
//! Return Gfx::Color for this TraceColor constants
Gfx::Color TraceColorColor(TraceColor c);
/**
* \class CTraceDrawingObject

View File

@ -3667,7 +3667,6 @@ void CPhysics::WheelParticle(TraceColor color, float width)
// Draw a trace on the ground.
if ( color != TraceColor::Default )
{
parti = static_cast<Gfx::ParticleType>(Gfx::PARTITRACE0+static_cast<int>(color));
step = 2.0f;
if ( color == TraceColor::BlackArrow ||
color == TraceColor::RedArrow )
@ -3704,11 +3703,11 @@ void CPhysics::WheelParticle(TraceColor color, float width)
if ( m_linMotion.realSpeed.x >= 0.0f )
{
m_particle->CreateWheelTrace(m_wheelParticlePos[0], m_wheelParticlePos[1], wheel1, wheel2, parti);
m_particle->CreateWheelTrace(m_wheelParticlePos[0], m_wheelParticlePos[1], wheel1, wheel2, color);
}
else
{
m_particle->CreateWheelTrace(m_wheelParticlePos[1], m_wheelParticlePos[0], wheel2, wheel1, parti);
m_particle->CreateWheelTrace(m_wheelParticlePos[1], m_wheelParticlePos[0], wheel2, wheel1, color);
}
m_wheelParticlePos[0] = wheel1;