aboutsummaryrefslogtreecommitdiff
path: root/src/model.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/model.c')
-rw-r--r--src/model.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/model.c b/src/model.c
index bb8758f..5607e95 100644
--- a/src/model.c
+++ b/src/model.c
@@ -73,10 +73,19 @@ static Model *model_new(const char *name) {
}
static Primitive *model_add_primitive(Model *model, GLenum type, GLfloat *vertices, GLfloat *normals, GLfloat *texcoords,
- int n, PrimitiveAttrib attribs, GLfloat r, GLfloat g, GLfloat b, char *texture) {
+ int n, PrimitiveAttrib attribs, GLfloat r, GLfloat g, GLfloat b, char *texture,
+ GLfloat radius, GLfloat shininess) {
Primitive *p;
+ /* Sanity check */
+ if ( type == PRIMITIVE_HEMISPHERE ) {
+ if ( !(attribs & ATTRIB_RADIUS) ) {
+ fprintf(stderr, "Radius must be specified for all hemispheres in model '%s'\n", model->name);
+ return NULL;
+ }
+ }
+
p = malloc(sizeof(Primitive));
if ( p == NULL ) return NULL;
@@ -112,6 +121,8 @@ static Primitive *model_add_primitive(Model *model, GLenum type, GLfloat *vertic
p->col_g = g;
p->col_b = b;
p->texture = texture;
+ p->radius = radius;
+ p->shininess = shininess;
model->attrib_total = model->attrib_total | attribs;
model->primitives = realloc(model->primitives, sizeof(Primitive *) * (model->num_primitives+1));
@@ -162,6 +173,8 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render
GLfloat col_r = 0.0;
GLfloat col_g = 0.0;
GLfloat col_b = 0.0;
+ GLfloat radius = 0.0;
+ GLfloat shininess = 100.0;
PrimitiveAttrib attribs;
char *texture;
@@ -197,7 +210,7 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render
if ( line[0] == '\n' ) {
if ( num_vertices > 0 ) {
model_add_primitive(model, type, vertices, normals, texcoords, num_vertices,
- attribs, col_r, col_g, col_b, texture);
+ attribs, col_r, col_g, col_b, texture, radius, shininess);
num_vertices = 0;
type = PRIMITIVE_TRIANGLES;
attribs = ATTRIB_NONE;
@@ -211,6 +224,9 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render
if ( strncmp(line, "TRIANGLES", 9) == 0 ) {
type = PRIMITIVE_TRIANGLES;
}
+ if ( strncmp(line, "HEMISPHERE", 10) == 0 ) {
+ type = PRIMITIVE_HEMISPHERE;
+ }
if ( sscanf(line, "%f %f %f %f %f", &forget, &forget, &forget, &x, &y) == 5 ) {
texx = x; texy = y;
@@ -246,6 +262,12 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render
attribs = attribs | ATTRIB_COLOUR;
col_r = r; col_g = g; col_b = b;
}
+ if ( sscanf(line, "radius %f", &radius) == 1 ) {
+ attribs = attribs | ATTRIB_RADIUS;
+ }
+ if ( sscanf(line, "shiny %f", &shininess) == 1 ) {
+ attribs = attribs | ATTRIB_SHINY;
+ }
if ( strncmp(line, "texture", 7) == 0 ) {
if ( strlen(line) < 9 ) {
fprintf(stderr, "Invalid texture specification\n");