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

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

Working with Maps and Levels(10)

Continue now with the cBarrier class declaration:

When you need to assign a mesh to a barrier, use the set_mesh function, passing the
barrier’s identification number to set, as well as cMesh objects to use.
For setting an animation for a barrier, you pass the barrier’s
identification number, cAnimation object, the name of the animation to use, and the
time the animation is set (using a timer function such as timeGetTime).

You need to assign meshes and animations.
Each barrier has a dedicated cObject to use for orientation, but first a mesh must be
assigned via the set_mesh function. Animations are sure to follow using the set_anim
function. Take a look at each of the functions responsible for setting those meshes
and animations.

After you've loaded or created barriers, assign the meshes by their respective barrier
identification numbers. Notice that the set_anim function is just like the
cObject::set_anim_set function—you have the name of the animation and the starting
time of the animation.

Both functions simply scan through the linked list of barriers looking for a matching
identification number.

    void set_mesh(long id, cMesh* mesh)
    {
        
for(sBarrier* bar = m_root_barrier; bar != NULL; bar = bar->next)
        {
            
if(bar->id == id)            
                bar->
object.create(mesh);
        }
    }

    
void set_anim(long id, cAnimation* anim, pcstr name, long start_time)
    {
        
for(sBarrier* bar = m_root_barrier; bar != NULL; bar = bar->next)
        {
            
if(bar->id == id)            
                bar->
object.set_anim_set(anim, name, start_time);            
        }
    }

After you assign a mesh and animation, you can render a barrier to the display using
the following render function. The render function takes as arguments the current
time to update the animations (again using timeGetTime) and the viewing frustum to
use for clipping out the barriers that are out of the viewpoint.

The only other exclusive function in cBarrier (as opposed to cTrigger) is Render,
which takes a time value that is used to update the barriers’ animations and a viewing
frustum that is used to clip out unseen barrier objects. Take a look at the render
function code:

void cBarrier::render(ulong time_now, cFrustum* frustum)
{
    
for(sBarrier* bar = m_root_barrier; bar != NULL; bar = bar->next)
    {
        cObject* 
object = &bar->object;

        
float radius;
        
object->get_bounds(NULL, NULL, NULL, NULL, NULL, NULL, &radius);

        
if(frustum->is_sphere_in(bar->x_pos, bar->y_pos, bar->z_pos, radius))
        {
            
object->move(bar->x_pos, bar->y_pos, bar->z_pos);
            
object->rotate(bar->x_rot, bar->y_rot, bar->z_rot);

            
object->update_anim(time_now, true);
            
object->render();
        }
    }
}

In the preceding render function, the linked list of barriers is scanned, and for each
barrier, a frustum check is performed. If a barrier is in the view, its respective animation
is updated and the mesh is rendered.

When it comes time to start adding barriers to the linked list, the cBarrier class
comes packed with as many functions to do so as cTrigger.
 

public:

    
void add_sphere(long id, bool enabled,
                    
float x_pos,  float y_pos,  float z_pos,
                    
float x_rot,  float y_rot,  float z_rot,
                    
float cx_pos, float cy_pos, float cz_pos,
                    
float radius)
    {
        sBarrier* bar = add_barrier(BARRIER_SPHERE, id, enabled, x_pos, y_pos, z_pos, x_rot, y_rot, z_rot);

        bar->x1     = cx_pos;
        bar->y1     = cy_pos;
        bar->z1     = cz_pos;
        bar->radius = radius * radius;
    }

    
