{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

fish_working

fish_working - main.cpp Template code for drawing an...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
//////////////////////////////////////////////////// // main.cpp // Template code for drawing an articulated figure. // CS 174A //////////////////////////////////////////////////// #ifdef _WIN32 #include <windows.h> #endif #include <GL/gl.h> #include <GL/glu.h> #include <math.h> #include <iostream> using namespace std; #include <GL/glut.h> #include "Ball.h" #include "FrameSaver.h" #include "Timer.h" /* Global Variables. The use of global variables is not considered good practice in programming and in most cases they can be avoided. However for graphics applications the need for global resources arises very frequently for you may require some data that is shared, by all callbacks. The best way to deal with this problem is to use a Singleton design pattern, yet we stick with globals here for simplicity. */ FrameSaver g_frameSaver; Timer g_timer; BallData *g_arcBall = NULL; int g_width = 300; int g_height = 300; int g_button = -1; float g_zoom = 1; int g_previousY = 0; int g_animate = 0; int g_recording = 0; void resetArcball(); void save_image(); void instructions(); void set_color(float r, float g, float b); const int STRLEN = 100; typedef char STR[STRLEN]; float AngleY=0.0; float OscY=0.0; float AngleTail=0.0;
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
#define X 0 #define Y 1 #define Z 2 // The eye point and look-at point. double g_eye[3] = {0, 0.0, 50.0}; double g_ref[3] = {0.0, 0.0, 0.0}; double g_time = 0.0 ; ///////////////////////////////////////////////////// // PROC: drawCylinder() // DOES: this function // render a solid cylinder oriented along the Z axis. Both bases are of radius 1. // The bases of the cylinder are placed at Z = 0, and at Z = 1. // // // Don't change. ////////////////////////////////////////////////////// void drawCylinder(void) { static GLUquadricObj *cyl = NULL ; if( cyl == NULL ) { cyl = gluNewQuadric() ; } if( cyl == NULL ) { cerr << "Cannot allocate cylinder." << endl; return ; } gluQuadricDrawStyle(cyl,GLU_FILL) ; gluQuadricNormals(cyl,GLU_SMOOTH) ; gluCylinder(cyl,1.0,1.0,1.0,10,10) ; } ////////////////////////////////////////////////////// // PROC: drawCone() // DOES: this function // render a solid cone oriented along the Z axis with base radius 1. // The base of the cone is placed at Z = 0, and the top at Z = 1. // // Don't change. ////////////////////////////////////////////////////// void drawCone(void) { glutSolidCone(1,1,20,20) ; }
Image of page 2
////////////////////////////////////////////////////// // PROC: drawSquareTex() // DOES: this function // draws a tesselated square. // // Don't change. ////////////////////////////////////////////////////// void drawSquareTex() { float i,j ; int NSUB = 50 ; float d = 1.0 / NSUB ; for( i = -0.5 ; i < 0.5 ; i += d ) for( j = -0.5 ; j < 0.5 ; j+= d ) { glBegin(GL_POLYGON) ; glNormal3f(0,0,1) ; float r = 1.0 ; //r = 0.5 + i+j ; float radius = 0.5 ; r = 0.5 + cos((i*i+j*j)*20*3.14) ; set_color(r,0.5,0.1) ; glVertex3f(i,j,0) ; glVertex3f(i+d,j,0) ; glVertex3f(i+d,j+d,0) ; glVertex3f(i,j+d,0) ; glEnd() ; } } ////////////////////////////////////////////////////// // PROC: drawCube() // DOES: this function draws a cube with dimensions 1,1,1 // centered around the origin.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern