   Rotation Algorithm
  Does anyone know a REALLY FAST rotation algorithm , because i`m still using ddraw and it doesn't have a rotation function included.And mine is a bit slow...   
  Well, let's start with showing us what yours is.  We can't exactly make a faster one without knowing the state of the current one.  So just get that code up and we'll see about getting your algorithim faster.-AJ   ;  Oh hhahah must have slipped my mindint Draw_BOB16Rot(BOB_PTR bob,UCHAR *dest_buffer ,double alpha ) // surface to draw the bob on{// draw a bob at the x,y defined in the BOB// on the destination surface defined in destUSHORT Dest_r;    USHORT Dest_g;  USHORT Dest_b; USHORT scr_pixelcol; // is this a valid bobif (!bob)    return(0);// is bob visibleif (!(bob->attr & BOB_ATTR_VISIBLE))   return(1);USHORT  *dest_ptr;  // working pointers // lock the display surfaces ( BACKBUFFER & BOB SURFACE )DDraw_Lock_Back_Surface();(bob->images[bob->curr_frame])->Lock(NULL,  &ddsd,  DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR ,  NULL);// assign a pointer to the memory surface for manipulationdest_ptr   = (USHORT *)ddsd.lpSurface;int lpitch16 = back_lpitch >> 1;int lpitch_bob = ddsd.lPitch >> 1;// Iterate through the imagefor ( int y = 0 ; y < bob->height ; y++ ){for (int x = 0 ; x < bob->width ; x++ ){int real_x = bob->x + x;int real_y = bob->y + y;//used for clipping errorif ( (real_x < SCREEN_WIDTH && real_x > 0) && (real_y < SCREEN_HEIGHT && real_y > 0) ){// GET THE COLOR OF PIXELS FOR SOURCE AND DESTINATION//USHORT dest_pixelcol = ((USHORT *)back_buffer)[pos]; // 1111100000000000 = 63488 PURE RED// 0000011111100000 = 4032  PURE GREEN// 0000000000011111 = 31    PURE BLUE// GET VALUES FOR PIXEL ( RGB )//USHORT red_part   = (dest_pixelcol & 63488) >> 11;// give red color only for pixel//USHORT green_part = (dest_pixelcol & 2016) >> 6;// give green color only for pixel//USHORT blue_part  = (dest_pixelcol & 31);// give blue color only for pixel//USHORT sred_part   = (scr_pixelcol & 63488) >> 11;// give red color only for pixel//USHORT sgreen_part = (scr_pixelcol & 2016) >> 6;// give green color only for pixel//USHORT sblue_part  = (scr_pixelcol & 31);// give blue color only for pixel /// *** NO HOLES *************double rangle = alpha;double cos_val=cos(rangle);double sin_val=sin(rangle);double half_w=bob->width>>1;double half_h=bob->height>>1;//  for(j=0;j<temp->h;j++){//for(i=0;i<temp->w;i++){double bs= x - half_w;double cs= y - half_h;int as=bs*sin_val+cs*cos_val+half_w;int gs=bs*cos_val-cs*sin_val+half_h; scr_pixelcol  = dest_ptr[as + gs*lpitch_bob];//USHORT color=getpixel(temp,as,gs);//putpixel(temp1,i,j,color);//// *** NO HOLES ***** ///////////   int pos = real_x + real_y*lpitch16; // the actual loc on screen  // NOW FINALLY OUTPUT THE NEW PIXELif ( as < bob->width && gs < bob->height && as > 0 && gs > 0 && scr_pixelcol != 31)((USHORT *)back_buffer)[pos] = scr_pixelcol ;  //x,y// make this now the new color} //end clipping }}    // unlock the surfacesDDraw_Unlock_Back_Surface();(bob->images[bob->curr_frame])->Unlock(NULL);// return successreturn(1);} // end Draw_BOB16;  Source tagged and formatted. [smile]int Draw_BOB16Rot(BOB_PTR bob,UCHAR *dest_buffer ,double alpha ) // surface to draw the bob on{// draw a bob at the x,y defined in the BOB// on the destination surface defined in destUSHORT Dest_r;USHORT Dest_g;USHORT Dest_b;USHORT scr_pixelcol;// is this a valid bobif (!bob)return(0);// is bob visibleif (!(bob->attr & BOB_ATTR_VISIBLE))return(1);USHORT *dest_ptr; // working pointers// lock the display surfaces ( BACKBUFFER & BOB SURFACE )DDraw_Lock_Back_Surface();(bob->images[bob->curr_frame])->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR ,NULL);// assign a pointer to the memory surface for manipulationdest_ptr = (USHORT *)ddsd.lpSurface;int lpitch16 = back_lpitch >> 1;int lpitch_bob = ddsd.lPitch >> 1;// Iterate through the imagefor ( int y = 0 ; y < bob->height ; y++ ){for (int x = 0 ; x < bob->width ; x++ ){int real_x = bob->x + x;int real_y = bob->y + y;//used for clipping errorif ( (real_x < SCREEN_WIDTH && real_x > 0) && (real_y < SCREEN_HEIGHT && real_y > 0) ){// GET THE COLOR OF PIXELS FOR SOURCE AND DESTINATION//USHORT dest_pixelcol = ((USHORT *)back_buffer)[pos];// 1111100000000000 = 63488 PURE RED// 0000011111100000 = 4032 PURE GREEN// 0000000000011111 = 31 PURE BLUE// GET VALUES FOR PIXEL ( RGB )// USHORT red_part = (dest_pixelcol & 63488) >> 11; // give red color only for pixel// USHORT green_part = (dest_pixelcol & 2016) >> 6; // give green color only for pixel//USHORT blue_part = (dest_pixelcol & 31); // give blue color only for pixel// USHORT sred_part = (scr_pixelcol & 63488) >> 11; // give red color only for pixel// USHORT sgreen_part = (scr_pixelcol & 2016) >> 6; // give green color only for pixel// USHORT sblue_part = (scr_pixelcol & 31); // give blue color only for pixel/// *** NO HOLES *************double rangle = alpha;double cos_val=cos(rangle);double sin_val=sin(rangle);double half_w=bob->width>>1;double half_h=bob->height>>1;// for(j=0;j<temp->h;j++){// for(i=0;i<temp->w;i++){double bs= x - half_w;double cs= y - half_h;int as=bs*sin_val+cs*cos_val+half_w;int gs=bs*cos_val-cs*sin_val+half_h;scr_pixelcol = dest_ptr[as + gs*lpitch_bob];//USHORT color=getpixel(temp,as,gs);// putpixel(temp1,i,j,color);//// *** NO HOLES ***** ///////////int pos = real_x + real_y*lpitch16; // the actual loc on screen// NOW FINALLY OUTPUT THE NEW PIXELif ( as < bob->width && gs < bob->height && as > 0 && gs > 0 && scr_pixelcol != 31)((USHORT *)back_buffer)[pos] = scr_pixelcol ; //x,y// make this now the new color} //end clipping}}// unlock the surfacesDDraw_Unlock_Back_Surface();(bob->images[bob->curr_frame])->Unlock(NULL);// return successreturn(1);} // end Draw_BOB16;  1.) Try using sin and cos tables.  You have 360 values (of rotation), just generate a table (array) of each of these values (so that's two arrays, one for sin, one for cos) at the init stage of your application.2.) Look into trying fixed point math.  With todays CPUs, the benefit might be negligible, but I used it years ago with Ddraw (exactly what you are doing now) and there was benefit to this.HTH   ;  It may not be what you're looking for, but last time I needed to do this I used a Direct3D quad (using 2D coordinates), and just rotated the points of the quad. Very fast, and not too much of a pain to do - but it's not pure DirectDraw, and is arguably lazier than doing it yourself. :-)   ;  Ok i`ll try the table thing. I don't really know what you mean about the fixed point math..i know it's floats right..but ...can you give me an example please   ;  Before going esoteric: Use some general optimizations:(1) use ++x (pre-ops) instead of x++ (post-ops)(2) Moveint real_y = bob->y + y;and the related part of the if clause && (real_y < SCREEN_HEIGHT && real_y > 0)out of the inner loop.(3) Move _especially_double rangle = alpha;double cos_val=cos(rangle);double sin_val=sin(rangle);double half_w=bob->width>>1;double half_h=bob->height>>1;even out of both loops!(4) Movereal_y*lpitch16out of the inner loop.In short: don't compute more than absolutely needed inside of loops (especially no trigonometric functions!). Look which variables don't change, and move them out as far as possible.EDIT: Should look like this:int Draw_BOB16Rot(BOB_PTR bob,UCHAR *dest_buffer ,double alpha ) // surface to draw the bob on{   // draw a bob at the x,y defined in the BOB   // on the destination surface defined in dest   USHORT Dest_r;   USHORT Dest_g;   USHORT Dest_b;   USHORT scr_pixelcol;   // is this a valid bob   if (!bob) return(0);   // is bob visible   if (!(bob->attr & BOB_ATTR_VISIBLE)) return(1);   USHORT *dest_ptr; // working pointers   // lock the display surfaces ( BACKBUFFER & BOB SURFACE )   DDraw_Lock_Back_Surface();   (bob->images[bob->curr_frame])->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR , NULL);   // assign a pointer to the memory surface for manipulation   dest_ptr = (USHORT *)ddsd.lpSurface;   int lpitch16 = back_lpitch >> 1;   int lpitch_bob = ddsd.lPitch >> 1;   double rangle = alpha;   double cos_val=cos(rangle);   double sin_val=sin(rangle);   double half_w=bob->width>>1;   double half_h=bob->height>>1;   // Iterate through the image   for ( int y = 0 ; y < bob->height ; ++y ){  int real_y = bob->y + y;  if( real_y < SCREEN_HEIGHT && real_y > 0 ) { int pos_y = real_y*lpitch16; for (int x = 0 ; x < bob->width ; ++x ){    int real_x = bob->x + x;    //used for clipping error    if ( real_x < SCREEN_WIDTH && real_x > 0 ){  double bs= x - half_w;  double cs= y - half_h;  int as=bs*sin_val+cs*cos_val+half_w;  int gs=bs*cos_val-cs*sin_val+half_h;  scr_pixelcol = dest_ptr[as + gs*lpitch_bob];  int pos = real_x + pos_y; // the actual loc on screen  // NOW FINALLY OUTPUT THE NEW PIXEL  if ( as < bob->width && gs < bob->height && as > 0 && gs > 0 && scr_pixelcol != 31)((USHORT *)back_buffer)[pos] = scr_pixelcol ; //x,y// make this now the new color    } //end clipping } }   }   // unlock the surfaces   DDraw_Unlock_Back_Surface();   (bob->images[bob->curr_frame])->Unlock(NULL);   // return success   return(1);} // end Draw_BOB16(Untested code! Please verify carefully!)Even here minor optimizations are possible, but I think it will already boost the speed (mainly due to moving the sin/cos stuff).[Edited by - haegarr on December 11, 2005 10:39:35 AM];  Google is your friend. :)http://www.bookofhook.com/Article/GameDevelopment/AnIntroductiontoFixedPoin.html;  OK thankyou I will try it.p.s is pre-ops REALLY faster than post-ops ? how many times faster ?   