2013年6月28日星期五(7-14,离散采样理论)

大概看了下,缩放无非就是采样,或者复制象素,或者混合。或者用一定采样频率。把上个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再封装了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值