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

天行健 君子當自強而不息

創建游戲內核(6)【接口與實現分離版】

 

本篇是創建游戲內核(5)【接口與實現分離版】的續篇,關于該內核的細節說明請參考創建游戲內核(6),這個版本主要是按照功能劃分模塊的思想,并嚴格按照接口與實現相分離的原則來寫的,沒有用面向對象的思想來寫,沒有繼承沒有多態。大家可以對比兩個版本,比較優劣。

接口:

/*************************************************************************
PURPOSE:
    Interface for D3D camera.
*************************************************************************/


#ifndef _CORE_CAMERA_H_
#define _CORE_CAMERA_H_

#include "core_common.h"

typedef 
void* CAMERA;

CAMERA camera_create();

void camera_move(CAMERA camera, float x_pos, float y_pos, float z_pos);
void camera_rotate(CAMERA camera, float x_rot, float y_rot, float z_rot);

void camera_point(CAMERA camera, 
                  
float x_eye, float y_eye, float z_eye, 
                  
float x_at, float y_at, float z_at);

void camera_set_start_track(CAMERA camera);
void camera_set_end_track(CAMERA camera);

void camera_track(CAMERA camera, float time_ratio, float time_length);
void camera_update(CAMERA camera);

D3DXMATRIX* camera_get_matrix(CAMERA camera);

float camera_get_x_pos(CAMERA camera);
float camera_get_y_pos(CAMERA camera);
float camera_get_z_pos(CAMERA camera);

float camera_get_x_rot(CAMERA camera);
float camera_get_y_rot(CAMERA camera);
float camera_get_z_rot(CAMERA camera);

#endif
 

實現:
/***********************************************************************************
PURPOSE:
    Implement for D3D camera.
***********************************************************************************/


#include "core_common.h"
#include "core_camera.h"

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_world;           
// world transform matrix
    D3DXMATRIX mat_translation;     // translation matrix
    D3DXMATRIX mat_rotation;        // rotation matrix
} *_CAMERA_PTR;

//----------------------------------------------------------------------------------------
// Create camera.
//----------------------------------------------------------------------------------------
CAMERA camera_create()
{
    _CAMERA_PTR _camera = (_CAMERA_PTR) malloc(
sizeof(_CAMERA));

    memset(_camera, 0, 
sizeof(_CAMERA));

    
return (CAMERA) _camera;
}

//----------------------------------------------------------------------------------------
// move camera to new position.
//----------------------------------------------------------------------------------------
void camera_move(CAMERA camera, float x_pos, float y_pos, float z_pos)
{
    _CAMERA_PTR _camera = (_CAMERA_PTR) camera;

    _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);
}

//-------------------------------------------------------------------------
// rotate camera.
//-------------------------------------------------------------------------
void camera_rotate(CAMERA camera, float x_rot, float y_rot, float z_rot)
{
    D3DXMATRIX _mat_x_rot, _mat_y_rot, _mat_z_rot;

    _CAMERA_PTR _camera = (_CAMERA_PTR) camera;

    _camera->x_rot = x_rot;
    _camera->y_rot = y_rot;
    _camera->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);
}

//-------------------------------------------------------------------------
// move camera to new position and look at new target position.
//-------------------------------------------------------------------------
void camera_point(CAMERA 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
    camera_move(camera, x_eye, y_eye, z_eye);
    camera_rotate(camera, _x_rot, _y_rot, 0.0);
}