void add_box(long id, bool enabled,
                 
float x_pos,  float y_pos,  float z_pos,
                 
float x_rot,  float y_rot,  float z_rot,
                 
float x_min,  float y_min,  float z_min,
                 
float x_max,  float y_max,  float z_max)
    {
        sBarrier* bar = add_barrier(BARRIER_SPHERE, id, enabled, x_pos, y_pos, z_pos, x_rot, y_rot, z_rot);

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

    
void add_cylinder(long id, bool enabled,
                      
float x_pos,  float y_pos,  float z_pos,
                      
float x_rot,  float y_rot,  float z_rot,
                      
float cx_pos, float cy_pos, float cz_pos,
                      
float radius, float height)
    {
        sBarrier* bar = add_barrier(BARRIER_SPHERE, id, enabled, x_pos, y_pos, z_pos, x_rot, y_rot, z_rot);

        bar->x1     = cx_pos;
        bar->y1     = cy_pos;
        bar->z1     = cz_pos;
        bar->radius = radius * radius;
        bar->y2     = height;
    }

    
void add_triangle(long id, bool enabled,
                      
float x_pos,  float y_pos,  float z_pos,
                      
float x_rot,  float y_rot,  float z_rot,
                      
float x1, float z1,
                      
float x2, float z2,
                      
float x3, float z3,
                      
float cy_pos, float height)
    {
        sBarrier* bar = add_barrier(BARRIER_SPHERE, id, enabled, x_pos, y_pos, z_pos, x_rot, y_rot, z_rot);

        bar->x1 = x1;
        bar->z1 = z1;
        bar->x2 = x2;
        bar->z2 = z2;
        bar->x3 = x3;
        bar->z3 = z3;
        bar->y1 = cy_pos;
        bar->y2 = height;
    }   

    
void remove(long id)
    {
        sBarrier* bar = m_root_barrier;

        
while(bar != NULL)
        {
            sBarrier* next_bar = bar->next;

            
if(bar->id == id)
            {
                
// remove from list

                
if(bar->prev)
                    bar->prev->next = bar->next;
                
else
                    m_root_barrier = bar->next;

                
if(bar->next)
                    bar->next->prev = bar->prev;

                bar->next = NULL;
                delete bar;

                m_num_barriers--;
            }

            bar = next_bar;
        }
    }

    
bool get_enable_state(long id)
    {
        
for(sBarrier* bar = m_root_barrier; bar != NULL; bar = bar->next)
        {
            
if(bar->id == id)
                
return bar->enabled;
        }

        
return false;
    }

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

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

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

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

    
void render(ulong time_now, cFrustum* frustum);
    
long get_barrier(float x_pos, float y_pos, float z_pos);    
} *cBarrierPtr;


Other function:

bool cBarrier::load(const char* filename)
{
    free();     
// remove all current barriers

    FILE* fp = fopen(filename, "rb");
    
if(fp == NULL)
        
return false;

    
// start looping, reading in until EOF reached.
    for(;;)
    {
        
long id = get_next_long_2(fp);
        
if(id == -1)
            
break;

        
long type    = get_next_long_2(fp);
        
bool enabled = get_next_long_2(fp) ? true : false;   

        
// get coordinate and rotation
        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_rot = get_next_float_2(fp);
        
float y_rot = get_next_float_2(fp);
        
float z_rot = get_next_float_2(fp);

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

        
// read in rest depending on type
        switch(type)
        {
        
case BARRIER_SPHERE:
            x1     = get_next_float_2(fp);
            y1     = get_next_float_2(fp);
            z1     = get_next_float_2(fp);
            radius = get_next_float_2(fp);

            add_sphere(id, enabled, 
                       x_pos, y_pos, z_pos, x_rot, y_rot, z_rot, 
                       x1, y1, z1, radius);
            
break;

        
case BARRIER_BOX:
            x1 = get_next_float_2(fp);
            y1 = get_next_float_2(fp);
            z1 = get_next_float_2(fp);
            x2 = get_next_float_2(fp);
            y2 = get_next_float_2(fp);
            z2 = get_next_float_2(fp);

            add_box(id, enabled, 
                    x_pos, y_pos, z_pos, x_rot, y_rot, z_rot,
                    x1, y1, z1, x2, y2, z2);

            
break;

        
case BARRIER_CYLINDER:
            x1     = get_next_float_2(fp);
            y1     = get_next_float_2(fp);
            z1     = get_next_float_2(fp);
            radius = get_next_float_2(fp);
            y2     = get_next_float_2(fp);

            add_cylinder(id, enabled, 
                         x_pos, y_pos, z_pos, x_rot, y_rot, z_rot,
                         x1, y1, z1, radius, y2);

            
break;

        
case BARRIER_TRIANGLE:
            x1 = get_next_float_2(fp);
            z1 = get_next_float_2(fp);
            x2 = get_next_float_2(fp);
            z2 = get_next_float_2(fp);
            x3 = get_next_float_2(fp);
            z3 = get_next_float_2(fp);
            y1 = get_next_float_2(fp);
            y2 = get_next_float_2(fp);

            add_triangle(id, enabled, 
                         x_pos, y_pos, z_pos, x_rot, y_rot, z_rot,
                         x1, z1, x2, z2, x3, z3, y1, y2);

            
break;
    
        
default:    // some error occurred
            fclose(fp);
            free();
            
return false;
        }
    }

    fclose(fp);
    
return true;
}

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

