Cs408 assignment 5 - create a program to display a 2d view


Create a program to display a 2D view of grid-based simulation of gas moving in a flat space. See on-line notes on Gaseous Phenomena. The method for performing simulation of gaseous phenomena is explained in the "Explanation of Gas Simulation Program".

https://www2.cs.uregina.ca/~anima/408/Notes/Gas/index.htm

For your program, you will need to create a graphical display of a grid (large 2D array), by displaying each location as a rectangle of some colour. The colours are used to represent density. Although you may choose your own colouring scheme, the following way of setting the R, G, B colour components gives a nice display where high densities correspond to bright colours.

R = density
G = density * density * 0.05
B = density * density * density * 0.0001

The size of the grid should be controlled by symbolic constants. Initially, try 200 x 200. Each cell in the grid is drawn as a rectangle (GL_QUAD). Use a double ‘for' loop to display 200 x 200 rectangles. It is straightforward to calculate the x and y locations of each rectangle. Use an orthogonal projection, rather than the usual perspective projection, by replacing the gluPerspective command with a
gluOrtho2D(0, WIDTH, 0, HEIGHT);

In your program you should choose some way of representing the current simulation state, which has a current density for each cell and a current (x, y) velocity for each cell. You can use three 2D arrays or one 2D array of structs or classes, or any other way of structuring your data that you want. You will also require an identical set of values for the previous state of the simulation.

To initialize the simulation, set all densities and velocities to zero (0). Every cell should have a 1/20 chance of having some nonzero amount of gas in it. If there is gas, choose a random mass for it between 0 and 100 and random initial velocity, with x and y each between -3.0 and +3.0.

During each simulation step, you will have an old grid and a new grid. Here is a simple approach. Initially set every cell in a new grid to zero. Go through the old grid cell by cell. For each cell, calculate where the given amount of gas (as expressed by its density) should move according to the current velocity recorded for the cell. Update the corresponding four cells in the new grid by changing their densities and velocities. After updating is complete, display the new grid. Then set the old grid to the new grid and repeat. This approach is described in the "Explanation of Gas Simulation Program".notes.

For your program, increase efficiency by avoiding copying the new grid to the old grid at the end of each frame. Instead of doing this copying, you can simply switch which grid you are using for each purpose. One way of doing so is to have two grids in a 2-element array instead of having an old grid and a new grid. For frame i, use grid [i % 2] as the old grid and grid [1 - i % 2] as the new grid.

Creative Feature: Add a creative feature of your choice to your simulation at least 1/5 as large in scope as the above features. Several ideas may result from thinking about which aspects of the users might want to change at runtime.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Cs408 assignment 5 - create a program to display a 2d view
Reference No:- TGS02247360

Expected delivery within 24 Hours