//-------------------------------------------------------------------------
// set camera's start tracking position and rotation.
//-------------------------------------------------------------------------
void camera_set_start_track(CAMERA camera)
{
    _CAMERA_PTR _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 camera_set_end_track(CAMERA camera)
{
    _CAMERA_PTR _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 camera_track(CAMERA camera, float time_ratio, float time_length)
{
    _CAMERA_PTR _camera = (_CAMERA_PTR) camera;

    
float _time_offset = time_length * time_ratio;

    
float _x = (_camera->end_x_pos - _camera->start_x_pos) / time_length * _time_offset;
    
float _y = (_camera->end_y_pos - _camera->start_y_pos) / time_length * _time_offset;
    
float _z = (_camera->end_z_pos - _camera->start_z_pos) / time_length * _time_offset;

    camera_move(camera, _camera->start_x_pos + _x, _camera->start_y_pos + _y, _camera->start_z_pos + _z);

    _x = (_camera->end_x_rot - _camera->start_x_rot) / time_length * _time_offset;
    _y = (_camera->end_y_rot - _camera->start_y_rot) / time_length * _time_offset;
    _z = (_camera->end_z_rot - _camera->start_z_rot) / time_length * _time_offset;

    camera_rotate(camera, _camera->start_x_rot + _x, _camera->start_y_rot + _y, _camera->start_z_rot + _z);
}

//-------------------------------------------------------------------------
// update new camera world transform matrix.
//-------------------------------------------------------------------------
void camera_update(CAMERA camera)
{
    _CAMERA_PTR _camera = (_CAMERA_PTR) camera;

    D3DXMatrixMultiply(&_camera->mat_world, &_camera->mat_translation, &_camera->mat_rotation);
}

//-------------------------------------------------------------------------
// Get camera world transform matrix.
//-------------------------------------------------------------------------
D3DXMATRIX* camera_get_matrix(CAMERA camera)
{
    camera_update(camera);

    
return & ((_CAMERA_PTR) camera)->mat_world;
}

//-------------------------------------------------------------------------
// Get camera current position (x coordinate).
//-------------------------------------------------------------------------
float camera_get_x_pos(CAMERA camera)
{
    
return ((_CAMERA_PTR) camera)->x_pos;
}

//-------------------------------------------------------------------------
// Get camera current position (y coordinate).
//-------------------------------------------------------------------------
float camera_get_y_pos(CAMERA camera)
{
    
return ((_CAMERA_PTR) camera)->y_pos;
}

//-------------------------------------------------------------------------
// Get camera current position (z coordinate).
//-------------------------------------------------------------------------
float camera_get_z_pos(CAMERA camera)
{
    
return ((_CAMERA_PTR) camera)->z_pos;
}

//-------------------------------------------------------------------------
// Get camera current rotation (x coordinate).
//-------------------------------------------------------------------------
float camera_get_x_rot(CAMERA camera)
{
    
return ((_CAMERA_PTR) camera)->x_rot;
}

//-------------------------------------------------------------------------
// Get camera current rotation (y coordinate).
//-------------------------------------------------------------------------
float camera_get_y_rot(CAMERA camera)
{
    
return ((_CAMERA_PTR) camera)->y_rot;
}

//-------------------------------------------------------------------------
// Get camera current rotation (z coordinate).
//-------------------------------------------------------------------------
float camera_get_z_rot(CAMERA camera)
{
    
return ((_CAMERA_PTR) camera)->z_rot;
}

 

posted on 2007-10-02 23:52 lovedday 閱讀(189) 評論(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>
            国产欧美一区二区精品忘忧草| 亚洲精选在线| 久久久久高清| 国产欧美一区二区三区另类精品 | 亚洲毛片网站| 欧美手机在线视频| 亚洲视频一区在线| 亚洲国产婷婷综合在线精品| 亚洲一区二区高清视频| 欧美一区二区| 亚洲国产精品一区二区www在线| 老司机一区二区| 亚洲精品一区二| 久久久久www| 中文精品视频| 精品成人在线视频| 欧美天天在线| 农村妇女精品| 欧美在线高清| 99日韩精品| 欧美第一黄网免费网站| 午夜精品久久久久久久久久久久| 精品1区2区| 国产精品区一区二区三区| 老司机精品视频一区二区三区| 夜夜嗨av一区二区三区中文字幕| 久久久久久久久久久一区| 99在线精品免费视频九九视| 国产一区清纯| 国产精品美女www爽爽爽| 蜜臀91精品一区二区三区| 一区二区久久久久| 欧美国产一区二区三区激情无套| 午夜在线a亚洲v天堂网2018| 日韩一级黄色大片| 亚洲大胆在线| 国产在线播精品第三| 国产精品美女久久久| 欧美激情国产精品| 久久性天堂网| 欧美一级网站| 亚洲综合色噜噜狠狠| 亚洲三级影院| 久久天天躁狠狠躁夜夜爽蜜月| 亚洲综合色在线| 99av国产精品欲麻豆| 亚洲经典自拍| 1024国产精品| 尤物九九久久国产精品的特点| 国产精品美女一区二区在线观看| 欧美黄色aa电影| 欧美成人精品福利| 欧美顶级大胆免费视频| 久久婷婷国产麻豆91天堂| 欧美影院在线播放| 欧美一区=区| 久久精品欧美日韩精品| 久久黄色网页| 久久婷婷久久| 亚洲精品国产无天堂网2021| 久久综合导航| 欧美伊人久久久久久午夜久久久久 | 小处雏高清一区二区三区| 亚洲一区二区三区精品视频| 夜夜爽99久久国产综合精品女不卡 | 久久资源在线| 欧美~级网站不卡| 欧美成人精品一区| 欧美精品在线视频观看| 女女同性精品视频| 欧美人交a欧美精品| 欧美日本视频在线| 欧美性久久久| 国产在线视频不卡二| 狠狠色香婷婷久久亚洲精品| 在线观看日韩一区| 一本色道久久综合狠狠躁篇怎么玩 | 欧美激情精品久久久久久蜜臀 | 亚洲第一页中文字幕| 亚洲盗摄视频| 亚洲精品久久久久久久久久久久久 | 欧美黑人在线观看| 亚洲黄色尤物视频| 亚洲一区二区精品在线观看| 性久久久久久久久久久久| 久久久水蜜桃| 欧美视频在线观看免费网址| 国产欧美在线看| 91久久久久久| 香蕉久久精品日日躁夜夜躁| 久久综合九色综合欧美狠狠| 亚洲人被黑人高潮完整版| 亚洲欧美制服中文字幕| 久久免费视频在线观看| 欧美日韩高清在线| 国产一区二区黄色| 在线综合亚洲欧美在线视频| 久久久久成人精品| 亚洲精品婷婷| 久久精品国产免费| 国产一级揄自揄精品视频| 狠狠色丁香久久婷婷综合_中| 欧美色区777第一页| 国产精品免费视频观看| 国产亚洲福利一区| 99国产精品一区| 久久人人97超碰国产公开结果 | 亚洲图片欧美日产| 日韩小视频在线观看| 欧美不卡视频一区| 亚洲精品中文在线| 性色av一区二区三区在线观看 | 久久成人亚洲| 欧美国产日韩一区二区三区| 亚洲一区久久久| 欧美成人免费网站| 精品成人在线| 欧美一区二区高清在线观看| 91久久夜色精品国产网站| 午夜性色一区二区三区免费视频 | 国产精品欧美日韩久久| 亚洲中午字幕| 久久视频一区| 午夜精品福利一区二区蜜股av| 欧美日韩1区2区3区| 91久久亚洲| 免费看的黄色欧美网站| 销魂美女一区二区三区视频在线| 欧美激情女人20p| 亚洲人体1000| 亚洲福利视频一区| 女人天堂亚洲aⅴ在线观看| 一区二区在线观看视频在线观看| 羞羞色国产精品| 亚洲影音先锋| 国产综合在线看| 久久综合狠狠综合久久激情| 久久国产精品第一页| 国产亚洲高清视频| 久热这里只精品99re8久| 久久久人成影片一区二区三区 | 亚洲性感激情| 一区二区三区欧美视频| 国产精品卡一卡二卡三| 午夜宅男欧美| 欧美一区二区在线免费播放| 伊人天天综合| 亚洲一区激情| 国产一区二区福利| 久久蜜臀精品av| 亚洲欧美国产高清va在线播| 国产精品久久毛片a| 午夜精品理论片| 欧美影院一区| 亚洲一区视频在线观看视频| 国产精品一区久久| 亚洲欧美偷拍卡通变态| 欧美在线观看www| 曰韩精品一区二区| 亚洲国产欧美日韩精品| 欧美大片91| 欧美亚洲免费| 久久久久久亚洲精品中文字幕| 亚洲国产精品高清久久久| 亚洲黑丝在线| 国产精品私拍pans大尺度在线| 久久免费视频网| 欧美日韩精品国产| 久久精品一区二区三区不卡| 国产精品青草久久久久福利99| 在线亚洲免费| 欧美亚洲免费| 亚洲人www| 亚洲男人影院| 亚洲激情视频在线播放| 亚洲免费在线播放| 亚洲精品国产精品国自产观看浪潮| 亚洲三级观看| 狠狠色伊人亚洲综合网站色| 日韩小视频在线观看专区| 国内视频精品| 中文亚洲字幕| 亚洲精品一区二区三区不| 欧美一区1区三区3区公司| 亚洲精品一区二| 久久国产精品久久国产精品| 亚洲视频一区| 欧美18av| 可以看av的网站久久看| 欧美视频精品在线| 亚洲第一精品福利| 黑人中文字幕一区二区三区| 亚洲影视在线| 亚洲线精品一区二区三区八戒| 免费成人激情视频| 裸体一区二区| 激情亚洲网站| 国产精品永久入口久久久| 国内精品国产成人| 日韩视频在线免费观看|