Oh and I'm definetly doing SOMETHING wrong. Occassionally I manage to get into state where where when I'm pointing to direction 276(in angles) ie pretty much straight to left my heading is south-west(about 220 in angles). I push forward and it goes south west. I push backward and direction turns 180 to north-east. What am I doing wrong here?
Edit: I think I found this error atleast. It's the angleToRad table! Since GDK seems to use angles a lot I need them. Lots of trigonometric functions like sin etc however use radians so I need them as well so I made pre-generated table which contains radians for the angles where I can look them up as needed(faster than calculating on the fly). However there's some SERIOUS accuracy loss. Basicly radians change only at intervals of 60 degrees...What's wrong with my code?
float angleToRad[360];
for (int i=0;i<360;i++) {
angleToRad[i]=i/57,29577951;
}
Can't float handle 0.0xxx type of numbers?
Edit: Oh I COULD of course just check the darkGDK documents and note there's Sin and Cos functions that handle angles right there...Oops! Anyway so now it's working but if somebody could check the code anyway and see if I'm doing something wrong either in code or in my physics I would be grateful.
Edit2: More problems! Collision detection is way too early! Notable gap remains when it detects "collision". Any better ways to do it? ATM I'm doing it like this:
dbSetObjectCollisionOn(id);
dbSetObjectCollisionToPolygons(id);
Called every time object is created.
int objectCollided=dbObjectCollision(SHIP, 0);
if(objectCollided>ASTEROID_MIN && objectCollided < ASTEROID_MAX) {
char buffer[50];
sprintf(buffer, "Too bad. Game over! Your score is: %i", score);
dbText(150, 50, buffer);
dbSync( );
dbWaitKey();
return;
}
And this is the one in main loop where I check wether ship has collided with asteroid.
So any better ways to compare wether they collided or not? Now is bit too close to make sense.