Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

ColorCube.cpp

00001 #include <iostream>
00002 #include <math.h>
00003 #include <gl/glut.h>
00004 
00005 #include "LifeVariables.h"
00006 #include "ColorCube.h"
00007 #include "ArcBall.h"
00008 
00009 using namespace std;
00010 
00011 ColorCube::ColorCube(int width, int height): ArcBall_t(width, height) {}
00012 
00013 
00014 void ColorCube::polygon(int a, int b, int c , int d) {
00015     glBegin(GL_POLYGON);
00016     glColor3fv(colors[a]);
00017     glVertex3fv(colors[a]);
00018     
00019     glColor3fv(colors[b]);
00020     glVertex3fv(colors[b]);
00021     
00022     glColor3fv(colors[c]);
00023     glVertex3fv(colors[c]);
00024     
00025     glColor3fv(colors[d]);
00026     glVertex3fv(colors[d]);
00027     glEnd();
00028 }
00029 
00030     
00031 void ColorCube::colorcube() {           
00032     polygon(0,3,2,1);
00033     polygon(2,3,7,6);
00034     polygon(0,4,7,3);
00035     polygon(1,2,6,5);
00036     polygon(4,5,6,7);
00037     polygon(0,1,5,4);
00038 }
00039 
00040 
00041 void ColorCube::render() {
00042     glPushAttrib(GL_CURRENT_BIT);
00043     glMatrixMode(GL_MODELVIEW);    
00044     glPushMatrix();
00045         glLoadIdentity();
00046         glMultMatrixf(finalTransformation.M);        
00047         glTranslatef(-0.5, -0.5, -0.5);        
00048         this->colorcube();
00049     glPopMatrix();
00050     glPopAttrib();    
00051 }
00052 
00053 
00054 void ColorCube::onMouseDown(int x, int y) {
00055     this->mousePosition.s.X = x;
00056     this->mousePosition.s.Y = y;    
00057 
00058     // Set Last Static Rotation To Last Dynamic One
00059     lastRotation = currentRotation;
00060     // Update Start Vector And Prepare For Dragging
00061         this->click(&this->mousePosition);
00062 
00063     // store the selected color as member
00064     glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, selectedColor);
00065     
00066     cout << "x= " << x << " y= " << y <<endl;
00067     cout << "SLECTED_COLOR " << selectedColor[0] << " " << selectedColor[1]<<" "<< selectedColor[2] << endl;
00068 }
00069 
00070 
00071 void ColorCube::onMouseUp(int x, int y) {
00072     throw;
00073 }
00074 
00075 
00076 void ColorCube::onMouseDrag(int x, int y) {
00077     this->mousePosition.s.X = x;
00078     this->mousePosition.s.Y = y;    
00079     Quat4fT currentQ;
00080     // Update End Vector And Get Rotation As Quaternion
00081     this->drag(&this->mousePosition, &currentQ);
00082     // Convert Quaternion Into Matrix3fT
00083     Matrix3fSetRotationFromQuat4f(&currentRotation, &currentQ);
00084     // Accumulate Last Rotation Into This One
00085     Matrix3fMulMatrix3f(&currentRotation, &lastRotation);                               
00086     // Set Our Final Transform's Rotation From This One
00087     Matrix4fSetRotationFromMatrix3f(&finalTransformation, &currentRotation);    
00088 }
00089 
00090 
00091 float* ColorCube::getColor() {
00092   return selectedColor;
00093 }
00094 
00095 
00096 

Generated on Mon Dec 12 15:20:26 2005 for CCube by  doxygen 1.4.1