Original Post
I have been writing some image rotation but when it get to the line where is want an array of Point object it crashes, no warning no nothing the debugger in msvc ee just offers disassembly. the function under quastion is: the offending line(s) have been highlighted could anyone shead some light on this? many thanks
// return a rotated bitmap
SDL_Surface *rotateimage(SDL_Surface *src, float theta, bool square)
{
// new size
int tempwidth, tempheight;
// wrap theta between -180 and 180
if( theta > 180 )
theta -= 360;
// convert angle to radians
float angle = DegToRad(theta);
// pre-calculate sin & cos
float cosine = cos(angle);
float sine = sqrt( 1 - ( cosine*cosine ) );
// calculate size of new image
if( square == true )
{
tempwidth = tempheight = (int)ceil( src->w * M_SQRT_2 * sin( ( angle ) + M_PI_4 ) );
}
else
{
tempwidth = (int)ceil( src->h * cos( angle ) + src->w * sin( angle ) );
tempheight = (int)ceil( src->h * sin( angle ) + src->w * cos( angle ) );
}
// create new surface
Rotated = SDL_CreateRGBSurface( SDL_HWSURFACE, tempwidth, tempheight,
src->format->BitsPerPixel, rmask, gmask, bmask, amask);
// Fill image with bright pink
Uint32 colorkeypink = SDL_MapRGB( Rotated->format, 0xFF, 0, 0xFF );
SDL_FillRect(Rotated, NULL, colorkeypink);
// 2 array containing the endpoints
Point * End1 = new Point[src->h];
Point * End2 = new Point[src->h];
// calculate new origin
int x0 = tempwidth >> 1;
int y0 = tempheight >> 1;
// calculate new position for upper-left corner
float ulx = (float)-x0; // translate
float uly = (float)-y0; // translate
float ulrx = ulx*cosine - uly*sine; // rotate
float ulry = ulx*sine + uly*cosine; // rotate
ulrx = ceil( ulrx + x0 ); // untranslate
ulry = ceil( ulry + y0 ); // untranslate
// place the upper-left pixel in the new image
putpixel( Rotated, ulrx, ulry, getpixel( src, 0, 0 ) );
// calculate new position for upper-right corner
float urx = (float)(src->w - x0); // translate
float ury = (float)-y0; // translate
float urrx = urx*cosine - ury*sine; // Rotate
float urry = urx*sine + ury*cosine; // Rotate
urrx = ceil( urrx + x0 ); // untranslate
urry = ceil( urry + y0 ); // untranslate
// place the upper-right pixel in the new image
putpixel( Rotated, urrx, urry, getpixel( src, src->w, 0 ) );
// calculate new position for lower-right corner
float lrx = (float)(src->w - x0); // translate
float lry = (float)(src->h - y0); // translate
float lrrx = lrx*cosine - lry*sine; // Rotate
float lrry = lrx*sine + lry*cosine; // Rotate
lrrx = ceil( lrrx + x0 ); // untranslate
lrry = ceil( lrry + y0 ); // untranslate
// place the lower-right pixel in the new image
putpixel( Rotated, lrrx, lrry, getpixel( src, src->w, src->h ) );
// calculate new position for lower-left corner
float llx = (float)-x0; // translate
float lly = (float)(src->h - y0); // translate
float llrx = llx*cosine - lly*sine; // Rotate
float llry = lly*sine + lly*cosine; // Rotate
llrx = ceil( llrx + x0 ); // untranslate
llry = ceil( llry + y0 ); // untranslate
// place the lower-left pixel in the new image
putpixel( Rotated, llrx, llry, getpixel( src, 0, src->h ) );
// now we have the four corners use Bresenham's line algorithm to
// find the position of the pixel between UL & LL and UR & LR
BresenhamLine( ulrx, llrx, ulry, llry, 1 );
BresenhamLine( urrx, lrrx, urry, lrry, 1 );
// loop through the horisonal line on orginal image
for( int y = 0; y < src->h; y++)
{
BresenhamLine( End1[y].x, End2[y].x, End1[y].y, End2[y].y, 0 );
}
return Rotated;
}