Ejemplo n.º 1
0
static int create_mesh(int i)
{
    int j;

    if ((j = vecadd(get_object(i)->mv)) >= 0)
    {
        struct object_mesh *m = get_object_mesh(i, j);

        m->fv = vecnew(0, sizeof (struct object_face));
        m->ev = vecnew(0, sizeof (struct object_edge));
    }
    return j;
}
Ejemplo n.º 2
0
void recv_create_object(void)
{
    /* Unpack the object header. */

    int i = new_object();
    int n = recv_index();

    int j, k;

    struct object      *o = get_object(i);
    struct object_mesh *m = NULL;

    o->count = 1;

    /* Unpack the vertices and meshes. */

    o->vv = recv_vector();
    o->mv = vecnew(n, sizeof (struct object_mesh));

    for (j = 0; j < n; ++j)
        if ((k = vecadd(o->mv)) >= 0)
        {
            m = (struct object_mesh *) vecget(o->mv, k);

            m->brush = recv_index();
            m->fv    = recv_vector();
            m->ev    = recv_vector();
        }

    /* Encapsulate this object in an entity. */

    recv_create_entity();
}
Ejemplo n.º 3
0
struct entity_func *startup_sprite(void)
{
    if ((sprite = vecnew(MIN_SPRITES, sizeof (struct sprite))))
        return &sprite_func;
    else
        return NULL;
}
Ejemplo n.º 4
0
struct entity_func *startup_object(void)
{
    if ((object = vecnew(MIN_OBJECTS, sizeof (struct object))))
        return &object_func;
    else
        return NULL;
}
Ejemplo n.º 5
0
struct entity_func *startup_camera(void)
{
    if ((camera = vecnew(MIN_CAMERAS, sizeof (struct camera))))
        return &camera_func;
    else
        return NULL;
}
Ejemplo n.º 6
0
static struct uniform *get_uniform(struct brush *b, const char *n)
{
    struct uniform *u = NULL;

    /* Ensure that the uniform vector exists. */

    if (b->uniform == NULL)
        b->uniform = vecnew(4, sizeof (struct uniform));

