My First 3D Graphics Program
Well, this was more fun with graphics. The assignment was to make some sort
of interactive 3D world in OpenGL. So I did that. My picture contains the
following:
- A bouncing blue ball (ooh, alliteration!). It bounces around in the
xy-plane but does not move in the z-direction. It is bounded by the edges of
the window and will bounce back upon hitting them. The motion of the ball
also takes into account gravitational acceleration and elasticity (whenever
it bounces off the ground, the magnitude of its velocity is cut by 10%).
Finally, it's a bit interactive by itself; If, due to elasticity, the ball
is getting too low and not bouncing up enough, middle-clicking with the
mouse doubles its instantaneous velocity.
- A box and leash. There's a little green cube at the bottom that doesn't
do much by itself. It's attached by a yellow leash (a really deformed
cube) to a green pole (another deformed cube) on the y-axis.
- A teapot and a donut. If they're gonna give us something as silly as
glutSolidTeapot, I might as well use it... and
then I carefully placed a donut (aka "brown torus") around the handle of the
teapot.
- A sign. Again, it's a bunch of deformed and translated cubes, but the
end result is a sign. I used a stroke font to create the writing that
welcomes the user to My 3D World.
So, if you were paying attention to everything above, you're thinking, So
you've created this ... umm ... interesting 3D world, but that's only
half the assignment. Where's the interactivity? And that's a very
good question! So here's the answer:
- Mouse interactivity: I already described how the middle mouse button
will give the ball an extra boost. But there's more! Clicking with the left
moust button will start rotating everything (except the ball) around the
y-axis at a certain speed; left-clicking more increases the speed.
Right-clicking, on the other hand, rotates it all the other way. Also, note
that the lights will rotate with everything else!
- Keyboard interactivity, part I: Hitting "L" will intensify the lights.
Hitting "l" will detensify the lights, even if "detensify" is not really a
word.
- Keyboard interactivity, part II: Hitting "R" rotates the screen one way
about the y-axis, and hitting "r" sends it the other way. What is the point
of this, you ask, if the mouse can rotate it as well? Well, there are two
reasons: first, the lights do not move with this rotation; and
second, this will also move around the bouncing ball, giving its motion a
new appearance. Rotating ninety degrees this way will make the ball appear
to move only vertically!
Here are some thumbnailed views of my program from different angles. Click
on any one to blow it up.
Or click here to see them animated.
And, as always, the code is viewable
here.