Index: apps/plugins/spacerocks.c =================================================================== --- apps/plugins/spacerocks.c (revision 23917) +++ apps/plugins/spacerocks.c (working copy) @@ -527,6 +527,7 @@ struct Asteroid { struct Point position; + struct Point rotation; struct Point vertices[NUM_ASTEROID_VERTICES]; bool exists; int explode_countdown; @@ -539,6 +540,7 @@ struct Ship { struct Point position; + struct Point rotation; struct Point vertices[NUM_SHIP_VERTICES]; bool exists; int explode_countdown; @@ -637,20 +639,40 @@ /* Rotate polygon */ static void rotate_polygon(struct Point* vertices, int num_vertices, - int cos, int sin) + struct Point* rotation, int cos, int sin) { struct Point* point; int n; long temp_x, temp_y; + temp_x = rotation->x; + temp_y = rotation->y; + rotation->x = (temp_x*cos - temp_y*sin)/SIN_COS_SCALE; + rotation->y = (temp_y*cos + temp_x*sin)/SIN_COS_SCALE; + /* lame method to normalize vector. + * this is not accurate but maybe enough. */ +#define MIN_SCALE (SCALE-5) +#define MAX_SCALE (SCALE+5) + temp_x = rotation->x*rotation->x + rotation->y*rotation->y; + if (temp_x <= MIN_SCALE*MIN_SCALE) + { + rotation->x = rotation->x*SCALE/MIN_SCALE; + rotation->y = rotation->y*SCALE/MIN_SCALE; + } + else if (temp_x >= MAX_SCALE*MAX_SCALE) + { + rotation->x = rotation->x*SCALE/MAX_SCALE; + rotation->y = rotation->y*SCALE/MAX_SCALE; + } +#undef MIN_SCALE +#undef MAX_SCALE + point = vertices; n = num_vertices; while (n--) { - temp_x = point->x; - temp_y = point->y; - point->x = temp_x*cos/SIN_COS_SCALE - temp_y*sin/SIN_COS_SCALE; - point->y = temp_y*cos/SIN_COS_SCALE + temp_x*sin/SIN_COS_SCALE; + point->x = (point->dx*rotation->x - point->dy*rotation->y)/SCALE; + point->y = (point->dy*rotation->x + point->dx*rotation->y)/SCALE; point++; } } @@ -849,6 +871,7 @@ static void rotate_asteroid(struct Asteroid* asteroid) { rotate_polygon(asteroid->vertices, NUM_ASTEROID_VERTICES, + &asteroid->rotation, asteroid->speed_cos, asteroid->speed_sin); } @@ -908,6 +931,9 @@ point->y = asteroid_vertices[n+1]; point->x *= asteroid->radius/20; point->y *= asteroid->radius/20; + /* use dx and dy as a master copy for ratation */ + point->dx = point->x; + point->dy = point->y; point++; } @@ -937,6 +963,9 @@ asteroid->position.dx *= SCALE/10; asteroid->position.dy *= SCALE/10; + asteroid->rotation.x = SCALE; + asteroid->rotation.y = 0; + /* Now rotate the asteroid a bit, so they all look a bit different */ for(n = (rb->rand()%30)+2; n--; ) rotate_asteroid(asteroid); @@ -1044,6 +1073,8 @@ ship.position.y = CENTER_LCD_Y * SCALE; ship.position.dx = 0; ship.position.dy = 0; + ship.rotation.x = SCALE; + ship.rotation.y = 0; ship.exists = true; ship.explode_countdown = 0; ship.invulnerable_time = INVULNERABLE_TIME; @@ -1056,6 +1087,9 @@ point->y = ship_vertices[n+1]; point->x *= SCALE; point->y *= SCALE; + /* use dx and dy as a master copy for ratation */ + point->dx = point->x; + point->dy = point->y; /* grab a copy of the ships points for the lives display: */ lives_point->x = point->x; lives_point->y = point->y; @@ -1129,7 +1163,8 @@ { if (ship.exists) { - rotate_polygon(ship.vertices, NUM_SHIP_VERTICES, cos, sin); + rotate_polygon(ship.vertices, NUM_SHIP_VERTICES, + &ship.rotation, cos, sin); } }