首页 > > 详细

CSE387Lab7 FIRST PART

 Lab7

FIRST PART
Getting Started 
1. Download and extract the CSE387Lab7 solution. 
2. Use MSVC 2017 to open and run it.
As always, unless you are debugging, run the lab in the release mode.
3. Change the clear color that is set in the main to the color of your choice.
4. Run the solution. You will see a pyramid centered around the World coordinate origin. Below it is a plane that is composed of four triangles. The plane is eight units wide. It is positioned three units below the world coordinate origin. The World coordinate x axis is pointing to the right. The world coordinate y axis is pointing up and the positive z axis is pointing out of the screen. The view point is at 0, 0, 12 relative to World coordinates. The viewing direction is described by the vector 
[ 0, 0, -1].
 
Figure 1: Pyramid above plane.
Pyramids
5. Complete the Pyramid constructor in Lab.cpp so that is specifies the vertex locations and color that describe the triangles needed to create a three dimensional pyramid. The pyramid should be composed of six triangles; one for each side and two for the base. “Front faces” on which the vertices appear in counter-clockwise order should face outward (eventually we will not be rendering back faces). The pyramid should be centered on the object coordinate {O} origin both vertically and horizontally.
 
Figure 2: Object coordinate origin should be in the center of the pyramid.
The pyramid face that faces the object coordinate z direction has already been specified. Since there are six triangles that make up the surface of the pyramid, a total of eighteen vertices will have to be pushed into the pyramidVertices vector (three for each triangle). 
Modeling Transformations
You will now make several additional pyramids and modify the renderObjects function so that it renders each of them. Each will have a different position, orientation, and color. The geometry of all the pyramids should be the same i.e. they all have the same height and width. If at any time, if you determine that the vertex locations that you specified in the step described above are in error, go back and correct the problem.
5. Modify the modeling transformation of the center pyramid so that it is rotated 45 degrees about its own y axis.
6. Render another pyramid on the right side of the one above the center of the board at a distance of three units along the World coordinate x axis. Make it a different color.
7. Render another pyramid on the left side of the one above the center of the board at a distance of three units along on the negative World coordinate x axis. Use a scale transformation to give the pyramid a height and width of 2 units. Make it a different color.
 
Figure 2: Three pyramids above the board.
8. Make the center pyramid continuously rotate about the Object coordinate y axis (spin in place). 
9. Make the right hand pyramid continuously rotate about the Object coordinate x axis (spin in place). 
10. Make the left hand pyramid continuously rotate about the Object coordinate z axis (spin in place). 
11. Add two additional pyramids to the scene that are rendered as being one unit wide and one unit high. Put one on the front left corner of the board and one on the back right corner of the board. They should both be the same color and should be rendered using the same set of vertices.
Since there is currently no hidden surface removal algorithm in the place, you will have to consider rendering order in order to make these two pyramids appear to be sitting on the board. Hint: Should they be rendered before or after the board is rendered?
 
Figure 3: Rotating pyramids with two pyramids on board corners.
12. Finally, add a pyramid which “orbits” the entire board at a distance of 10.0 units in a horizontal plane. The plane of the orbit should be 3 units above the world coordinate origin. The pyramid should appear to be moving clockwise if you were looking down at the board from somewhere on the World coordinate y axis. For an extra challenge, make the pyramid “tumble” in the direction of travel (the same way a tire would roll). 
 
Figure 4: Pyramid orbiting above the board.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
SECOND PART
1. Run the solution. You will should see something similar to the scene depicted below. The viewing transformation for this view is set in the main. Take a look. 
 
// Set the initial viewing transformation for the scene
viewingTransformation = glm::translate( glm::vec3(0.0f, 0.0f, -12.0) );
The red pyramid is at the center/origin of the World coordinate frame. In other words, its XYZ position is 0,0,0.
 
