#include #include #include #include #include #include "shape.h" using namespace std; Triangle theTriangle; Triangle theStandardTriangle; float forward[16]; float backward[16]; inline float min(float f1, float f2) {return f11) d--; break; case '+': d++; break; case 'n': theTriangle=createRandomTriangle(); theStandardTriangle = theTriangle.standardize(forward,backward); break; default: break; } glutPostRedisplay(); } void motion(int x, int y) { static int currX=-1; static int currY=-1; if (currX>0 && abs(x-currX) < width/6 && abs(y-currY) < height/6) { phi += (double) (x-currX)/ (double) width * 3.14159; theta += (double) (y-currY)/ (double) height * 3.14159; // limit theta to -4pi/9 and 4pi/9 if (theta < -4*3.14159/9.0) theta = -4*3.14159/9.0; if (theta > 4*3.14159/9.0) theta = 4*3.14159/9.0; } currX = x; currY = y; glutPostRedisplay(); } Triangle createRandomTriangle() { // create three random vertices in the 10x10x10 cube centered // at the origin float vals[3]; Tuple v[3]; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) vals[j] = (((float) rand()/ (float) RAND_MAX) - 0.5f)*100.0f; v[i] = Tuple(vals[0],vals[1],vals[2]); } return Triangle(v[0], v[1], v[2]); }