《3d游戏编程大师技巧》笔记

最近沉迷游戏实在颓废,好对不起媳妇儿╮(╯▽╰)╭。

王者荣耀已经上王者了,从今天开始杜绝此类易沉迷游戏!!!


书看了就忘,不过我肯定至少会看两遍的。

1、

//这个函数通过REST_BIT来清除object状态state标记,state可以有多个状态的混合。

void Reset_OBJECT4DV1(OBJECT4DV1_PTR obj)
{
// this function resets the sent object and redies it for 
// transformations, basically just resets the culled, clipped and
// backface flags, but here's where you would add stuff
// to ready any object for the pipeline
// the object is valid, let's rip it apart polygon by polygon

// reset object's culled flag
RESET_BIT(obj->state, OBJECT4DV1_STATE_CULLED);

// now the clipped and backface flags for the polygons 
for (int poly = 0; poly < obj->num_polys; poly++)
    {
    // acquire polygon
    POLY4DV1_PTR curr_poly = &obj->plist[poly];
    
    // first is this polygon even visible?
    if (!(curr_poly->state & POLY4DV1_STATE_ACTIVE))
       continue; // move onto next poly

    // reset clipped and backface flags
    RESET_BIT(curr_poly->state, POLY4DV1_STATE_CLIPPED);
    RESET_BIT(curr_poly->state, POLY4DV1_STATE_BACKFACE);

    } // end for poly

} // end Reset_OBJECT4DV1
#define RESET_BIT(word,bit_flag) ((word)=((word) & (~bit_flag)))

2.//这个函数是16位rgb索引表转换24位rgb格式

int RGB_16_8_IndexedRGB_Table_Builder(int rgb_format,             // format we want to build table for
                                                                  // 99/100 565
                                      LPPALETTEENTRY src_palette, // source palette
                                      UCHAR *rgblookup)           // lookup table
{
.....
if (rgb_format==DD_PIXEL_FORMAT565)
   {
   // there are a total of 64k entries, perform a loop and look them up, do the least 
   // amount of work, even with a pentium, there are 65536*256 interations here!
   for (int rgbindex = 0; rgbindex < 65536; rgbindex++)
     ...
           int r = (rgbindex >> 11) << 3; // 16位右移11位 左移动3位补3个0 转成8位
           int g = ((rgbindex >> 5) & 0x3f) << 2;//16位移动5位和6个1与运算 保证除了后六位其它位都是0 左移动2位补全2个0 0x3f二进制是00000000 00111111
           int b = (rgbindex & 0x1f) << 3;//同上
    ...
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值