Figure 1: Initial view.
3. Change the widow title to Viewing Transformations in the main function in Lab.cpp
// Create a window using a string and make it the current window.
GLuint world_Window = glutCreateWindow("Viewing Transformations");
4. Download and open Sphere.cpp. 
5. Add the Sphere struct declaration to ShapeStructs.h and add the definitions of the Sphere struct to ShapeStructs.cpp.
6. Replace the right hand pyramid with a sphere with a radius of one unit.
 
Figure 2: Pyramid replaced by sphere
Adding Some GLUT Menus
7. Add the following view menu function to Lab.cpp somewhere above the main function.
 
void viewMenu( int value )
{
switch( value ) {
 
case( 1 ):
 
// TODO
PerVertex::viewingTransformation = glm::translate( 
glm::vec3( 0.0f, 0.0f, -25.0 ) );
break;
 
case( 2 ):
 
// TODO
 
 
break;
 
case( 3 ):
 
// TODO
 
break;
 
 
case( 4 ):
 
// TODO
 
break;
 
case( 5 ):
 
// TODO
 
break;
 
case( 6 ):
 
// TODO
 
break;
 
default:
std::cout << "Invalid view selection " << std::endl;
}
 
// Signal GLUT to call display callback
glutPostRedisplay( );
 
} // end viewMenu
 
8. Add the following polygon rendering mode menu function to Lab.cpp somewhere above the main function.
 
void polygonRenderMenu( int value )
{
switch( value ) {
 
case( 0 ):
 
PerVertex::polygonRenderMode = FILL;
break;
case( 1 ):
 
PerVertex::polygonRenderMode = LINE;
break;
 
default:
std::cout << "Invalid polygon render selection " << std::endl;
}
 
// Signal GLUT to call display callback
glutPostRedisplay( );
 
} // end polygonRenderMenu
9. Add the following statements to the main function after the statements the register all the callback functions.
 
// Create polygon render submenu
int polyMenuid = glutCreateMenu( polygonRenderMenu );
// Specify menu items and integer identifiers
glutAddMenuEntry( "Fill", 0 );
glutAddMenuEntry( "Line", 1 );
 
// Create view submenu
int viewMenuid = glutCreateMenu( viewMenu );
// Specify menu items and integer identifiers
glutAddMenuEntry( "View 1", 1 );
glutAddMenuEntry( "View 2", 2 );
glutAddMenuEntry( "View 3", 3 );
glutAddMenuEntry( "View 4", 4 );
glutAddMenuEntry( "View 5", 5 );
glutAddMenuEntry( "View 6", 6 );
 
// Create main submenu
int menu1id = glutCreateMenu( mainMenu );
glutAddSubMenu( "Render", polyMenuid );
glutAddSubMenu( "View", viewMenuid );
glutAddMenuEntry( "Quit", 0 );
 
// Attach menu to right mouse button
glutAttachMenu( GLUT_RIGHT_BUTTON );
 
10. Try out the render menu.
 
Figure 3: Scene rendered in “wireframe”
Different Views Different Ways
Take a look at the viewMenu function in Lab.cpp. It has been set up to allow the viewingTransformation matrix to be modified by selecting “view 1” through “view 6” on a pop-up menu that is tied to the right mouse button. In the following steps you will modify each case statement to achieve a desired view of the scene.
2. In the switch statement case for view equals 1, use GLM translate to set the viewingTransformation matrix, so that you can view the center of the scene from 14 units away with the big pyramid on the left. The rendered view will appear nearly the same as the initial view except everything will be a bit bigger. 
 
3. In the case for view equals 2, use the same translate as in the previous step, but also use a GLM rotate to set the viewing transformation matrix to allow you to view the scene from the same direction and distance, but elevated 45 degrees. You should still be looking at the center of the board.
 
4. In the case for view equals 3, use both GLM translate and rotate to create the necessary transformation matrices to set the viewing matrix to allow you to view the scene from directly above. When viewing the scene on the monitor, the objects above the reference plane should make a vertical line with the big pyramid at the bottom of the window.
 
