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.

Beginners > rotData

#9046 - hnager - Sun Jul 27, 2003 2:57 am

I have multiple sprites on screen which all should be able to rotate independantly of eachother (they can move in totally seperate paths). Anybody see anything wrong with this rotation function?:

Code:
void Sprite::rotate(s32 angle){

   s32 pa,pb,pc,pd;

   pa = ((zoom) * (s32)COS[angle])>>8;    //(do my fixed point multiplies and shift back down)
   pb = ((zoom) * (s32)SIN[angle])>>8;
   pc = ((zoom) * (s32)-SIN[angle])>>8;
   pd = ((zoom) * (s32)COS[angle])>>8;
   
   rotData[OAMSpriteNum].pa = pa;  //put them in my data struct
   rotData[OAMSpriteNum].pb = pb;
   rotData[OAMSpriteNum].pc = pc;
   rotData[OAMSpriteNum].pd = pd;
}


Strange thing is that I can trace out to the console the OAMSpriteNum and they are definately different than eachother - here is the case/switch which moves/rotates:

Code:

      switch(dir){

         case ANT_RIGHT:
            setX(getX() + 2);
            this->rotate(90);
            break;
         case ANT_LEFT:
            setX(getX() - 2);
            this->rotate(-90);
            break;
         case ANT_UP:
            setY(getY() - 2);
            this->rotate(0);
            break;
         case ANT_DOWN:
            setY(getY() + 2);
            this->rotate(180);
            break;
         default:
            break;
      }


Thanks again - anybody else ever encounter that issue?

#9062 - hnager - Sun Jul 27, 2003 6:22 pm

sprites[i].attribute0 = COLOR_256 | SQUARE | ROTATION_FLAG | ants[i].getY();
sprites[i].attribute1 = SIZE_16 | ROTDATA(i) | ants[i].getX();
sprites[i].attribute2 = 0;

Forgot that part - actually, I forgot that part 2 projects ago, but in those projects I only had one sprite rotating so I never realized it was wrong.