// CBall implementation // // Author: Josh Jenkins // Inertia Productions 2003 // http://homepages.ihug.com.au/~grom #include "CBall.h" // Class declaration //////////////////////////////////////////////////////////////////// // Constructor CBall::CBall(): x(0.0f), y(0.0f), z(0.0f), xi(0.5f), yi(0.5f), zi(0.0f), radius(0.5f) { color[0] = 1; // Set the ball color color[1] = 1; color[2] = 0; sphere = gluNewQuadric(); // Create a pointer to a quadric object gluQuadricNormals(sphere, GLU_SMOOTH); // Create smooth normals gluQuadricTexture(sphere, GL_TRUE); // Create texture coords } //////////////////////////////////////////////////////////////////// // Destructor CBall::~CBall() { gluDeleteQuadric(sphere); // Remove the quadric from memory } //////////////////////////////////////////////////////////////////// // Draw to opengl screen CBall::Draw() { float mat_diff[] = { color[0], color[1], color[2], 1.0 }; // We have to set material properties when dealing with quadrics glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diff); glPushMatrix(); // Save current matrix, so translation doesnt affect rest of program glTranslatef(x+radius/2, y-radius/2, z+radius/2); // Translate sphere so it is centered around x,y,z gluSphere(sphere, radius/2, 10, 10); // Draw sphere glPopMatrix(); // Restore matrix } //////////////////////////////////////////////////////////////////// // Reset the ball position and vector CBall::Reset() { x = y = z = 0; xi = 0.5f; yi = 0.5f; zi = 0; } //////////////////////////////////////////////////////////////////// CBall::Update() { // Implement this later }