SUN YAT-SEN UNIVERSITY
Homework 4: Let’s Go 3D
Computer Graphics
2017-03-29
1. Introduction
So far we have drawn many amazing objects, but they are all in 2D. In this homework, let’s draw our first 3D object —— a simple cube! What’s more, let’s make the cube move around!
Warning: All codes and documents should be written and submitted individually, without copying existed answers (Neither from other student nor from the Internet). Plagiarism = Fail. Besides, there may be at least 30% penalty for late homework.
2. Tasks
2.1 Pre-requirement
-
Language: Only C/C++ is accepted in this homework.
-
Libraries: Only OpenGL and freeGLUT/GLFW can be used.
-
OS/IDE: Any OS/IDE can be used.
2.2 Draw a cube
Let’s draw a cube in 3D world, and place it to (0,0,0).
- Disable deep test by calling function
glDisable(GL_DEPTH_TEST)
, draw a cube with 0.1 length of size. - Enable deep test by calling function
glEnable(GL_DEPTH_TEST)
and draw the cube again. Remember to callglClear(GL_DEPTH_BUFFER_BIT)
in your main cycle. Write down the differences and what the mechanism of deep test is in the report. - Write down your main algorithm and post your results in your report.
- Hints: You may draw the cube by using primitives
GL_QUADS
, that makes you should draw 6 quads in total. You can also draw the cube by usingGL_TRIANGLES
, that makes you should draw 12 triangles in total. You should also draw 6 faces of the cube in different colors.
2.3 Translations
Implement translation of the cube.
- The cube should be placed at (0,0,0) in the world.
- The cube should translate back and forward along x-axis.
- The cube should translate in a steady speed, but you can customize your speed.
- Write down your main algorithm and post your results in your report.
2.4 Rotations
Implement rotation of the cube.
- The cube should be placed at (0,0,0) in the world.
- The cube should rotate around y=x axis in the XoY plane.
- The cube should rotate in a steady speed, but you can customize your speed.
- Enable and disable the deep test, what is the difference now?
- Write down your main algorithm and post your results in your report.
2.5 Scaling
Implement scaling of the cube.
- The cube should be placed at (0,0,0) in the world.
- Scale the cube in a ratio which is equal to
sin(t)
, where t represents time. - You may want to include
<math.h>
and<time.h>
in your code. - Write down your main algorithm and post your results in your report.
2.6 Bonus: Combination
Let’s do something funny~ Now we want to combine 3 kinds of transformations together. In this time, we need 2 cubes.
- The first cube should be placed in (0,0,0), each time becomes bigger than it was. So the cube may ends up with a unlimited size! HaHa!
- The first cube should also rotate along y-axis in a steady speed.
- The second cube should be place in (0.8,0,0), then it would start to rotate around y=x axis in XoY plane.
- While the second cube is rotating itself, it should also ‘rotate’ around the first cube. To be precise, the second cube should translate around the first cube in the XoY plane.
- Write down your main algorithm and post your results in your report.
- P.S. Have you figure out what it looks like? Yes, the 2 cubes are moving like the Sun and the Earth. The sun is growing larger each year, just like the first cube. The earth is moving around the sun, while rotating itself, just like the second cube.
3. Submitting Format
Please submit your homework to sysucg2017@163.com. You subject of the email should be as same as your attachment(aka. your .zip file)
Only a .zip file should be submitted. Under the .zip file, the content should look like this:
classTpye_studentID_Name_hw?_version?/
|— src/
|— doc/
|— bin/
- classType: R for required class(必修班); E for elective class(选修班).
- studentID: 1xxxxxxx
- Name: Your Chinese Name.
- hw?: Specific which homework you are submitting.
- version?: Specific if you modify your submitted homework, only the last version would be graded. Started with version0.
- src/: The folder holds your project, including source files.(Make sure you execute the clean command, we don’t need those temporary files)
- doc/: Only one PDF should be included.
- bin/: Executable program and a ReadMe.txt to tell us how to run your program.
For example, a student in required class want to submit homework2 for the second time, his .zip file should be:
R_16214382_泽拉图_hw2_version1.zip
|—R_16214382_泽拉图_hw2_version1/
|—src/ ——放整个工程
|—doc/ ——放report.pdf
|—bin/ ——放可执行文件和readm