<< Chapter < Page Chapter >> Page >

Figure 2 Screen shot of the graphic output from GM01test04.

Missing image.

Figure 3 Screen shot of the graphic output from GM01test03.

Missing image.

I included these two programs in this module primarily to provide a good comparison between 2D and 3D, both from a programming viewpoint and a behaviorviewpoint.

Eight predator objects and one prey object

In both versions shown in Figure 2 and Figure 3 , you see eight predator objects (colored black) pursuing a red prey object. The actual length of every predator object is the same as the length of every other predator objectand the length of the prey object is the same as the length of the predator objects.

Some significant differences

At first glance, the two versions may look the same. However, they are significantly different. In Figure 2 , the prey and the predators are constrained to move in a single plane. Hence, the apparent length of each predator is thesame as the length of every other predator and is also the same as the length of the prey regardless of the direction in which the object is moving.

However, in Figure 3 , the predators and the prey are free to move in any direction in a 3D world. As a result, at any point in time, the objects may bemoving parallel to or at an angle to the x-y plane. When the 3D world is projected onto the viewing plane, those objects that are moving at an angle tothe viewing plane will be foreshortened. In the extreme case, (as shown earlier in Figure 1 ) , when an object is moving directly toward or directly away from the viewer, its apparent length will go to zero. (At least one predator is almost in that state in Figure 3 .)

In Figure 3 the apparent lengths of the predator and prey objects are all different indicating that they are all moving in slightly different directionsin the 3D world.

The flocking algorithms in these two programs are much simpler than the algorithm used in Figure 1 . I encourage you to experiment with the flocking algorithms for these two programs to see what you can produce that is new anddifferent from my version of the two programs.

StringArt04

The fourth program named StringArt04 is completely different from the other three programs. In a previous module, I presented and explained a programthat rotates a disk around an arbitrary anchor point in 3D space with the ability to rotate by different angles around each of the three axes. It can bevery difficult to visualize exactly what is happening with such complexrotations. This program animates the rotation process and runs it in slow motion so that you can see exactly what is happening as the disk moves and rotates fromits initial position and orientation to its final position and orientation.

For example. set the values as follows, click the Animate button, and watch the rotations take place.

  • Number Points = 24
  • Number Loops = 10
  • Rotate around Z (deg) = 360
  • Rotate around X (deg) = 360
  • Rotate around Y (deg) = 360
  • X anchor point = 50
  • Y anchor point = 0
  • Z anchor point = 0

This should give you a good idea as to the process. Then change the parameters to other values, click the button, and observe the results.

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