Files
0ad/source/tools/atlas/GameInterface/Brushes.cpp
T
Ykkrosh 8a11f53011 # More consistent terrain-space coordinate names
# Removed more ancient unused code
# Partial VC2005 compatibility for Atlas editor / AoE3Ed
# Terrain overlay rendering system; used to implemented Atlas brush
display
# Renamed 'right' to 'left'

This was SVN commit r3771.
2006-04-17 20:02:51 +00:00

111 lines
2.2 KiB
C++

#include "precompiled.h"
#include "Brushes.h"
#include "ps/Game.h"
#include "ps/World.h"
#include "graphics/Terrain.h"
#include "lib/ogl.h"
#include "maths/MathUtil.h"
#include "renderer/TerrainOverlay.h"
using namespace AtlasMessage;
class BrushTerrainOverlay : public TerrainOverlay
{
public:
BrushTerrainOverlay(const Brush* brush)
: TerrainOverlay(300), m_Brush(brush)
{
}
void GetTileExtents(
int& min_i_inclusive, int& min_j_inclusive,
int& max_i_inclusive, int& max_j_inclusive)
{
m_Brush->GetBottomLeft(min_i_inclusive, min_j_inclusive);
m_Brush->GetTopRight(max_i_inclusive, max_j_inclusive);
// But since brushes deal with vertices instead of tiles,
// we don't want to include the top/right row
--max_i_inclusive;
--max_j_inclusive;
}
void ProcessTile(int i, int j)
{
int i0, j0;
m_Brush->GetBottomLeft(i0, j0);
// Colour this tile based on the average of the surrounding vertices
float avg = (
m_Brush->Get(i-i0, j-j0) + m_Brush->Get(i-i0+1, j-j0) +
m_Brush->Get(i-i0, j-j0+1) + m_Brush->Get(i-i0+1, j-j0+1)
) / 4.f;
RenderTile(CColor(0, 1, 0, avg*0.8f), false);
RenderTileOutline(CColor(1, 1, 1, 0.4f), 1, true);
}
const AtlasMessage::Brush* m_Brush;
};
Brush::Brush()
: m_W(0), m_H(0), m_TerrainOverlay(NULL), m_Data(NULL)
{
}
Brush::~Brush()
{
delete m_TerrainOverlay;
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::GetCentre(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;
y = cy;
}
void Brush::GetBottomLeft(int& x, int& y) const
{
GetCentre(x, y);
x -= (m_W-1)/2;
y -= (m_H-1)/2;
}
void Brush::GetTopRight(int& x, int& y) const
{
GetBottomLeft(x, y);
x += m_W-1;
y += m_H-1;
}
void Brush::SetRenderEnabled(bool enabled)
{
if (enabled && !m_TerrainOverlay)
{
m_TerrainOverlay = new BrushTerrainOverlay(this);
}
else if (!enabled && m_TerrainOverlay)
{
delete m_TerrainOverlay;
m_TerrainOverlay = NULL;
}
}
Brush AtlasMessage::g_CurrentBrush;