From 4907cd758a8f2d227b76fb82e557487b1197d0be Mon Sep 17 00:00:00 2001 From: Ash Tyndall Date: Fri, 21 Oct 2011 20:35:54 +0800 Subject: [PATCH] --- helper.c | 17 ++++++++--------- scene.c | 19 ++++++++++--------- types.h | 9 +++------ 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/helper.c b/helper.c index bd5f37b..b4dbc9a 100644 --- a/helper.c +++ b/helper.c @@ -298,21 +298,20 @@ int addSceneObject(int id) { curObject = nObjects; - sceneObjs[nObjects].mesh = -1; + sceneObjs[nObjects].mesh = -1; // Teapot is -1 mesh sceneObjs[nObjects].texture = -1; sceneObjs[nObjects].x = 0; sceneObjs[nObjects].y = 0; sceneObjs[nObjects].z = 0; - sceneObjs[nObjects].scale = (vector*)calloc( 3, sizeof(vector[0]) ); + sceneObjs[nObjects].scale[0] = 0; + sceneObjs[nObjects].scale[1] = 0; + sceneObjs[nObjects].scale[2] = 0; - sceneObjs[nObjects].rotation.parameter = 0; - sceneObjs[nObjects].rotation.vect = (vector*)calloc( 3, sizeof(vector[0]) ); - - if ( sceneObjs[nObjects].scale == NULL || sceneObjs[nObjects].rotation.vect == NULL ) { - fprintf(stderr, "Could not allocate memory for Scene Object! Shutting down!\n"); - exit(EXIT_FAILURE); - } + sceneObjs[nObjects].rotation.amount = 0; + sceneObjs[nObjects].rotation.vector[0] = 0; + sceneObjs[nObjects].rotation.vector[1] = 0; + sceneObjs[nObjects].rotation.vector[2] = 0; nObjects += 1; // New object in scene diff --git a/scene.c b/scene.c index b55b491..d794a0f 100644 --- a/scene.c +++ b/scene.c @@ -385,18 +385,18 @@ void display() { drawFloor(); // Draw sceneObjs array - glPushMatrix(); - for ( int i = 0; i < nObjects; i++ ) { + for ( int i = 0; i < nObjects; i++ ) { + glPushMatrix(); SceneObject so = sceneObjs[i]; // Apply rotation vector - vector* rv = so.rotation.vect; + GLfloat* rv = &so.rotation.vector; printf("%f, %f, %f\n", rv[0], rv[1], rv[2]); - /* glRotatef(so.rotation.parameter, *rv[0], *rv[1], *rv[2]); + glRotatef(so.rotation.amount, rv[0], rv[1], rv[2]); // Apply scaling vector - vector* sv = so.scale; - glScalef(*sv[0], *sv[1], *sv[2]); + GLfloat* sv = &so.scale; + glScalef(sv[0], sv[1], sv[2]); // Apply translation vector glTranslatef(so.x, so.y, so.z); @@ -407,7 +407,7 @@ void display() { glBindTexture(GL_TEXTURE_2D, so.texture); } else { glBindTexture(GL_TEXTURE_2D, 0); - }*/ + } // Draw actual object if ( so.mesh > 0 ) { @@ -420,8 +420,9 @@ void display() { } glBindTexture(GL_TEXTURE_2D, 0); - } - glPopMatrix(); + glPopMatrix(); + } + // Draw a white ball over the light source glPushMatrix(); diff --git a/types.h b/types.h index 91813ee..be7c1e4 100644 --- a/types.h +++ b/types.h @@ -34,19 +34,16 @@ typedef struct { GLubyte *rgbData; // Array of bytes with the colour data for the texture } texture; - -typedef GLfloat vector[3]; // Vector datatype - typedef struct { - GLfloat parameter; // Transform amount - vector* vect; // Transform vector + GLfloat amount; // Transform amount + GLfloat vector[3]; // Transform vector } transform; typedef struct { int mesh; // Mesh index number int texture; // Texture index number float x,y,z; // Scene position - vector* scale; // Scale vector + GLfloat scale[3]; // Scale vector transform rotation; // Rotation transformation } SceneObject; -- 2.20.1