Homework5

SUN YAT-SEN UNIVERSITY

Homework 5: Views && Perspective

Computer Graphics
2017-04-10

1. Introduction

So far we have learn how to move the objects in the virtual world, but it seems that we always observe the virtual world in a fix position. Hence, let’s move around and look around on this world! In this homework, you are required to manipulate the view/camera in OpenGL and to know the differences and correlation between this homework and homework6.

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

2.2 Projections

Projection define how a virtual 3D world projects into a 2D screen such that we can see it. There are 2 kinds of projections are used in OpenGL: perspective projection and orthographic projection.

2.3 View Changing

You are required to change the view of the camera to observe the cube.

Hints: You may want to change your camera position in a circle. Try:

camPosX=sin(clock()/1000.0)*Radius;
camPosZ=cos(clock()/1000.0)*Radius;

Since sin(x)^2+cos(x)^2=1, that make sure we form a circle in XoZ plane.

2.4 Bonus: the Camera Class

Implement a Camera class to provide a FPS (First Person Shooting) view, which means when you press w,a,s,d, it would feel like if you were ‘walking around’ in the virtual world. When you move your mouse, it would feel like if you were ‘looking around’.

Hints:
The header of the Camera may be:(You can change it if you like)

class Camera{
public:
	...
	void moveForward(GLfloat const distance);
	void moveBack(GLfloat const distance);
	void moveRight(GLfloat const distance);
	void moveLeft(GLfloat const distance);
	...
	void rotate(GLfloat const pitch, GLfloat const yaw);
	...
private:
	...
	GLfloat pfov,pratio,pnear,pfar;
	GLfloat cameraPosX,cameraPosY,cameraPosZ;
	GLfloat cameraFrontX,cameraFrontY,cameraFrontZ;
	GLfloat cameraRightX,cameraRightY,cameraRightZ;
	GLfloat cameraUpX,cameraUpY,cameraUpZ;
	...
};

P.S. In the method void Camera::rotate(GLfloat const pitch, GLfloat const yaw), ‘pitch’ and ‘yaw’ means the Euler angles. Euler angles are 3 values that can represent any rotation in 3D, defined by Leonhard Euler somewhere in the 1700s. The following image gives them a visual meaning:

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/

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/        ——放可执行文件和readme