(no commit message)
authorAsh Tyndall <[email protected]>
Fri, 21 Oct 2011 12:35:54 +0000 (20:35 +0800)
committerAsh Tyndall <[email protected]>
Fri, 21 Oct 2011 12:35:54 +0000 (20:35 +0800)
helper.c
scene.c
types.h

index bd5f37b..b4dbc9a 100644 (file)
--- a/helper.c
+++ b/helper.c
@@ -298,21 +298,20 @@ int addSceneObject(int id) {
 
   curObject = nObjects;
 
 
   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].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
 
 
   nObjects += 1; // New object in scene
 
diff --git a/scene.c b/scene.c
index b55b491..d794a0f 100644 (file)
--- a/scene.c
+++ b/scene.c
@@ -385,18 +385,18 @@ void display() {
     drawFloor();\r
     \r
     // Draw sceneObjs array\r
     drawFloor();\r
     \r
     // Draw sceneObjs array\r
-    glPushMatrix();\r
-      for ( int i = 0; i < nObjects; i++ ) {\r
+    for ( int i = 0; i < nObjects; i++ ) {\r
+      glPushMatrix();\r
         SceneObject so = sceneObjs[i];\r
 \r
         // Apply rotation vector\r
         SceneObject so = sceneObjs[i];\r
 \r
         // Apply rotation vector\r
-        vector* rv = so.rotation.vect;\r
+        GLfloat* rv = &so.rotation.vector;\r
         printf("%f, %f, %f\n", rv[0], rv[1], rv[2]);\r
         printf("%f, %f, %f\n", rv[0], rv[1], rv[2]);\r
-       /* glRotatef(so.rotation.parameter, *rv[0], *rv[1], *rv[2]);\r
+        glRotatef(so.rotation.amount, rv[0], rv[1], rv[2]);\r
 \r
         // Apply scaling vector\r
 \r
         // Apply scaling vector\r
-        vector* sv = so.scale;\r
-        glScalef(*sv[0], *sv[1], *sv[2]);\r
+        GLfloat* sv = &so.scale;\r
+        glScalef(sv[0], sv[1], sv[2]);\r
 \r
         // Apply translation vector\r
         glTranslatef(so.x, so.y, so.z);\r
 \r
         // Apply translation vector\r
         glTranslatef(so.x, so.y, so.z);\r
@@ -407,7 +407,7 @@ void display() {
           glBindTexture(GL_TEXTURE_2D, so.texture);\r
         } else {\r
           glBindTexture(GL_TEXTURE_2D, 0);\r
           glBindTexture(GL_TEXTURE_2D, so.texture);\r
         } else {\r
           glBindTexture(GL_TEXTURE_2D, 0);\r
-        }*/\r
+        }\r
 \r
         // Draw actual object\r
         if ( so.mesh > 0 ) {\r
 \r
         // Draw actual object\r
         if ( so.mesh > 0 ) {\r
@@ -420,8 +420,9 @@ void display() {
         }\r
 \r
         glBindTexture(GL_TEXTURE_2D, 0);\r
         }\r
 \r
         glBindTexture(GL_TEXTURE_2D, 0);\r
-      }\r
-    glPopMatrix();\r
+      glPopMatrix();\r
+    }\r
+    \r
 \r
     // Draw a white ball over the light source\r
     glPushMatrix();\r
 \r
     // Draw a white ball over the light source\r
     glPushMatrix();\r
diff --git a/types.h b/types.h
index 91813ee..be7c1e4 100644 (file)
--- 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;
 
     GLubyte *rgbData;   // Array of bytes with the colour data for the texture
 } texture;
 
-
-typedef GLfloat vector[3]; // Vector datatype
-
 typedef struct {
 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
 } 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;
 
     transform rotation; // Rotation transformation
 } SceneObject;
 

UCC git Repository :: git.ucc.asn.au