CMirror::CMirror() { p0=CVec3df(-2.5,0.0,-2.0); p1=CVec3df(2.5,0.0,-2.0); p2=CVec3df(-2.5,3.0,-2.0); showMirror=true; p3=p1+p2-p0; initReflectionMatrix(); initWorldToMirrorTransformation(); }
void CCatmullRom::displayCurve() { // display the Catmull-Rom spline representing the profile curve using // a green line (RGB=(0,1,0)) with a width of WIDTH_CURVE double xArray[100]; double yArray[100]; for (int i=0; i<n; i++) { xArray[i]= ctrlPoints[i]->getArray()[0]; yArray[i]= ctrlPoints[i]->getArray()[1]; } glColor3f(0,1,0); //CATMULL-ROM SPLINE glLineWidth(WIDTH_CURVE); glBegin(GL_LINE_STRIP); for(int i=1;i<n-2;i++) { for(int j=0; j<NUM_CIRCUMFERENTIAL_POINTS; j++) { double deltay = 0.5*(yArray[i+1]-yArray[i-1]); double deltax = 0.5*(xArray[i+1]-xArray[i-1]); CVec3df n = CVec3df(deltax, deltay, 0).cross(CVec3df(0, 1, 0)); surfaceNormals[i][j][0] = n.getArray()[0]; surfaceNormals[i][j][2] = n.getArray()[1]; surfaceNormals[i][j][1] = n.getArray()[2]; double t = j*0.0200; double xPoint = xArray[i]+(t*(-xArray[i-1]+xArray[i+1])/2)+pow(t,2)*(xArray[i-1]-2.5*xArray[i]+2*xArray[i+1]-0.5*xArray[i+2])+ pow(t,3)*(-0.5*xArray[i-1]+1.5*xArray[i]-1.5*xArray[i+1]+0.5*xArray[i+2]); double yPoint = yArray[i]+(t*(-yArray[i-1]+yArray[i+1])/2)+pow(t,2)*(yArray[i-1]-2.5*yArray[i]+2*yArray[i+1]-0.5*yArray[i+2])+ pow(t,3)*(-0.5*yArray[i-1]+1.5*yArray[i]-1.5*yArray[i+1]+0.5*yArray[i+2]); curvePoints[i] = CVec3df(xArray[i], yArray[i],0); glVertex2f(xPoint, yPoint); } } glEnd(); for(int i=0; i<NUM_CURVE_POINTS; i++){ for(int j=0; j<NUM_CIRCUMFERENTIAL_POINTS; j++){ float angle = (M_PI*j*2)/NUM_CIRCUMFERENTIAL_POINTS; surfacePoints[i][j][0]= curvePoints[i].getArray()[0]*cos(angle); surfacePoints[i][j][2]= curvePoints[i].getArray()[0]*sin(angle); surfacePoints[i][j][1]= curvePoints[i].getArray()[1]; } } }
void init(void) { // select clearing color (for glClear) glClearColor (1.0, 1.0, 1.0, 0.0); // RGB-value for white // initialize view (simple perspective projection) glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(6.0, (GLfloat) windowWidth/(GLfloat) windowHeight, 5.0, 55.0); gluLookAt(0,0,45, -0.8,0.2,0, 0,1,0); trackball.tbInit(GLUT_LEFT_BUTTON); lighting.init(); // Initialise balls ball1.setPosition(CVec3df(-2,0,-1)); ball1.setVelocity(CVec3df(25,0,0)); ball2.setPosition(CVec3df(2,0.20,-1)); ball2.setVelocity(CVec3df(-33,30,0)); ball1.setMass(2.25); ball2.setMass(1); // Distribute trees randomly over the front half of the ground plane such // that the minimum distance between any two trees is at least minDistanceTrees GLfloat x,z,xx,zz; // (x,z) positions of trees bool validPosition; int i; for(i=0;i<numTrees;i++) { do { validPosition=true; x=(GLfloat) randomDouble(-1.95,1.95); z=(GLfloat) randomDouble(0,1.95); for(int j=0;j<i;j++) { // position is valid if the distance between the trunks of each tree is at least minDistanceTrees trees[j].getPosition(xx,zz); if (sqrt((xx-x)*(xx-x)+(zz-z)*(zz-z))<minDistanceTrees) { validPosition=false; break;} } } while (validPosition==false); trees[i].setPosition(x,z); } // Distribute flowers randomly over the back half of the ground plane such // that the minimum distance between any two flowers is at least minDistanceFlowers // x,z,xx,zz; // (x,z) positions of trees for(i=0;i<numFlowers;i++) { do { validPosition=true; x=(GLfloat) randomDouble(-1.95,1.95); z=(GLfloat) randomDouble(-1.8,-1.1); for(int j=0;j<i;j++) { // position is valid if the distance between the stems of each tree is at least minDistanceFlowers flowers[j].getPosition(xx,zz); if (sqrt((xx-x)*(xx-x)+(zz-z)*(zz-z))<minDistanceFlowers) { validPosition=false; break;} } } while (validPosition==false); flowers[i].setPosition(x,z); } // initialise three texture names glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(3, texName); ground.setTexture(texName[0]); monument.setTexture(texName[1]); trees[0].setTexture(texName[2]); }