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

            天行健 君子當自強而不息

            Working with Maps and Levels(13)

            Creating the Auto Map Class

            The auto map class I've developed for the book will load a cMesh object and compress
            it into a flat version of the map. The flattened map is stored in a series of vertex
            buffers. These vertex buffers use only the X-, Y-, and Z-coordinates of each
            vertex plus a single diffuse color. This means that auto maps are compact and easy
            to render. This also means that you can use alpha blending to overlay the map on
            the screen without covering the crucial gaming action going on.

            Each map section has an associated flag that defines whether it is visible. The class
            allows you to enable or disable those visibility flags, and to make sure that the
            player’s hard work is not in vain, save and load those visibility flags.

            Enough talk; now check out the class declaration:

            //-------------------------------------------------------------------------------------------
            // The sVertex structure is a custom vertex structure than contains only the 3D coordinates.
            // This is used to retrieve coordinate information from a mesh's vertex buffer.
            //-------------------------------------------------------------------------------------------
            typedef struct sVertex
            {
                float x, y, z;
            } *sVertexPtr;

            typedef struct sMapVertex
            {
                
            float x, y, z;      // coordinate
                D3DCOLOR diffuse;   // map color
            } *sMapVertexPtr;

            #define AUTO_MAP_FVF    (D3DFVF_XYZ | D3DFVF_DIFFUSE)

            /********************************************************************************************/

            typedef 
            class cAutoMap
            {
            private:
                
            long    m_num_sections;
                
            bool*   m_visible;                          // visibility of sections
                DIRECT3DVERTEXBUFFER9_PTR*  m_map_vb;       // map vertex buffer array

                IDirect3DVertexBuffer9*     m_arrow_vb;     

                D3DVIEWPORT9                m_viewport;     
            // area to draw map
                cCamera                     m_camera;       

                
            float                       m_scale;        // scale used to draw map

                
            //////////////////////////////////////////////////////////////////////////////

            public:
                cAutoMap()
                {
                    m_num_sections  = 0;
                    m_visible      = NULL;
                    m_map_vb       = NULL;
                    m_arrow_vb     = NULL;
                    
                    m_camera.rotate(1.57f, 0.0f, 0.0f); 
            // point camera down
                    set_viewport(0, 0, 100, 100);

                    m_scale = 1.0f;
                }

                ~cAutoMap()
                {
                    free();
                }

                
            void free()
                {
                    
            if(m_map_vb)
                    {
                        
            for(long i = 0; i < m_num_sections; i++)
                            release_com(m_map_vb[i]);

                        delete[] m_map_vb;
                        m_map_vb = NULL;           
                    }

                    m_num_sections = 0;

                    delete[] m_visible;
                    m_visible = NULL;

                    release_com(m_arrow_vb);
                }

                
            long get_num_section()
                {
                    
            return m_num_sections;
                }

                
            void set_viewport(long x_pos, long y_pos, long width, long height)
                {
                    
            // define an area to draw the map

                    m_viewport.X      = x_pos;
                    m_viewport.Y      = y_pos;
                    m_viewport.Width  = width;
                    m_viewport.Height = height;
                    m_viewport.MinZ   = 0.0f;
                    m_viewport.MaxZ   = 1.0f;
                }

                
            void visible_section(long section)
                {
                    
            // enable a map section's visibility flag

                    m_visible[section] = 
            true;
                }
                
                
            void invisible_section(long section)
                {
                    
            // disable a map section's visibility flag

                    m_visible[section] = 
            false;
                }

                
            //////////////////////////////////////////////////////////////////////////////

            public:
                
            bool create(pcstr filename, long color);

                
            bool load(pcstr filename);
                
            bool save(pcstr filename);
                
                
            void render(cCamera* old_camera,
                            
            float map_x_pos, float map_y_pos, float map_z_pos,
                            
            float num_arrows,
                            
            float* arrow_x_pos, float* arrow_z_pos, float* angle);
            } *cAutoMapPtr;


            From the start, you can see that I’ve defined two vertex structures. You use the first,
            sVertex, to access the vertex coordinates from the source meshes. You use the
            second vertex structure, sMapVertex, to store the map sections.

            Following the vertex structures are a collage of variables. Notice the number of map sections in use, an array of vertex
            buffers, an array of char variables used to mark sections of the map that are visible,
            a viewport structure, a cCamera, a scaling factor variable, and a pointer vertex buffer.

            You should be comfortable with everything except the pointer vertex buffer and the
            scaling factor. To make things easier on you, a map being loaded is scaled down to a
            workable size. When you render the auto map, you need to specify coordinates from
            the large map scale, but the auto map class will scale them down to fit the small map.

            For example, a map that is 1,024 units in width and depth is scaled down to 256
            units in width and depth. In fact, all maps are scaled down to a size of 256 x 256,
            regardless of their size in the .X file.

            As for the pointer vertex buffer, I’ve added the capability to display an arrow
            pointer that represents each character on the map. The arrow pointer points in the
            direction each character is facing. This vertex buffer simply contains three points
            and is rendered using a red diffuse color.

            In addition to the class’s private variables, you must deal with the functions.

            posted on 2007-12-10 15:31 lovedday 閱讀(202) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            7国产欧美日韩综合天堂中文久久久久| 国产成人久久久精品二区三区 | 2019久久久高清456| 久久精品国产一区| 久久精品国产亚洲av麻豆图片| 国产韩国精品一区二区三区久久| 久久精品亚洲男人的天堂| jizzjizz国产精品久久| 亚洲精品乱码久久久久久按摩 | 夜夜亚洲天天久久| 久久久噜噜噜久久中文字幕色伊伊| 久久久久亚洲AV片无码下载蜜桃| 香蕉aa三级久久毛片| 久久久久一本毛久久久| 久久久久九国产精品| 久久久久高潮毛片免费全部播放 | 99久久久精品免费观看国产| 久久亚洲2019中文字幕| 99久久国产免费福利| 亚洲AV日韩精品久久久久久久| 久久精品综合一区二区三区| 久久精品国产第一区二区三区| 国产精品久久久久蜜芽| 色婷婷狠狠久久综合五月| 久久国产精品久久久| 久久97精品久久久久久久不卡| 无码人妻少妇久久中文字幕蜜桃| 亚洲欧美国产日韩综合久久| 久久国产亚洲精品| 欧美黑人激情性久久| 色综合色天天久久婷婷基地| 精品熟女少妇aⅴ免费久久| 久久青青草原精品国产不卡| 国产精品VIDEOSSEX久久发布| 婷婷久久香蕉五月综合加勒比| 少妇久久久久久被弄高潮| 精品人妻伦九区久久AAA片69| 久久99久国产麻精品66| 中文字幕无码免费久久| 久久AⅤ人妻少妇嫩草影院| 久久99精品国产麻豆不卡|