//FIXME no equals check with == on double or float bring in an epsilon bool Line::IntersectionWith(const Point &p1, const Point &p2) const { Point AC = _point1 - p1; Point DC = p2 - p1; Point BA = _point2 - _point1; double denominator = BA.CrossProduct(DC); double numerator = DC.CrossProduct(AC); if (denominator == 0.0) { // the lines are superposed if (numerator == 0.0) { // the segment are superposed return IsInLineSegment(p1) || IsInLineSegment(p2); } else { // the lines are just parallel and do not share a common point return false; } } double r = numerator / denominator; if (r < 0.0 || r > 1.0) { return false; } double s = (BA.CrossProduct(AC)) / denominator; if (s < 0.0 || s > 1.0) { return false; } return true; }
/* * display * a function to display the model * Parameters: * none * Returns: * none */ void display(void) { if (stereo == 0){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(vangle, 1.0, dnear, dfar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(myCam.Eye.x, myCam.Eye.y, myCam.Eye.z, myCam.Rotate.x, myCam.Rotate.y, myCam.Rotate.z, myCam.ViewNorm.x, myCam.ViewNorm.y, myCam.ViewNorm.z); glColor3f(red, green, blue); myWorld.draw_world(); // draw all objects in the world }else{ Point r; GLdouble ratio, radians, wd2, ndfl; GLdouble left1, right1,top1,bottom1,near1,far1; near1 = 0.1; far1 = 10000; near1 = myCam.focalLength / 5; /*Misc Stuff */ ratio = myCam.screenWidth / (GLdouble)myCam.screenHeight; radians = DTOR * myCam.aperture / 2; wd2 = near1 * tan(radians); ndfl = near1 / myCam.focalLength; r.CrossProduct(myCam.ViewVector, myCam.ViewNorm); r.Normalize(); /* Derive the two eye positions */ r.x *= myCam.eyesep / 2.0; r.y *= myCam.eyesep / 2.0; r.z *= myCam.eyesep / 2.0; r.printPoint(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //left eye glMatrixMode(GL_PROJECTION); glLoadIdentity(); left1 = - ratio * wd2 - 0.5 * myCam.eyesep * ndfl; right1 = ratio * wd2 - 0.5 * myCam.eyesep * ndfl; top1 = wd2; bottom1 = - wd2; glFrustum(left1,right1,bottom1,top1,near1,far1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(myCam.Eye.x + r.x, myCam.Eye.y + r.y,myCam.Eye.z + r.z, myCam.Rotate.x + r.x, myCam.Rotate.y + r.y, myCam.Rotate.z + r.z, myCam.ViewNorm.x,myCam.ViewNorm.y,myCam.ViewNorm.z); glColor3f(0.0, 0.0, 0.4); glLineWidth(3.0); glScalef(8.0, 8.0, 8.0); myWorld.draw_world(); printf("LEft eye done\n"); //right eye glMatrixMode(GL_PROJECTION); glLoadIdentity(); left1 = - ratio * wd2 + 0.5 * myCam.eyesep * ndfl; right1 = ratio * wd2 + 0.5 * myCam.eyesep * ndfl; top1 = wd2; bottom1 = - wd2; glFrustum(left1,right1,bottom1,top1,near1,far1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(myCam.Eye.x - r.x,myCam.Eye.y - r.y,myCam.Eye.z - r.z, myCam.Rotate.x - r.x, myCam.Rotate.y - r.y, myCam.Rotate.z - r.z, myCam.ViewNorm.x,myCam.ViewNorm.y,myCam.ViewNorm.z); glColor3f(0.4, 0.0, 0.0); glScalef(8.0, 8.0, 8.0); myWorld.draw_world(); } glFlush(); glutSwapBuffers(); }