    if (b->uniform)
    {
        int i;

        /* Search for an existing uniform of the given name. */

        for (i = 0; i < vecnum(b->uniform); ++i)
            if (!strcmp(((struct uniform *) vecget(b->uniform, i))->name, n))
                return   (struct uniform *) vecget(b->uniform, i);

        /* This uniform does not exist.  Create it. */

        if ((u = (struct uniform *) vecget(b->uniform, vecadd(b->uniform))))
        {
            u->name = memdup(n, 1, strlen(n) + 1);
            u->rows = 0;
            u->cols = 0;
            u->indx = 0;
            u->vals = NULL;
        }
    }
    return u;
}
Ejemplo n.º 7
0
struct entity_func *startup_galaxy(void)
{
    if ((galaxy = vecnew(MIN_GALAXIES, sizeof (struct galaxy))))
        return &galaxy_func;
    else
        return NULL;
}
Ejemplo n.º 8
0
static void RecvProxy_VectorDirtySurround( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
	Vector &vecold = *((Vector*)pOut);
	Vector vecnew( pData->m_Value.m_Vector[0], pData->m_Value.m_Vector[1], pData->m_Value.m_Vector[2] );

	if ( vecold != vecnew )
	{
		vecold = vecnew;
		((CCollisionProperty*)pStruct)->MarkSurroundingBoundsDirty();
	}
}
Ejemplo n.º 9
0
static struct object_mesh *read_usemtl(vector_t mv, const char *line,
                                                    const char *file)
{
    int i;

    if ((i = vecadd(mv)) >= 0)
    {
        struct object_mesh *m = (struct object_mesh *) vecget(mv, i);

        if (line)
            m->brush = send_create_brush(file, parse_name(line));
        else
            m->brush = 0;

        m->fv = vecnew(0, sizeof (struct object_face));
        m->ev = vecnew(0, sizeof (struct object_edge));

        return m;
    }
    return NULL;
}
Ejemplo n.º 10
0
int startup_brush(void)
{
    if ((brush = vecnew(16, sizeof (struct brush))))
    {
        int i;

        /* Create a default brush. */

        if ((i = new_brush()) >= 0)
        {
            struct brush *b = get_brush(i);

            b->count = 1;
            b->state = 0;
            b->flags = BRUSH_DIFFUSE | BRUSH_SPECULAR |
                       BRUSH_AMBIENT | BRUSH_SHINY;

            b->d[0] = BRUSH_DIFFUSE_R;
            b->d[1] = BRUSH_DIFFUSE_G;
            b->d[2] = BRUSH_DIFFUSE_B;
            b->d[3] = BRUSH_DIFFUSE_A;

            b->s[0] = BRUSH_SPECULAR_R;
            b->s[1] = BRUSH_SPECULAR_G;
            b->s[2] = BRUSH_SPECULAR_B;
            b->s[3] = BRUSH_SPECULAR_A;

            b->a[0] = BRUSH_AMBIENT_R;
            b->a[1] = BRUSH_AMBIENT_G;
            b->a[2] = BRUSH_AMBIENT_B;
            b->a[3] = BRUSH_AMBIENT_A;

            b->x[0] = BRUSH_SHININESS;

            b->line_width = 1.0f;

            return 1;
        }
    }
    return 0;
}
Ejemplo n.º 11
0
static int read_obj(const char *filename, struct object *o)
{
    char L[MAXSTR];
    char W[MAXSTR];
    FILE *fin;

    int i, j, n = 0;

    /* Initialize the object element vectors. */

    vector_t vv = o->vv = vecnew(0, sizeof (struct object_vert));
    vector_t mv = o->mv = vecnew(0, sizeof (struct object_mesh));

    if (filename)
    {
        path_push(get_file_path(filename));

        /* Initialize the loader vector caches. */

        _uv = vecnew(1024, sizeof (struct vec2));
        _nv = vecnew(1024, sizeof (struct vec3));
        _vv = vecnew(1024, sizeof (struct vec3));

        uerr = nerr = verr = 0;

        if ((fin = open_file(get_file_name(filename), "r")))
        {
            /* Create a default catch-all group using the default material. */

            struct object_mesh *m = read_usemtl(mv, NULL, NULL);
            const char         *F = NULL;
        
            /* Process each line, invoking the handler for each keyword. */

            while (fgets(L, MAXSTR, fin))
                if (sscanf(L, "%s%n", W, &n) >= 1)
                {
                    char *V = L + n;

                    if      (!strcmp(W, "mtllib")) F = read_mtllib(mv, V);
                    else if (!strcmp(W, "usemtl")) m = read_usemtl(mv, V, F);

                    else if (!strcmp(W, "f"))  read_f(vv, m->fv, V);
                    else if (!strcmp(W, "l"))  read_l(vv, m->ev, V);

                    else if (!strcmp(W, "vt")) read_vt(V);
                    else if (!strcmp(W, "vn")) read_vn(V);
                    else if (!strcmp(W, "v" )) read_v (V);
                }
            
            fclose(fin);
        }
        else error("OBJ file '%s': %s", filename, system_error());

        /* Remove any empty meshes. */

        for (i = 0; i < vecnum(o->mv); )
            if (vecnum(((struct object_mesh *) vecget(o->mv, i))->fv) ||
                vecnum(((struct object_mesh *) vecget(o->mv, i))->ev))
                i++;
            else
            {
                memmove(vecget(o->mv, i),
                        vecget(o->mv, i + 1),
                       (vecnum(o->mv) - i - 1) * sizeof (struct object_mesh));
                vecpop(o->mv);
            }

        /* Compute tangent and bitangent vectors. */

        calc_tbn(o);

        /* Sort meshes such that transparent ones appear last. */

        for (i = 0; i < vecnum(o->mv); ++i)
            for (j = i + 1; j < vecnum(o->mv); ++j)
            {
                struct object_mesh *mi = vecget(o->mv, i);
                struct object_mesh *mj = vecget(o->mv, j);
                struct object_mesh  mt;

                if (get_brush_t(mi->brush) > get_brush_t(mj->brush))
                {
                     mt = *mi;
                    *mi = *mj;
                    *mj =  mt;
                }
            }

        /* Release the loader caches. */

        vecdel(_vv);
        vecdel(_nv);
        vecdel(_uv);

        /* Report index errors. */

        if (uerr > 0)
            error("OBJ file '%s' has %d bad texture indices", filename, uerr);
        if (nerr > 0)
            error("OBJ file '%s' has %d bad normal indices",  filename, nerr);
        if (verr > 0)
            error("OBJ file '%s' has %d bad vertex indices",  filename, verr);

        path_pop();
    }
    return 1;
}