gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Sprite rotation errors

#178142 - aidan_aidan - Sun Dec 15, 2013 6:21 pm

I am using a sine and cosine lookup table 2048 in length (angles are between 0 and 2048) with values between -256 and 256. The problem is that the sprite is pausing briefly before and after every 90 degrees (the angle is being increased at 60 divisions per second (every vBlank)). I have an affine background that is rotating just fine without this pausing using the same lut so I have no idea what is going on. Thank for any help.

video illustrating the problem
http://youtu.be/8gweFiSobwc


The function with the code (nothing in the main other than this function being called):

Code:

void railGame(void)
{
   u32 vBlankBool_A = 0,
      vBlankBool_B = 0,
      earthAngle = 0,
      gunAngle = 512;
      
   s32 earthPA = 0,
      earthPB = 0,
      earthPC = 0,
      earthPD = 0;
      //512 +/- 171
   point earthRotationTex = {256, 256},
        earthRotationScr = {120, 256};
       
   affSprite gun = {&OAMLOC[0], &OAMLOC[1], &OAMLOC[2], &OAMLOC[3], &OAMLOC[7], &OAMLOC[11], &OAMLOC[15]};
   *gun.attribute0      = GUNATTRIBUTE0;
   *gun.attribute1      = GUNATTRIBUTE1;
   *gun.attribute2     = GUNATTRIBUTE2;
   *gun.pa = *gun.pd    = 256;
   *gun.pb = *gun.pc   = 0;
      
   DISPCNT = (MODE1 | BG0_ENABLE | BG1_ENABLE | BG2_ENABLE | OBJ_ENABLE | OBJ1D);
   BG0CNT  = (CBB2 | SBB31 | BG_REG_32X32 | BGCOLOR16);
   BG1CNT  = (CBB1 | SBB29 | BG_REG_64X32 | BGCOLOR16);
   BG2CNT  = (CBB0 | SBB27 | BG_AFF_64X64 | BGCOLOR256);
   
   loadBGpalette(&railGameBGpalette[0]);
   loadOBJpalette(&railGameOBJpalette[0]);
   loadBGtiles(&earthTiles[0], EARTHTILESLENGTH, CBB0_U32_LOC);
   loadOBJtiles(&blank4bppTile[0], TILELENGTH4BPP);
   loadOBJtiles(&gunTiles[0], GUNTILESLENGTH);
   loadBGmap(&earthMap[0], AFF64X64U32_LENGTH, SBB27_U32_LOC, PALETTE0);
   
   BG2PA = BG2PD = 255;
   BG2PB = BG2PC = 0;
   
   BG2X = 0;
   BG2Y = 0;
      
   while(1)
   {
      vBlankBool_A = (DISPSTAT & VBLANKFLAG);
      
      if(vBlankBool_A & ~vBlankBool_B)
      {
         keyPoll();
         
         earthAngle++;
         if(earthAngle > CIRCLE_DIVISION - 1)
         {
            earthAngle = 0;
         }
         
         if(keyDown(BUTTON_L))
         {
            gunAngle += 3;
         }
         if(keyDown(BUTTON_R))
         {
            gunAngle -= 3;
         }
         if(gunAngle > 716)
         {
            gunAngle = 716;
         }
         if(gunAngle < 308)
         {
            gunAngle = 308;
         }
         
         *gun.pa = *gun.pd = sine[gunAngle];
         *gun.pb = cosine[gunAngle];
         *gun.pc = -cosine[gunAngle];
         
         *gun.attribute0 = GUNATTRIBUTE0 | (((-sine[gunAngle] * 142) >> 8) + 240);
         *gun.attribute1 = GUNATTRIBUTE1 | (((cosine[gunAngle] * 142) >> 8) + 104);
         
         earthPA = earthPD = cosine[earthAngle];
         earthPB = -sine[earthAngle];
         earthPC = sine[earthAngle];
         
         BG2X = (earthRotationTex.x << 8) - (earthPA * earthRotationScr.x + earthPB * earthRotationScr.y);
         BG2Y = (earthRotationTex.y << 8) - (earthPC * earthRotationScr.x + earthPD * earthRotationScr.y);
         
         BG2PA = earthPA;
         BG2PB = earthPB;
         BG2PC = earthPC;
         BG2PD = earthPD;
      }
      
      vBlankBool_B = vBlankBool_A;
   }
}

_________________
French re f draft free e w shredder for c rt