大概看了下,缩放无非就是采样,或者复制象素,或者混合。或者用一定采样频率。把上个DEMO的3个机器人放缩了。
在alient_obj结构体中,加上 以下三项,
int width;
int height;
float scale;
具体到每个机器人
aliens[0].width = 72;
aliens[0].height = 80;
aliens[0].scale = ( ( float ) ( 1 + rand() % 20 ) ) / 10;
aliens[0].y += ( 72 - aliens[0].scale * 72 );
aliens[1].width = 72;
aliens[1].height = 80;
aliens[1].scale = ( ( float ) ( 1 + rand() % 20 ) ) / 10;
aliens[1].y += ( 72 - aliens[1].scale * 72 );
加了个函数,将目标矩形和源矩形不同大小,成倍数。
int DDraw_Draw_Surface_Scaled( LPDIRECTDRAWSURFACE7 source, int x, int y, int width_src, int height_src, int width_dest, int height_dest, LPDIRECTDRAWSURFACE7 dest, int transparent )
{
RECT dest_rect, source_rect;
dest_rect.left = x;
dest_rect.top = y;
dest_rect.right = x + width_dest - 1;
dest_rect.bottom = y + height_dest - 1 ;
source_rect.left = 0;
source_rect.top = 0;
source_rect.right = width_src - 1;
source_rect.bottom = height_src - 1;
if( transparent )
{
if( FAILED( dest->Blt( & dest_rect, source, & source_rect, ( DDBLT_WAIT | DDBLT_KEYSRC ), NULL ) ) )
return ( 0 );
}
else
{
if( FAILED( dest->Blt( & dest_rect, source, & source_rect, ( DDBLT_WAIT ), NULL ) ) )
return ( 0 );
}
return ( 1 );
}
在game_main部分,只是稍微替换下,
for( int index = 0; index < 3; index ++ )
{
DDraw_Draw_Surface_Scaled( aliens[index].frames[animation_seq[aliens[index].current_frame]],
aliens[index].x, aliens[index].y,
aliens[index].width, aliens[index].height,
( float ) aliens[index].width * aliens[index].scale,
( float ) aliens[index].height * aliens[index].scale,
lpddsback, 1 );
}
截图如下。
这个地方只有一个函数,好封装了,这里略过,看看t3dlib1.cpp里面,OHMYGOD,原来是BOB引擎部分,看来今天要大动干戈了。但是还是不太了解,估计要到后面的OUTPOST再封装了。