辅导 Python glFrustum、讲解程序语言

- 首页 >> Python编程


Overview

This assignment is a follow-up for assignment 4, however, you can start with the template code given below, instead of using your existing code from assignment 4.

In this assignment, you will add polygon clipping to the code, in order to avoid projecting objects that fall outside the field of view of the camera. In this assignment we will use an image plane at a distance of 8 units along the view vector from the camera and ranging, in the camera coordinate system, from -5 to 5 in both the x and y directions.

All the drawing needs to be done using OpenGL 2D drawing functions. You are not allowed to use any of the built-in 3D OpenGL drawing functions, such as glVertex3f, gluPerspective, glFrustum, glOrtho, gluLookAt, etc. anywhere in your code. In order to see if the clipping routine is working properly, set gluOrtho2D(-1.1,1.1,-1.1,1.1), while the projection transformation maps the view frustum to a standard view volume extending from -1.0 to 1.0 in the x and y directions.

You are required to use the same clipping routine for both perspective and parallel projection. You must clip in homogeneous coordinates. You can assume that all the polygons that will enter the clipping routine will be triangles.

OPTIONAL FUNTIONALITY:   We can improve the efficiency of a clipping routine by devising simple tests for whether or not an object is entirely outside or entirely inside the view volume. In this assignment, you can surround every 3D object with an axis-aligned bounding box. This is simply a rectangular box that completely encloses the object. Before doing polygon clipping, you can check whether or not all six faces of the bounding box are inside or outside the view volume. If the bounding box is outside the volume, then the object it contains is trivially rejected and clipped away. If the bounding box is completely inside the volume, then the whole object can be projected without clipping. This saves you from having to clip each face of an object individually. Only objects whose bounding boxes intersect the clipping planes must be clipped on a face-by-face basis. You don't need to clip the bounding boxes themselves, only the objects within the boxes.

Interface Details

In this assignment, you will add the following additional functionality to the selection interface, as follows:

MIDDLE mouse button - moves the near plane towards or away from the camera. Note that the near plane should stay between the camera and the far plane. You should set a minimum distance between the near and far plane. Similarly, you should set a minimum distance between the camera and near plane. The size and distance from the camera of the image plane remains fixed.

RIGHT mouse button - moves the far plane towards or away from the camera. Similar to the near plane movement case, ensure that the far plane remains behind the near plane.

In your program, all other functionality for assignment 4 (already present in the template code) should be present and operational with the additional functionality for this assignment.

For full credit, all of the above functionality must be fully implemented!


Note : Scene Layout Info

Please use the same scene layout file format as you used in assignment 4.


Template Code

Download the template code and unzip it into your home directory. All the functionality required in assignment 4 is present in the template code. A place holder function for the clipping routine is also included, and called from the display function.


References for Clipping

Here are some references for clipping in Homogeneous coordinates:

1.The original paper by Sutherland and Hodgeman where they present polygon clipping in homogeneous coordinates: Ivan E. Sutherland , Gary W. Hodgman, Reentrant polygon clipping, Communications of the ACM, v.17 n.1, p.32-42, Jan. 1974. Directly from ACM portal (Links to an external site.). Temporary local copy is located here.

Actions

3.More information on why you need to do clipping in homegeneous coordinates: James F. Blinn , Martin E. Newell, Clipping using homogeneous coordinates, Proceedings of the 5th annual conference on Computer graphics and interactive techniques, p.245-251, August 23-25, 1978. Directly from ACM portal (Links to an external site.). Temporary local copy is located here.

Actions



站长地图