1
0
forked from 0ad/0ad
0ad/source/tools/atlas/GameInterface/Brushes.cpp
janwas 6668ad6e1c CTerrain, Brushes: made CalcFromPosition static and added float x,y overload
minimap, PatchRData, renderer: fix ELOSState comparison vs & and use
SAFE_DELETE
ia32: add rounding control constants (for FISTP)
premake: set /QIfist compiler setting which causes float->int casts to
go through FISTP instruction instead of _ftol2() (much faster, but
requires CPU state to have been set)
LOSManager.cpp: cache m_TilesPerSize; use MIN/MAX; use
CTerrain::CalcFromPosition; clean up GetUnitState a bit. now runs at
203ns, down from 222

This was SVN commit r3099.
2005-11-06 01:33:16 +00:00

82 lines
1.4 KiB
C++

#include "precompiled.h"
#include "Brushes.h"
#include "ps/Game.h"
#include "graphics/Terrain.h"
#include "lib/ogl.h"
#include "maths/MathUtil.h"
using namespace AtlasMessage;
Brush::Brush()
: m_W(0), m_H(0), m_Data(NULL), m_Enabled(false)
{
}
Brush::~Brush()
{
delete[] m_Data;
}
void Brush::SetData(int w, int h, const float* data)
{
m_W = w;
m_H = h;
delete[] m_Data;
m_Data = data;
}
void Brush::GetBottomRight(int& x, int& y) const
{
CVector3D c = m_Centre;
if (m_W % 2) c.X += CELL_SIZE/2.f;
if (m_H % 2) c.Z += CELL_SIZE/2.f;
i32 cx, cy;
CTerrain::CalcFromPosition(c, cx, cy);
x = cx - (m_W-1)/2;
y = cy - (m_H-1)/2;
}
void Brush::SetRenderEnabled(bool enabled)
{
m_Enabled = enabled;
}
void Brush::Render()
{
if (! m_Enabled)
return;
glPointSize(4.f); // TODO: does this clobber state that other people expect to stay unchanged?
glDisable(GL_DEPTH_TEST);
glBegin(GL_POINTS);
int x0, y0;
GetBottomRight(x0, y0);
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
for (int dy = 0; dy < m_H; ++dy)
{
for (int dx = 0; dx < m_W; ++dx)
{
glColor3f(0.f, clamp(m_Data[dx + dy*m_W], 0.f, 1.f), 0.f);
CVector3D pos;
terrain->CalcPosition(x0+dx, y0+dy, pos);
glVertex3f(pos.X, pos.Y, pos.Z);
//debug_printf("%f %f %f\n", pos.X, pos.Y, pos.Z);
}
}
glEnd();
glEnable(GL_DEPTH_TEST);
}
Brush AtlasMessage::g_CurrentBrush;