Description
Computer Graphics, Lab Assignment 5
+ LabAssignment2/
+ 1/
- py
+ 2/
- py
+ 3/
- py
- The submission time is determined not when the commit is made but when the git push is made.
- Write down a Python program to draw a transformed triangle and its local frame in a 3D space. A. Set the window title to your student ID and the window size to (480,480).
- Use the following drawFrame() and drawTriangle() to draw the frame and triangle:
|
- First draw an untransformed white triangle and a global frame.
- Then draw a transformed blue triangle and its local frame. The triangle should be first rotated by 30 degrees and then translated by (0.6, 0, 0) w.r.t. the global frame. E. Expected result:
- Files to submit: A Python source file (Name the file whatever you want (in English). Extension should be .py)
- Write down a Python program to draw a transformed triangle in a 3D space.
- Set the window title to your student ID and the window size to (480,480).
- Use the following code snippet:
gCamAng = 0
gComposedM = np.identity(4)
def render(M, camAng):
# enable depth test (we’ll see details later)Â Â Â Â glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)Â Â Â Â glEnable(GL_DEPTH_TEST)
glLoadIdentity()
# use orthogonal projection (we’ll see details later)Â Â Â Â glOrtho(-1,1, –1,1, –1,1)
# rotate “camera” position to see this 3D space better (we’ll see details later)
gluLookAt(.1*np.sin(camAng),.1, .1*np.cos(camAng), 0,0,0, 0,1,0)
# draw coordinate: x in red, y in green, z in blue    glBegin(GL_LINES)    glColor3ub(255, 0, 0)    glVertex3fv(np.array([0.,0.,0.]))    glVertex3fv(np.array([1.,0.,0.]))    glColor3ub(0, 255, 0)    glVertex3fv(np.array([0.,0.,0.]))    glVertex3fv(np.array([0.,1.,0.]))    glColor3ub(0, 0, 255)    glVertex3fv(np.array([0.,0.,0]))    glVertex3fv(np.array([0.,0.,1.]))    glEnd()
# draw triangle    glBegin(GL_TRIANGLES)    glColor3ub(255, 255, 255)    glVertex3fv((M @ np.array([.0,.5,0.,1.]))[:-1])    glVertex3fv((M @ np.array([.0,.0,0.,1.]))[:-1])    glVertex3fv((M @ np.array([.5,.0,0.,1.]))[:-1])    glEnd()
def key_callback(window, key, scancode, action, mods):
global gCamAng, gComposedMÂ Â Â Â if action==glfw.PRESS or action==glfw.REPEAT:
if key==glfw.KEY_1:
gCamAng += np.radians(-10)Â Â Â Â Â Â Â Â elif key==glfw.KEY_3:Â Â Â Â Â Â Â Â Â Â Â Â gCamAng += np.radians(10)
- If you press or repeat a key, the triangle should be transformed as shown in the Table.
Note that key 1 and 3 are already implemented in the above code snippet.
Key Transformation | |||
Q      Translate by -0.1 in x direction w.r.t global coordinate | |||
E Â Â Â Â Â Translate by 0.1 in x direction w.r.t global coordinate | |||
A Â Â Â Â Â Rotate about y axis by -10 degrees w.r.t local coordinate | |||
D Â Â Â Â Â Rotate about y axis by +10 degrees w.r.t local coordinate | |||
W Â Â Â Â Rotate about x axis by -10 degrees w.r.t local coordinate | |||
S Â Â Â Â Â Rotate about x axis by +10 degrees w.r.t local coordinate | |||
1 | Rotate camera -10 degree | ||
3 | Rotate camera 10 degree | ||
- Transformations should be accumulated (composed with previous one).
- You’ll need two global variables to store current accumulated transformation and current camera angle.
- Files to submit: A Python source file (Name the file whatever you want (in English). Extension should be .py)