790 likes | 808 Views
Explore system design, algorithms, and pseudo code in interactive game design. Understand game objects, animations, and input/output. Learn about geometric transformations and procedural animation.
E N D
Yingcai Xiao • Yingcai Xiao Interactive Game Design Final Overview
Monday, May 7th, 5:15 pm – 7:15 pmIn ClassroomClose Book When/Where
What • System/Algorithm Design • No aesthetic design • Concepts • Systems • Algorithms • Pseudo code (logic not syntax)
Coverage • All lecture notes • All assignments • Everything else covered in the class. • Thoroughly understand what you did in the assignments.
Video Game: Interactive animation Display Device Driver (GDI) Input Device Driver Game (Software)
Video Game: Interactive animation Similar to all other programs: data, algorithms, input, output. Data: Game Objects Algorithms: Animation Input: Interactive Events Output: Display
Game Objects (GO) GO = Geometry + Attribute
Yingcai Xiao Surface and Volume Representation of Game Objects
Game Objects (GO) Geometry: primitives: points, lines, triangles, polygons, spheres tetrahedrons, hexahedrons, … meshes: grids: elevation, uniform, rectlinear, structured, tin: triangular integrated network
Game Objects (GO) Geometry: meshes: indexed Analytical: planes, curves, surfaces, parametrical lines, curves, …
Parametric Form of a Line: • x(t) = x0 + t * (x1 – x0) • y(t) = y0 + t * (y1 – y0) • 0 <= t <= 1 • x(t) = (1-t) * x0 + t * x1 • y(t) = (1-t) * y0 + t * y1 • 0 <= t <= 1
Game Objects (GO) Geometry: Stroked: stroked primitives stroked free curves and surfaces composite: avatars, prefabs, packages, …
Elevation Gridorigin: 0,0,0spacing: 1,1,1dimension: 5, 5elevation:1,2,3,4,5,11, 12, 13, 14, 15,21, 22, 23, 24, 25,31, 32, 33, 34, 35,41, 42, 43, 44, 45 • Yingcai Xiao
Game Objects (GO) Conversions to indexed meshes:
Voxel-based Game Objects Voxelization: to partition a volume into connected voxels. Two types of voxelization: game objects game space
Voxelization of Game Space and GOs To partition a game space and GOs into connected voxels. Uniform Grid Rectlinear Grid Structured Grid Unstructured Grid
Uniform Grid • IJK space • x = i*dx + x0 • y = j*dy + y0 • z = k*dz + z0 • Data array (i, j, k), loop i first, then j, k last. • Simple, compact and speedy retrieval. • Not flexible
Rectlinear Grid • Dimension: nx, ny, nz • Nonuniform spacing, but straight grid lines. float x[44]={0.0,1.2,2.8,3.9…….} float y[33]={1.0,……………} float z[22]={0.8,……………}
Rectlinear Grid • IJK space. x = x[I]; y = y[J]; z = z[K]; • Data array (i, j, k), i changes first, then j, k last. • Simple • compact (takes O(nx +ny + nz) more space) • speedy retrieval • Little more flexible
Structured Grid • Dimension: nx, ny, nz • Nonuniform spacing • IJK space (no formula) • Coordinates of each grid node need to be given. x(I,J,K), y(I,J,K), z(I,J,K)
Indexed Volume / Surface • No dimensions parameters: nx, ny, nz • No IJK space • Coordinates of each node need to be given • Most flexible, can represent any structures • Easy to modify geometry, only need to change the point list. • Not compact (need space to save xyz values and cell information) • Slow retrieval
The Three Faces of Designing GO Appearance • The Artistic Face: • aesthetic – beautiful and ugly • done by artists • The Communication Face: • show and tell (convey a message) • done by communication experts • The Technical Face • the enabler (can or can’t), game engine design and development. • done by computer scientists
Attributes (Appearance) • Color • Shades • Texture • Transparency
Color • Gamma Correction • Dynamic Range • Color Models
Types of Gemtetric Transformations Rigid-body Transformation: T and R. change: location, orientation; not change: size, angle between elements. Affine Transformation: S, SH change: size, location, angle; not change: line (parallelism). Note: uniform scaling is between the two. It changes size but not angle. So far, our S, R, SH are all around the origin.
Procedural Morphing • Use scripts to change the geometry of game objects at run-time. • A demo in Unity3D to change the geometry of a plane to a wave form.
Demo in Unity3D • To change the geometry of a plane to a wave form. • Create a new project with Character Controller package. • Add a plane (GameObject->CreateOhters->Plane) • Scale it in the Inspector to 10X10 (in x and z). • Uncheck the Mesh Collider (in the Inspector) • Add a light (GameObject->CreateOhters->DirectionalLight) • Add a FPC (Project->Assets->StandardAssets->CharacterControllers->FirstPersonController, drag-and-drop it to Hierarchy.) • Move it up. (Change its y position in the Inspector to 11). • Add script to morph the plane (Plane->Inspector->AddComponent->NewScript->JavaScript) name it Wave. • Add the code on the next page to the Wave.js in Mono. • Build->Build All in Mono to make sure there is no compilation errors.
Demo in Unity3D (Wave) • #pragma strictfunction Start () { var mesh: Mesh = this.GetComponent(MeshFilter).mesh; var verts: Vector3[] = mesh.vertices; for (var v = 0; v < verts.Length; v++) { verts[v].y = Random.Range(0,10); } mesh.vertices = verts; mesh.RecalculateBounds(); mesh.RecalculateNormals(); this.gameObject.AddComponent(MeshCollider); }function Update () {}
Time-dependentCarpet Plots y(r,t) = A e-r-at cos(2π (r-Vt) /λ); r = sqrt ((x-x0)*(x-x0)+ (z-z0)*(z-z0)) P0(x0, y0, z0) : center of the wave A: amplitude of the wave V: velocity of the wave λ: wave length of the wave a: speed of decaying t = current time – time of impact (t0)
Yingcai Xiao • Yingcai Xiao EDP Scripting
EDP: Event-driven programmingApplication awaits in an idle state and responds to user requests by calling the corresponding even handlers. EDP • Yingcai Xiao
A menu in C++: char c; bool done = false; while(!done) { cout << “Please make your selection, q to end:” cin >> c; switch(c) { case “+”: add( ); break; case “-”: sub( ); break; case “q”: done = true; break; } } Event Loop Event Mapping & Event Dispatching Event Events Event Handler
Key Components of EDP • Events • Event loop • Event mapping • Event dispatching • Event handlers • All, but the handlers, are taken care of by the game engine and its underplaying graphics and OS platform.
EDP in Unity3D • Unity game engine supports EDP. • Download the EDP-Scripting project. • Open it with Unity3D and select scene1. • Object Cylinder and Terrain. • Note: animation1 was created using Unity GUI. • IGD5 script was created to do simulation. • Simulation is animation obeying certain rules, e.g., trajectory of a projectile.
EDP-Scripting Demo Coding • To create scripts: • Assets->Create->C# Script • Name it in the Assets Pane. public class Test:MonoBehaviour{ void Start () { /* initialization at the start of the application */} void Update ( ) { /* invoked at every frame of drawing */} }
using UnityEngine;using UnityEngine.UI;using System.Collections;public class IGD5 : MonoBehaviour { float time = 0; float threshold = 0.5f; bool isReady = true; bool isSimulate = false; int collisionCount = 0; public Vector3 speed = new Vector3(5,5,0); public GameObject score; // the text object for displaying score // Use this for initialization void Start () { } C# Code Example: IGD5.cs
//colision detection void OnCollisionEnter (Collision collision) { if (collision.gameObject.tag == "terrain") { collisionCount++; score.GetComponent<Text>().text = "Score : " + collisionCount; } } void simulationControl () { transform.position = new Vector3 ( //colision detection void OnCollisionEnter (Collision collision) { if (collision.gameObject.tag == "terrain") { collisionCount++; score.GetComponent<Text>().text = "Score : " + collisionCount; } } void simulationControl () { transform.position = new Vector3 ( transform.position.x + speed.x*Time.deltaTime, transform.position.y + speed.y*Time.deltaTime, transform.position.z); } C# Code Example: IGD5.cs
void Update () { if (!isReady) { if (time >= threshold) { isReady = true; time = 0; } else { time += Time.deltaTime; } } else void Update () { if (!isReady) { if (time >= threshold) { isReady = true; time = 0; } else { time += Time.deltaTime; } } else C# Code Example: IGD5.cs
{ if (Input.GetKey (KeyCode.G)) { if (gameObject.GetComponent<Rigidbody> ()) { gameObject.rigidbody.useGravity = !gameObject.rigidbody.useGravity; } else { gameObject.AddComponent<Rigidbody> (); } isReady = false; } else if (Input.GetKey (KeyCode.A)) { if (animation.isPlaying) gameObject.animation.Stop(); else gameObject.animation.Play (); isReady = false; } C# Code Example: IGD5.cs
else if (Input.GetKey (KeyCode.S)) { ///simulation isSimulate = !isSimulate; //on-off isReady = false; } } //Animation control if (isSimulate) simulationControl(); }} C# Code Example: IGD5.cs
Kinect for Windows Release date : November 2010 Kinect : natural user interface that provides real-time gesture recognition. Sensors: RGB camera and 3D depth sensor.
The Gang of Four OpenNI: a general-purpose framework for obtaining data from 3D sensors NITE: a skeleton-tracking and gesture-recognition library SensorKinect: the driver for interfacing with the Microsoft Kinect ZigFu: Unity Package (Assets and Scripts)
OpenNI • Production Nodes: • a set of components that have a productive role in the data creation process required for Natural Interaction based applications. • the API of the production nodes only defines the language. • The logic of data generation must be implemented by the modules that plug into OpenNI. • E.g. for a production node that represents the functionality of generating hand-point data, the logic of hand-point data generation must come from an external middleware component that is both plugged into OpenNI, and also has the knowledge of how to produce such data.
Yingcai Xiao • Yingcai Xiao Artificial Intelligence in Game Development