示例#1
0
文件: world.cpp 项目: zot/CubeCreate
bool getentboundingbox(extentity &e, ivec &o, ivec &r)
{
    switch(e.type)
    {
        case ET_EMPTY:
            return false;
        case ET_MAPMODEL:
        {
            LogicEntityPtr entity = LogicSystem::getLogicEntity(e); // INTENSITY
            model *m = entity.get() ? entity->getModel() : NULL; // INTENSITY
            if(m)
            {
                vec center, radius;
                m->boundbox(0, center, radius, entity.get()); // INTENSITY: entity
                rotatebb(center, radius, e.attr1);
                o = e.o;
                o.add(center);
                r = radius;
                r.add(1);
                o.sub(r);
                r.mul(2);
                break;
            }
        }
        // invisible mapmodels use entselradius
        default:
            o = e.o;
            o.sub(GETIV(entselradius));
            r.x = r.y = r.z = GETIV(entselradius)*2;
            break;
    }
    return true;
}
示例#2
0
static inline void decalboundbox(const entity &e, DecalSlot &s, vec &center, vec &radius)
{
    float size = max(float(e.attr5), 1.0f);
    center = vec(0, s.depth * size/2, 0);
    radius = vec(size/2, s.depth * size/2, size/2);
    rotatebb(center, radius, e.attr2, e.attr3, e.attr4);
}
示例#3
0
vec& CLogicEntity::getAttachmentPosition(const char *tag)
{
    // If last actual render - which actually calculated the attachment positions - was recent
    // enough, use that data
    vec *pos = (vec*)attachment_positions.access(tag);
    if (pos) {
        if ((lastmillis - *((int*)(pos + 1))) < 500) return *pos;
    }
    static vec missing; // Returned if no such tag, or no recent attachment position info. Note: Only one of these, static!
    if (getType() == LE_DYNAMIC) {
        missing = dynamicEntity->o;
    } else {
        if (staticEntity->type == ET_MAPMODEL) {
            vec center, radius;
            if (staticEntity->m) {
                staticEntity->m->collisionbox(center, radius);
                if (staticEntity->attr[3] > 0) {
                    float scale = staticEntity->attr[3] / 100.0f;
                    center.mul(scale); radius.mul(scale);
                }
                rotatebb(center, radius, staticEntity->attr[0], staticEntity->attr[1], staticEntity->attr[2]);
                center.add(staticEntity->o);
                missing = center;
            } else missing = staticEntity->o;
        } else {
            missing = staticEntity->o;
        }
    }
    return missing;
}
示例#4
0
bool getentboundingbox(extentity &e, ivec &o, ivec &r)
{
    switch(e.type)
    {
        case ET_EMPTY:
            return false;
        case ET_MAPMODEL:
        {
            model *m = loadmodel(NULL, e.attr[1]);
            if(m)
            {
                vec center, radius;
                m->boundbox(center, radius);
                rotatebb(center, radius, e.attr[0]);

                o = e.o;
                o.add(center);
                r = radius;
                r.add(1);
                o.sub(r);
                r.mul(2);
                break;
            }
        }
        // invisible mapmodels use entselradius
        default:
            o = e.o;
            o.sub(entselradius);
            r.x = r.y = r.z = entselradius*2;
            break;
    }
    return true;
}
示例#5
0
static inline void transformbb(const entity &e,vec &center, vec &radius)
{
    if(e.attr[3] > 0) {
        float scale = e.attr[3]/100.0f;
        center.mul(scale);
        radius.mul(scale);
    }
    rotatebb(center, radius, e.attr[0], e.attr[1], e.attr[2]);
}
示例#6
0
static inline void mmcollisionbox(const entity &e, model *m, vec &center, vec &radius)
{
    m->collisionbox(center, radius);
    if(e.attrs[5])
    {
       float scale = max(e.attrs[5]/100.0f, 1e-3f);
       center.mul(scale);
       radius.mul(scale);
    }
    rotatebb(center, radius, e.attrs[1], e.attrs[2], e.attrs[3]);
}
示例#7
0
bool getentboundingbox(const extentity &e, ivec &o, ivec &r)
{
    switch(e.type)
    {
        case ET_EMPTY:
            return false;
        case ET_DECAL:
            {
                DecalSlot &s = lookupdecalslot(e.attr[0], false);
                vec center, radius;
                decalboundbox(e, s, center, radius);
                center.add(e.o);
                radius.max(entselradius);
                o = vec(center).sub(radius);
                r = vec(center).add(radius).add(1);
                break;
            }
        case ET_MAPMODEL:
            if(model *m = entities::getmodel(e))
            {
                vec center, radius;
                mmboundbox(e, m, center, radius);
                center.add(e.o);
                radius.max(entselradius);
                o = vec(center).sub(radius);
                r = vec(center).add(radius).add(1);
                break;
            }
        case ET_OBSTACLE: /* OF */
        {
            int a = e.attr[3], b = e.attr[4], c = e.attr[5];
            if (!a || !b || !c) {
                o = vec(e.o).sub(entselradius);
                r = vec(e.o).add(entselradius+1);
                break;
            }
            vec center = vec(0, 0, 0), radius = vec(a, b, c);
            rotatebb(center, radius, e.attr[0], e.attr[1], e.attr[2]);
            center.add(e.o);
            radius.max(entselradius);
            o = vec(center).sub(radius);
            r = vec(center).add(radius).add(1);
            break;
        }
        // invisible mapmodels use entselradius
        default:
            o = vec(e.o).sub(entselradius);
            r = vec(e.o).add(entselradius+1);
            break;
    }
    return true;
}
示例#8
0
static inline void transformbb(const entity &e, vec &center, vec &radius)
{
    if(e.attr5 > 0) { float scale = e.attr5/100.0f; center.mul(scale); radius.mul(scale); }
    rotatebb(center, radius, e.attr2, e.attr3, e.attr4);
}
示例#9
0
static inline void mmcollisionbox(const entity &e, model *m, vec &center, vec &radius)
{
    m->collisionbox(center, radius);
    rotatebb(center, radius, e.attr1);
}
示例#10
0
static inline void mmboundbox(const entity &e, model *m, vec &center, vec &radius)
{
    m->boundbox(center, radius);
    rotatebb(center, radius, e.attr1);
}
示例#11
0
void rendermodel(vec &color, vec &dir, const char *mdl, int anim, int varseed, int tex, float x, float y, float z, float yaw, float pitch, float speed, int basetime, dynent *d, int cull, const char *vwepmdl)
{
    model *m = loadmodel(mdl); 
    if(!m) return;
    if(cull)
    {
        vec center;
        float radius = m->boundsphere(0/*frame*/, center);   // FIXME
        center.add(vec(x, y, z));
        if((cull&MDL_CULL_DIST) && center.dist(camera1->o)/radius>maxmodelradiusdistance) return;
        if(cull&MDL_CULL_VFC)
        {
            if(refracting)
            {
                if(center.z+radius<refracting-waterfog || center.z-radius>=refracting) return;
            }
            else if(reflecting && center.z+radius<=reflecting) return;
            if((reflecting || refracting) && center.dist(camera1->o)-radius>reflectdist) return;
            if(isvisiblesphere(radius, center) >= VFC_FOGGED) return;
        };
        if((cull&MDL_CULL_OCCLUDED) && modeloccluded(center, radius)) return;
    };
    if(showboundingbox)
    {
        if(d) render3dbox(d->o, d->eyeheight, d->aboveeye, d->radius);
        else if((anim&ANIM_INDEX)!=ANIM_GUNSHOOT && (anim&ANIM_INDEX)!=ANIM_GUNIDLE)
        {
            vec center, radius;
            if(showboundingbox==1) m->collisionbox(0, center, radius);
            else m->boundbox(0, center, radius);
            rotatebb(center, radius, int(yaw));
            center.add(vec(x, y, z));
            render3dbox(center, radius.z, radius.z, radius.x, radius.y);
        };
    };

    if(d) lightreaching(d->o, color, dir);
    m->setskin(tex);  
    glColor3fv(color.v);
    m->setshader();
    if(renderpath!=R_FIXEDFUNCTION)
    {
        vec rdir(dir);
        rdir.rotate_around_z((-yaw-180.0f)*RAD);
        rdir.rotate_around_y(-pitch*RAD);
        glProgramEnvParameter4f_(GL_VERTEX_PROGRAM_ARB, 0, rdir.x, rdir.y, rdir.z, 0);

        vec camerapos = vec(player->o).sub(vec(x, y, z));
        camerapos.rotate_around_z((-yaw-180.0f)*RAD);
        camerapos.rotate_around_y(-pitch*RAD);
        glProgramEnvParameter4f_(GL_VERTEX_PROGRAM_ARB, 1, camerapos.x, camerapos.y, camerapos.z, 1);

        if(refracting) setfogplane(1, refracting - z);
    };

    model *vwep = NULL;
    if(vwepmdl)
    {
        vwep = loadmodel(vwepmdl);
        if(vwep->type()!=m->type()) vwep = NULL;
    };

    if(!m->cullface) glDisable(GL_CULL_FACE);
    m->render(anim, varseed, speed, basetime, x, y, z, yaw, pitch, d, vwep);
    if(!m->cullface) glEnable(GL_CULL_FACE);
};