<< Chapter < Page Chapter >> Page >

The program named GM01test04

This animation program is designed to exercise many of the 2D features of the GM01 game-math library. The animation is generally based on the idea of a flocking behavior similar to that exhibited by birds and fish. A set of GM01.Point2D objects is created with random locations to act as predators. An additional GM01.Point2D object is also created to play the part of a prey object.

The prey object is drawn in red while the predators are drawn in black asshown in Figure 2 . An algorithm is executed that attempts to cause the predators to chase the prey object without colliding with one another.

Even though the algorithm causes the predators to chase the prey object, it also tries to keep the predators from colliding with the prey object.

The user input GUI

A GUI is provided that contains an input text field for the number of predators plus a Start button and a Stop button. The GUI also contains check boxes that allow the user to elect to display points only,direction vectors only, or both. (Both the point and the direction vector is always displayed for the prey object.)

The user specifies the number of randomly-placed predators and clicks the Start button, at which time the animation begins and the predators start chasing the prey object. Prey-object motion is random.

The animation continues until the user clicks the Stop button. The user can click the Stop button, change any of the input parameters, and then click the Start button again to re-start the animation with different parameters such as the number of predator objects.

Swimming in formation

An unexpected result is that the algorithm seems to cause the predators to come together and swim in formation while chasing the prey object. The mostcommon formation is hexagonal as shown in Figure 9 , which shows 12 predators swimming in a hexagonal formation.

(Note that some of the twelve predators are hidden by other predators.)

Figure 9 Twelve predators swimming in a hexagon formation in GM01test04.

Missing image.

Other formations appear as well

Some triangles, diamonds, and incomplete hexagons also appear. For example, Figure 10 shows six predators swimming in a diamond formation.

Figure 10 Six predators swimming in a diamond formation.

Missing image.

No explanation for this behavior

I haven't given the matter a lot of thought, but at this point, I have no explanation for this behavior. Note that the tendency to swim in formation ismore visually obvious when only the points are displayed. When the vectors are displayed, it is more difficult to pick out the formation.

Dogged determination

On the other hand, the animation is most impressive when the direction vectors are displayed, with or without points, because the vectors illustratethe dogged determination and undying focus that the predators maintain while chasing the prey object.

Won't explain the code

Once you understand the code in the program named GM01test08 that I explained earlier in this module, you should have no difficulty understandingthe code in this program. Therefore, I won't explain the code in this program. I included this program in this module mainly to illustrate the differencesbetween 2D and 3D from both a visual and programming viewpoint.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask