aboutsummaryrefslogtreecommitdiff
path: root/src/model.c
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-18 23:58:59 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-18 23:58:59 +0000
commit723f4a5e4693afbf5654bd830e78db13df9020ca (patch)
tree854684a756a40da1e939a782f1510d497518b60d /src/model.c
parent6741901029cd322a4abf61a91ac34afabf9b093a (diff)
More environment mapping stuff
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@28 84d2e878-0bd5-11dd-ad15-13eda11d74c5
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");