Graphics Project 2004

Topic:

Choose a mood, or an emotion. Now create a virtual world with a forest scene to match. Examples could include: An orchard on a bright sunny day, with swarms of bees and other insects frolicking amongst the blossoms, a dark somber forest at night under moonlight with discarded glass bottles producing specular highlights, a tropical jungle with armies of ants amongst the fallen leaves. The scene must contain the following in some form:

Here is the poem that the mood of my forest scene is based on:

The Donkey --- G.K. Chesterton

When fishes flew and forests walked
And figs grew upon thorn,
Some moment when the moon was blood,
Then surely i was born;

With monstrous head and sickening cry
And ears like errant wings,
The devil's walking parody
On all four-footed things.

The tattered outlaw of the earth,
Of ancient crooked will;
Starve, scourge, deride me: I am dumb,
I keep my secret still.

Fools! For I also had my hour;
One far fierce hour and sweet:
There was a shout about my ears,
And palms before my feet.

The particular elements of the poem that I attempted to implement were the flying fishes, the moon of blood, palm trees and of course a donkey.

Requirements fulfilled:

My code for this project modified and extended the version of the sample code used in practials that was provided for us. The following code segments will highlight my changes and additions to this version. The complete source code is available for download here.

Terrain suitable to the context.
The first problem that I tackled was that of creating a suitable terrain. In order to do this, I first made a bumpy, textured floor using Blender and exported this as an .OFF object.

 w.addObject (new Object (Point (0.0, 10.0, 0.0), 90.0, Vector (1.0, 0.0, 0.0), 600.0, readOff ("newfloor"), Colour (0.2, 0.7, 0.2), 50.0));
 
To this I added several tree OFF objects to make up my forest. The floor initially looked like this:
View of floor

At least one of the following effects: fog, motion blur, depth of field, shadows, environment mapping, transparency.
For this section I implemented fog as we had done in prac 16 and shadows similar to the way we implemented them in Prac 15. To see the effect it was first necessary to enable the fog.

void initializeGL ()
        {

	  glShadeModel (GL_SMOOTH);
          glEnable (GL_DEPTH_TEST);

	  glEnable (GL_FOG);
	  glEnable (GL_NORMALIZE);
          glEnable (GL_LIGHTING);
	  ....

        GLint fogMode;
        GLfloat density;
	GLfloat fogColor[4] = {0.1, 0.2, 0.3, 1.0};

        fogMode = GL_EXP2;
        glFogi (GL_FOG_MODE, fogMode);
        glFogfv (GL_FOG_COLOR, fogColor);
        glFogf (GL_FOG_DENSITY, 0.05);

        glClearColor(0.1, 0.2, 0.3, 1.0);
        }

void paintGL ()
        {
...
...
      //to draw shadows:
	  for (std::vector::iterator i = world->obs.begin (); i != world->obs.end () -1; i++)
            {
	    	 Ti::transformPush ();
	   	 Ti::transformTranslate ((*i)->position.coord[0], (*i)->position.coord[1], (*i)->position.coord[2]);
           	 Ti::transformRotate ((*i)->angle, (*i)->axis.coord[0], (*i)->axis.coord[1], (*i)->axis.coord[2]);
           	 Ti::transformScale ((*i)->scale, (*i)->scale, (*i)->scale);
         	 // draw shadow
		 if ((*i)->shape != NULL)
  	         (*i)->shape->render ();
		 Ti::transformPop ();

            }

	  glEnable (GL_LIGHTING);
	  ...



A path to be followed by the camera/viewer, using splines.
I decided to use a BSpline for my camera path and so used the spline code from Prac 3 as a starting point. To implement it I needed to instantiate an object of the Curve class which we had access to. Once I had added this object to the World class,

      Curve* curvecam;

I could use it in my main method as follows:
      //camera bits
  string splinedefn = "BSpline 3 6 [{0,200.0,-100.0} {80.0,100.0,-50.0} {100.0,70.0,-20.0} {110.0,50.0,-20.0} {80.0,70.0,-50.0} {-10.0,100.0,-100.0}] [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]";

  istringstream stm (splinedefn);
  w.curvecam = Curve::createCurve (stm);
In order to get the camera transformations to actually follow the spline I needed to associate the transformation co-ordinates with the curve co-ordinates:
 //moving the camera according to the BSpline coordinates:
	  Ti::transformTranslate (0.0, 0.0, world->curvecam->curveAt(tval).coord[2]);
	  Ti::transformRotate (world->curvecam->curveAt(tval).coord[0], 0.0, 1.0, 0.0);
	  tval +=0.01;

	  //so that the camera movements loop around
	  if (tval >= 1)
	  	tval = 0.0;
(tval was previously initialised to 0.0).

angle1 angle2 angle3
This sequence of pictures demonstrates the movement of the camera along the spline. As the camera moves further away the fog thickens...

At least one light, producing specular highlights.
The lighting code I only modified slightly, changing the colour and position of my lights and making sure that everything was enabled correctly. My modified code is as follows:

  void initializeGL ()
        {
	...

glEnable (GL_LIGHTING);

          glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
          GLfloat global_ambient[] = { 0.0, 0.1, 0.0, 1.0 };
          glLightModelfv (GL_LIGHT_MODEL_AMBIENT, global_ambient);
          glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
	  ...
In my main method:
  w.addLight (new Light (Point (-50.0, 10.0, 0.0), Colour (0.8, 0.6, 0.6)));
  w.addLight (new Light (Point (0.0, 10.0, 0.0), Colour (1.0, 0.1, 0.1)));
The specular highlights were only really visible when the fog was turned off though.


An animated object containing internal transformations (moving parts,for example, flapping bird, walking dog).
I had many problems getting an animated object. My intention was to animate my own version of the donkey (as applicable to the poem) showing the donkey looking at the blood red moon. However... my animation failed to export properly resulting in a "segmentation fault". The donkey's motion was supposed to be something along the lines of:

Donkey animation
At the risk of being perceived of 'cheating' I therefore borrowed the ready-animated donkey code from the sample practical code simply to comply with the theme suggested by my poem. I make no claim to rendering that donkey animation - all credit goes to Shaun Bangay!


Texture mapping.
I performed texture mapping on my floor object to create a grassy terrain. I also tried to add texture to my version of the animated donkey object. These are the textures that I used:

grass texture" " donkey texture


A number of objects moving according to a flocking algorithm.
Here I re-used the code that we had been given in Prac 18 but adjusted the number of boids, their proximity and influence on each other. To stick with the theme of my poem, I used blender to enlarge a fish OFF object that I could then set to be the boid in the main method.

#define NUMBOIDS 15

#define LIMIT 100.0

#define PROXIMITY 20.0
#define INFLUENCE 50.0

#define BoidD 0.9// how much of previous direction is maintained.
#define BoidC 0.7 // cohesion
#define BoidA 0.2 // alignment
#define BoidS 0.2 // separation
#define BoidR 0.5 // random factor
...
int main (int argc, char * argv [])

{
...
	bug = readOff ("salmon3");
...
Flocking Fish


Results:

These two pictures show the incredible difference in quality between rendering the scene using Renderman (left) and OpenGL (right).
Renderman Forest OpenGL Forest

All the source code necessary to render the scene is available here

Cathy Irwin - Graphics Project 2004
e-mail me