Additional Hints for Gravity Well Assignment Recall the following: Most of the code will be inside the "darea" class. You need to make modifications to the "iroutine" procedure, which should initialize all data. You need to complete the definition of the "body" class. I've given you body::calcforce. You need to: write the body::updateposition() method, which changes the position of an object according to its velocity and UTIME value. That is, "xcord += xvel * UTIME", etc ... void body::updateposition() { xcord += xvel * UTIME; ycord += yvel * UTIME; zcord += zvel * UTIME; } write the constructor of the body class, which should create a body object with a given mass, radius and initial position. The initial velocity should be zero. body:: body(double m, int r, double x, double y, double z) { mass =m; radius = r; xcord = x; ycord=y; zcord = z; xvel = yvel = zvel = 0; } You then need to modify "animate", which should call boxworld routines for graphical rendering. This part may involve the writing of other methods as well. I will now show you, step by step, how to make an array of 2 objects interact with eachother. I will choose to use a static array. To make things interesting, you should use a dynamic array. 0. Re-download asn2.h from the class webpage for some modifications. Then define body::body (constructor) and body::updateposition() as explained above. 1. Declare array B in the darea class (do this in the header file): body *B[2]; Note that B is an array of pointers to body objects, but B is itself a statically allocated array. 2. Initialize the array in the darea::iroutine procedure. B[0] = new body(MEARTH,10,50*UDIST,50*UDIST,150*UDIST); B[1] = new body(MSUN,25,500*UDIST,50*UDIST,50*UDIST); I've just created one body with mass the size of the earth, and another the mass of the sun, with arbitrary initial coordinates. Notice that the coordinates are multiplied by UDIST, the scaling factor. That is, the calculations concerning gravity will be made with "real world" coordinates. However, when calling the drawing routines, they need to be converted back to screen coordinates. (this is not true of "radius", however). 3. Now, each time that the darea::animate method is executed, you need to compute the effect of gravity on each of these objects, then use the "box" object to render them graphically. Even though there are only 2 objects in our array, I will use loops for generality: ////////////////// Do some drawings: for (int m=0;m<2;m++) for(int n=0;n<2;n++) { if (m!=n) B[m]->calcforce(B[n]); } for(int m=0;m<2;m++) B[m]->updateposition(); // Render graphically: int x, y, z; for(int m=0;m<2;m++) { x = (int) (B[m]->xcord / UDIST); y = (int) (B[m]->ycord / UDIST); z = (int) (B[m]->zcord / UDIST); box.drawcircle(dbuffer,true,x,y,z,B[m]->radius,rgc); } ///////////////// The nested loop calculates the force between every pair of objects. That is, they change the velocity of the objects. The next loop updates the position of each object according to the cumulated force. The final loop draws the bodies as red circles at the coordinates, after scaling down these coordinates. If you find the simulation too slow, you can change the UTIME constant in the header file. You should also #define a constant instead of using a number like "2" as I did above. ----- Now, in order to simulate the gravity well, you should declare the following array, which arranges the body objects: body * grid[rows][cols]; You will have to experiment with the values for rows and cols. Each object in the grid should be initialized with coordinates that reflect its position in the grid. Forexample, the the x and y coordinates of grid[i][j] should be something like i*gap, j*gap, where "gap" is the distance you want between planets. Note that you should NOT replace the "B" array with this array, because then the "calcforce" computations will become needlessly complicated. Wrather, the grid array should point to the same objects as the "B" array. To draw the mesh, instead of drawing a circle for each body, you will need to draw a line between adjacent bodies. As gravity changes the positions of the bodies, these lines will also be changed, which will give you the 3D effect.