青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

Working with Maps and Levels(4)

Creating a Trigger Class

Adhering to object-oriented programming techniques, create a class that will handle
a list of triggers and determine which (if any) has been touched by a character. The
class uses a structure to store the information of each trigger—the coordinates, type,
and so on. Each trigger is also assigned an identification number that it uses to refer
back to itself. The entire list is maintained as a linked list of structure.

The cTrigger class can load and save a trigger file, which makes editing lists of triggers
easier. This file is text-based, making it easier to read and edit. Each trigger
in the map uses a single line of text written in this order: an identification number,
the type of trigger (0=sphere, 1=box, 2=cylinder, 3=triangle), and the default enabled
status (if the trigger is enabled when loaded). A value of 0 means that the trigger
is disabled, and a value of 1 means that the trigger is enabled.

Depending on the type of trigger you are defining, the trigger must include a few
more values. Spheres require the X-, Y-, and Z-coordinates and the radius, as shown
in the following:

ID 0 ENABLED X Y Z RADIUS

Boxes have the coordinates of the opposing corners:

ID 1 ENABLED X1 Y1 Z1 X2 Y2 Z2

You define cylinders by the lower-center coordinates plus the radius and height:

ID 2 ENABLED X Y Z RADIUS HEIGHT

Finally, you define triangles by the X- and Z-coordinates of the three corners, in a
clockwise order, as seen from above the triangle on the Y-axis (much as a polygon
face is defined in Chapter 6, “Drawing with DirectX Graphics”). The Y-coordinate for
all three points of the triangle and the height of the trigger round out this definition:

ID 3 ENABLED X1 Z1 X2 Z2 X3 Z3 Y HEIGHT

I’ll get back to the trigger data file in a moment. For now, take a look at the class
definition of the trigger class. The class starts
out with an enum list that defines each type of trigger shape that you can use:

enum TriggerTypes { TRIGGER_SPHERE = 0, TRIGGER_BOX, TRIGGER_CYLINDER, TRIGGER_TRIANGLE };

Each trigger you define requires a structure that contains the information pertinent
to the trigger—the trigger’s location, enabled state, and unique identification
number. Each type of trigger uses a set of coordinates to define its location on the
map, as well as additional data to define the trigger’s radius, opposing corner coordinates,
and so on. The structure that contains the information about each trigger
created is as follows:

typedef struct sTrigger
{
    
long type;  // TRIGGER_SPHERE, TRIGGER_BOX, etc.
    long id;
    
bool enabled;

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

    sTrigger* prev;
    sTrigger* next;

    ///////////////////////////////////////////////////////////
   sTrigger() { prev = next = NULL; }
  ~sTrigger() { delete next; next = NULL; }
} *sTriggerPtr;

Notice that the sTrigger structure maintains a set of linked list pointers, as well as a
constructor and a destructor that clear the linked list pointers and free the linked
list, respectively.

In order to utilize the sTrigger structure, you use the trigger class, which manages
the linked list of triggers and enables you to save and load lists of those triggers.
Take a look at the trigger class declaration:

typedef class cTrigger
{
private:
    
long        m_num_triggers;
    sTrigger*   m_root_trigger;

    
////////////////////////////////////////////////////////////////////////////
public:
    cTrigger()
    {
        m_num_triggers = 0;
        m_root_trigger = NULL;
    }

    ~cTrigger()
    {
        free();
    }

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

        m_num_triggers = 0;
    }

    
long get_num_triggers()
    {
        
return m_num_triggers;
    }

    sTrigger* get_root_trigger()
    {
        
return m_root_trigger;
    }

    
void enable(long id)
    {
        set_enable_state(id, 
true);
    }

    
void disable(long id)
    {
        set_enable_state(id, 
false);
    }

    
void add_sphere(long id, bool enabled,
                    
float x_pos, float y_pos, float z_pos,
                    
float radius)
    {
        sTrigger* trigger = add_trigger(TRIGGER_SPHERE, id, enabled);
    
        trigger->x1 = x_pos;
        trigger->y1 = y_pos;
        trigger->z1 = z_pos;
        trigger->radius = radius * radius;
    }

    
void add_box(long id, bool enabled,
                 
float x_min, float y_min, float z_min,
                 
float x_max, float y_max, float z_max)
    {
        sTrigger* trigger = add_trigger(TRIGGER_BOX, id, enabled);

        
// setup trigger data (fix for min/max radius)
        trigger->x1 = min(x_min, x_max);
        trigger->y1 = min(y_min, y_max);
        trigger->z1 = min(z_min, z_max);
        trigger->x2 = max(x_min, x_max);
        trigger->y2 = max(y_min, y_max);
        trigger->z2 = max(z_min, z_max);
    }

    
