# 3D Game Development Terminology

Before you start, make certain you are familiar with the following concepts and terminology.

# 3D Graphics and Audio

OpenGL is the Open Graphics Library, a platform-independent specification for rendering 2D/3D computer graphics. For Java, there are two implementations of OpenGL-based renderers:

1. Lightweight Java Game Library (LWJGL)
2. Java OpenGL (JOGL)

OpenAL is the Open Audio Library, a platform-independent 3D audio API.

# Context, Display, Renderer

The jME Context makes settings, renderer, timer, input and event listeners, display system, accessible to a JME game.

- The jME Display System is what draws the custom JME window (instead of Java Swing).
- The input system is what lets you respond to user input via mouse, keyboard, and joystick.
- The renderer is what does all the work of calculating how to draw the 3D scenegraph to the 2D screen.
  - The Shader is a programmable part of the rendering pipeline. The jME3 game engine uses it to offer advanced customizable materials.

# Geometry

## Coordinates

Coordinates represent a location in a coordinate system, relative to the origin (0,0,0). m. In 3D space, you need to specify three coordinate values to locate a point: x,y,z. As opposed to a vector (which looks similar), a coordinate does not have a "direction".

### The Origin

The origin is the central point in the 3D world. It's at the coordinates (0,0,0). Code sample: `Vector3f origin = new Vector3f( Vector3f.ZERO );`

## Vectors

A vector has a length and a direction. It is used like an arrow pointing at a point in 3D space. A vector starts at the origin (0,0,0), and ends at the target coordinate (x,y,z). Backwards directions are expressed with negative values. Code sample: `Vector3f v = new Vector3f( 17 , -4 , 0 );`

### Unit Vectors

A unit vector is a basic vector with a length of 1 world unit. Since its length is fixed (and it thus can only point at one location anyway), the only interesting thing about this vector is its direction.

- `Vector3f.UNIT_X` = ( 1, 0, 0) = right
- `Vector3f.UNIT_Y` = ( 0, 1, 0) = up
- `Vector3f.UNIT_Z` = ( 0, 0, 1) = forwards
- `Vector3f.UNIT_XYZ` = 1 wu diagonal right-up-forewards

### Normalized Vectors

A normalized vector is a custom unit vector. A normalized vector is not the same as a (surface) normal vector. When you normalize a vector, it still has the same direction, but you lose the information where the vector originally pointed. For instance, you normalize vectors before calculating angles.

### Surface Normals

A surface normal is a vector that is perpendicular to a plane. You calculate the Surface Normal by calculating the cross product.

### Cross Product

The cross product is a calculation that you use to find a perpendicular vector (an orthogonal, a "right angle" at 90°). In 3D space, speaking of an orthogonal only makes sense with respect to a plane. You need two vectors to uniquely define a plane. The cross product of the two vectors, `v1 × v2`, is a new vector that is perpendicular to this plane. A vector perpendicular to a plane is a called Surface Normal. Example: The x unit vector and the y unit vector together define the x/y plane. The vector perpendicular to them is the z axis. JME can calculate that this equation is true:
`( Vector3f.UNIT_X.cross( Vector3f.UNIT_Y ) ).equals( Vector3f.UNIT_Z )` == true

## Polygon, Mesh, Vertex

Most visible objects in a 3D scene are made up of polygon meshes – characters, terrains, buildings, etc. A mesh is a grid-like structure that represents a complex shape. The advantage of a mesh is that it is mathematically simple enough to render in real time, and detailed enough to be recognizable. Every shape is reduced to a number of connected polygons, usually triangles; even round surfaces such as spheres are reduced to a grid of triangles. The polygons' corner points are called vertices. Every vertex is positioned at a coordinate, all vertices together describe the outline of the shape. You create 3D meshes in tools called mesh editors, e.g in Blender. Learn more about 3D maths here.

# Materials: Color, Lighting/Shading

What we call "color" is merely part of an object's light reflection. The onlooker's brain uses shading and reflecting properties to infer an object's shape and material. Factors like these make all the difference between chalk vs milk, skin vs paper, water vs plastic, etc! (External examples)

## Color

### Ambient color

- The uniform base color of the mesh – what it looks like when not influenced by any light source.
- Usually similar to the Diffuse color.
- This is the minimum color you need for an object to be visible.

### Diffuse color

- The base color of the mesh plus shattered light and shadows that are caused by a light source.
- Usually similar to the Ambient color.

## Light Sources

### Emissive color

- The color of light emitted by a light source or glowing material.
- Only glowing materials such as lights have an emissive color, normal objects don't have this property.
- Often white (sun light).

## Reflections

### Shininess

