Computer Graphics, Lab Assignment 4
+ LabAssignment2/
+ 1/
+ 2/
+ 3/
- 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 in a 2D space.
- Set the window title to your student ID and the window size to (480,480).
- Complete the render() function below to draw a triangle in the manner described in C.
- You have to use OpenGL transformation functions. Do not use numpy matrix multiplication for composing transformations.
| def render(): |
|
| glClear(GL_COLOR_BUFFER_BIT) |
| glLoadIdentity() |
|
|
|
|
# draw cooridnates glBegin(GL_LINES) glColor3ub(255, 0, 0) glVertex2fv(np.array([0.,0.])) glVertex2fv(np.array([1.,0.])) glColor3ub(0, 255, 0) glVertex2fv(np.array([0.,0.])) glVertex2fv(np.array([0.,1.])) glEnd() glColor3ub(255, 255, 255)
| ########################### |
| # implement here |
|
| ########################### |
drawTriangle()
| def drawTriangle(): |
|
| glBegin(GL_TRIANGLES) |
|
| glVertex2fv(np.array([0.,.5])) glVertex2fv(np.array([0.,0.])) glVertex2fv(np.array([.5,0.])) |
| glEnd() |
|
|
|
|
|
|
- If you press or repeat a key, the triangle should be transformed as shown in the Table:
| Key |
Transformation |
| Q |
Translate by -0.1 in x direction |
| E |
Translate by 0.1 in x direction |
| A |
Rotate by 10 degrees counterclockwise |
| D |
Rotate by 10 degrees clockwise |
| 1 |
Reset the triangle with identity matrix |
- Transformations should be accumulated (composed with previous one) unless you press 1.
- You may need a global variable (like a python list object) to store key inputs.
- Files to submit: A Python source file (Name the file whatever you want (in English). Extension should be .py) F.Expected result:
- Write down a Python program to draw rotating point p=(0.5, 0) and vector v=(0.5, 0) in a 2D space.
- Set the window title to your student ID and the window size to (480,480).
- Use the following render() and fill # your implementation parts to render p and v.
- Hint: Render the vector v as a line segment starting from the origin (0,0).
| def render(M): |
|
| glClear(GL_COLOR_BUFFER_BIT) |
| glLoadIdentity() |
|
|
|
|
| # draw cooridnate glBegin(GL_LINES) |
|
| glColor3ub(255, 0, 0) |
|
| glVertex2fv(np.array([0.,0.])) glVertex2fv(np.array([1.,0.])) |
| glColor3ub(0, 255, 0) |
|
| glVertex2fv(np.array([0.,0.])) glVertex2fv(np.array([0.,1.])) |
| glEnd() |
|
|
|
|
|
glColor3ub(255, 255, 255)
| # draw point p |
|
| glBegin(GL_POINTS) |
|
| # your implementation |
| glEnd() |
|
|
|
|
|
| # draw vector v |
|
| glBegin(GL_LINES) |
|
| |
# your implementation |
| glEnd() |
|
|
|
|
|
|
|
- Expected result: Uploaded LabAssignment5-1.mp4
- Do not mind the initial angle.
- p and v should be t rad rotated when t seconds have elapsed since the program was executed.
- You need to somehow combine a rotation matrix and a translation matrix to produce the expected result.
- Files to submit: A Python source file (Name the file whatever you want (in English). Extension should be .py)
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.