Homework 2

OpenGL and Glut

Modified

ASSIGNMENT (2 parts)

  1. Exercise 2.4, implement a turtle graphics API using OpenGL. A typical turtle graphics API includes:
    init(x, y, theta) Initialize (x,y) turtle position and orientation angle.
    forward( distance ) Move turtle forward distance in turtle world. Draw line if pen is down.
    right( angle ) Turn turtle right by angle degrees.
    left( angle ) Turn turtle left by angle degrees.
    pen( position ) Position down for line drawing as turtle moves forward or up for no line drawing.

     

    For example, a turtle (OK, a cat):

    • initially at the center of turtle world pointing toward the positive x axis - init(0,0,0)
    • positions the pen down - pen(down)
    • moves forward 2 - forward( 2 )
    • turns left 90 degrees - left( 90 )
    • and moves forward 1 - forward( 1 )
               ö
               #  
       ö""ö
      

    Test by:

    1. rotating a square about one corner,
    2. generating the Sierpinski gasket of Figure 2.36 on page 80.

    Hints:

    1. the turtle is in degrees but C math functions use radians (the conversion of angle q from degrees to radians is: q*3.14159/180.0)
    2. forward(distance) must compute the change in X and Y position when moving distance at orientation q degrees.

      X += distance * cos(q*3.14159/180.0)
      Y += distance * sin(q*3.14159/180.0)

  2. Exercise 2.16, yet another bouncing ball.

    Hints: The simulation can be relatively simple but should account for gravity and the elasticity of the ball.  You should consult an elementary physics text for a detailed discussion of gravity and elasticity.

    1. Determining the distance traveled by the ball and upward travel time following the rebound. The vertical distance traveled is:

    distance traveled = gravity * time2 / 2

    One way to model the ball bouncing is to increment time on the way down and decrement time on the way up after a bounce.

    The height of the bounce is determined by e (coefficient of restitution which we can arbitrarily choose 0..1) where:

    height' = e2*distance traveled

    A ball with elasticity of 0.4 dropped from 10 meters would rebound to 1.6 meters.

    The height of the rebound allows the calculation of the time of upward travel by:

    time = sqrt( 2*height'/gravity)

 

TEST

  1. Using your turtle graphics API, draw a square with the upper-right corner centered in the window; redraw the square in small, uniform angle increments, 360 degrees about the original square's upper-right corner. To verify the accuracy of your algorithm, repeat, rotating 3600 degrees about the original upper-right corner. The visual effect will be interesting.
  2. Using your turtle graphics API, generate the Sierpinski gasket of FIGURE 2.38 on page 80.
  3. The bouncing ball; the visual effect should be based on the physical model of a bouncing ball.

 

EMAIL

  1. To  with subject: YOUR NAME: B481 and Homework 2.
  2. Send a Web accessible link to a zip file named with your last name as Lastname.zip containing:

    Files stored on your W: drive are Web accessible by: http://homepages.ius.edu/username/filename

    To setup your IUS account to publish Web pages:
    1. Login to the IUS LAN.
    2. Click http://www.ius.edu/SpinWeb to run a setup utility and follow instructions.

    Ftp files by:

    1. ftp webftp.ius.edu
    2. ads/username
    3. password
  3. Instructions on executing each.

 

COMPILING AND EXECUTING IN VISUAL STUDIO

The following assignment serves as an introduction to OpenGL and Glut on a Microsoft system. OpenGL is part of Visual Studio while Glut for Windows must be downloaded (see above link).

To create an empty console project:

  1. In Visual Studio, select: File | New | Project
  2. In Other Languages select: C++ | Console Application
  3. Name: gasket
  4. On next screen, select: Application Settings | Empty Project

To add the code for the Sierpinski gasket:

  1. Select: View | Solution Explorer
  2. Right click: Source Files | Add | New Item
  3. Download gasket.c
  4. Copy and paste the code.

To define the location of glut.h and glut libraries

  1. Select: Project | Properties | Configuration Properties | C/C++
  2. Enter: Additional Include Directories, the location of the glut installation, probably C:\glut
  3. Select: Linker
  4. Enter: Additional Library Directories, the location of the glut installation, probably C:\glut

To execute and produce Figure 2.2 on page 45 of the text:

  1. Select: Build | Build Solution (ignore the warning).
  2. Select: Debug | Start without Debugging