Game Development Reference
In-Depth Information
5.13G RADIENTS
In the previous section we talked about generating heat maps to represent different types
of statistical information. At the core of the heat map generation algorithm is the use of ra-
dial gradients that when drawn additively will produce the desired intensity that represent
the accumulation of some data at some location. In many situations we could just run our
favorite image editing software and create the gradient we need, save it as a file and load it
when needed, often it is useful to generate the data procedurally at runtime, based on para-
meters from the user or from the data being received, heatmaps are one such use case.
The gradients we implement are linear and radial, though more are definitely possible. We
start by implementing a base class that holds the interface any implemented gradients must
provideandwe'llputthesharedfunctionalityinthebaseclasswhichisawaytoaccessthe
gradient's data.
class gradient
{
gradient(unsigned int size, const color& startColor, const color& endColor, bool reverse=false);
virtual ~gradient();
const unsigned int* Data() const { return m_data; }
const unsigned int Size() const { return m_size; }
protected:
unsigned int m_size;
unsigned int* m_data;
color m_startColor;
color m_endColor;
bool m_reverse;
};
We will build the gradient within the class' constructor, notice that the base class was left
clear of anything but the actual gradient data, this is deliberate to avoid adding platform
specific code in a class that stands well enough on its own. To provide a mechanism to
store a gradient into a texture we can implement a class that will receive a reference to a
gradient,thisclasscanperformplatformspecificoperations,orideallyprovideaninterface
to per-platform implementations.
class gradient_texture
{
public:
gradient_texture(device_direct3d* device, gradient& gradient)
Search WWH ::




Custom Search