I am making a simple matrix editor and I want to reshape the matrix. I have a circle (which is shown simply using spheres) to show you which tiles you are going to raise or lower.
The way I am curretly doing it is by having 2 for loops, one for all the x tiles of a matrix and one for the z tiles, and I get their position on the XZ plane. If the distance from the center of the circle is within the radius, the tiles can move.
But this is very slow, and I cant figure out a better way to do it. It would be easy if the circle was a fixed size, but that's not the case.
Here is my code:
void FPSS::Matrix::Handle(float Raise, float SpdX, float SpdZ, float RadInc)
{
_curx += SpdX;
_curz += SpdZ;
_rad += RadInc;
int TX, TZ;
float TSX, TSZ;
TSX = _sx / _tx;
TSZ = _sz / _tz;
TX = int( _curx / TSX );
TZ = int( _curz / TSZ );
for ( int tx = 0; tx < _tx; tx++ )
for ( int tz = 0; tz < _tz; tz++ )
{
float ctx = tx * TSX;
float ctz = tz * TSZ;
float dist = sqrt( ( ( ctx - _curx ) * ( ctx - _curx ) ) + ( ( ctz - _curz ) * ( ctz - _curz ) ) );
if ( dist <= _rad )
{
dbSetMatrixHeight( _mat, tx, tz, dbGetMatrixHeight( _mat, tx, tz ) + Raise );
dbUpdateMatrix( _mat );
}
}
for ( int o = 0; o < 10; o++ )
dbPositionObject( _cobj[o], _curx + ( dbSin( 36.0f * o ) * _rad ), dbGetGroundHeight( _mat, dbObjectPositionX( _cobj[o] ), dbObjectPositionZ( _cobj[o] ) ), _curz + ( dbCos( 36.0f * o ) * _rad ) );
}
Don't you just hate that Zotoaster guy?