- Degree of shininess of a surface (0-128).
- Shiny objects have small, clearly outlined specular highlights. (E.g. glass, water, silver)
- Normal objects have wide, blurry specular highlights. (E.g. metal, plastic, stone, polished materials)
- Uneven objects are not shiny and have no specular highlights. (E.g. cloth, paper, wood, snow)

### Specular Color

- If the material is shiny, then the Specular Color is the color of the reflected highlights.
- Usually the same as the emissive color of the light source (e.g. white).
- You can use colors to achieve special specular effects, such as metallic or iridescent reflections.
- Non-shiny objects don't use a specular color.

# Materials: Textures

Textures are part of Materials. In the simplest case, an object could have just one texture, the Color Map, loaded from one image file. When you think back of old computer games you'll remember this looks quite plain. The more information you (the game designer) provide additionally to the Color Map, the higher the degree of detail and realism. Whether you want photo-realistic rendering or "toon" rendering (Cel Shading), everything depends on the quality of your materials and texture maps. Modern 3D graphics use several layers of information to describe one material, each layer is a Texture Map.

## Texture Maps

### Color Map

- A simple image file (or a procedural texture).
- The image can have alpha channels for transparency.
- A color map is the minimum texture you need. All other texture maps are optional improvements.

### Diffuse Map

- The Diffuse Map specifies the intensity of color.
- Its basically the same as a Color Map but its called Diffuse Map in a lighting environment, as it defines the color the object "diffuses".

### Bump Map

Bump maps are used to describe detailed shapes that would be too hard or simply too inefficient to sculpt in a mesh editor. You use Normal Maps to model cracks in walls, rust, skin texture, or a canvas weave. You use Height Maps to model whole terrains with valleys and mountains.

#### Height Map

- A height map is a grayscale image looking similar to a terrain map used in topography. Brighter grays represent higher areas and darker grays lower areas.
- A heightmap can represent 256 height levels and is mostly used to roughly outline terrains.
- You can draw a heightmap by hand in any image editor.

#### Normal Map

- A well-done Normal Map makes a shape more detailed–without the need to add costly polygons to the mesh. It contains shading information that makes the object appear smoother and more fine-grained.
- The Normal Map is displayed looking like a false-color version of the Color Map–but it is never used for coloring, instead, each RGB value encodes transformation data. This displacement data is represented by Surface Normals of the slopes, hence the name.
- It's hard to draw normal maps by hand. Generally you use software tools to calculate them off 3D models.

### Specular Map

- A Specular Map further improves the realism of an object's surface: It contains extra information about shininess and makes the shape appear more realistically illumated.
- Start out with a gray value that corresponds to the average shininess/dullness of this material. Then add ligher grays for smoother, shinier, more reflective areas; and darker grays for duller, rougher, worn-out areas. The resulting image file looks similar to a grayscale version of the Color Map.
- You can use colors in a specular map to create certain reflective effects (iridiscence, metallic).

## Seamless Tiled Textures

This is a very simple, commonly used type of texture. When texturing a wide area (e.g. walls, floors), you don't create one huge texture, instead you tile a small texture repeatedly to fill the area. A seamless texture is an image file that has been designed so that it can be used as tiles: The right edge matches the left edge, and the top edge matches the bottom edge. The onlooker cannot easily tell where one starts and the next one ends, thus creating an illusion of a huge texture. The downside is that the tiling becomes painfully obvious when the area is viewed from a distance. Also you cannot use it on more complex models such as characters.

## UV Maps

Creating a texture for a cube is easy – but what about a character with a face and extremities? For more complex objects, you design the texture in the same ways as a sewing pattern: One image file contains the outline of the front, back, and side of the object, next to one another. Specific areas of the flat texture (UV coordinates) map onto certain areas of your 3D model (XYZ coordinates), hence the name UV map. Getting the seams and mappings right is crucial: You will have to use a graphic tool like Blender to create UV Maps. It's worth the while to learn this, UV mapped models look a lot more professional.

## Environment Maps

Environment Maps are used to create the impression of reflections and refractions. You create a Cube Map to represent your environment, similar to a skybox. (Sphere Maps are possible, but often look too distorted.) You give the Cube Map a set of images showing a "360° view" of the completed scene. The renderer uses this as base to texture the reflective surface. Of course these reflections are static and not "real", e.g. the player will not see his avatar's face reflected, etc… But they cause the desired "glass/mirror/water" effect, and are fast enough to render in real usecases, it's better than nothing.

## MIP Map Texture

You provide the texture in two or three resolutions to be stored in one file (MIP = "multum in parvo" = "many in one"). Depending on how close (or far) the camera is, the engine automatically renders a more (or less) detailed texture for the object. Thus objects look smooth from close up, but don't waste resources with unspottable details when far away. Good for everything, but requires more time to create and more space to store textures.

