|
|
Re: How is this done ? Track map
[Re: Realspawn]
#422936
05/21/13 07:42
05/21/13 07:42
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
I will try to explain what is done into that code. I create the panels in run time in the first steps of main 'funtion':
bmpMinimap = bmap_create ( "minimap.tga" );
bmpCar = bmap_create ( "player.tga" );
panMinimap = pan_create ( "flags=SHOW;", 1 );
pan_setneedle ( panMinimap, 0, 256, 256, bmpMinimap, 256, 256, 90, 0, 360, panMinimap->skill_x );
pan_setneedle ( panMinimap, 0, 256, 256, bmpCar, 16, 16, 90, 0, 360, camera->skill_x );
panMinimap->bmap = bmap_createblack ( 512, 512, 24 );
panMinimap->target_map = bmap_createblack ( 512, 512, 24 );
PANEL *panMap = pan_create ( "flags=SHOW", 1 );
panMap->bmap = panMinimap->target_map;
There are two panels. 'panMiniMap' is used to contain all the needles used for the minimap and is rendered over its 'render_target'. 'panMap' is just used to show the main panel 'render_target'. I did it this way becuase the needle member of a panel is also rendered out of the bounds of the panel when it gets out of it, and this way just the part inside its panel bounds will be shown. Initially, 'panMinimap' has two needles: the first one is the map itself, and the second is the player icon. I used 'panMinimap->skill_x' for the needle orientation. I set 'panMinimap->skill_y' as the proportion between the minimap bitmap size and the level size in order to compute the needle pivot:
panMinimap->skill_y = bmap_width ( bmpMinimap ) / ( level_ent->max_x * 2 ) ;
...
while ( !key_esc )
...
proc_mode = PROC_EARLY;
...
panMinimap->skill_x = -camera.pan;
vecTemp.x = camera->x * panMinimap->skill_y;
vecTemp.y = -camera->y * panMinimap->skill_y;
pan_setneedle ( panMinimap, 1, 256, 256, bmpMinimap, 256+vecTemp.x, 256+vecTemp.y, 90, 0, 360, panMinimap->skill_x );
I used 'proc_mode = PROC_EARLY' in order to ensure that the panel skills are computed first, so all other needles have the actual frames 'skill_x' and 'skill_y' values updated at their computation time. The needle angle allocated in 'skill_x'
panMinimap->skill_x = -camera.pan;
is the negative of the players 'pan', because the screen (and panels) coordinate system is clockwise while the world coordinate system is counterclockwise. With this issue in mind the Y coordinate of the offset of the background has to be computed same:
vecTemp.x = camera->x * panMinimap->skill_y;
vecTemp.y = -camera->y * panMinimap->skill_y; // inverse Y, so convert to counterclockwise coordinate system.
And finally inside 'main' we need to update the needle pivot position:
pan_setneedle ( panMinimap, 1, 256, 256, bmpMinimap, 256+vecTemp.x, 256+vecTemp.y, 90, 0, 360, panMinimap->skill_x );
With this few lines of code we have a minimap that rotates with the camera pan, and computes its offset with the camera position. The enemies icons are created into the first lines of the entity action:
var needleIndex = 3;
action actCar ()
{
pan_setneedle ( panMinimap, 0, 256, 256, bmpCar, 16, 16, 90, 0, 360, my->skill1 );
var myIndex = needleIndex;
needleIndex += 1;
...
I used a global int to store the amount of needles, so we know the actual enemys' needle to further computations by this count i inside the action while loop:
pan_setneedle ( panMinimap, myIndex, 256+vecTemp.x, 256+vecTemp.y, bmpCar, 16, 16, 90, 0, 360, my->skill1 );
The enemies icon needles are rotated from its center, so the only things to compute is the offset (vecTemp) from the player and its orientation (my->skill1).
vecTemp.x = ( camera->x - my->x ) * panMinimap->skill_y;
vecTemp.y = -( camera->y - my->y ) * panMinimap->skill_y; // inverse!
vec_rotate ( &vecTemp, vector ( 90-panMinimap->skill_x, 0, 0 ) );
my->skill1 = ang ( my->pan - camera->pan );
The offset vector (vecTemp) is rotated by '90-panMinimap->skill_x' because the icons are looking to the right (X positive), and in the minimap they look up. The angle of the enemies icon (my->skill1) is the difference to the players orientation because the minimap is already oriented with the player. that's all folks! I hope it helps  Salud!
|
|
|
|