Example #1
0
/** \brief reads mesh definition.
  *
  * The read num_normals value is positive when normals are available and negative when light
  * values are available. The values get set appropiatly.
  */
void TR_Level::read_tr_mesh(SDL_RWops * const src, tr4_mesh_t & mesh)
{
    int i;

    read_tr_vertex16(src, mesh.centre);
    mesh.collision_size = read_bit16(src);
    mesh.flags = read_bitu8(src);
    mesh.dummy = read_bitu8(src);

    mesh.num_vertices = read_bit16(src);
    mesh.vertices = (tr5_vertex_t*)malloc(mesh.num_vertices * sizeof(tr5_vertex_t));
    for (i = 0; i < mesh.num_vertices; i++)
        read_tr_vertex16(src, mesh.vertices[i]);

    mesh.num_normals = read_bit16(src);
    if (mesh.num_normals >= 0) {
        mesh.num_lights = 0;
        mesh.normals = (tr5_vertex_t*)malloc(mesh.num_normals * sizeof(tr5_vertex_t));
        for (i = 0; i < mesh.num_normals; i++)
            read_tr_vertex16(src, mesh.normals[i]);
    } else {
        mesh.num_lights = -mesh.num_normals;
        mesh.num_normals = 0;
        mesh.lights = (int16_t*)malloc(mesh.num_lights * sizeof(int16_t));
        for (i = 0; i < mesh.num_lights; i++)
            mesh.lights[i] = read_bit16(src);
    }

    mesh.num_textured_rectangles = read_bit16(src);
    mesh.textured_rectangles = (tr4_face4_t*)malloc(mesh.num_textured_rectangles * sizeof(tr4_face4_t));
    for (i = 0; i < mesh.num_textured_rectangles; i++)
        read_tr_face4(src, mesh.textured_rectangles[i]);

    mesh.num_textured_triangles = read_bit16(src);
    mesh.textured_triangles = (tr4_face3_t*)malloc(mesh.num_textured_triangles * sizeof(tr4_face3_t));
    for (i = 0; i < mesh.num_textured_triangles; i++)
        read_tr_face3(src, mesh.textured_triangles[i]);

    mesh.num_coloured_rectangles = read_bit16(src);
    mesh.coloured_rectangles = (tr4_face4_t*)malloc(mesh.num_coloured_rectangles * sizeof(tr4_face4_t));
    for (i = 0; i < mesh.num_coloured_rectangles; i++)
        read_tr_face4(src, mesh.coloured_rectangles[i]);

    mesh.num_coloured_triangles = read_bit16(src);
    mesh.coloured_triangles = (tr4_face3_t*)malloc(mesh.num_coloured_triangles * sizeof(tr4_face3_t));
    for (i = 0; i < mesh.num_coloured_triangles; i++)
        read_tr_face3(src, mesh.coloured_triangles[i]);
}
Example #2
0
/** \brief reads a room portal definition.
  *
  * A check is preformed to see wether the normal lies on a coordinate axis, if not an exception gets thrown.
  */
void TR_Level::read_tr_room_portal(SDL_RWops * const src, tr_room_portal_t & portal)
{
    portal.adjoining_room = read_bitu16(src);
    read_tr_vertex16(src, portal.normal);
    read_tr_vertex16(src, portal.vertices[0]);
    read_tr_vertex16(src, portal.vertices[1]);
    read_tr_vertex16(src, portal.vertices[2]);
    read_tr_vertex16(src, portal.vertices[3]);
    if ((portal.normal.x == 1.0f) && (portal.normal.y == 0.0f) && (portal.normal.z == 0.0f))
        return;
    if ((portal.normal.x == -1.0f) && (portal.normal.y == 0.0f) && (portal.normal.z == 0.0f))
        return;
    if ((portal.normal.x == 0.0f) && (portal.normal.y == 1.0f) && (portal.normal.z == 0.0f))
        return;
    if ((portal.normal.x == 0.0f) && (portal.normal.y == -1.0f) && (portal.normal.z == 0.0f))
        return;
    if ((portal.normal.x == 0.0f) && (portal.normal.y == 0.0f) && (portal.normal.z == 1.0f))
        return;
    if ((portal.normal.x == 0.0f) && (portal.normal.y == 0.0f) && (portal.normal.z == -1.0f))
        return;
        Sys_extWarn("read_tr_room_portal: normal not on world axis");
}
Example #3
0
void TR_Level::read_tr3_room_vertex(SDL_RWops * const src, tr5_room_vertex_t & room_vertex)
{
	read_tr_vertex16(src, room_vertex.vertex);
	// read and make consistent
	room_vertex.lighting1 = read_bit16(src);
	room_vertex.attributes = read_bitu16(src);
	room_vertex.lighting2 = read_bit16(src);
	// only in TR5
	room_vertex.normal.x = 0;
	room_vertex.normal.y = 0;
	room_vertex.normal.z = 0;
	room_vertex.colour.r = room_vertex.lighting1 / 32767.0f;
	room_vertex.colour.g = room_vertex.lighting1 / 32767.0f;
	room_vertex.colour.b = room_vertex.lighting1 / 32767.0f;
	room_vertex.colour.a = 255;
}
Example #4
0
/** \brief reads a room vertex definition.
  *
  * lighting1 gets converted, so it matches the 0-32768 range introduced in TR3.
  * lighting2 is introduced in TR2 and is set to lighting1 for TR1.
  * attributes is introduced in TR2 and is set 0 for TR1.
  * All other values are introduced in TR5 and get set to appropiate values.
  */