5. Repeat steps 4, 5, and 6 for the cases 4 through 6 in the viewMenu function. Use only GLM lookAt. Note: You will have to do a little trig to get the view for case 5 to match the view for case two.
Using Arrows and Keys to Control the View
1 Add the following global declarations to the top of lab.cpp
 
double zTrans = -14.0f;
double rotationX = 0.0f; 
double rotationY = 0.0f;
2 KeyboardCB is called whenever a letter key if pressed. SpecialKeysCB is called whenever a non-letter key is pressed. The code below is designed to set the viewing transformation using the globals you added in the previous step. Copy it into KeyboardCB just above the call to glutPostRedisplay. 
 
// Set the viewing transformation based on the values held in the global
// varaiables zTrans, rotationX, and rotationY.
glm::dmat4 transView = glm::translate(glm::vec3(0.0f, 0.0f, zTrans));
glm::dmat4 rotateViewX = glm::rotate(glm::radians(rotationX), 
   glm::vec3(1.0f, 0.0f, 0.0f));
glm::dmat4 rotateViewY = glm::rotate(glm::radians(rotationY), 
   glm::vec3(0.0f, 1.0f, 0.0f));
 
viewingTransformation = transView * rotateViewX * rotateViewY;
6. In KeyboardCB, add cases for ‘w’ and ‘s’ so that the objects in the scene will move towards the view point when the ‘w’ key is pressed and away from the view point when the ‘s’ key is pressed.
7. In SpecialKeysCB, modify the cases in the function to produce the following behaviors:
Pressing the up arrow causes the objects in the scene to rotate downward
Pressing the down arrow causes the objects in the scene to rotate upward 
Pressing the right arrow causes the objects in the scene to rotate to the left
Pressing the left arrow causes the objects in the scene to rotate to the right
 
 
THIRD PART
1. Change the widow title to “Projection and Viewport Transformations” in the main function in Lab.cpp
// Create a window using a string and make it the current window.
GLuint world_Window = glutCreateWindow("Projection and Viewport Transformations");
2. Add the following enumerated type declaration and the declaration for the global View_Type variable to the global variable declared at the top of lab.cpp.
/********************** GLOBALS *****************************/
// Viewing parameters
enum View_Type { FULL_SCREEN, VERTICAL_SPLIT, HORIZONTAL_SPLIT };
View_Type view = FULL_SCREEN;
Adding Some GLUT Menus
3. Add the following view port menu function to Lab.cpp somewhere above the main function.
 
void viewPortMenu(int value)
{
switch (value) {
 
case(0):
 
// "Quit" selected on the menu
glutLeaveMainLoop();
break;
case(1):
 
view = FULL_SCREEN;
 
ResizeCB((int)PerVertex::xViewportMax,
(int)PerVertex::yViewportMax);
 
break;
 
case(2):
 
view = VERTICAL_SPLIT;
std::cout << "vertical" << std::endl;
break;
 
case(3):
 
view = HORIZONTAL_SPLIT;
 
std::cout << "horizontal" << std::endl;
 
break;
 
default:
std::cout << "Invalid view selection " << std::endl;
}
 
// Signal GLUT to call display callback
glutPostRedisplay();
 
} // end viewPortMenu
 
9. Add the following statements to the main function after the statements the register all the callback functions.
 
...
 
// Create viewport submenu
int viewportMenuid = glutCreateMenu(viewPortMenu);
// Specify menu items and integer identifiers
glutAddMenuEntry("Full Screen", 1);
glutAddMenuEntry("Vertical Split", 2);
glutAddMenuEntry("Horizontal Split", 3);
 
...
 
