Website: www.cs.sjsu.edu/faculty/rucker/cs116b.htm
Prof. Rudy Rucker, MH 213, 924-5147, How to email me.
Office Hours:
T, Th 12:00 - 1:30
T, Th 4:15 - 5:00
Class meets T, Th, 10:30 - 11:45 AM, MH 225
Midterm: Thursday, March 25
Final Exam: Friday, May 21, 0945-1200
Latest Info
April 15, 2004----------------------
Ray tracing links. These are by an ace New Zealand programmer named
Nick Chapman (a.k.a. "Ono-Sendai" after the cyberdeck
brand in William Gibson's Neuromancer).
The first link is to Chapman's real-time raytracer. Get the demo
1.2 from this page, it's an amazing executable. Be sure and look
in the readme doc for info about the controls. He has some
source code here, but not the complete buildable source. Nick says
the code is so optimized that it would be exceedingly hard to read
and learn from. And, quite reasonably, he probably doesn't quite
feel like giving this incredible hack away.
http://homepages.paradise.net.nz/nickamy/raytracer/raytracer.htm
The second link is to Chapman's simple raytracer. You can get the
complete buildable source of Version 1.0 from this page.
http://homepages.paradise.net.nz/nickamy/simpleraytracer/simpleraytracer.htm
Or you can get a very slightly altered version of Nick's Simple
Raytracer 1.0 source here from my page, I'll call it version 1.01.
Nick Chapman's Simple Raytracer,
Version 1_01
The (trivial) changes I made were to (a) pragma out some annoying
warnings with a line in maths.h, (b) add a useful clean.bat file
for removing junk files before zipping, (c) add a Visual Studio.NET
*.sln project file to supplement the Visual Studio 6.0 *.dsw project
file it comes with.
March 18, 2004 ----------------------
Check the Review for Midterm
over the weekend, and bring in review questions on Tuesday.
March 11, 2004 ----------------------
Download all the Red
Book 1.4 Sample Code.
We'll be talking about some Bezier code. Here's a build of the
three Red Book Bezier examples, with a Visual Studio project. bezier1.zip.
March 9, 2004 ----------------------
SGI files
for using OpenGL 1.2, 1.3, 1.4 and extensions. (Jason Tong found
this link.)
Bump
Mapping tutorial by Paul Baker found by J. Tong. Download Baker's
source code example to build (slightly tweaked to build on vanilla
windows machine.)
Some users have reported getting stripes when doing alpha blending.
Possibly there could be a fix in this "sorting" trick
found in alphablend.c at the SGI
Advanced97 site
A similar approach might help if you have stripes in a big textured
rectangle, the rectangle might be z-fighting with its back side.
/* draw the
front and then the back faces (essentially sorts the
polygons). */
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
draw_image();
glCullFace(GL_BACK);
draw_image();
glDisable(GL_CULL_FACE);
Feburary, 2004 ----------------------
Latest build of Pop at the www.rudyrucker.com/computer
game site is 35.2, if your'e interested. This fixes most of
the bugs the CS 240 students found. Also I found a way to get OpenGL
1.2, 1.3 and extensions to work (yes, Windows still ships with OpenGL
1.1 ONLY --- are you suprised?) But there's a simple workaround,
just include a file called glext.h from SGI. And now our critters
have delayed specular lighting, which means they look nicer! PickNPop
is well again, too.
|
Hmwk 1. Due Tuesday, Feb 17, 2004
Fix: Insert the following two bold lines before the gluLookAt call
in the setProjectionMatrix method in donuts.cpp. The comments explain
why.
glMatrixMode(GL_MODELVIEW); /* I learned from David Lin
that I need to have the gluLookAt acting on the MODELVIEW matrix
and not on the PROJECTION matrix. It acts on whatever matrix is
active, as the OPenGL doc says, "The matrix generated by gluLookAt
postmultiplies the current matrix." Not having this line here
meant that our viewpoint calcuations were messed up and specular
highlights were in the wrong place when we put in
::glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE ); */
glLoadIdentity(); /* Clear out any old gluLookAt resuts from
the MODELVIEW matrix. */
gluLookAt(eye.x(), eye.y(), eye.z(), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
It may possibly be that you should NOT use ::glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,
GL_TRUE ); after all. In one demo I was seeing a confusing problem
with it. If your highlights don't look righ with LOCAL_VIEWER on,
turn it off, and put the eye out at the positive z axis with the
lights more or less behind you, and then it should look OK. But
if the LOCAL_VIEWER doesn't seem to be hurting, leave it in.
Overview: I want you to design and implement four classes: cColor,
cLight, cLightingModel and cMaterial, and then use these with the
molecules6.zip demo program to
create two demo programs involving lighting. You will hand in (1)
printouts of your (a) cColor, (b)Material, and (c) cLight class
prototypes (they can live in a single file with a name like lighting.h
and be implemented in lighting.cpp), nicely formatted, (2) a FUNKYDONUTS.EXE
executable, (3) a SPECULAR.EXE executable.
Note that you don't REALLY need the cLight or cLightingModel class
for this problem, but the cMaterial class will be quite useful.
You should work on your apps at the same time as you develop the
classes in any case.
I built a fresh molecules demo that doesn't start out with the
"gun-turret" shaped cheerleader. I still need to add a
.NET project file. I put the viewer up in the positive octant. I
make the lighting model better and improved the comments on the
lights. I got rid of an old bug where we were specifitying the viewer
"up" to be the Z axis, when we really want it up to be
the Y, and the old viewer was confused and put -Y for the up. I
also commented in ::glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE
);
which seemed to beimportant if your viewer doesn't happen to be
at, like (0,0,z) looking towards -z. If you built your SPECULAR
program without this switch turned on and with the old molecules
3, the highlights will be on the back of the balls. The new fix
in setProjetionMatrix will make this better as well.
Details.
(1) (a) class cColor : public cVector inherits from our cVector
class but it has an extra _alpha field. Although it has the same
Real _x, _y, _z fields as cVector, we'll have mutators with color
names, like Real red(){return _x;} and accessors with color names,
like void setRed(Real r){CLAMP(red, 0.0, 1.0); _x = r;}, where CLAMP
is a macro I defined in realnumber.h. Or you could block copy the
cVector code and rewrite from scratch. We will also have a static
cColor method randomColor() that uses a method from the cRandomizer
class. And a member void setRandom value to randomize a color, possibly
with some args about the brightness range. These shouldn't change
the alpha which we normally set separately I think we need glSetVertex()
and maybe a glSetMaterial(...) as well. Or, maybe better, simply
a copyTo(Real *valarray) method that copies the r,g,b,alpha into
a valarray that can be used by opengl calls.
(1) (b) class cMaterial should have, I think, the following fields.
cColor _ambient_rho, _diffuse_rho, specular_rho, specifying the
reflectivity relative to the three types of light, also a Real _alpha
field for transparency (possibly more transparency fields will be
used later on), also a Real _specular_exp or, if you like, _shininess,
for the specular exponent, also a boolean _smoothing_onoff. We'll
need a some randomizing methods, also some methods for putting normal
useful values into the fields. By default always put some shade
of gray for the _specular_rho. Usually _ambient_rho and _diffuse_rho
should be the same, but in this demo we can play with having them
different. Avoid having any 0 fields in the cColor slots, as then
you don't pick up color from lights. Look at p. 423 of the book
for inspiration. And we'll need a glSetMaterial method (same name
as the cColor::setMaterial(), but it does more).
(1) (c) class cLighting needs a cVector _position, a boolean _isatinfinity,
cColor _ambient_intensity, _diffuse_intensity, specular_intensity,
and a boolean _onoff. We'll need some spotlight fields, too. OpenGL
interface methods will include glInstall() and glEnable(boolean
onoff). Maybe some more methods.
(1) (d) LIghitngModel needs several fields as well.
(2) FUNKYDONUTS.EXE Give each cAssembly a cMaterial *_pmaterial
field (pointer members are always better, but if you're scared of
them, use a cMaterial _material field), and by default randomize
the cMaterial to some reasonably diverse random values. Have four
lights in the world, by default all will be on, but you can toggle
them individiually with th 1, 2, 3, 4 hotkeys. The lights should
be as follows
i) pure ambient, maybe (0.25, 0.25, 0.25), no specular or diffuse.
Since it's all ambient, it doesn't matter where you put it, so just
put it at the origin.
ii, iii, iv) The other three lights will have 0 ambient intensity,
only diffuse and specular. Each will use the similar diffuse and
specular color, though maybe one is stronger than the other, and
they will be, respectivley, mainly red, mainly green, and mianly
white. Cahnge these specs if you like. Position the lights anywhere
you like --- the bottom line is that the demo should look as interesting
as possible, with nice highlights on the smoot things and clearly
distinguishable faces on the polyhedra. Also consider whether to
make them positional or directional. Tell me on a piece of paper
where the lights are.
As well as the 1,2,3,4 hotkeys and the default molecules5
hotkeys add a g hotkey. Have the g (for go) key step through
a sequence of different shapes so you can compare the materials
better, have the order be sphere, cone, torus, teapot, tetrahedron,
icosahedron, and possibly a bonus shape like maybe an old snowman
or cheerleader.
Have the s key toggle smoothing on and off.
(3) SPECULAR. The goal here is to reproduce figure 8.15 in our
textbook, see pp. 419-419 for a description. But I'd like to see
colors. Have the objects not moving through space, just sitting
still or possibly rotating on their individual axes. As in FUNKYDONUS,
have the g (for go) key step through a sequence of different
shapes so you can compare, have the order be sphere, cone, torus,
teapot, tetrahedron, icosahedron, and possibly a bonus shape like
maybe an old snowman or cheerleader. In this program have the objects
material be gray colored to facilitate comparision, but have colored
lights. Have the s key toggle smoothing on and off. Use the
same material for all the objects, probably just some kind of gray.
I think keep same colored lights as before, maybe drop the ambeitn
light. We can discuss this a bit more. It will proably look better
with ::glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE ). The
new fix in setProjetionMatrix will make this better as well.
|