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 > Very strange error

#153525 - TheMagnitude - Tue Apr 01, 2008 11:33 am

Ok. These two lines of code that simply set the x and y value of an instance, work on no$gba but don't work on the hardware and instead seem to (delete/hide) all sprites.

Code:
bulletIns->x = instances[i]->x + ship->spriteSize / 2 + 14 * cos(instances[i]->spriteAngle) - bullet->spriteSize / 2;
bulletIns->y = instances[i]->y + ship->spriteSize / 2 + 14 * sin(instances[i]->spriteAngle) - bullet->spriteSize / 2;


*bulletIns and *instances[i] are members of class:

Code:
class instance
{
   public:
      instance(float, float, object*);
      instance(object*);
      ~instance();
      object* parent;
      float x,
           y,
           hspeed,
           vspeed,
           spriteAngle;
      SpriteEntry* sprite;
      bool wrap;
      void updateSprite();
      void step();
      void setMotion(float, float);
      void addForce(float, float);
} * instances[SPRITE_COUNT];


and *bullet and *ship are members of class:

Code:
class object
{
   public:
      object() {};
      object(SpriteEntry* s);
      char spriteSize;
      SpriteEntry* sprite;
};


I think its something to do with data types because this works:

Code:
bulletIns->x = 200;
bulletIns->y = 200;


Is there something with the ARM processor that cant handle certain data type conversions or something?

#153528 - simonjhall - Tue Apr 01, 2008 12:30 pm

Why don't you try printing out the numbers you're working with, to see which ones differ? It's a bit hard to tell from just this!

Things to also remember
a) there's no floating-point unit, all fp maths is done via an emulation library which is very slow but should work correctly
b) sin and cos (and tan?) have special libnds versions which work differently, make sure you're not using them here else you'll get results that you don't expect
c) the real hardware is always right, the emulators are the ones that aren't working correctly!
_________________
Big thanks to everyone who donated for Quake2

#153529 - elwing - Tue Apr 01, 2008 12:34 pm

simonjhall wrote:
c) the real hardware is always right, the emulators are the ones that aren't working correctly!

lol, i dont' agree... sure if an emulator don't produce the same result as the hardware then the emulator is faulty, since the only goal of an emulator is to mimic the behaviour of the real hardware... but that don't mean the real hardware is always working right :D

#153531 - a128 - Tue Apr 01, 2008 1:20 pm

Youre Sprites does not show up?

Maybe you use ATTR0_ROTSCALE and you did not initialized the rotation parameters?!

I had this problem yesterday...the Emulator NO$GBA displayed it...but the hardware not

NO$GBA 2.6a displayed the sprites simply because the emulatior does not support rotations for sprites?!!!!!!


Last edited by a128 on Wed Apr 02, 2008 8:33 am; edited 1 time in total

#153532 - TheMagnitude - Tue Apr 01, 2008 1:29 pm

simonjhall wrote:

b) sin and cos (and tan?) have special libnds versions which work differently, make sure you're not using them here


Make sure I dont use them here? Why shouldn't I use them here?

a128 wrote:

Youre Sprites does not show up?

Maybe you use ATTR0_ROTSCALE and you did not initialized the rotation parameters?!

I had this problem yesterday...the Emulator NO$GBA displayed it...but the hardware not

I'm not sure what ATTR0_ROTSCALE is but I use
Code:
void rotateSprite(SpriteRotation * spriteRotation, u16 angle) {
    s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4;
    s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4;
    // ROTATION MATRIX
    spriteRotation->hdx = c;
    spriteRotation->hdy = s;
    spriteRotation->vdx = -s;
    spriteRotation->vdy = c;
}

for rotation.

im new to DS dev so I could be wrong.

#153533 - simonjhall - Tue Apr 01, 2008 1:35 pm

TheMagnitude wrote:
simonjhall wrote:

b) sin and cos (and tan?) have special libnds versions which work differently, make sure you're not using them here


Make sure I dont use them here? Why shouldn't I use them here?
The proper sin and cos functions take inputs in radians, but the libnds versions take a number from 0 to 512. So make sure you're using the version you think you are.

But yeah, just take it back a notch and make it a lot more simple, just so you can see exactly is going wrong.
_________________
Big thanks to everyone who donated for Quake2

#153534 - TheMagnitude - Tue Apr 01, 2008 1:36 pm

Hey wait a minute, when I #include <math.h> I can use cos and sin, but theres no mention of cos and sin in math.h, does this mean Im including the math.h from the standard c library instead of the math.h from ndslib?

#153540 - wintermute - Tue Apr 01, 2008 3:33 pm

ndslib is obsolete, you're talking about libnds.

<math.h> is the standard header for libm included with devkitARM.

<arm9/math.h> is the libnds header which includes the DS hardware math functions. This file is included from <nds.h>
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#153541 - TheMagnitude - Tue Apr 01, 2008 4:18 pm

wintermute wrote:
ndslib is obsolete, you're talking about libnds.

<math.h> is the standard header for libm included with devkitARM.

<arm9/math.h> is the libnds header which includes the DS hardware math functions. This file is included from <nds.h>
Ah thankyou thats cleared a few things up :)

#153573 - silent_code - Wed Apr 02, 2008 4:52 am

just five words: send code. ;^D

#153667 - TheMagnitude - Thu Apr 03, 2008 5:36 pm

silent_code wrote:
just five words: send code. ;^D
I have deleted piece of code for now and Ill develop the same thing but with Fixed Point numbers and see if I still have the same problem, and if I do then Im lost and I will =)