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 > mode 5 sprites odd

#82989 - silent_code - Thu May 11, 2006 6:47 pm

hi!

i hope someone can help me with a sprites issue. as the subject says i use mode 5 8bit rotation sprites. but somehow they shear oddly. anyone had the same problem and solved it?

it's strange cuz it doesn't happen to all sprites... looks like something overwrites certain bits or whatever. the rotation attribute in the following pic should be 0!?

[Images not permitted - Click here to view it]

i will post some sources as necessary.

maybe i screw up the values while writing them in? my sprites have floats for coordinates (i know that floats suck and i'll change that as soon as i have fixed a few other things). when updating oam i do it like (just and example)

...
x = (int16)((int)(player.x - 29.0f));
...
spriteEntry->attribute[1] &= 0xFE00;
spriteEntry->attribute[1] |= (x & 0x01FF);
...

for each coordinate, where player is a float and x an int16... casting is sh*t, i know, but it's just a first implementation. ;) the double int casting is the result of trieing ANYTHING the syntax won't forbid to use...

please don't tell me to read up on sprites, cuz i have done that already, but if you have some good resource (that isn't already like ten times on the forum) it was nice of you to post it.

thanks in advance!

#84591 - silent_code - Tue May 23, 2006 3:16 pm

not rotating the sprites helps... but as soon as a sprite is rotated (let's say by 0/512 as u16) it starts looking odd again...

seems like i've to solve it myself :(

#84821 - tepples - Wed May 24, 2006 10:20 pm

Have you managed to get similar code working on Game Boy Advance?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#85077 - silent_code - Fri May 26, 2006 10:28 pm

nope, in my gba days i used not to work with hardware rotation (i made some demos with out rotation at all or isometric demos, where the rotation had to be prebacked in the sprites).

i'm using the standard functions found everywhere... i don't know what's wrong... i use the sprite entry and sprite rotation structures provided by libnds. then i assign a sprite rotation index to my sprites (there are only 32 of them distributed over all 128 sprite entries, right?) and rotate them... maybe some sources will make it clear:

the entity class:

Code:
class ent
{
public:
   float x, y, vx, vy;

   u16 r;              // rotation

        ... some other attributes of int and float (health etc.)...

   SpriteEntry* m_oam;
   u16 m_gfxID;      // graphics id (location of the first tile of the sprites gfx)

   void create(SpriteEntry* oam, u16 gfxID);

        ... some other methods...
};


the create method:

Code:
void ent::create(SpriteEntry* oam, u16 gfxID)
{
   if(oam != NULL)
   {
      m_oam = oam;
      m_gfxID = gfxID;

      m_oam->attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 256;
      m_oam->attribute[1] = ATTR1_ROTDATA(0) | ATTR1_SIZE_32 | 84;
      m_oam->attribute[2] = ATTR2_PRIORITY(1) | m_gfxID;

      rotateSprite((SpriteRotation*)m_oam, 0);  // <- will cause sprite to look odd
      setSpritePriority(m_oam, 1);  // won't do a thing, as well as ATTR2_PRIORITY(1) [s. a.] ????!!!!
   }
}


yes, i'm still using floats (shame on me), but it's running and as long as i can't get rid (and understand it) of that odd behaviour, i don't see why i should change it ;)

i mean everything has a type, i cast where necessary, so there shouldn't be any problem... man, that sucks.

another example:

Code:
SpriteEntry *sgShot;

...

sgShot = &spritesMain[1];

sgShot->attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 91;
sgShot->attribute[1] = ATTR1_ROTDATA(1) | ATTR1_SIZE_8 | 256;
sgShot->attribute[2] = 128;

rotateSprite((SpriteRotation*)sgShot, 0);  // same goes for this
setSpritePriority(sgShot, 0);  // and this!


the sprite rotation procedure:

Code:
void rotateSprite(SpriteRotation *spriteRotation, u16 angle)
{
   s16 s = -SIN[angle & 0x1FF] >> 4;
   s16 c = COS[angle & 0x1FF] >> 4;

   spriteRotation->hdx = c;
   spriteRotation->hdy = -s;
   spriteRotation->vdx = s;
   spriteRotation->vdy = c;
}


it makes me crazy!!!

thanks for any help or tips (hell, even random suggestions are welcome)!

Rob


ps: i just found a nice statement on mega etk's site: "-Added some frames to weapons to avoid rotation code" that's kinda ironic, isn't it? I NEED hardware rotation though... (i don't know why he wants to avoid it, though)