青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

創建游戲內核(6)【C風格版】

 

本篇是創建游戲內核(5)【C風格版】的續篇,關于該內核的細節說明請參考創建游戲內核(6)

 

接口:

typedef struct CAMERA
{
    
float x_pos, y_pos, z_pos;                      // camera current position
    float x_rot, y_rot, z_rot;                      // camera current rotation

    
float start_x_pos, start_y_pos, start_z_pos;    // start tracking position
    float start_x_rot, start_y_rot, start_z_rot;    // start tracking rotation

    
float end_x_pos, end_y_pos, end_z_pos;          // end tracking position
    float end_x_rot, end_y_rot, end_z_rot;          // end tracking rotation

    D3DXMATRIX mat_view;                           
// world transform matrix
    D3DXMATRIX mat_translation;                     // translation matrix
    D3DXMATRIX mat_rotation;                        // rotation matrix
} *CAMERA_PTR;

CAMERA_PTR create_camera();
void destroy_camera(CAMERA_PTR camera);

void move_camera(CAMERA_PTR camera, 
                 
float x_pos, float y_pos, float z_pos);

void move_camera_rel(CAMERA_PTR camera, 
                     
float x_add, float y_add, float z_add);

void rotate_camera(CAMERA_PTR camera, 
                   
float x_rot, float y_rot, float z_rot);

void point_camera(CAMERA_PTR camera, 
                  
float x_eye, float y_eye, float z_eye, 
                  
float x_at, float y_at, float z_at);

void start_track_camera(CAMERA_PTR camera);
void end_track_camera(CAMERA_PTR camera);
void track_camera(CAMERA_PTR camera, float time_ratio);
void update_camera_pos(CAMERA_PTR camera);

實現:

//----------------------------------------------------------------------------------------
// Create camera.
//----------------------------------------------------------------------------------------
CAMERA_PTR create_camera()
{
    CAMERA_PTR camera = (CAMERA_PTR) malloc(
sizeof(CAMERA));

    memset(camera, 0, 
sizeof(CAMERA));

    
return camera;
}

//----------------------------------------------------------------------------------------
// Destroy camera.
//----------------------------------------------------------------------------------------
void destroy_camera(CAMERA_PTR camera)
{
    free(camera);
}

//----------------------------------------------------------------------------------------
// move camera to new position.
//----------------------------------------------------------------------------------------
void move_camera(CAMERA_PTR camera, 
                 
float x_pos, float y_pos, float z_pos)
{    
    camera->x_pos = x_pos;
    camera->y_pos = y_pos;
    camera->z_pos = z_pos;

    D3DXMatrixTranslation(&camera->mat_translation, -x_pos, -y_pos, -z_pos);
}

//----------------------------------------------------------------------------------------
// Move camera to new position relative to current position.
//----------------------------------------------------------------------------------------
void move_camera_rel(CAMERA_PTR camera, 
                     
float x_add, float y_add, float z_add)
{
    move_camera(camera, 
                camera->x_pos + x_add, camera->y_pos + y_add, camera->z_pos + z_add);
}

//-------------------------------------------------------------------------
// rotate camera.
//-------------------------------------------------------------------------
void rotate_camera(CAMERA_PTR camera, 
                   
float x_rot, float y_rot, float z_rot)
{
    D3DXMATRIX mat_x_rot, mat_y_rot, mat_z_rot;    

    camera->x_rot = x_rot;
    camera->y_rot = y_rot;
    camera->z_rot = z_rot;

    D3DXMatrixRotationX(&mat_x_rot, -x_rot);
    D3DXMatrixRotationY(&mat_y_rot, -y_rot);
    D3DXMatrixRotationZ(&mat_z_rot, -z_rot);

    camera->mat_rotation = mat_z_rot;

    D3DXMatrixMultiply(&camera->mat_rotation, &camera->mat_rotation, &mat_y_rot);
    D3DXMatrixMultiply(&camera->mat_rotation, &camera->mat_rotation, &mat_x_rot);
}

//-------------------------------------------------------------------------
// rotate camera.
//-------------------------------------------------------------------------
void rotate_camera_rel(CAMERA_PTR camera, 
                       
float x_add, float y_add, float z_add)
{
    rotate_camera(camera, 
                  camera->x_pos + x_add, camera->y_pos + y_add, camera->z_pos + z_add);
}

