diff --git a/lesson02/lesson2.c b/lesson02/animation.c similarity index 64% rename from lesson02/lesson2.c rename to lesson02/animation.c index d88a005..eddf45b 100755 --- a/lesson02/lesson2.c +++ b/lesson02/animation.c @@ -17,6 +17,7 @@ #include "slash.h" #include "openBracket.h" +#include "closeBracket.h" #define PI 3.1415 @@ -30,6 +31,10 @@ float xrot = 0.0f; float yrot = 0.0f; float zrot = 0.0f; +float xrot_scene = 0.0f; +float yrot_scene = 0.0f; +float zrot_scene = 0.0f; + float i = 0.3; int full = 0; int oszi = 0; @@ -192,7 +197,7 @@ void ReSizeGLScene(int Width, int Height) glMatrixMode(GL_MODELVIEW); } -void rota(int what) +void rotate(int what) { usleep(10); switch(what) @@ -216,77 +221,6 @@ void rota(int what) if (zrot >= 360) zrot = 0; } - -void DrawCloseBracket(){ - // draw a square (quadrilateral) - glBegin(GL_QUADS); // start drawing a polygon (4 sided) - - // Down - // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - - // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad - - // Bottom Face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad - - // Right face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - - // Left Face - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad - - // Up - // Front Face (note that the texture's corners have to match the quad's corners) - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - - // Back Face - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad - - // Top Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - - // Left Face - glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad - - // Right face - glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad - glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad - glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad - glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad - - glEnd(); // done with the polygon -} - - /* The main drawing function. */ void DrawGLScene() { @@ -296,40 +230,35 @@ void DrawGLScene() glTranslatef(0.0f,0.0f,-8.0f); // Move Left 1.5 Units And Into The Screen 6.0 - glRotatef(xrot, 1.0f, 0.0f, 0.0f); - glRotatef(yrot, 0.0f, 0.0f, 0.0f); - glRotatef(zrot, 0.0f, 0.0f, 1.0f); + glRotatef(xrot_scene, 1.0f, 0.0f, 0.0f); + glRotatef(yrot_scene, 0.0f, 1.0f, 0.0f); + glRotatef(zrot_scene, 0.0f, 0.0f, 1.0f); glTranslatef(0.0f, sin((yrot*PI)/180), 0.0f); glBindTexture(GL_TEXTURE_2D, texture[0]); // choose the texture to use. glTranslatef(-3.0f, 0.0f, 0.0f); - DrawOpenBracket( 0.0f, yrot, 0.0f); + DrawOpenBracket( xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - DrawOpenBracket( 0.0f, yrot, 0.0f); + DrawOpenBracket( xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - DrawOpenBracket( 0.0f, yrot, 0.0f); + DrawOpenBracket( xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - DrawSlash(0.0f, yrot, 0.0f); + DrawSlash(xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(yrot, 0.0f, 1.0f, 0.0f); - DrawCloseBracket(); - glRotatef(yrot, 0.0f,-1.0f, 0.0f); + DrawCloseBracket(xrot, yrot, zrot, texture[0]); glTranslatef(1.2f, 0.0f, 0.0f); - glRotatef(yrot, 0.0f, 1.0f, 0.0f); - DrawCloseBracket(); - glRotatef(yrot, 0.0f,-1.0f, 0.0f); - + DrawCloseBracket(xrot, yrot, zrot, texture[0]); // swap buffers to display, since we're double buffered. glutSwapBuffers(); - if (oszi) rota(1); + if (oszi) rotate(1); } /* The function called whenever a key is pressed. */ @@ -359,10 +288,12 @@ void keyPressed(unsigned char key, int x, int y) break; case ' ': - zrot += 5; + zrot_scene += 5; + break; + + case '0': zrot_scene = xrot_scene = yrot_scene = 0; break; - case '0': zrot = xrot = yrot = 0; break; case 27: glutDestroyWindow(window); exit(0); default: @@ -378,20 +309,16 @@ void specialKeyPressed(int key, int x, int y) switch (key) { case GLUT_KEY_UP: - xrot += 5; - oszi = 0; + xrot_scene += 5; break; case GLUT_KEY_DOWN: - xrot -= 5; - oszi = 0; + xrot_scene -= 5; break; case GLUT_KEY_LEFT: - yrot += 5; - oszi = 0; + yrot_scene += 5; break; case GLUT_KEY_RIGHT: - yrot -= 5; - oszi = 0; + yrot_scene -= 5; break; default: break; diff --git a/lesson02/closeBracket.c b/lesson02/closeBracket.c new file mode 100644 index 0000000..eecbf9e --- /dev/null +++ b/lesson02/closeBracket.c @@ -0,0 +1,87 @@ +#include // Header File For The GLUT Library +#include // Header File For The OpenGL32 Library +#include // Header File For The GLu32 Library + +void DrawCloseBracket(float xrot, float yrot, float zrot, GLuint texture) +{ + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f, 1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f, 1.0f); + + glBindTexture(GL_TEXTURE_2D, texture); + + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + + // Down + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad + + // Bottom Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad + + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.4f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Top Left Of The Texture and Quad + + // Up + // Front Face (note that the texture's corners have to match the quad's corners) + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, 0.0f, -0.5f); // Bottom Left Of The Texture and Quad + + // Top Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + + // Left Face + glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, -0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.0f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.2f, -0.0f, 0.5f); // Bottom Left Of The Texture and Quad + + // Right face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.2f, 0.0f, -0.5f); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.4f, 0.5f, -0.5f); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.5f, 0.5f); // Top Left Of The Texture and Quad + + glEnd(); // done with the polygon + + glRotatef(xrot,-1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f,-1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f,-1.0f); + +} + +/* vim: set et sw=4 ts=4: */ + diff --git a/lesson02/closeBracket.h b/lesson02/closeBracket.h new file mode 100644 index 0000000..7e1b621 --- /dev/null +++ b/lesson02/closeBracket.h @@ -0,0 +1,6 @@ +#ifndef CLOSEBRACKET_H +#define CLOSEBRACKET_H + +void DrawCloseBracket(float xrot, float yrot, float zrot, GLuint texture); + +#endif diff --git a/lesson02/makefile b/lesson02/makefile index 41b2245..583143c 100755 --- a/lesson02/makefile +++ b/lesson02/makefile @@ -5,47 +5,17 @@ COMPILERFLAGS = -Wall CC = gcc CFLAGS = $(COMPILERFLAGS) $(INCLUDE) LIBRARIES = -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -OBJECTS = $(patsubst %.c, %.o, $(wildcard ./*.c)) +OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) -# for all, set the targets to be every lesson1.c-lesson13.c -# file, removing the .c extension. That is, at this point, -# it would produce lesson1, lesson2, lesson3,...,lesson13 targets. -# -all: $(basename $(wildcard lesson[1-9].c lesson1[0-3].c)) - -# same as for all, except set the targets to be -# lessonX.tar.gz from lessonX.c. This is really -# only used to build smaller tutorial .tar.gz files -# to send to nehe. -# -dist: $(foreach file,$(basename $(wildcard lesson[1-9].c lesson1[0-3].c)),$(file).tar.gz) - -# to produce, say, lesson1.tar.gz: -# -# 1. remove lesson1.tar.gz -# 2. build lesson1.tar containing README, makefile, lesson1.c, Data/lesson1/*. -# 3. gzip lesson1.tar. -# -lesson%.tar.gz : - tar cvf $(subst .tar.gz,.tar,$@) README makefile $(subst .tar.gz,.c,$@) $(wildcard Data/$(subst .tar.gz,,$@)/*); \ - gzip $(subst .tar.gz,.tar,$@); - -# to produce, say, lesson1: -# -# 1. compile the thing. uses the variables defined above. -# -lesson% : lesson%.o $(OBJECTS) - $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LIBDIR) $(LIBRARIES) +all : $(OBJECTS) + $(CC) $(CFLAGS) -o animation $(OBJECTS) $(LIBDIR) $(LIBRARIES) # to clean up: -# delete all of the lessonX files. clean: - rm $(wildcard lesson[1-9] lesson1[0-3]) + rm -f ./animation; + rm -f *.o -# to clean up the distributions: -# delete all of the lessonX.tar.gz files. -distclean: - rm $(wildcard lesson[1-9].tar.gz lesson1[0-3].tar.gz) +# to compile all .c %.o: %.c $(CC) -c -o $@ $< diff --git a/lesson02/openBracket.c b/lesson02/openBracket.c index 4845bc2..7701c22 100644 --- a/lesson02/openBracket.c +++ b/lesson02/openBracket.c @@ -3,12 +3,14 @@ #include // Header File For The GLu32 Library -void DrawOpenBracket(float xrot, float yrot, float zrot) +void DrawOpenBracket(float xrot, float yrot, float zrot, GLuint texture) { glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); glRotatef(zrot, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, texture); + // draw a square (quadrilateral) glBegin(GL_QUADS); // start drawing a polygon (4 sided) diff --git a/lesson02/openBracket.h b/lesson02/openBracket.h index 0ddccf9..8a0fd7a 100644 --- a/lesson02/openBracket.h +++ b/lesson02/openBracket.h @@ -1,11 +1,11 @@ -#ifndef SLASH_H -#define SLASH_H +#ifndef OPENBRACKET_H +#define OPENBRACKET_H /* * Draw a textured 2 boxed sharp opening bracket * rotate the object with the 3 args */ -void DrawOpenBracket(float xrot, float yrot, float zrot); +void DrawOpenBracket(float xrot, float yrot, float zrot, GLuint texture); #endif diff --git a/lesson02/slash.c b/lesson02/slash.c index 7260c2f..2771252 100644 --- a/lesson02/slash.c +++ b/lesson02/slash.c @@ -3,12 +3,14 @@ #include // Header File For The GLu32 Library -void DrawSlash(float xrot, float yrot, float zrot){ +void DrawSlash(float xrot, float yrot, float zrot, GLuint texture){ glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); glRotatef(zrot, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, texture); // choose the texture to use. + // draw a square (quadrilateral) glBegin(GL_QUADS); // start drawing a polygon (4 sided) diff --git a/lesson02/slash.h b/lesson02/slash.h index 61f10e1..f57ed96 100644 --- a/lesson02/slash.h +++ b/lesson02/slash.h @@ -6,6 +6,6 @@ * rotate the object with the 3 args */ -void DrawSlash(float xrot, float yrot, float zrot); +void DrawSlash(float xrot, float yrot, float zrot, GLuint texture); #endif