void add_cylinder(long id, bool enabled,
                      
float x_pos, float y_pos, float z_pos,
                      
float radius, float height)
    {
        sTrigger* trigger = add_trigger(TRIGGER_CYLINDER, id, enabled);

        trigger->x1     = x_pos;
        trigger->y1     = y_pos;
        trigger->z1     = z_pos;
        trigger->radius = radius * radius;
        trigger->y2     = height;
    }

    
void add_triangle(long id, bool enabled,
                      
float x1, float z1,
                      
float x2, float z2,
                      
float x3, float z3,
                      
float y_pos, float height)
    {
        sTrigger* trigger = add_trigger(TRIGGER_TRIANGLE, id, enabled);
        
        trigger->x1 = x1;
        trigger->z1 = z1;
        trigger->x2 = x2;
        trigger->z2 = z2;
        trigger->x3 = x3;
        trigger->z3 = z3;
        trigger->y1 = y_pos;
        trigger->y2 = height;
    }

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

private:
    sTrigger* add_trigger(
long type, long id, bool enabled)
    {
        
// allocate a new trigger structure and link in

        sTrigger* trigger = 
new sTrigger;

        trigger->prev = NULL;
        trigger->next = m_root_trigger;

        
if(m_root_trigger)
            m_root_trigger->prev = trigger;

        m_root_trigger = trigger;

        trigger->type    = type;
        trigger->id      = id;
        trigger->enabled = enabled;

        m_num_triggers++;

        
return trigger;
    }

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

public:
    
bool load(const char* filename);
    
bool save(const char* filename);

    
void remove(long id);
    
long get_trigger(float x_pos, float y_pos, float z_pos);
    
bool get_enable_state(long id);    

private:     
    
void  set_enable_state(long id, bool state);
} *cTriggerPtr;

Most of the functions deal with only a linked list of sTrigger structures—add a structure,
remove a structure, find a structure and modify it, and so on. For a closer
look at what’s going on, take a minute or two to review the following sections,
which provide the code for each function.

posted on 2007-12-09 15:39 lovedday 閱讀(222) 評論(0)  編輯 收藏 引用

