Asteroid clone, and distortion of the player's ship

This is a discussion on Asteroid clone, and distortion of the player's ship within the Game Programming forums, part of the General Programming Boards category; I have a problem with the game I'm making atm (an Asteroids clone ), anyway, I'm programming the object rotation ...

  1. #1
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195

    Asteroid clone, and distortion of the player's ship

    I have a problem with the game I'm making atm (an Asteroids clone ), anyway, I'm programming the object rotation methods so that the player can turn etc and so that the asteroids can have 'spin' as they go past. Anyway, I'm stuck on the rotation calculations. I've got something which is close to being right, but over a reasonably long period the shape of the space craft slowly becomes more and more distorted. I'm not really sure why, one idea I did have is that the program is rounding the numbers slightly, and that over time it causes a gradual distortion of the player's ship, since the calculations are done with floats and doubles, and the results (since they are pixel positions on the screen), are saved as ints.

    When I first started making this method, I initially did it so that it would turn 90 degrees in either way, depending on the button pushed, but I want to give a little more control, and so had to use the rotation matrix.

    This is the 90 degrees way:
    Code:
    for(idx=0; idx<SHIP_PNUM; idx++)
                  {
                             /* Sort out the temp variables */
                             corner_temp1 = Player.position_corners_new[idx][0];
                             corner_temp2 = Player.position_corners_new[idx][1];
                             
                             /* Sort out the coordinate transformation */
                             Player.position_corners_new[idx][0] = (int)(Player.com_position.X - (corner_temp2 - Player.com_position.Y));
                             Player.position_corners_new[idx][1] = (int)(Player.com_position.Y + (corner_temp1 - Player.com_position.X));
                  }
    This is the attempt at a more generalised rotation:
    Code:
    for(idx=0; idx<SHIP_PNUM; idx++)
                  {
                             /* Sort out the temp variables */
                             corner_temp1 = Player.position_corners_new[idx][0];
                             corner_temp2 = Player.position_corners_new[idx][1];
                             
                             /* Sort out the coordinate transformation */
                             Player.position_corners_new[idx][0] = (int)(Player.com_position.X + (corner_temp1 - Player.com_position.X)*cos(rot_speed) + (corner_temp2 - Player.com_position.Y)*sin(rot_speed));
                             Player.position_corners_new[idx][1] = (int)(Player.com_position.Y + (corner_temp2 - Player.com_position.Y)*cos(rot_speed) - (corner_temp1 - Player.com_position.X)*sin(rot_speed));
                  }
    Note: The first one does a rotation clockwise, the second one does a rotation counter-clockwise.

    Variables:
    Player.position_corners_new - Holds details about the location of corners of the ship (i.e. what makes the ship what it is) on the screen.

    Player.com_position - Type COORD which holds the information about where the centre of mass of the player is on the screen (all rotations are done around this point)

    rot_speed - Constant which determines the rotational sensitivity of the controls

    [edit] The rotation stuff for the 90 degree one works fine, I just can't generalise it so that it covers any amount of rotation [/edit]
    Last edited by Swarvy; 10-06-2008 at 11:53 AM.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Shouldn't
    Code:
    Player.position_corners_new[idx][0] = (int)(Player.com_position.X + (corner_temp1 - Player.com_position.X)*cos(rot_speed) + (corner_temp2 - Player.com_position.Y)*sin(rot_speed));
    Be
    Code:
    Player.position_corners_new[idx][0] = (int)(Player.com_position.X + (corner_temp1 - Player.com_position.X)*cos(rot_speed) + (corner_temp2 - Player.com_position.Y)*-sin(rot_speed));

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21