Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 4 ■ an IntroduCtIon to Game desIGn: Game desIGn ConCepts, Genres, enGInes, and teChnIques


3D Models: The Foundation of the Role-Playing Style of Gaming


One of the newer forms of electronic gameplay involves real-time rendered virtual worlds, thanks to the
advent of real-time rendering platforms such as OpenGL ES 3 and Vulkan, which are used in Android,
HTML5, JavaFX, and DirectX (DirectX is used in Microsoft products such as Xbox and Windows). 3D models
provide far more flexible, advanced, and photorealistic gameplay because they combine all of the other
new media types (except for digital audio) into one; because textures, materials, and shaders can use digital
imagery and digital video; and because 3D geometry mesh objects can use their actual geometry to calculate
collisions with the actual object, and in three dimensions instead of two on top of that. Add in the fact that
3D assets can react in real time to multiple lights and cameras, and you have a far more powerful game
design environment with i3D, albeit more complex from a mathematics and a Java coding standpoint.
Since 3D and i3D are so complex, there are a plethora of optimization considerations, such as
optimizing the mesh (geometry), a process called low-poly modeling that involves using points, edges, and
faces sparingly and then using smoothing groups to provide a smooth curvature that could also be achieved
simply by adding more geometry. I also covered some of the optimization principles of using fewer pixels,
lower color depth, and fewer channels that would be used for texture maps, which are images, in Chapter 2.
Similarly, for 3D animation, in Chapter 2 I covered some of the optimization principles that would be used
for animation data, which is similar to digital video, such as using fewer pixels, fewer frames, lower color
depth, and fewer channels, along with simpler interpolation algorithms.
Another optimization for 3D and i3D games has to do with the number of lights that are utilized to
light a virtual world. Light calculations tend to be expensive, so much so that most game engines, including
JavaFX, limit the number of allowed lights to eight or fewer. The fewer light objects you can use, the fewer
calculations the rendering engine will have to do and the higher frame rate (faster) your game will run at.
The same consideration would apply to cameras in 3D animation software. When you’re rendering out
to film, for instance, you can render out as many camera views of the scene as you need with no (real-time)
processor penalty. When a consumer electronics device is processing that 3D (versus a massive render
farm of workstations), it becomes important to minimize the number of cameras as each one is outputting
the equivalent of an uncompressed raw digital video data stream. In this situation you have a 3D rendering
engine generating another uncompressed 2D animation (video) asset in real time, which again takes up a
lot of your processing power, so use this only if your game absolutely requires a real-time Head’s Up Display
(HUD), for instance, for a real-time second gameplay perspective.


Collision Detection: The Foundation of Game Asset Interaction


Another important component, or aspect, of gameplay for some types of games is collision detection
because if your game elements simply flew right past each other on the screen and never did anything
cool when they touch, or “intersect” each other, then you really would not have much of a game! Imagine
a pinball game or billiards without any collision detection! Once you add a collision detection engine
comprised of intersection logic processing routines, your game will be able to ascertain when any 2D vector
sprites or 3D models are touching or overlapping each other by processing intersections of their component
geometry, usually edges, lines, curves, or their bounds (BoundingBox).
A collision detection will call (that is, trigger) related game logic processing routines that will ascertain
what happens when any given 2D sprites or 3D models, such as a projectile and the main character,
intersect. For instance, when a projectile intersects the main character, damage points might accrue, a life
force index might be decreased, or a death throes animation might be started. If a treasure item intersects
with (that is, is picked up by) a main character, on the other hand, power or capability points might accrue,
the life force index might be increased, or an “I found it” jubilation animation might be started.
As you can see, depending on the type of game you are creating, the collision detection engine for
the game could well be one of the foundational design elements behind your gameplay, besides your i2D
sprites or i3D models, which represent your characters, projectiles, treasures, enemies, obstacles, and props
themselves, which is why I’ve covered these in this order. Once a collision is detected, often your physics

Free download pdf