// Create main submenu
int menu1id = glutCreateMenu( mainMenu );
glutAddSubMenu( "Render", polyMenuid );
glutAddSubMenu( "View", viewMenuid );
glutAddSubMenu("Viewport", viewportMenuid);
glutAddMenuEntry( "Quit", 0 );
10. In the RenderSceneCB function replace the call to the RenderObjects function with the following switch statement.
 
// Draw the objects in the scene
switch(view) {
 
case VERTICAL_SPLIT:
 
twoViewsSplitVertically();
break;
 
case HORIZONTAL_SPLIT:
 
// TODO
//twoViewsSplitHorizontally();
break;
 
default:
renderObjects();
}
Creating a Perspective Projection Matrix
10. Add a function to Lab.cpp called myPerspective that will generate a perspective projection matrix. The parameters of the function should be the same as the glm::perspective function. Replace all calls to the glm::perspective function in Lab.cpp with calls to myPerspective
Two Views of the Scene Split Vertically
11. Add the following  function to Lab.cpp somewhere above the main function.
 
// Draws two views of the scene. One on the right and one on the left.
void twoViewsSplitVertically()
{
// Render left side view
double viewportWidth = (PerVertex::xViewportMax-PerVertex::xViewportMin)/2.0;
double viewportHeight = (PerVertex::yViewportMax - PerVertex::yViewportMin);
 
PerVertex::projectionTransformation = myPerspective(45.0, 
((double)viewportWidth) / ((double)viewportHeight), 0.1f, 100.0);
 
// Set viewport transformation for left view
PerVertex::viewportTransformation =
glm::translate(dvec3(0.0, 0.0, 0.0)) *
glm::scale(dvec3((double)(viewportWidth)/(PerVertex::xNdcMax-
PerVertex::xNdcMin),
(double)(viewportHeight)/(PerVertex::yNdcMax-PerVertex::yNdcMin),1.0)) *
glm::translate(dvec3(-PerVertex::xNdcMin, -PerVertex::yNdcMin, 0.0));
 
renderObjects();
 
// TODO
 
 
} // end twoViewsSplitVertically
12. While the program is running, right click to bring up the pop-up menu. Select “Vertical Split.” You should see a single view of the screen on the left half of the screen. 
 
13. Complete the twoViewsSplitVertically function so that it renders both left and right hand views. The two views should be identical. The objects should not be distorted in either view. To do this, you will have to use two different viewport transformations. You should use the same projection transformation for both views.
 
Two Views of the Scene Split Horizontally
14. Create the twoViewsSplitHorizontally function that is called by the RenderSceneCB function. It should render both top and bottom views. The two views should be identical. The objects should not be distorted in either view. To do this, you will have to use two different viewport transformations. You should use the same projection transformation for both views.
 
Orthographic Projections
15. Modify the twoViewsSplitVertically function so that the right hand view is rendered using an orthographic projection. You will have to use a different projection transformation for each view to accomplish this. 
Modify the parameters that are passed the glm::ortho so that the objects in both views are roughly the same size.
 
16. Modify the twoViewsSplitHorizontally function so that the top view is rendered using an orthographic projection. Again, the size of the objects should be roughly the same in both views.
 
Creating a Orthographic Projection Matrix
17. Add a function to Lab.cpp called myOrthographic that will generate an orthographic projection matrix. The parameters of the function should be the same as the glm::ortho function. Replace all calls to the glm::ortho function in Lab.cpp with calls to myOrtho.
 
Turn it in 
1. Copy the folder containing your solution to the desktop.
2. Change the name of the folder to CSE287LabSeven followed by your unique identifier. For instance “CSE287LabSevenBachmaer.”
3. Open the solution. Make sure it still runs.
4. Clean the solution by clicking on clean.bat. (The will delete all the intermediate temporary files that are part of your project and reduce the size of your submission.)
5. Zip up the solution folder using the standard windows compression tool. (No 7zips, rars, etc.)
6. Submit your zip archive of the solution through canvas.
You will need to have this project available and complete when you start the next lab.
 
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!