//-------------------------------------------------------------------------
// move camera to new position and look at new target position.
//-------------------------------------------------------------------------
void point_camera(CAMERA_PTR camera, 
                  
float x_eye, float y_eye, float z_eye, 
                  
float x_at, float y_at, float z_at)
{
    
// calculate angles between points

    
float x_diff = x_at - x_eye;
    
float y_diff = y_at - y_eye;
    
float z_diff = z_at - z_eye;

    
float x_rot = (float) atan2(-y_diff, sqrt(x_diff * x_diff + z_diff * z_diff));
    
float y_rot = (float) atan2(x_diff, z_diff);

    
// move camera to new position and look at new target
    move_camera(camera, x_eye, y_eye, z_eye);
    rotate_camera(camera, x_rot, y_rot, 0.0);
}

//-------------------------------------------------------------------------
// set camera's start tracking position and rotation.
//-------------------------------------------------------------------------
void start_track_camera(CAMERA_PTR camera)
{    
    camera->start_x_pos = camera->x_pos;
    camera->start_y_pos = camera->y_pos;
    camera->start_z_pos = camera->z_pos;

    camera->start_x_rot = camera->x_rot;
    camera->start_y_rot = camera->y_rot;
    camera->start_z_rot = camera->z_rot;
}

//-------------------------------------------------------------------------
// set camera's end tracking position and rotation.
//-------------------------------------------------------------------------
void end_track_camera(CAMERA_PTR camera)
{    
    camera->end_x_pos = camera->x_pos;
    camera->end_y_pos = camera->y_pos;
    camera->end_z_pos = camera->z_pos;

    camera->end_x_rot = camera->x_rot;
    camera->end_y_rot = camera->y_rot;
    camera->end_z_rot = camera->z_rot;
}

//-------------------------------------------------------------------------
// move camera to new position and ratation by giving time, 
// 0 <= time_ratio <= 1.
//-------------------------------------------------------------------------
void track_camera(CAMERA_PTR camera, float time_ratio)
{       
    
float x_move = (camera->end_x_pos - camera->start_x_pos) * time_ratio;
    
float y_move = (camera->end_y_pos - camera->start_y_pos) * time_ratio;
    
float z_move = (camera->end_z_pos - camera->start_z_pos) * time_ratio;

    move_camera(camera, 
        camera->start_x_pos + x_move, camera->start_y_pos + y_move, camera->start_z_pos + z_move);

    
float x_rotate = (camera->end_x_rot - camera->start_x_rot) * time_ratio;
    
float y_rotate = (camera->end_y_rot - camera->start_y_rot) * time_ratio;
    
float z_rotate = (camera->end_z_rot - camera->start_z_rot) * time_ratio;

    rotate_camera(camera, 
        camera->start_x_rot + x_rotate, camera->start_y_rot + y_rotate, camera->start_z_rot + z_rotate);
}

//-------------------------------------------------------------------------
// update new camera world transform matrix.
//-------------------------------------------------------------------------
void update_camera_pos(CAMERA_PTR camera)
{
    D3DXMatrixMultiply(&camera->mat_view, &camera->mat_translation, &camera->mat_rotation);
}

posted on 2007-10-25 20:25 lovedday 閱讀(184) 評論(0)  編輯 收藏 引用

