Exemplo n.º 1
0
void TranslateTriangle( triangle *thisTriangle, float x, float y, float z ) {

    int i;

    for( i=0; i<3; i++ ) {
        thisTriangle->vertices[3*i] += x;
        thisTriangle->vertices[3*i + 1] += y;
        thisTriangle->vertices[3*i + 2] += z;
    }
    TranslatePlane(thisTriangle->PNor, thisTriangle->vertices[0], thisTriangle->vertices[1], thisTriangle->vertices[2]);
}
Exemplo n.º 2
0
// HuntForWorld will never return CONTENTS_SKY or CONTENTS_SOLID leafs
dleaf_t*        HuntForWorld(vec_t* point, const vec_t* plane_offset, const dplane_t* plane, int hunt_size, vec_t hunt_scale, vec_t hunt_offset)
{
    dleaf_t*        leaf;
    int             x, y, z;
    int             a;

    vec3_t          current_point;
    vec3_t          original_point;

    vec3_t          best_point;
    dleaf_t*        best_leaf = NULL;
    vec_t           best_dist = 99999999.0;

    vec3_t          scales;

    dplane_t        new_plane = *plane;

    if (hunt_scale < 0.1)
    {
        hunt_scale = 0.1;
    }

    scales[0] = 0.0;
    scales[1] = -hunt_scale;
    scales[2] = hunt_scale;

    VectorCopy(point, best_point);
    VectorCopy(point, original_point);

    TranslatePlane(&new_plane, plane_offset);

    if (!hunt_size)
    {
        hunt_size = DEFAULT_HUNT_SIZE;
    }

    for (a = 1; a < hunt_size; a++)
    {
        for (x = 0; x < 3; x++)
        {
            current_point[0] = original_point[0] + (scales[x % 3] * a);
            for (y = 0; y < 3; y++)
            {
                current_point[1] = original_point[1] + (scales[y % 3] * a);
                for (z = 0; z < 3; z++)
                {
                    vec3_t          delta;
                    vec_t           dist;

                    current_point[2] = original_point[2] + (scales[z % 3] * a);
                    SnapToPlane(&new_plane, current_point, hunt_offset);
                    VectorSubtract(current_point, original_point, delta);
                    dist = VectorLength(delta);

                    if (dist < best_dist)
                    {
                        if ((leaf = PointInLeaf(current_point)) != g_dleafs)
                        {
                            if ((leaf->contents != CONTENTS_SKY) && (leaf->contents != CONTENTS_SOLID))
                            {
                                if (x || y || z)
                                {
                                    //dist = best_dist;
                                    best_leaf = leaf;
                                    VectorCopy(current_point, best_point);
                                    continue;
                                }
                                else
                                {
                                    VectorCopy(current_point, point);
                                    return leaf;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (best_leaf)
        {
            break;
        }
    }

    VectorCopy(best_point, point);
    return best_leaf;
}