67 #ifndef _graphicsproceduralcellgenerator_cpp
68 #define _graphicsproceduralcellgenerator_cpp
70 #include "Graphics/Procedural/Texture/cellgenerator.h"
73 #include "MathTools/mathtools.h"
82 GenColour(1.0,1.0,1.0,1.0),
106 MathTools::MersenneTwisterGenerator32 NumGen(this->
GenSeed);
112 Real RandNum1 = NumGen.GeneratePositiveReal();
113 Real RandNum2 = NumGen.GeneratePositiveReal();
114 CellPoints[X + Y * this->
GenDensity].X = ( X + 0.5 + ( RandNum1 - 0.5 ) * ( 1 - Regularity ) ) / this->GenDensity - 1.0 / TargetWidth;
115 CellPoints[X + Y * this->
GenDensity].Y = ( Y + 0.5 + ( RandNum2 - 0.5 ) * ( 1 - Regularity ) ) / this->GenDensity - 1.0 / TargetHeight;
120 for(
Whole Y = 0 ; Y < TargetHeight ; ++Y )
122 for(
Whole X = 0 ; X < TargetWidth ; ++X )
125 PixelPos.
X =
static_cast<Real>( X ) / static_cast<Real>( TargetWidth ),
126 PixelPos.
Y =
static_cast<Real>( Y ) / static_cast<Real>( TargetHeight );
130 Real NextMinDist = MinDist;
131 Integer Xo = X * this->GenDensity / TargetWidth;
132 Integer Yo = Y * this->GenDensity / TargetHeight;
133 for(
Integer V = -1 ; V < 2 ; ++V )
135 Integer Vo = ( ( Yo + this->GenDensity + V ) % this->GenDensity ) * this->
GenDensity;
136 for(
Integer U = -1 ; U < 2 ; ++U )
138 Vector3 CellPos = CellPoints[ ( ( Xo + this->GenDensity + U ) % this->GenDensity ) + Vo ];
139 if( U == -1 && X * this->GenDensity < TargetWidth )
141 if( V == -1 && Y * this->GenDensity < TargetHeight )
143 if( U == 1 && X * this->GenDensity >= TargetWidth * ( this->GenDensity - 1 ) )
145 if( V == 1 && Y * this->GenDensity >= TargetHeight * ( this->GenDensity - 1 ) )
149 if( Norm < MinDist ) {
150 NextMinDist = MinDist;
152 }
else if( Norm < NextMinDist ) {
162 MinDist = MathTools::Clamp( 2 * NextMinDist * this->GenDensity - 1,
Real(0.0),
Real(1.0) );
167 MinDist = MathTools::Clamp( 1 - MinDist * this->GenDensity,
Real(0.0),
Real(1.0) );
173 MinDist = MathTools::Clamp( ( NextMinDist - MinDist ) * this->GenDensity,
Real(0.0),
Real(1.0) );
182 cfc = ( ( Xo & 1 ) ^ ( Yo & 1 ) ) != 0;
183 Coeff = ( 1 - 2 * cfc ) / 2.5;
204 {
return "CellGenerator"; }
void SetRedByte(const Whole X, const Whole Y, const ColourChannelType Red)
Sets the red colour value of a specified pixel. the X or Y location go beyond the set size of this te...
bool Boole
Generally acts a single bit, true or false.
virtual String GetName() const
Gets the name of this generator.
Colours in the centers of each cell such that there is a cross connecting each of the four corners wi...
CellGenerator & SetColour(const ColourValue &Colour)
Sets the colour of the interior of the cells.
Real X
Coordinate on the X vector.
Real Z
Coordinate on the Z vector.
virtual void AddToTextureBuffer(TextureBuffer &Buffer) const
Replaces and populates the pixels as configured in this generator to a TextureBuffer.
Cells are layed out in a normal grid pattern with their centers coloured in according to the set Cell...
Whole GetWidth() const
Get the pixel width of this texture.
int Integer
A datatype used to represent any integer close to.
ColourValue GenColour
The colour of the interior of the cells generated.
CellGenerator & SetDensity(const Whole Density)
Set the density of cells in texture.
CellMode GenMode
Describes how the cells are layed out.
Whole GenSeed
The seed to be used for the random number generator.
virtual ~CellGenerator()
Class destructor.
CellGenerator()
Class constructor.
uint8_t UInt8
An 8-bit unsigned integer.
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
CellGenerator & SetPattern(const CellPattern Pattern)
Set the cell pattern of texture.
CellGenerator & SetMode(const CellMode Mode)
Set the cell mode of texture.
Real Distance(const Vector3 &OtherVec) const
Gets the distance between this and another vector.
Colours in the centers of each cell such that there is a circle in the middle with increasing colour ...
float Real
A Datatype used to represent a real floating point number.
Combines CP_Cross and CP_Cone.
void SetGreenByte(const Whole X, const Whole Y, const ColourChannelType Green)
Sets the green colour value of a specified pixel. the X or Y location go beyond the set size of this ...
CellPattern GenPattern
Describes how the cells are coloured.
CellMode
An enum to describe how the cells are layed out.
Real GreenChannel
Value from 0.0 to 1.0 representing the amount of green present in the colour. 1.0 if very green...
Real AlphaChannel
Value from 0.0 to 1.0 representing the transparency of the colours. 1.0 is opaque and 0...
CellGenerator & SetRegularity(const UInt8 Regularity)
Set the regularity of texture.
Cells are layed out in a normal grid pattern, but will alternate the cell colour and background colou...
Real Y
Coordinate on the Y vector.
void SetAlphaReal(const Whole X, const Whole Y, const Real Alpha)
Sets the alpha colour value of a specified pixel. the X or Y location go beyond the set size of this ...
void SetValues(const Real Red, const Real Green, const Real Blue, const Real Alpha)
Sets each of the colour channels.
CellPattern
An enum to describe how the cells are coloured.
Create a texture consisting of cells aligned in a grid, or a chessboard.
A convenience buffer that stores pixel colour values of a texture to be generated.
This is used to represent a point in space, or a vector through space.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Whole GetHeight() const
Get the pixel height of this texture.
Real BlueChannel
Value from 0.0 to 1.0 representing the amount of blue present in the colour. 1.0 if very blue...
Whole GenDensity
The number of oclumns and rows of cells to be generated.
Real RedChannel
Value from 0.0 to 1.0 representing the amount of red present in the colour. 1.0 if very red...
Whole GenRegularity
A value between 1 and 255 that determines how uniform the cells are.
CellGenerator & SetSeed(const Whole Seed)
Sets the seed for the "random" number generator.
void SetBlueByte(const Whole X, const Whole Y, const ColourChannelType Blue)
Sets the blue colour value of a specified pixel. the X or Y location go beyond the set size of this t...
std::string String
A datatype used to a series of characters.