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.

DS development > simple oamRotateScale question

#172318 - radiodee1 - Sat Jan 30, 2010 2:18 pm

I have this code, which I think should rotate a single sprite on the screen. The problem is that somehow it makes all the sprites on the screen rotate. What am I doing wrong? ( 'x' and 'y' are the x and y position of the sprite on the screen, and 'sprites[0].gfxPtr' is the pointer to the sprite's memory.)
Code:
oamSet(&oamMain, 0, x, y, 0, 0, SpriteSize_16x16,     
  SpriteColorFormat_16Color, sprites[0].gfxPtr, 0, false, false, false, false, false);
 
for(i = 0; i < 32768; i = i + 1000) {
 
  oamRotateScale(&oamMain, 0, i, (1 << 8), (1<<8));
 
  swiWaitForVBlank();
  oamUpdate(&oamMain);

}

#172319 - Azenris - Sat Jan 30, 2010 4:13 pm

Im not sure about the functions you used as I havnt used them. Dunno if this helps at all but rotation (i think) is done by rotating a rotation set, not an individual sprite.

There aer 32 rotation sets in total and when creating a sprite you specify which rotation set is belongs to. maybe you have placed all the sprites into the same set as the one your trying to rotate.

You can also instead of setting the rotset on the non-rotating ones you could just disable the bit to have them rotate

Code:
OBJ Attribute 0 (R/W)

  Bit   Expl.
  0-7   Y-Coordinate           (0-255)
  8     Rotation/Scaling Flag  (0=Off, 1=On)
  When Rotation/Scaling used (Attribute 0, bit 8 set):
    9     Double-Size Flag     (0=Normal, 1=Double)
  When Rotation/Scaling not used (Attribute 0, bit 8 cleared):
    9     OBJ Disable          (0=Normal, 1=Not displayed)
  10-11 OBJ Mode  (0=Normal, 1=Semi-Transparent, 2=OBJ Window, 3=Prohibited)
  12    OBJ Mosaic             (0=Off, 1=On)
  13    Colors/Palettes        (0=16/16, 1=256/1)
  14-15 OBJ Shape              (0=Square,1=Horizontal,2=Vertical,3=Prohibited)

_________________
My Homebrew Games

#172321 - SteveH - Sat Jan 30, 2010 7:02 pm

To rotate a single sprite you need to set it's afflineIndex to a value of 0 - 31, if you are using affineIndex 0 as no rotation, then you should set the sprite that you want to rotate to another affineIndex number.

The definition of the oamSet function (copied from the libnds docs) is as follows, as you can see you need to set the tenth paramater to the value of the affine data that you want to use.

Code:

void    oamSet  (OamState  *oam, int id, int x, int y, int priority, int palette_alpha, SpriteSize  size, SpriteColorFormat  format, const void *gfxOffset, int affineIndex, bool  sizeDouble, bool  hide, bool  hflip, bool  vflip, bool  mosaic)


Your code snippet is correct, but what you want to do is something like this:

Code:

oamSet(&oamMain, 0, 10, 10, 0, 0, SpriteSize_16x16,     
  SpriteColorFormat_16Color, sprites[0].gfxPtr, 0, false, false, false, false, false);
 
oamSet(&oamMain, 1, 50, 10, 0, 0, SpriteSize_16x16,     
  SpriteColorFormat_16Color, sprites[0].gfxPtr, 1, false, false, false, false, false);
 
for(i = 0; i < 32768; i = i + 1000) {
 
  oamRotateScale(&oamMain, 1, i, (1 << 8), (1<<8));
 
  swiWaitForVBlank();
  oamUpdate(&oamMain);

}


The code above should rotate the second sprite and leave the first sprite alone.

#172324 - radiodee1 - Sun Jan 31, 2010 12:05 am

thanks. that's a great help.