公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美一区二区三区的| 亚洲一区网站| 久久欧美肥婆一二区| 一本色道久久加勒比88综合| 欧美午夜精彩| 欧美一区2区三区4区公司二百| 午夜精品美女自拍福到在线| 国产日韩欧美| 开心色5月久久精品| 免费日韩视频| 亚洲一区二区三区四区中文| 亚洲一区二区三区四区中文| 国产亚洲午夜| 最新国产成人av网站网址麻豆 | 亚洲狼人精品一区二区三区| 欧美日韩精品久久久| 午夜久久资源| 久久五月激情| 亚洲午夜一二三区视频| 欧美一区二区久久久| 91久久久久久久久| 亚洲一级二级| 亚洲精品亚洲人成人网| 亚洲一区二区三区四区中文 | 欧美日韩国产色站一区二区三区| 亚洲天堂av高清| 久久久久国内| 亚洲欧美制服另类日韩| 久久亚洲高清| 欧美一区二区三区四区在线| 模特精品裸拍一区| 久久国产精品免费一区| 欧美激情在线观看| 久久偷窥视频| 国产精品爽黄69| 亚洲高清av| 一区二区在线视频观看| 亚洲免费小视频| 在线亚洲伦理| 欧美国产激情| 老色批av在线精品| 国产午夜亚洲精品不卡| 亚洲视频大全| 一本色道久久88综合亚洲精品ⅰ| 久久久久久久久久久久久久一区| 午夜精品久久久久久久白皮肤 | 亚洲免费人成在线视频观看| 99国产精品久久久| 欧美3dxxxxhd| 欧美jizz19性欧美| 一区二区在线免费观看| 欧美一区二区视频在线观看2020 | 在线视频你懂得一区| 久久综合综合久久综合| 久久人人九九| 黑人一区二区| 欧美在线视频网站| 亚洲欧美制服中文字幕| 国产精品国产a| 在线综合亚洲欧美在线视频| 一本一道久久综合狠狠老精东影业 | 亚洲综合欧美| 国产精品扒开腿爽爽爽视频| 99日韩精品| 中文日韩在线视频| 欧美日韩国产综合视频在线观看中文 | 亚洲一二三四区| 欧美日韩一本到| 亚洲美女诱惑| 在线亚洲观看| 国产精品乱码一区二区三区| 夜夜嗨av一区二区三区网站四季av | 欧美本精品男人aⅴ天堂| 韩国三级电影一区二区| 久久野战av| 最新国产成人在线观看| 亚洲午夜一级| 国产精品一区二区久久国产| 亚洲毛片网站| 中文欧美日韩| 欧美日韩一区二| 亚洲精品日韩精品| 亚洲午夜精品一区二区| 国产精品久久久亚洲一区| 欧美在线免费播放| 亚洲国产另类久久久精品极度| 亚洲国产日韩一级| 欧美精品电影在线| 中文一区在线| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲激情啪啪| 国产精品免费小视频| 久久精品一区二区三区不卡| 亚洲福利视频三区| 亚洲欧美日韩网| 影音先锋久久久| 欧美久久视频| 久久激情综合网| 欧美激情欧美激情在线五月| 一本色道久久综合亚洲精品按摩 | 久久久久久久成人| 日韩一级免费观看| 另类春色校园亚洲| 一本大道久久a久久精二百| 国产视频一区欧美| 欧美国产亚洲另类动漫| 午夜视频在线观看一区二区| 亚洲国产视频一区二区| 久久精品欧洲| 亚洲私人黄色宅男| 最新中文字幕一区二区三区| 国产精品私人影院| 欧美日韩视频第一区| 久久这里只精品最新地址| 亚洲影视在线播放| 日韩午夜在线观看视频| 老鸭窝毛片一区二区三区| 亚洲欧美日韩综合国产aⅴ| 亚洲激情一区二区三区| 狠狠网亚洲精品| 国产精品日韩专区| 欧美日韩亚洲综合在线| 久久亚洲影院| 欧美一级淫片aaaaaaa视频| 亚洲精品日韩欧美| 亚洲第一主播视频| 美日韩精品视频| 欧美一区二区三区久久精品茉莉花 | 亚洲精品国产精品国自产观看浪潮 | 先锋影音国产精品| 一区二区三区**美女毛片| 亚洲国产精品福利| 免费成人高清| 久久久免费精品| 欧美在线免费| 欧美伊人久久| 午夜视频一区二区| 亚洲深夜激情| 9国产精品视频| 亚洲精品免费网站| 亚洲激情在线激情| 日韩网站在线观看| 亚洲免费高清| 亚洲视频一二区| 亚洲午夜激情网页| 国产精品99久久久久久有的能看| 日韩亚洲一区二区| 亚洲午夜精品网| 亚洲午夜免费视频| 午夜欧美大片免费观看| 亚洲免费视频观看| 欧美一级视频精品观看| 欧美一区二区三区久久精品茉莉花| 亚洲欧美激情视频在线观看一区二区三区 | 欧美日韩激情小视频| 欧美日韩综合另类| 国产麻豆午夜三级精品| 国内精品国产成人| 亚洲第一区在线| 一本在线高清不卡dvd | 国产精品毛片a∨一区二区三区|国| 欧美激情久久久久| 欧美乱妇高清无乱码| 国产精品福利av| 国产伦精品一区二区三区视频黑人| 国产一区二区丝袜高跟鞋图片| 亚洲电影成人| 亚洲视频一区在线观看| 久久精品国产77777蜜臀| 免费看亚洲片| 99成人在线| 欧美中文字幕| 欧美麻豆久久久久久中文| 国产欧美va欧美va香蕉在| 亚洲国产岛国毛片在线| 亚洲欧美日韩区| 欧美成人一区二免费视频软件| 亚洲美女电影在线| 久久福利毛片| 欧美午夜精品久久久久久人妖| 激情视频亚洲| 亚洲一区二区成人在线观看| 久久亚洲二区| 亚洲永久网站| 欧美精品导航| 亚洲国产精品传媒在线观看 | 久久国产精品99国产| 亚洲清纯自拍| 久久野战av| 国产一区二区三区免费不卡 | 国产农村妇女精品一区二区| 最新日韩精品| 免费观看30秒视频久久| 中文成人激情娱乐网| 欧美成人精精品一区二区频| 国产亚洲一级高清| 欧美在线免费视屏| 亚洲手机成人高清视频| 欧美连裤袜在线视频| 亚洲福利专区|