公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲激情视频在线| 久久久999精品视频| 欧美主播一区二区三区美女 久久精品人 | 欧美 日韩 国产一区二区在线视频| 免费高清在线视频一区·| 欧美二区在线播放| 亚洲日本无吗高清不卡| 99亚洲视频| 销魂美女一区二区三区视频在线| 久久久久久亚洲精品杨幂换脸| 免费成人毛片| 国产精品久久久久国产a级| 国产视频综合在线| 亚洲精品国产精品国自产在线 | 亚洲人成欧美中文字幕| 亚洲午夜av在线| 久久久999精品免费| 欧美日韩福利视频| 狠狠综合久久av一区二区小说| 一区二区三区国产精华| 久久这里只有精品视频首页| 一本色道久久综合狠狠躁篇的优点| 久久精品国产亚洲5555| 欧美日韩一区免费| 亚洲福利视频免费观看| 欧美伊人久久久久久久久影院| 亚洲欧洲另类国产综合| 久久精品日韩| 国产区二精品视| 亚洲精品自在在线观看| 久久国产高清| 99精品国产一区二区青青牛奶| 欧美专区在线| 欧美午夜性色大片在线观看| 最新国产成人av网站网址麻豆| 欧美一区二区大片| 日韩一级欧洲| 欧美激情一区二区久久久| 尤物99国产成人精品视频| 性18欧美另类| 中文国产亚洲喷潮| 欧美精品一级| 亚洲伦伦在线| 欧美高清在线视频| 久久久一二三| 精品成人一区二区| 久久米奇亚洲| 久久精品72免费观看| 国产小视频国产精品| 欧美一区二区三区四区视频| 亚洲网站在线播放| 国产精品麻豆va在线播放| 亚洲一区二区三区四区视频| 亚洲人成网站精品片在线观看| 久久婷婷久久一区二区三区| 国内外成人在线视频| 久久久久99精品国产片| 欧美在线精品免播放器视频| 国产亚洲精品美女| 久久久久久伊人| 久久久国产精品一区二区中文 | 亚洲精品一区二区在线| 蜜桃av久久久亚洲精品| 久久五月天婷婷| 亚洲国产精品一区制服丝袜 | 欧美国产日韩在线| 欧美fxxxxxx另类| 亚洲美女尤物影院| 99re6热在线精品视频播放速度| 欧美精品一区二区三区一线天视频| 亚洲免费观看在线视频| 99精品视频免费| 国产精品乱人伦中文| 久久精品中文字幕一区二区三区 | 欧美成人福利视频| 亚洲精品一区中文| 在线视频免费在线观看一区二区| 国产精品日韩一区二区| 久久久综合香蕉尹人综合网| 免费视频一区| 午夜在线观看免费一区| 久久国产精品一区二区| 亚洲国产成人久久| 一区二区欧美精品| 国内综合精品午夜久久资源| 六月婷婷一区| 久久一区二区三区四区| 亚洲视频综合| 在线观看欧美日韩国产| 亚洲每日在线| 在线成人国产| 亚洲一区二区三区四区中文| 伊人成综合网伊人222| 亚洲毛片一区二区| 激情成人综合| 一区二区三区色| 亚洲国产福利在线| 一本色道久久88综合亚洲精品ⅰ| 国产在线拍偷自揄拍精品| 亚洲乱码国产乱码精品精可以看| 国产一区二区三区免费观看| 亚洲欧洲日产国产网站| 国产中文一区二区| 一区二区三区四区蜜桃| 亚洲黄网站在线观看| 欧美一区二区视频在线| 亚洲综合精品四区| 蜜臀av国产精品久久久久| 久久不射中文字幕| 欧美午夜免费影院| 亚洲激情一区二区三区| 1769国产精品| 久久久久国产精品www | 午夜精品久久久久久久99热浪潮| 欧美高清影院| 欧美激情影院| 一区二区三区无毛| 午夜精品免费视频| 性久久久久久| 国产精品www色诱视频| 亚洲黄色精品| 亚洲精品久久| 欧美成人午夜剧场免费观看| 欧美18av| 亚洲激情第一页| 鲁大师影院一区二区三区| 噜噜噜91成人网| 亚洲福利在线看| 免费看精品久久片| 免费在线国产精品| 在线观看视频日韩| 久久综合九色综合久99| 免费欧美日韩| 亚洲日本激情| 欧美高清在线观看| 亚洲精品社区| 亚洲男人的天堂在线观看| 国产精品久久久久久久久婷婷| 一区二区三区.www| 午夜国产不卡在线观看视频| 国产欧美日韩精品一区| 欧美与黑人午夜性猛交久久久| 久久久综合精品| 在线观看视频一区| 欧美激情第三页| 在线性视频日韩欧美| 欧美在线三级| 亚洲国产成人在线| 欧美精品一区视频| 亚洲私人影院| 巨乳诱惑日韩免费av| 亚洲日本国产| 亚洲国产婷婷综合在线精品| 黄页网站一区| 久久久亚洲欧洲日产国码αv | 男男成人高潮片免费网站| 极品尤物av久久免费看| 欧美成人精品高清在线播放| 亚洲久久在线| 久久爱www久久做| 亚洲狠狠丁香婷婷综合久久久| 欧美久久一级| 午夜在线精品| 亚洲国产激情| 欧美一区二区三区免费视频| 亚洲第一精品久久忘忧草社区| 欧美日韩三级视频| 久久精品国产视频| 99re热这里只有精品视频| 玖玖综合伊人| 午夜精品福利在线| 亚洲精品在线三区| 国产日韩精品视频一区| 欧美电影美腿模特1979在线看| 亚洲综合色在线| 亚洲国产影院| 久久在线免费视频| 亚洲综合精品一区二区| 91久久精品国产| 国产一区二区主播在线| 欧美午夜久久| 欧美黄色免费网站| 久久精品视频在线看| 亚洲一区激情| 日韩午夜av电影| 亚洲第一久久影院| 久久久夜色精品亚洲| 亚洲欧美日韩视频一区| 亚洲精品资源美女情侣酒店| 影音先锋亚洲视频| 国产日韩一区在线| 国产精品久久久久久久久果冻传媒 | 美女视频一区免费观看| 欧美亚洲免费| 一区二区三区日韩欧美| 亚洲高清毛片| 在线观看日韩欧美| 一区二区三区在线免费视频 | 亚洲福利视频在线| 国内精品国产成人|