void TR_Level::read_tr_room_vertex(SDL_RWops * const src, tr5_room_vertex_t & room_vertex)
{
    read_tr_vertex16(src, room_vertex.vertex);
    // read and make consistent
    room_vertex.lighting1 = (8191 - read_bit16(src)) << 2;
    // only in TR2
    room_vertex.lighting2 = room_vertex.lighting1;
    room_vertex.attributes = 0;
    // only in TR5
    room_vertex.normal.x = 0;
    room_vertex.normal.y = 0;
    room_vertex.normal.z = 0;
    room_vertex.colour.r = room_vertex.lighting1 / 32768.0f;
    room_vertex.colour.g = room_vertex.lighting1 / 32768.0f;
    room_vertex.colour.b = room_vertex.lighting1 / 32768.0f;
    room_vertex.colour.a = 1.0f;
}
Example #5
0
void TR_Level::read_tr3_room_vertex(SDL_RWops *const src, tr5_room_vertex_t & room_vertex)
{
    read_tr_vertex16(src, room_vertex.vertex);
    // read and make consistent
    room_vertex.lighting1 = read_bit16(src);
    room_vertex.attributes = read_bitu16(src);
    room_vertex.lighting2 = read_bit16(src);
    // only in TR5
    room_vertex.normal.x = 0;
    room_vertex.normal.y = 0;
    room_vertex.normal.z = 0;

    room_vertex.colour.r = ((room_vertex.lighting2 & 0x7C00) >> 10  ) / 62.0f;
    room_vertex.colour.g = ((room_vertex.lighting2 & 0x03E0) >> 5   ) / 62.0f;
    room_vertex.colour.b = ((room_vertex.lighting2 & 0x001F)        ) / 62.0f;
    room_vertex.colour.a = 1.0f;
}
Example #6
0
/** \brief reads a room vertex definition.
  *
  * lighting1 gets converted, so it matches the 0-32768 range introduced in TR3.
  * lighting2 is introduced in TR2 and is set to lighting1 for TR1.
  * attributes is introduced in TR2 and is set 0 for TR1.
  * All other values are introduced in TR5 and get set to appropiate values.
  */
void TR_Level::read_tr_room_vertex(SDL_RWops * const src, tr5_room_vertex_t & room_vertex)
{
    read_tr_vertex16(src, room_vertex.vertex);
    // read and make consistent
    float data = read_bitu16(src);
    data = data < 0.0f || data > 8191.0f ? 0.0f : data;
    
    room_vertex.lighting1 = (8191 - data);
    
    
    // only in TR2
    room_vertex.lighting2 = room_vertex.lighting1;
    room_vertex.attributes = 0;
    // only in TR5
    room_vertex.normal.x = 0;
    room_vertex.normal.y = 0;
    room_vertex.normal.z = 0;
    room_vertex.colour.r = room_vertex.lighting1 / 8191.0f;
    room_vertex.colour.g = room_vertex.lighting1 / 8191.0f;
    room_vertex.colour.b = room_vertex.lighting1 / 8191.0f;
    room_vertex.colour.a = 1.0f;
}