## Procedural Textures

A procedural texture is generated from repeating one small image, plus some pseudo-random, gradient variations (Perlin noise). Procedural textures look more natural than static rectangular textures, for instance, they look less distorted on spheres. On big meshes, their repetitiveness is much less noticable than tiled seamless textures. Procedural textures are ideal for irregular large-area textures like grass, soil, rock, rust, and walls. See also: jMonkeyPlatform NeoTexture plugin See also: Creating Materials in Blender, Blender: Every Material Known to Man

# Animation

In 3D games, Skeletal Animation is used for animated characters, but in principle the skeleton approach can be extended to any 3D mesh (for example, an opening crate's hinge can be considered a joint). Unless you animate a 3D cartoon, realism of animated characters is generally a problem: Movement can look alien-like mechanical or broken, the character appears hollow, or as if floating. Professional game designers invest a lot of effort to make characters animate in a natural way (including motion capturing).

## Rigging and Skinning

An animated character has an armature: An internal skeleton (Bones) and an external surface (Skin). The Skin is the visible outside of the character and it includes clothing. The Bones are not visible and are used to interpolate (calculate) the morphing steps of the skin. JME3, the game engine, only loads and plays your recorded animations. You must use a tool (such as Blender) to set up (rig, skin, and animate) a character.

1. Rigging: The Construction of a character's skeleton.
   - Create as few Bones as possible to decrease complexity.
   - Bones are connected in a parent-child hierarchy: Moving one bone can pull another bone with it (e.g. arm pulls hand).
   - Bones follow a certain naming scheme so the 3D engines know what's what.
2. Skinning: The association of individual bones with the corresponding skin sections.
   - Each Bone is connected to a part of the Skin. Animating the (invisible) Bone pulls the (visible) Skin with it.
     E.g. the thigh Bone is connected to the upper leg Skin.
   - One part of the Skin can be affected by more than one bone (e.g. knee, elbow).
   - The connection between bones and skin sections is gradual: You assign weights how much each skin polygon is affected by any bone's motion.
     E.g. when the thigh bone moves, the leg is fully affected, the hips joints less so, and the head not at all.
3. Keyframe Animation: A keyframe is one recorded snapshot of a motion sequence.
   - A series of keyframes makes up one animation.
   - Each model can have several animations. Each animation has a name to identify it (e.g. "walk", "attack", "jump").
   - You specify in your game code which keyframe animation to load, and when to play it.

## Kinematics

- Forward kinematics: "Given the angles of all the character's joints, what is the position of the character's hand?"
- Inverse kinematics: "Given the position of the character's hand, what are the angles of all the character's joints?"

## Controller and Channel

In the JME3 application, you register animated models to the Animation Controller. The controller object gives you access to the available animation sequences. The controller has several channels, each channels can run one animation sequence at a time. To run several sequences, you create several channels, and run them in parallel.

# Artificial Intelligence (AI)

Non-player (computer-controlled) characters (NPCs) are only fun in a game if they do not stupidly bump into walls, or blindly run into the line of fire. You want to make NPCs "aware" of their surroundings and let them make decisions based on the game state – otherwise the player can just ignore them. The most common use case is that you want to make enemies interact in a way so they offer a more interesting challenge for the player. "Smart" game elements are called artificially intelligent agents (AI agents). An AI agent can be an NPC, but also an "automatic alarm system" that locks doors after an intruder alert, or a trained pet. The domain of artificial intelligence deals, among other things, with:

- Knowledge – An agent only "knows" what it can "see and hear", this implies that things can be hidden from it. You can make a group of agents share knowledge (e.g. guards with two-way radios know, other guards don't know about the intruder).
- Goal Planning – The agent has a priority to achieve a specific goal (a future state). It splits the goal into subgoals, determines tactics and strategies, and prioritizes them. The agent keeps testing whether the current state is closer to the (sub)goal. If unsuccessful, the agent changes the tactics/strategy. E.g. Finding the best path to reach a target in a changing environment.
- Problem solving – The agent uses a given set of facts and rules to deduct what state it is in. In every state, only a certain subset of reactions makes sense. The actual decision depends on the agent's goal. Examples: If target in range, attack or protect base or raise alarm. If idle, lay traps or heal oneself or recharge ammunition. If floor on fire, then danger. If danger, escape or kamikaze.

There are lots of resources explaining interesting AI algorithms:

- A* (A-Star) pathfinding for beginners
- A* (A-star) pathfinding theory
- "Z-Path" algorithm (backwards pathfinding)
- Goal-Oriented Action Planning
- Java Neural Networks
- …

view online version