bool cBarrier::save(const char* filename)
{
    
if(m_num_barriers == 0)
        
return false;

    FILE* fp = fopen(filename, "wb");
    
if(fp == NULL)
        
return false;

    
for(sBarrier* bar = m_root_barrier; bar != NULL; bar = bar->next)
    {
        
int enabled = bar->enabled ? 1 : 0;

        
char buf[1024];

        sprintf(buf, "%lu %lu %lu %lf %lf %lf %lf %lf %lf",
                bar->id, bar->type, enabled,
                bar->x_pos, bar->y_pos, bar->z_pos,
                bar->x_rot, bar->y_rot, bar->z_rot);

        
// write out remaining data depending on type
        switch(bar->type)
        {
        
case BARRIER_SPHERE:
            fprintf(fp, "%s %lf %lf %lf %lf\r\n",
                    buf, bar->x1, bar->y1, bar->z1, bar->radius);

            
break;

        
case BARRIER_BOX:
            fprintf(fp, "%s %lf %lf %lf %lf %lf %lf\r\n",
                    buf, bar->x1, bar->y1, bar->z1, bar->x2, bar->y2, bar->z2);

            
break;

        
case BARRIER_CYLINDER:
            fprintf(fp, "%s %lf %lf %lf %lf %lf\r\n",
                    buf, bar->x1, bar->y1, bar->z1, bar->radius, bar->y2);

            
break;

        
case BARRIER_TRIANGLE:
            fprintf(fp, "%s %lf %lf %lf %lf %lf %lf %lf %lf\r\n",
                    buf,
                    bar->x1, bar->z1, bar->x2, bar->z2, bar->x3, bar->z3,
                    bar->y1, bar->y2);

            
break;
        }
    }

    fclose(fp);
    
return true;
}

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

long cBarrier::get_barrier(float x_pos, float y_pos, float z_pos)
{
    D3DXVECTOR2 norm_vec;

    
for(sBarrier* bar = m_root_barrier; bar != NULL; bar = bar->next)
    {
        
// only bother if enabled
        if(! bar->enabled)
            
continue;

        
float x_diff, y_diff, z_diff, dist;

        
switch(bar->type)
        {
        
case BARRIER_SPHERE:
            
// check distance from sphere
            x_diff = fabs(bar->x1 - x_pos);
            y_diff = fabs(bar->y1 - y_pos);
            z_diff = fabs(bar->z1 - z_pos);

            dist = x_diff * x_diff + y_diff * y_diff + z_diff * z_diff;

            
if(dist <= bar->radius)
                
return bar->id;
            
            
break;

        
case BARRIER_BOX:
            
// check if inside box
            if((x_pos >= bar->x1 && x_pos <= bar->x2) &&
               (y_pos >= bar->y1 && y_pos <= bar->y2) &&
               (z_pos >= bar->z1 && z_pos <= bar->z2))
            {
                
return bar->id;
            }

            
break;

        
case BARRIER_CYLINDER:
            
// first make sure within height bounds
            if(y_pos >= bar->y1 && y_pos <= bar->y1 + bar->y2)
            {
                
// check distance from cylinder
                x_diff = fabs(bar->x1 - x_pos);
                y_diff = fabs(bar->y1 - y_pos);
                z_diff = fabs(bar->z1 - z_pos);

                dist = x_diff * x_diff + y_diff * y_diff + z_diff * z_diff;

                
if(dist <= bar->radius)
                    
return bar->id;
            }

            
break;

        
case BARRIER_TRIANGLE:
            
// first make sure within height bounds
            if(y_pos >= bar->y1 && y_pos <= bar->y1 + bar->y2)
            {
                
// check if point in front of all lines

                // x1,z1 to x2,z2
                D3DXVec2Normalize(&norm_vec, &D3DXVECTOR2(bar->z2 - bar->z1, bar->x1 - bar->x2));

                
if(D3DXVec2Dot(&D3DXVECTOR2(x_pos - bar->x1, z_pos - bar->z1), &norm_vec) < 0)
                    
break;

                
// x2,z2 to x3,z3
                D3DXVec2Normalize(&norm_vec, &D3DXVECTOR2(bar->z3 - bar->z2, bar->x2 - bar->x3));

                
if(D3DXVec2Dot(&D3DXVECTOR2(x_pos - bar->x2, z_pos - bar->z2), &norm_vec) < 0)
                    
break;

                
// x3,z3 to x1,z1
                D3DXVec2Normalize(&norm_vec, &D3DXVECTOR2(bar->z1 - bar->z3, bar->x3 - bar->x1));

                
if(D3DXVec2Dot(&D3DXVECTOR2(x_pos - bar->x3, z_pos - bar->z3), &norm_vec) < 0)
                    
break;

                
return bar->id;
            }   

            
break;
        }
    }

    
return 0;   // means no barrier found
}

