Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSE 328 PROGRAMMING ASSIGNMENT THREE

The main objective of this programming assignment is to develop a simple 2D animation program based on the transformation and collision handling of commonly-used 2D primitives like circles, rectangles,triangles, etc. You will also learn more about OpenGL’s rendering pipeline (to be specific, shaderuniforms and tessellationshaders.)

Starting from this programming assignment, you will be granted complete access to the arsenal of modern OpenGL. Please feel free to explore different OpenGL commands, shaders, and other functionalities,including those not mentioned in our lectures. Please note that you are still required to use OpenGL in the core-profile mode (modern OpenGL). Deprecated functions in immediate mode (legacy OpenGL) are not permitted.

We will also pay more attention to performance. You are required to implement the animation of primitives via shader uniforms (to be specific, by updating transformation matrices.)  You are not allowed to apply transformations in the main C/C++ program and flush the whole vertex buffer to the rendering pipeline for every frame.  Moreover, you are also required to draw parametric curves with OpenGL tessellation shaders (rather than rasterize them manually in the C/C++ program and flush huge vertex buffers.)

Before you continue, please review the course materials and the handout documents carefully. If your tessellationshaderis not working, you could try to disable the 3D Acceleration feature of your VMWare host.

Please refer to the TA Help Page for general requirements, and take note that all deadlines are strictly enforced. To prevent late submissions caused by network issues, avoid submitting at the last minute!  Please also note that your credits for this programming assignment will be scaled by 50% (i.e., from 200 + 80 to 100 + 40) on Brightspace to match the overall grading schemes.

1    Base Part (200 points)

Figure 1: Illustration for a 2D animation based on a bouncing face (its interior is not shown.)

Write a program to animate bouncing faces in a rectangular viewport, as illustrated in Figure 1. We are still focusing on 2D graphics, so our bouncing faces are essentially bouncing disks (circles). Please note that it is required to draw circles via OpenGL tessellation shaders (which is the common routine in OpenGL to render parametric curves/surfaces.)

To be specific, a bouncing face consists of two round eyes and a triangular mouth (Figure 2(a)). This is the 1-st generation (detailed later) of the face.  Note that the centers of the circles of the two eyes and the face itself all have the same y-coordinate. The radius of each smaller (eye) circle is half

Figure 2: Illustration of the bouncing faces and their evolution rules. For a 1-st generation bouncing face which is centered at (0, 0) with radius 1, its left eye should be centered at ( −0.5, 0) with radius 0.5, its right eye should be centered at (0.5, 0) with radius 0.5, and the three vertices of its mouth should be ( −0.25, −0.5), (0.25, −0.5), and (0, −0.75). Bouncing faces with other generations should have their components scaled and translated accordingly.

of that of the larger (face) circle.  The 2-nd generation of the face has a smaller version of the face in one of the eyes (Figure 2(b)). The 3-rd generation of the face has a smaller version of the face in each of the eyes (Figure 2(c)). Generation 4, 5, 6, and 7 faces will have more eyes converted to faces. Similarly, generations 8 through 15 add another level of recursion.

The faces move until they hit either another face or the viewport boundary.  We assume that the surface is horizontal, flat, and smooth.  We also assume that all collisions are completely elastic. That is, the objects obey the laws of physics:  the conservation of energy and the conversation of momentum. As an edge case, when a bouncing face hits the viewport boundary (i.e., hits a wall), it bounces back with reflected velocity, i.e., with the same speed and a reflected direction.

The rules of generation evolution are as follows:  (1) All faces start at the 1-st generation; (2) If two faces collide, each increases its generation by one; (3) If a face collides with a wall, it bounces back with its generation unchanged.

For simplicity, we assume that no more than two faces would collide at the same time. That is, you do not have to handle collisions involving three or more bouncing faces. You could also assume that all bouncing faces have the same mass (faces with different masses will be handled in the BONUS part.)

Please note that different from previous programming assignments, there is no need to switch between parts (because we only have one part.)

1.1 Bouncing Face Creation (60 points)

The user will left-click the mouse to create a 1-st generation bouncing face which is centered at the clicked position.  For this sub-problem, the bouncing face does not need to move.  You also don’t have to care about collision handling and generation evolution.

The bouncing face’s attributes, i.e., its area density σ (kg per square unit distance in NDC), radius r (unit distance in NDC), and its velocity v =  (vx , vy ) (unit distance in NDC, per second) should be dynamically read from a configuration file.  That is, the user should be able to create a bouncing face, modify the configuration file, and create another bouncing face with the updated set of attributes. (Please note that although the area density σ is used in the BONUS part, you should still handle this item properly when reading the configuration file.)

The configuration file  pa3/etc/parameters.txt has exactly one line, which contains four space-separated floating point numbers, separately denoting σ , r, vx  and vy.  A positive vx  means to move toward the right, and a positive vy  means to move upwards.  A negative value means to move in the opposite direction.

1.2 Bouncing Face Animation (80 points)

The bouncing faces will start to move as soon as they are created. For this sub-problem, you do not have to worry about generation evolution. You should support as much as 16 bouncing faces.

The primitive operations you must implement first are thus: (1) Ball-ball collision: Aprocedure to detect when two circles (possibly of different radii) intersect; and (2) Ball-wall collision: A procedure to detect when a circle intersects a line segment. You can assume here that the line segment is either vertical or horizontal. As a special case, your program should reject user attempts to create bouncing faces that would collide with other faces or the viewport boundary (i.e., the added face overlaps with other faces or the viewport boundary at the time it is created.)

We promise that all bouncing faces will have the same mass for the base part. That is, you don’t have to handle density at present.  You also don’t have to handle collisions involving more than two bouncing faces.

You would also like to take special care of the bouncing faces to prevent them from “sticking together” after collisions due to the fixed discrete step size (frame rate) of the simulation. For example, you could consider trading the precision for a smooth, non-sticking visual effect.

1.3 Generation Evolution (60 points)

Extend the previous part by properly handling the generation evolution mechanism. Again, you would need to support as much as 16 bouncing faces to get the full credits for this part!

2 BOUNS (80 points)

Enhance the digital universe you have created with extra features. We list the following extensions as examples; however, you are not restricted by these suggested extensions only.  Other good ideas and implementations are strongly encouraged. Up to 80 points can be awarded for this bonus part.

Self-spin (30 points). Let the bouncing faces rotate with respect to their centers while moving.

Angry Faces (30 points). By default, all bouncing faces are white-colored. Bouncing faces are generally bad-tempered and would get angry (turn red) if you attempt to disturb them by adding another face that collides with them at the point of creation. Of course, such an attempt should be rejected by the program.  Nevertheless, they know that you attempted to disturb them and will still get angry. Fortunately, anger does not spread among bouncing faces, and the bouncing faces will eventually calm down (gradually turn back to white in a linear manner) if you leave themalone for 5 seconds.

Handling Mass (20 points). This time, we allow our bouncing faces to have different masses. You should handle area density σ and update your collision handler properly.

Ellipse Faces (40 points). Bouncing faces are now ellipsis instead of circles.

Other Possibilities. Please feel free to explore other possible extensions, e.g., bouncing faces” with rectangular shapes, vertical viewport surface (considering the gravitational acceleration),  and so on. However, please also email the TA with your proposal for whether it is acceptable  and how many points it may be worth.

Please note that your BONUS features should be compatible with all of the already-implemented functionalities (e.g., if you implement the first two suggested bonuses, then your bouncing faces should both be able to self-spin and be able to get angry.)