Opengl动画编程代写 | Assignment #3 B. Ross

本次加拿大作业案例是Opengl动画编程相关的的一个编程代写assignment

Due date: 12:00 noon, Monday November 20, 2021. No lates accepted.

Objectives: 3D OpenGL animation programming.

Hand in: Electronic submission of all source code, executables, and data (see assignment 1). Include cover sheet in submission files.

Note: You may work alone or in groups of 2 for this assignment. If in a group, all members must contribute equally to the assignment, and be able to answer questions about all submitted code.

Do both questions A and B. You should implement the application incrementally, in the suggested order of steps given. Then you should add several the components from the optional list, in any order you wish. Read the general requirements on page 4 before starting.General overview: Both questions involve particle simulations. The first question uses particles in an environment that has a simplified simulation of physics (gravity, collision). The second question uses particles with a flocking engine, to simulate a swarm of agents. Both questions use a similar animation engine described below for processing the particles and updating them within their environments

A particle list is a list of records. Each record represents one entity (particle, agent) in the system. Every time a new entity is created (key stroke, or perhaps automatically every few frames), a new record is created and inserted onto the list. Similarly, when an entity dies, its record is removed from the list. Each record contains all the information about that particle in the environment, and may include some or all of the following:

Position (px, py, pz): 3D coordinate of the position

Direction (dx, dy, dz): the direction vector that the entity is moving towards

Speed (S): higher numbers = faster speeds; 0 = stationary

Rotation angles and angle increments: used for spinning or orienting particles

Scale factors: used for differently scaled particles

Object shape type: used if different shapes/models are possible

Colour (R, G, B): could be for the whole object, or one RGB value per vertex, or a Material, or…

State: a value indicating the behaviour state (eg. foraging, schooling, exploding…)

Age: used if entities have a finite lifespan (Other special fields…?)

Next Record Pointer

To update a frame of a real-time animation, the following animation engine is used:

1. Frame and depth buffers are cleared.

2. Environment (ground, walls, etc.) is rendered 3. For each object in Particle List:

a. Update the particle:

– compute new position, based on environment rules and particle state

– compute other state variables for particle (kill it if required) b. Render the newly positioned and rotated particle, if it exists One pass through the list results in all the particles being updated and rendered. The particle update step is dependent upon the kind of simulation being done. When a new particle is created, it will have some initial position in the 3D world, a direction to move towards, and possibly an orientation (rotation) to reflect the direction it is moving. Its position is updated as follows:

Direction = (updated according to rules of environment)

Rotation = (update based on new direction, or random spinning)

Position = Position + Direction*Speed

The rules for updating the direction are given in A and B below. Speed is optional, and it can be altered as well, which results in accelerating behaviour.

A. Particle Cannon. This question simulates a particle cannon.

1. Define a large flat polygon to represent the ground. Its center should be at (0,0,0), and lay on the XZ plane. Also define a cannon (a solid cube, tetrahedron, or any shape you want). You can also define optional 3D shapes on the landscape, as targets for collision.

2. A particle takes the shape of a triangle, tetrahedron, small cube, or other shape. It has a record structure as described on p.1. The idea is that a particle resides in the scene at a particular position, and has a particular direction that it is traveling towards. When a particle is created, its start position is at the end of the cannon, with a direction (vx, vy, vz), where the directions are randomized a bit, but are generally in the direction where the cannon is pointed. The particle direction is updated during every frame as follows:

Direction = Direction + (0, -g, 0) : a particle with gravity pulling it down

This expression updates the velocity by applying a small gravitational effect (“-g”) to the velocity’s Y direction (up-down), making particles eventually fall downwards (-Y direction). You will have to find a suitable value of g through experimentation.

3. The speed can be taken to be 1 by default; if speed S key is invoked, then each particle is given arandom speed between 1 and N. This makes some particles fast, and others slow.

4. A particle will collide with the ground when its next Y position will take negative, and its X and Z are within the extents of the ground polygon. To simulate bouncing after a collision, you can simply change the sign of the Y field of the velocity vector (make it positive).

5. A particle will die when its Y position becomes less than some predetermined negative value. This happens when the particle bounces outside the area of the ground, and falls down the negative Y abyss.

6. There are 3 firing modes:

(a) By default, a constant stream of particles shoot out of the cannon.

(b) A manual firing option, so that when F is pressed, particles are shot. When F is released, particles cease. Note that you might need to limit the maximum number of active particles.

(c) Single shot mode — just fire 1 particle at a time, per key press.

7. Using another key, toggle a random spin mode to the particles in motion. This requires angle fields such as current angle (Ax,Ay,Az) and angle increments (dax,day,daz) in the particle record. Make sure you don’t get over- or under-flow with the angles, by assuring that angles are always between 0 to 360 degrees.

8. Add a friction mode in which particles lose momentum when they collide with the ground. Reduce the speed value by a set amount (eg. 10%). If a particle becomes stationary, kill it.

9. A reset key should reset the entire simulation to the initial configuration.

Options: Do 5 of the following. Do extras for a bonus marks (max 5 items extra for bonus).

10. Can you add trails to particles, like sparks, smoke, or…? Can alpha-blending give a smoke-like effect? 11. Make particles explode! This might happen after a random time span for the particle. It will involve keeping a state field (frame count?). When it is in an exploding state, you will replace the default particle record with new particle record(s), which will perform an exploding effect when rendered frame by frame. The remnants eventually die.

12. “Spray” mode. This controls the degree of randomness of directions assigned to new particles. It toggles between low spray (default, slightly randomness to initial direction) to high spray (wildly random).

13. Add a mode in which sparks are created from any collision of the particle with anything.

14.. Add normals to all visible surfaces. Then define lighting and materials for the scene.

15. Make your particles collide with objects on the ground. It will use a similar idea to ground collision, except that a minimum distance between the particle and object center will determine if a collision happens. (You should use “fast” squared distances). Friction should be applied during collisions.

16. Add textures to the surfaces.

17. Add a mode that lets the viewer’s eye be one of the particles.

18. Add a mode that gives particles different colours, sizes, and perhaps other unique behaviours.

19. A square hole sits on the ground. Particles will fall right through it.

20. Let particles collide with one another. Friction should be applied. Can you figure out how to make their collision detection efficient, and behave realistically?

21. Add sound FX!

23. Add your own idea!