• <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>

            天行健 君子當自強而不息

            創(chuàng)建游戲內(nèi)核(5)【OO改良版】

             

            本篇是創(chuàng)建游戲內(nèi)核(4)【OO改良版】的續(xù)篇,關(guān)于該內(nèi)核的細節(jié)說明請參閱創(chuàng)建游戲內(nèi)核(5)


            接口:

            class WORLD_POSITION
            {
            public:
                WORLD_POSITION();

                
            void init();
                
            void update();

                
            void copy_to(WORLD_POSITION* dest_pos);    
                
            void enable_billboard(BOOL use_billboard);

                D3DXMATRIX* get_matrix();
                
            void set_matrix(const D3DXMATRIX* mat_world);        
                
                
            void set_combine_matrix_1(D3DXMATRIX* matrix);
                
            void set_combine_matrix_2(D3DXMATRIX* matrix);    

                
            void move(float x_pos, float y_pos, float z_pos);
                
            void move_rel(float x_add, float y_add, float z_add);

                
            void rotate(float x_rot, float y_rot, float z_rot);
                
            void rotate_rel(float x_add, float y_add, float z_add);

                
            void scale(float x_scale, float y_scale, float z_scale);
                
            void scale_rel(float x_add, float y_add, float z_add);    

                
            float get_x_pos();
                
            float get_y_pos();
                
            float get_z_pos();
                
            float get_x_rotation();
                
            float get_y_rotation();
                
            float get_z_rotation();
                
            float get_x_scale();
                
            float get_y_scale();
                
            float get_z_scale();

            private:
                BOOL    m_use_billboard;                           
            // flag indicates whether use billboard

                
            float m_x_pos, m_y_pos, m_z_pos;                   // current position
                float m_x_rotation, m_y_rotation, m_z_rotation;    // rotation
                float m_x_scale, m_y_scale, m_z_scale;             // scale value

                D3DXMATRIX  m_mat_world;         
            // world transform matrix
                D3DXMATRIX  m_mat_scale;         // scale matrix
                D3DXMATRIX  m_mat_rotation;      // rotation matrix
                D3DXMATRIX  m_mat_translation;   // translation matrix
                D3DXMATRIX* m_mat_combine_1;     // pointer to combination matrix 1
                D3DXMATRIX* m_mat_combine_2;     // pointer to combination matrix 2
            };

            typedef WORLD_POSITION* WORLD_POSITION_PTR;
             

            實現(xiàn):

            //-------------------------------------------------------------------------
            // Constrcutor, initialize data member.
            //-------------------------------------------------------------------------
            WORLD_POSITION::WORLD_POSITION()
            {
                memset(
            this, 0, sizeof(*this));    
            }

            //-------------------------------------------------------------------------
            // Initialize world position.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::init()
            {
                m_use_billboard = TRUE;

                scale(1.0, 1.0, 1.0);
                update();
            }

            //-------------------------------------------------------------------------
            // update world tranform matrix.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::update()
            {
                D3DXMATRIX _mat_view, _mat_transposed;

                
            // setup billboarding matrix
                if(m_use_billboard)
                {
                    
            if(g_d3d_device)
                    {
                        g_d3d_device->GetTransform(D3DTS_VIEW, &_mat_view);
                        D3DXMatrixTranspose(&_mat_transposed, &_mat_view);

                        _mat_transposed._41 = _mat_transposed._42 = _mat_transposed._43 = 0.0;
                        _mat_transposed._14 = _mat_transposed._24 = _mat_transposed._34 = 0.0;
                    }
                    
            else
                        D3DXMatrixIdentity(&_mat_transposed);
                }

                
            // combine scaling and rotation matrices first
                D3DXMatrixMultiply(&m_mat_world, &m_mat_scale, &m_mat_rotation);

                
            // apply billboard matrix
                if(m_use_billboard)
                    D3DXMatrixMultiply(&m_mat_world, &m_mat_world, &_mat_transposed);

                
            // combine with translation matrix
                D3DXMatrixMultiply(&m_mat_world, &m_mat_world, &m_mat_translation);

                
            // combine with combined matrices (if any)
             
                
            if(m_mat_combine_1 != NULL)
                    D3DXMatrixMultiply(&m_mat_world, &m_mat_world, m_mat_combine_1);

                
            if(m_mat_combine_2 != NULL)
                    D3DXMatrixMultiply(&m_mat_world, &m_mat_world, m_mat_combine_2);
            }

            //-------------------------------------------------------------------------
            // copy world position information to another world position object.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::copy_to(WORLD_POSITION* dest_pos)
            {
                dest_pos->move(m_x_pos, m_y_pos, m_z_pos);
                dest_pos->rotate(m_x_rotation, m_y_rotation, m_z_rotation);
                dest_pos->scale(m_x_scale, m_y_scale, m_z_scale);
                dest_pos->enable_billboard(m_use_billboard);
            }

            //-------------------------------------------------------------------------
            // Enable or disable billboard.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::enable_billboard(BOOL use_billboard)
            {
                m_use_billboard = use_billboard;
            }

            //-------------------------------------------------------------------------
            // Get current world transform matrix.
            //-------------------------------------------------------------------------
            D3DXMATRIX* WORLD_POSITION::get_matrix()
            {
                
            // update world tranform matrix first.
                update();

                
            return &m_mat_world;
            }

            //-------------------------------------------------------------------------
            // set world transform matrix.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::set_matrix(const D3DXMATRIX* mat_world)
            {
                m_mat_world = *mat_world;
            }

            //-------------------------------------------------------------------------
            // set combination matrix 1 which will be combined with world matrix.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::set_combine_matrix_1(D3DXMATRIX* matrix)
            {
                m_mat_combine_1 = matrix;
            }

            //-------------------------------------------------------------------------
            // set combination matrix 2 which will be combined with world matrix.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::set_combine_matrix_2(D3DXMATRIX* matrix)
            {
                m_mat_combine_2 = matrix;
            }

            //-------------------------------------------------------------------------
            // move to new world position with specified relative value.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::move(float x_pos, float y_pos, float z_pos)
            {
                m_x_pos = x_pos;
                m_y_pos = y_pos;
                m_z_pos = z_pos;

                D3DXMatrixTranslation(&m_mat_translation, m_x_pos, m_y_pos, m_z_pos);
            }

            //-------------------------------------------------------------------------
            // move to new world position which relative to current position.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::move_rel(float x_add, float y_add, float z_add)
            {
                move(m_x_pos + x_add, m_y_pos + y_add, m_z_pos + z_add);
            }

            //-------------------------------------------------------------------------
            // rotate around x, y, z, axis with specified degree.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::rotate(float x_rot, float y_rot, float z_rot)
            {
                m_x_rotation = x_rot;
                m_y_rotation = y_rot;
                m_z_rotation = z_rot;

                
            // Builds a matrix with a specified yaw, pitch, and roll.
                D3DXMatrixRotationYawPitchRoll(&m_mat_rotation, m_y_rotation, m_x_rotation, m_z_rotation);
            }

            //-------------------------------------------------------------------------
            // rotate around x, y, z, axis which relative to cuurent x, y, z angle.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::rotate_rel(float x_add, float y_add, float z_add)
            {
                rotate(m_x_rotation + x_add, m_y_rotation + y_add, m_z_rotation + z_add);
            }

            //-------------------------------------------------------------------------
            // Build scaling matrix.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::scale(float x_scale, float y_scale, float z_scale)
            {
                m_x_scale = x_scale;
                m_y_scale = y_scale;
                m_z_scale = z_scale;

                D3DXMatrixScaling(&m_mat_scale, x_scale, y_scale, z_scale);
            }

            //-------------------------------------------------------------------------
            // Build scaling matrix with specified value and current scaling value.
            //-------------------------------------------------------------------------
            void WORLD_POSITION::scale_rel(float x_add, float y_add, float z_add)
            {
                scale(m_x_scale + x_add, m_y_scale + y_add, m_z_scale + z_add);
            }

            //-------------------------------------------------------------------------
            // Get current position's x coordinate.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_x_pos()
            {
                
            return m_x_pos;
            }

            //-------------------------------------------------------------------------
            // Get current position's y coordinate.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_y_pos()
            {
                
            return m_y_pos;
            }

            //-------------------------------------------------------------------------
            // Get current position's z coordinate.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_z_pos()
            {
                
            return m_z_pos;
            }

            //-------------------------------------------------------------------------
            // Get current rotation value which rotate around x axis.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_x_rotation()
            {
                
            return m_x_rotation;
            }

            //-------------------------------------------------------------------------
            // Get current rotation value which rotate around y axis.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_y_rotation()
            {
                
            return m_y_rotation;
            }

            //-------------------------------------------------------------------------
            // Get current rotation value which rotate around z axis.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_z_rotation()
            {
                
            return m_z_rotation;
            }

            //-------------------------------------------------------------------------
            // Get current scale value which around x axis.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_x_scale()
            {
                
            return m_x_scale;
            }

            //-------------------------------------------------------------------------
            // Get current scale value which around y axis.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_y_scale()
            {
                
            return m_y_scale;
            }

            //-------------------------------------------------------------------------
            // Get current scale value which around z axis.
            //-------------------------------------------------------------------------
            float WORLD_POSITION::get_z_scale()
            {
                
            return m_z_scale;
            }

            posted on 2007-10-06 17:57 lovedday 閱讀(325) 評論(0)  編輯 收藏 引用

            公告

            導航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評論

            久久免费视频观看| 午夜精品久久久久9999高清| 99久久免费只有精品国产| 久久亚洲国产精品一区二区| 久久最近最新中文字幕大全| 国产成人无码精品久久久免费| 一级女性全黄久久生活片免费 | 久久久久久久久无码精品亚洲日韩| 国产欧美久久久精品| 久久性精品| 久久精品国产免费| 欧美亚洲另类久久综合婷婷| 人妻精品久久久久中文字幕69| 久久精品夜色噜噜亚洲A∨| 国内精品久久久久影院日本 | 久久久久亚洲AV无码专区网站| 精产国品久久一二三产区区别| 色综合久久综精品| 久久国产精品无| 亚洲国产精品久久久久久| 久久久久久国产精品美女 | 亚洲中文久久精品无码ww16| 丰满少妇人妻久久久久久4| 久久精品无码午夜福利理论片 | 久久精品国产亚洲网站| 东方aⅴ免费观看久久av| 久久久久久噜噜精品免费直播| 国产精品久久免费| 国产亚洲综合久久系列| 伊人久久综合精品无码AV专区| 久久久久免费视频| 99久久精品无码一区二区毛片| 国产精品欧美久久久天天影视 | 欧美久久综合性欧美| 久久99国内精品自在现线| 亚洲成色WWW久久网站| 久久无码人妻一区二区三区午夜| 欧美成人免费观看久久| 亚洲国产精品一区二区三区久久| 久久久久无码精品国产app| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 |