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

天行健 君子當自強而不息

創建游戲內核(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>
            美日韩精品视频免费看| 91久久综合| 一本不卡影院| 欧美视频中文字幕| 亚洲欧美综合国产精品一区| 午夜精品久久久久久久男人的天堂 | 日韩亚洲欧美综合| 国产精品日韩欧美一区| 久久精品免费观看| 男女av一区三区二区色多| 夜夜嗨av一区二区三区中文字幕 | 午夜精品久久久久久久99热浪潮| 国产亚洲激情在线| 欧美国产日韩在线观看| 欧美久久电影| 久久国产视频网站| 男人的天堂亚洲在线| 在线亚洲欧美视频| 欧美一级片一区| 亚洲精品三级| 亚洲欧美中文日韩v在线观看| 影音先锋在线一区| 日韩视频免费观看高清完整版| 国产精品免费一区二区三区在线观看 | 欧美激情欧美激情在线五月| 亚洲欧美日韩区| 久久久噜噜噜久久中文字免| 中文在线资源观看网站视频免费不卡 | 亚洲制服欧美中文字幕中文字幕| 亚洲女性喷水在线观看一区| 91久久综合亚洲鲁鲁五月天| 亚洲欧美电影院| 亚洲理伦在线| 久久蜜桃精品| 欧美制服丝袜第一页| 欧美日韩不卡视频| 奶水喷射视频一区| 国产精品一区二区你懂得| 亚洲电影欧美电影有声小说| 国产精品有限公司| 日韩一级二级三级| 亚洲国产精品福利| 欧美资源在线观看| 午夜精品婷婷| 欧美午夜不卡| 亚洲精品一区二区三区不| 亚洲大胆在线| 久久精品国产99精品国产亚洲性色| 中文精品99久久国产香蕉| 欧美不卡在线| 欧美成人高清| 精品成人乱色一区二区| 香蕉视频成人在线观看| 亚洲欧美99| 国产精品视频网址| 亚洲网址在线| 亚洲欧美日韩一区二区三区在线| 欧美精品videossex性护士| 麻豆成人综合网| 极品少妇一区二区三区精品视频 | 亚洲精品久久久久久久久久久久 | 欧美手机在线视频| 99精品国产在热久久婷婷| aⅴ色国产欧美| 欧美精品亚洲精品| 亚洲精品视频二区| 一区二区三区免费观看| 欧美视频国产精品| 亚洲一区视频在线| 久久久91精品国产| 黑丝一区二区三区| 久久亚洲国产精品一区二区| 老司机午夜精品| 91久久国产综合久久| 欧美日韩第一页| av不卡在线| 欧美一区二区三区在线免费观看 | 国产精品日韩久久久久| 新狼窝色av性久久久久久| 乱中年女人伦av一区二区| 亚洲国产女人aaa毛片在线| 欧美激情精品久久久久久变态| 日韩视频在线一区| 欧美一区二区三区精品电影| 一区二区三区在线视频观看| 欧美成人免费观看| 亚洲视频视频在线| 久久综合色天天久久综合图片| 亚洲高清视频的网址| 欧美日韩另类国产亚洲欧美一级| 亚洲午夜激情网页| 久久影院午夜论| av不卡在线| 国产亚洲福利社区一区| 免费欧美电影| 亚洲伊人观看| 亚洲高清视频的网址| 香蕉成人久久| 亚洲国产欧美一区二区三区久久 | 亚洲日本欧美| 久久久成人网| 在线视频亚洲一区| 樱桃国产成人精品视频| 欧美午夜一区二区三区免费大片 | 亚洲免费高清视频| 久久视频在线视频| 亚洲欧美日韩人成在线播放| 在线精品在线| 国产亚洲在线观看| 欧美日韩精品一区视频| 欧美一进一出视频| 99国产精品久久久久久久| 欧美chengren| 久久精品国产99国产精品澳门| 一区二区三区视频在线看| 在线成人av| 国产亚洲一二三区| 国产精品久久久久久久第一福利| 欧美成人久久| 老司机久久99久久精品播放免费| 亚洲综合电影| 日韩午夜黄色| 亚洲人成人77777线观看| 久久在线免费| 久久精品国产精品亚洲综合| 亚洲欧美日韩在线观看a三区| 亚洲精品激情| 亚洲人永久免费| 在线成人www免费观看视频| 国产日本欧美一区二区三区在线 | 久久福利资源站| 欧美有码在线观看视频| 亚洲永久字幕| 亚洲欧美日韩精品久久亚洲区 | 亚洲国产欧美一区二区三区久久| 久久视频免费观看| 久久久无码精品亚洲日韩按摩| 欧美一区=区| 欧美在线短视频| 欧美怡红院视频一区二区三区| 亚洲欧美日韩一区二区三区在线观看 | 欧美日韩成人精品| 欧美日韩国产精品一卡| 欧美国产日韩在线| 欧美日韩国产成人精品| 欧美日韩国产精品专区| 欧美日韩mv| 国产精品高清网站| 国产精品福利在线观看| 国产欧美日本一区视频| 国产视频一区二区三区在线观看| 国产日韩一区欧美| 韩日欧美一区二区| 亚洲国产影院| 中文日韩在线视频| 久久精品免费播放| 欧美国产在线观看| 99在线热播精品免费| 亚洲中午字幕| 久久精品国产精品亚洲综合| 毛片av中文字幕一区二区| 欧美高清一区| 国产精品久久看| 激情欧美日韩一区| 亚洲免费不卡| 欧美在线日韩| 欧美风情在线观看| 99精品视频免费在线观看| 午夜精品久久久久久久久久久久 | 欧美日本免费| 午夜在线精品偷拍| 欧美国产日韩亚洲一区| 亚洲美女黄网| 久久高清福利视频| 欧美日韩精品伦理作品在线免费观看| 国产精品久久久久久久久果冻传媒| 国模吧视频一区| 一区二区不卡在线视频 午夜欧美不卡在 | 99re6这里只有精品| 欧美一区二视频| 欧美黄免费看| 亚洲伊人第一页| 欧美大胆成人| 国产精品视频自拍| 亚洲大胆在线| 久久激情网站| 宅男精品导航| 欧美国产先锋| 伊人精品在线| 欧美在线你懂的| 亚洲免费激情| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产精品福利在线观看| 日韩视频亚洲视频| 猛男gaygay欧美视频| 亚洲黄色有码视频| 久久美女艺术照精彩视频福利播放| 国产精品久久久对白| 一本色道久久综合亚洲精品高清 | 一本色道久久88亚洲综合88 |