CS4735 Computer Graphics
Lab 3 Sept. 27, 2004
Purpose: To gain complete understanding of how to
compute where lines intersect a plane in 3D.
1. As for all previous labs, log in to a
Linux workstation in ITD415, and create a subdirectory in your UNIX subdirectory
space called (e.g.) “L3”.
2.
Download the “planeint.tar” file from the CS4735 “Examples” web site
into your L3 subdirectory (use e.g. Mozilla).
3.
untar the planeint.tar file to get the original source code back.
4.
Type “make” to invoke the Makefile, which will, in turn, compile and
link the source code. This should
result in an executable file called “planeint”, which, when invoked (by typing ./planeint at the command
line) should draw a blue-grey rectangular patch with red orthogonal axes on
your screen. The patch corresponds to
the plane defined with point normal form n · (P – B) = 0, with n = (0.6, 0.9, 0.9) and B
= (0.2, 0.2, 0.2). Change the README
file to correspond to the program described below.
5. Modify the planeint program (specifically the myDisplay.cpp part) to draw a ray from a given point A towards the plane, and stop drawing where the line hits the plane. I suggest you implement a function (method) called
double lineIntPlane(double nx, double ny,
double nz,
double Bx, double By,
double Bz,
double Ax, double Ay,
double Az,
double cx, double cy,
double cz)
which returns the value thit where a line defined in parametric form P(t) = A + ct intersects a plane defined in point normal form n · (P – B) = 0. You will need to use equation (4.59) on page 186 of the text; i.e. to compute where the point of intersection occurs. Once you have this function working, test your program by drawing a green line of width 2 ((glLineWidth(2.0)) from A to A + c thit with A = (0.4, 1.3, 1.0) and c = (-0.2, -0.2, -0.2). Add a yellow point of size 4 (glPointSize(4.0)) drawn at point A to show which end of the ray is the starting point. What is the value of thit where the ray intersects the plane? Use the existing plane given in myDisplay.cpp as defined in 4. above. Remember that to draw points in 3D, use a sequence something like the following:
glBegin(GL_POINTS);
glVertex3f(Ax, Ay, Az);
glEnd();
For debugging, use printing to the standard output stream;
e.g.
std::cout << ″thit
= ″ << thit << ″\n″;
will print the value of variable thit as it is computed.
6. Put your ray drawing code in a loop of N times, and every time through the loop change the start point of the ray being drawn (e.g. Ay = Ay - 1.0/N). You should see a series of N parallel lines intersecting the plane. The result should be similar to that shown in Figure 1 below.
Figure 1. Result of drawing a series of 10 lines hitting a plane in 3D.
7. To experiment further, change the various values of s and t I have used to draw the plane to see what happens. You can also change the angle the camera is looking at the world by varying arguments to the gluLookAt(...) function in file init.cpp.