• <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)而不息

            Working with Maps and Levels(9)

            Blocking the Path with Barriers

            You know—detecting when your character is walking around the map bumping into walls or standing
            on solid ground. What about objects such as doors blocking your character’s way?
            Because a door is not part of the terrain, I didn’t include a door when I constructed
            the collision detection code. Now is the time to remedy that situation.

            Anything that bars clear passage of a character’s movement is called a barrier.
            Barriers can exist in two states—open (disabled) or closed (enabled). Characters
            are allowed to pass through a barrier when it is open, but they cannot pass through
            when the barrier is closed.

            You can treat barriers much as you do triggers. You can define a barrier similar to
            the way you define a trigger on a map. You can define barriers as spheres, boxes,
            cylinders, and triangles. Barriers can also have an enabled state, with true meaning
            that the barrier is blocking the character’s passage and false meaning that the way
            through the barrier is clear.

            The big difference between barriers and triggers is that barriers can have meshes
            and animation assigned to them. This relieves you of the burden of drawing the
            barrier and gives the job to the barrier engine. All you have to do is assign the
            meshes and animations.

            You start off using barriers with the barrier class declaration,
            which looks very similar to the trigger class declaration. Notice that I also
            define an enum list and structure (sBarrier) used to contain each barrier’s data:

            enum BarrierType
            {
                BARRIER_SPHERE = 0, BARRIER_BOX, BARRIER_CYLINDER, BARRIER_TRIANGLE
            };

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

            typedef 
            struct sBarrier
            {
                
            long    type;  // BARRIER_SPHERE, BARRIER_BOX, etc.
                long    id;
                
            bool    enabled;

                
            float   x_pos, y_pos, z_pos;
                
            float   x_rot, y_rot, z_rot;

                
            float   x1, y1, z1;
                
            float   x2, y2, z2;
                
            float   x3, z3;

                
            float   radius;

                cObject 
            object;

                sBarrier*   prev;
                sBarrier*   next;

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

                sBarrier()  
                { 
                    prev = next = NULL; 
                }

                ~sBarrier() 
                { 
                    delete next; next = NULL;  
                }
            } *sBarrierPtr;

            Here’s where the similarities between the triggers and barrier end. A barrier needs
            a graphical representation (a 3-D mesh), so the code adds a Graphics
            Core cObject object that is used to contain the barrier’s mesh and animation data.

            Getting back to the similarities of the trigger and barrier classes, notice the pointers
            that maintain the linked list as well as the sBarrier structure constructor and
            destructor.

            The similarities between triggers and barrier continue with the declaration of the
            barrier class:

            typedef class cBarrier
            {
            private:
                
            long        m_num_barriers;
                sBarrier*   m_root_barrier;

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

            public:
                cBarrier()
                {
                    m_num_barriers = 0;
                    m_root_barrier = NULL;
                }
                
                ~cBarrier()
                {
                    free();
                }

                
            void free()
                {
                    delete m_root_barrier;
                    m_root_barrier = NULL;

                    m_num_barriers = 0;
                }

                
            long get_num_barriers()
                {
                    
            return m_num_barriers;
                }

                sBarrier* get_root_barrier()
                {
                    
            return m_root_barrier;
                }
             

            Shift your focus for a moment to the arguments that the add_barrier function is taking.
            Aside from the position in which to position the barrier (using the x_pos, y_pos,
            and z_pos arguments), the add_barrier function takes the rotational values in which to
            draw the barrier’s mesh (using the x_rot, y_rot, and z_rot arguments that represent the
            X-, Y-, and Z-rotational values, in radians, respectively).

            Notice that the addition of rotational values throughout the barrier class, as well as
            the addition of an extra trio of coordinates that define the mesh’s position in the
            world. As you come upon these additional values, I’ll be sure to point them out.

                sBarrier* add_barrier(long type, long id, bool enabled,
                                      
            float x_pos, float y_pos, float z_pos,
                                      
            float x_rot, float y_rot, float z_rot)
                {
                    
            // allocate a new barrier structure and link in

                    sBarrier* bar = 
            new sBarrier;

                    bar->prev = NULL;
                    bar->next = m_root_barrier;

                    
            if(m_root_barrier)
                        m_root_barrier->prev = bar;

                    m_root_barrier = bar;

                    bar->type    = type;
                    bar->id      = id;
                    bar->enabled = enabled;
                    bar->x_pos   = x_pos;
                    bar->y_pos   = y_pos;
                    bar->z_pos   = z_pos;
                    bar->x_rot   = x_rot;
                    bar->y_rot   = y_rot;
                    bar->z_rot   = z_rot;

                    m_num_barriers++;

                    
            return bar;
                }  

            posted on 2007-12-10 13:50 lovedday 閱讀(185) 評(píng)論(0)  編輯 收藏 引用


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


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(lèi)(178)

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

            搜索

            最新評(píng)論

            武侠古典久久婷婷狼人伊人| 亚洲国产精品一区二区久久| 亚洲国产精品狼友中文久久久 | 国产精品久久久久久久| 久久精品欧美日韩精品| 久久精品国产亚洲麻豆| 香蕉aa三级久久毛片| 波多野结衣中文字幕久久| 国产精品女同一区二区久久| 亚洲午夜久久久久妓女影院| 伊人久久大香线蕉精品| 狠狠综合久久综合88亚洲| 国产精品伦理久久久久久| 亚洲国产精品无码久久一区二区| 秋霞久久国产精品电影院| 亚洲AV日韩精品久久久久久 | 9久久9久久精品| 久久综合视频网| 久久久精品视频免费观看| 亚洲成色WWW久久网站| 久久精品中文字幕一区| 国产精品视频久久| 久久人人爽人人爽人人AV | 99久久无色码中文字幕人妻| 97精品伊人久久久大香线蕉 | 久久丫精品国产亚洲av| 热综合一本伊人久久精品| 久久综合狠狠综合久久激情 | 人妻精品久久久久中文字幕69| 亚洲伊人久久成综合人影院| 精品国产热久久久福利| 99久久精品这里只有精品| 99久久99这里只有免费费精品| 久久综合九色综合网站| 亚洲国产精品久久久天堂 | 亚洲欧洲日产国码无码久久99| 婷婷久久精品国产| 久久精品亚洲男人的天堂| 久久久久国产亚洲AV麻豆| 久久青青草原精品国产不卡| 久久亚洲中文字幕精品一区四|