Asg 6: Translate/rotate the camera in 3D perspective

Objectives

Following Assignment 05, where the point_t object is used to read a file of points into a list (std::vector) and drawn in a 3D GLUT window, set up GLUT callbacks to translate and rotate the camera.

Assignment

  1. Using the C++ code from Assignment 05 to read in a list of 3D points.
  2. Create a camera_t object that contains the following data objects:
  3. Set up keyboard callbacks that adjust the camera position and reference to move (translate) the camera as well as to rotate the camera
  4. Suggested key bindings (if you use different ones, provide a USAGE file):

Details

  1. Your OpenGL code should set up a projection matrix with gluPerspective(90,1.0,1.0,1000.0);
  2. Your OpenGL code should just use an identity matrix for the modelview matrix, i.e., glLoadIdentity();
  3. Initialize the camera position, reference point, and tilt vector and use them as arguments to gluLookAt(), starting with:
  4. Set up keyboard callbacks so that, depending on the key pressed, e.g., j to translate left, the camera object is called so that "the camera moves itself", e.g., the_camera.truck(-0.1);.
  5. The camera object can be made global, e.g., declared as camera_t the_camera; at the top of main.cpp just like std::vector<point_t* > the_points.
  6. For camera rotations, take a look at these basic rotations expressed in matrix form. You will probably need to write these out in long form to change to position of the camera's reference point with respect to the camera's position.

Requirements

  1. Make sure to create a new point_t* each time data is read in (this gets added to the list).
  2. Make sure that you properly delete the list of points by deleteing each point pointer as you erase each one from the list (i.e., when the program exits).
  3. When you rotate the camera (e.g., pitch), it should eventually make a full 360 degree rotation.
  4. Test your rotation code with the camera in place, e.g., don't translate the camera before testing rotation.

Input

  1. The pointdata.txt file used to test the above program is:
     1.0 -1.0  1.0
    -1.0 -1.0  1.0
    -1.0 -1.0 -1.0
     1.0 -1.0 -1.0
    	

Output

  1. Expected output with the above input file is:
    *** printing list
    1.00, -1.00, 1.00
    -1.00, -1.00, 1.00
    -1.00, -1.00, -1.00
    1.00, -1.00, -1.00
    	
    and a window showing something like what appears below:

Supplemental

  1. Here is a Makefile that you can use to compile the project:
    .SUFFIXES: .c .o .cpp .cc .cxx .C
    
    UNAME = $(shell uname)
    PLATFORM = $(shell uname -p)
    
    CC = g++
    COPTS = -g -Wall
    
    INCDIR =
    LIBDIR =
    
    ifeq ("$(shell uname)", "Linux")
    INC = \
      -I/usr/lib/glut-3.7/include
    LIBDIR = \
      -L/usr/lib -L/usr/X11R6/lib -L/usr/lib/glut-3.7/lib/glut
    LIBS = \
      -lglut -lGLU -lGL -lXmu -lXi -lXext -lX11 -lm
    else
    ifeq ("$(shell uname)", "Darwin")
    LIBS = \
      -framework OpenGL -framework GLUT -framework Foundation -lstdc++
    endif
    endif
    
    .c.o:
    	$(CC) -c $(INCDIR) $(COPTS) -o $@ $<
    
    .cpp.o:
    	$(CC) -c $(INCDIR) $(COPTS) -o $@ $<
    
    all : main
    
    OBJECTS = \
    point.o
    
    main : $(OBJECTS) main.o
    	$(CC) -o $@ $(INCDIR) $(COPTS) $(OBJECTS) $@.o $(LIBDIR) $(LIBS)
    
    point.o: point.h point.cpp
    
    clean :
    	rm -f *.o
    	rm -rf main
    	

Turn in

Turn in all of your code, in one tar.gz archive of your asg##/ directory, including:
  1. A README file containing
    1. Course id--section no
    2. Name
    3. Brief solution description (e.g., program design, description of algorithm, etc., however appropriate).
    4. Lessons learned, identified interesting features of your program
    5. Any special usage instructions
  2. Makefile
  3. source code (.h headers and .cpp source)
  4. object code (do a make clean before tar)

How to hand in

See handin notes

Grading scheme