posted on 2007-12-10 14:11 lovedday 閱讀(263) 評論(0)  編輯 收藏 引用


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


公告

導(dǎo)航

統(tǒng)計

常用鏈接

隨筆分類(178)

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

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一本色道久久| 欧美人与禽猛交乱配| 亚洲黄色小视频| 一区二区三区视频免费在线观看| 亚洲一区三区电影在线观看| 久久久久久久久久久久久女国产乱 | 久久午夜视频| 篠田优中文在线播放第一区| 美女脱光内衣内裤视频久久影院| 欧美一区二区免费观在线| 欧美大片一区二区三区| 久久久久久97三级| 国产精品久久久99| 亚洲激情视频在线播放| 久久gogo国模裸体人体| 亚洲尤物在线| 国内精品久久久| 亚洲视频在线一区观看| 一区二区欧美亚洲| 奶水喷射视频一区| 欧美xx视频| 国产综合在线看| 欧美另类综合| 久久大逼视频| 久久亚洲欧美国产精品乐播| 国产精品揄拍一区二区| 一本久久知道综合久久| 久久久久久伊人| 狠狠入ady亚洲精品| 久久爱www久久做| 99国产精品久久久久久久久久| 亚洲精品1区2区| 久久成人久久爱| 日韩一级黄色av| 亚洲主播在线| 亚洲国产一区二区视频| 国产欧美午夜| 久久精品国产亚洲aⅴ| 9人人澡人人爽人人精品| 久久综合久久综合久久| 亚洲一区二区三区视频| 国产欧美日韩精品一区| 欧美精品一区二区三区一线天视频 | 一区二区三区日韩欧美精品| 一区二区三区在线观看国产| 麻豆91精品| 欧美专区日韩专区| 亚洲桃色在线一区| 91久久久久久国产精品| 美女91精品| 亚洲小少妇裸体bbw| 最新日韩在线| 亚洲电影观看| 欧美日韩国产一区二区三区地区 | 91久久精品日日躁夜夜躁国产| 国产欧美日韩精品a在线观看| 欧美日韩一区免费| 亚洲欧美日韩第一区| 久久久www成人免费精品| 亚洲主播在线观看| 宅男噜噜噜66一区二区66| 亚洲国产人成综合网站| 在线观看欧美视频| 欧美日本免费一区二区三区| 欧美 日韩 国产 一区| 美女图片一区二区| 老司机67194精品线观看| 一本色道久久综合亚洲精品婷婷| 亚洲国产精品尤物yw在线观看| 亚洲一区二区精品在线| 一区二区三区四区五区在线 | 欧美国产精品一区| 亚洲午夜一区| 亚洲一区二区三区午夜| 亚洲视频免费在线| 国产一区二区三区久久悠悠色av| 欧美成人免费va影院高清| 免费观看成人网| 欧美成人乱码一区二区三区| 欧美久色视频| 欧美日韩在线看| 国产精品久久久一本精品| 美女国产一区| 欧美精品在欧美一区二区少妇| 欧美大秀在线观看 | 欧美香蕉视频| 久久深夜福利免费观看| 麻豆久久久9性大片| 裸体一区二区| 欧美日韩免费观看一区=区三区| 欧美日韩国产一级| 国产农村妇女精品一二区| 国产综合视频| 亚洲人成网站777色婷婷| 中文在线不卡| 欧美一区日本一区韩国一区| 麻豆精品精华液| 欧美在线一级va免费观看| 亚洲深夜福利网站| 欧美一区二区三区四区在线观看| 久久精品伊人| 亚洲国产精品激情在线观看| 一本色道88久久加勒比精品| 欧美亚洲视频一区二区| 亚洲一区三区视频在线观看| 9色国产精品| 欧美综合77777色婷婷| 你懂的成人av| 国产精品欧美日韩| 国产精品久久夜| 激情婷婷欧美| 亚洲专区国产精品| 免费在线日韩av| 一本色道久久88精品综合| 欧美在线地址| 欧美日韩视频在线第一区| 国内精品久久久久影院薰衣草| 91久久国产精品91久久性色| 午夜亚洲影视| 亚洲激情第一页| 欧美一区二区福利在线| 欧美人与性动交α欧美精品济南到 | 久久久噜噜噜久久人人看| 亚洲日本欧美日韩高观看| 亚洲高清在线播放| 欧美激情视频在线播放| 欧美~级网站不卡| 亚洲一级黄色av| 欧美成人午夜免费视在线看片| 国产精品揄拍一区二区| 野花国产精品入口| 99在线精品视频在线观看| 久久久久久自在自线| 亚洲视频网在线直播| 亚洲色在线视频| 欧美精品免费在线观看| 欧美日韩亚洲一区二区三区在线 | 经典三级久久| 欧美一区二区三区久久精品茉莉花| 亚洲二区视频| 久久国产精品一区二区三区四区| 国产精品v亚洲精品v日韩精品| 亚洲乱码国产乱码精品精可以看| 亚洲欧洲一区| 女女同性精品视频| 欧美一区二区三区视频| 国产精品理论片在线观看| 一区二区动漫| 最新国产精品拍自在线播放| 免费黄网站欧美| 亚洲第一中文字幕在线观看| 久久久久99精品国产片| 亚洲制服少妇| 老司机午夜精品视频| 黄色成人片子| 久久综合国产精品| 久久精品91久久久久久再现| 国产欧美日韩精品一区| 久久精品国产亚洲5555| 亚洲第一黄色网| 噜噜噜躁狠狠躁狠狠精品视频| 1769国产精品| 欧美成人综合网站| 久热成人在线视频| 亚洲国产电影| 久久福利电影| 欧美伊人精品成人久久综合97 | 最新日韩在线视频| 欧美激情久久久久| 免费欧美网站| 99国产精品久久久久久久| 久久精品国产久精国产爱| 欧美一区二区免费视频| 黄色工厂这里只有精品| 麻豆精品一区二区综合av | 红桃视频欧美| 欧美国产精品劲爆| 欧美福利视频在线| 国精品一区二区三区| 快射av在线播放一区| 裸体女人亚洲精品一区| 99精品欧美一区二区三区| 日韩性生活视频| 国产精品久久久免费| 久久久人成影片一区二区三区| 久久综合99re88久久爱| 日韩午夜激情| 亚洲欧美日韩区| 亚洲国产精品久久久久婷婷884| 亚洲国产精品日韩| 国产精品高潮呻吟久久av无限| 欧美伊人久久久久久久久影院| 久久久国产亚洲精品| 国产日产欧美a一级在线| 蜜桃久久精品一区二区| 欧美日韩欧美一区二区| 久久精品视频免费| 欧美国产日韩在线观看| 亚洲欧美国产va在线影院| 一本久道久久综合婷婷鲸鱼|