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

            天行健 君子當(dāng)自強(qiáng)而不息

            Putting Together a Full Game(13)

             

            Dealing with Maps

            The sample game is divided into five maps (scenes). Each scene uses six bitmaps,
            each of which is loaded as textures that are drawn to the display for each frame.
            The game also uses an underlying simplified mesh for each scene. These simplified
            meshes aid in properly drawing the 3D characters that inhabit each scene.

            A total of four functions are contained within the application class that is used
            to work with scenes. These functions are load_level, free_level, get_height_below, and
            check_intersect. You use the get_height_below and check_intersect functions, which are
            presented in Chapter 12, to check for mesh-to-mesh intersections. In the case of
            the game, those mesh intersections are used to determine when characters intersect
            with the simplified scene mesh.

            float cApp::get_height_below(float x_pos, float y_pos, float z_pos)
            {
                
            // only one mesh in mesh level
                return closest_height_below(m_scene_mesh.get_root_mesh()->m_d3d_mesh, x_pos, y_pos, z_pos);
            }

            bool  cApp::check_intersect(float x_start, float y_start, float z_start,
                                        
            float x_end, float y_end, float z_end,
                                        
            float* dist)
            {
                
            // only one mesh in mesh level
                return is_ray_intersect_mesh(m_scene_mesh.get_root_mesh()->m_d3d_mesh,
                                             x_start, y_start, z_start,
                                             x_end, y_end, z_end,
                                             dist);
            }

            The load_level function loads the six scene textures and the simplified mesh and
            executes the script associated with loading the scene. An external file, which you
            see in just a moment, stores the position of the camera within each scene. Here is
            the code for load_level:

            bool cApp::load_level(int scene_index)
            {
                m_scene_index = scene_index;

                free_level();

                
            // load the backdrop textures

                
            char filename[MAX_PATH];

                
            for(int i = 0; i < 6; i++)
                {
                    sprintf(filename, "..\\Data\\Scene%u%u.bmp", scene_index, i+1);
                            
                    
            if(! load_texture_from_file(&m_scene_backdrops[i], filename, 0, D3DFMT_UNKNOWN))
                        
            return false;
                }

                
            // load the scene mesh and configure object

                sprintf(filename, "..\\Data\\Scene%u.x", scene_index);

                
            if(! m_scene_mesh.load(filename, "..\\Data"))
                    
            return FALSE;

                m_scene_object.create(&m_scene_mesh);

                
            // load the camera data

                sprintf(filename, "..\\Data\\Cam%u.txt", scene_index);

                FILE* fp = fopen(filename, "rb");

                
            if(fp == NULL)
                    
            return false;

                
            float x_pos = get_next_float_2(fp);
                
            float y_pos = get_next_float_2(fp);
                
            float z_pos = get_next_float_2(fp);
                
            float x_at  = get_next_float_2(fp);
                
            float y_at  = get_next_float_2(fp);
                
            float z_at  = get_next_float_2(fp);

                fclose(fp);

                m_camera.point(x_pos, y_pos, z_pos, x_at, y_at, z_at);
                set_display_camera(&m_camera);

                m_is_monster_last_frame = 
            false;

                
            // load script and execute it
                sprintf(filename, "..\\Data\\Scene%lu.mls", scene_index);
                m_game_script.execute(filename);

                
            return true;
            }

            After you load the scene’s mesh and create the scene’s object, you are ready to
            determine the placement of the camera used to render the 3-D graphics. You place
            the camera in each scene by first creating a text file for each scene. Name these
            files cam1.txt, cam2.txt, cam3.txt, cam4.txt, and cam5.txt—each named according
            to its respective scene number (scenes being numbered 1 through 5).

            Place a scene’s camera by opening the appropriate text file and reading in six numbers,
            each of which is used to determine the camera’s orientation in the scene. The
            first three numbers represent the position of the camera in the world, and the last
            three numbers are the coordinates to which the camera is pointed.

            After you load the six numbers and orient the camera, call the set_display_camera
            function to inform Direct3D of the new view transformation being used by the camera.

            After you position the camera in the file, the class clears a flag that determines
            whether monsters are currently in the scene (for combat processing) and then
            executes the script associated with the scene.

            There's not much to do in load_level as you can see. The free_level function is rather
            trouble-free as well. It frees the scene’s textures and simplified mesh, removes every
            character from the character controller (except for the player, that is), and clears
            all spells currently being processed. Here is the complete free_level function code:

            void cApp::free_level()
            {
                
            for(int i = 0; i < 6; i++)
                    release_com(m_scene_backdrops[i]);

                m_scene_mesh.free();
                m_barrier.free();
                m_trigger.free();
                m_game_spells.free();

                
            // free all non-pc characters

                sCharacter* next_char;

                
            for(sCharacter* char_ptr = m_game_chars.get_root_char(); char_ptr != NULL; char_ptr = next_char)
                {
                    next_char = char_ptr->next;

                    
            if(char_ptr->type != CHAR_PC)
                        m_game_chars.remove_char(char_ptr);
                }
            }


            posted on 2007-12-29 23:22 lovedday 閱讀(252) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(178)

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

            搜索

            最新評(píng)論

            亚洲精品无码成人片久久| 久久福利青草精品资源站免费| 久久狠狠一本精品综合网| 久久久久久国产精品无码下载 | 狠狠色婷婷久久综合频道日韩| 久久精品国产清自在天天线| 国内精品久久久久影院免费| 少妇久久久久久被弄到高潮| 久久久久亚洲精品天堂| 久久久受www免费人成| 91精品国产色综合久久| 久久综合视频网| 国产精品久久久久一区二区三区| 国产精品乱码久久久久久软件| 国产精品久久精品| 97久久婷婷五月综合色d啪蜜芽 | 国产一区二区精品久久岳| 奇米影视7777久久精品人人爽| 久久中文字幕一区二区| 久久午夜无码鲁丝片| 日韩欧美亚洲国产精品字幕久久久| A狠狠久久蜜臀婷色中文网| 一本久久精品一区二区| 久久综合九色综合久99| 亚洲AV无码久久精品蜜桃| 亚洲国产成人久久一区久久| 久久国产高清字幕中文| 精品熟女少妇av免费久久| 久久人人爽人人人人片av| 亚洲婷婷国产精品电影人久久 | 午夜精品久久久久久久无码| 99久久无码一区人妻| 久久福利青草精品资源站免费| 精品免费久久久久久久| 亚洲精品乱码久久久久久按摩 | 久久国产精品成人影院| 伊人久久大香线蕉av一区| 中文成人无码精品久久久不卡| 久久最新免费视频| 久久人人添人人爽添人人片牛牛| 无码人妻久久一区二区三区蜜桃|