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

            天行健 君子當自強而不息

            創建游戲內核(5)【OO改良版】

             

            本篇是創建游戲內核(4)【OO改良版】的續篇,關于該內核的細節說明請參閱創建游戲內核(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;
             

            實現:

            //-------------------------------------------------------------------------
            // 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 閱讀(327) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            日韩精品久久无码人妻中文字幕 | 亚洲综合伊人久久综合| 伊人久久大香线焦AV综合影院| 久久久久久久久无码精品亚洲日韩| 久久久青草青青亚洲国产免观| 亚洲国产精品综合久久网络 | 久久人人爽人人精品视频| 精品国产乱码久久久久久呢| 蜜臀久久99精品久久久久久小说 | 日韩电影久久久被窝网| 久久精品成人免费网站| 热久久最新网站获取| 丁香久久婷婷国产午夜视频| 77777亚洲午夜久久多喷| 久久久久这里只有精品 | 亚洲级αV无码毛片久久精品| 精品久久久久久综合日本| 亚洲欧美伊人久久综合一区二区 | 无码专区久久综合久中文字幕| 久久久久亚洲?V成人无码| 久久九九亚洲精品| 新狼窝色AV性久久久久久| 久久久国产99久久国产一| 久久久久亚洲av毛片大| 久久成人18免费网站| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区| 99久久精品免费看国产一区二区三区 | 久久精品国产99久久久| 亚洲中文字幕无码一久久区| 麻豆久久久9性大片| 伊人久久大香线蕉无码麻豆| 久久久久亚洲精品男人的天堂| 国产福利电影一区二区三区久久久久成人精品综合 | 精品国产乱码久久久久久郑州公司| 久久综合色老色| 久久精品国产久精国产一老狼| 麻豆av久久av盛宴av| 久久久久av无码免费网| 亚洲一级Av无码毛片久久精品| 狠狠色噜噜色狠狠狠综合久久 | 久久人人爽人人爽人人片AV不 |