Games Development 2 Entity Update & Rendering CO3301 Week 2, Part 1.

Slides:



Advertisements
Similar presentations
Our Friend the Dot Product
Advertisements

Exploration of advanced lighting and shading techniques
Physics: Laws of Motion Soon Tee Teoh CS 134. Newtons Laws of Motion First Law: When there is no net force on an object, its velocity would remain the.
7.2. AI E NGINE AND S TEERING B EHAVIOUR I Design of an AI Engine and introduction to steering in game AI.
7.3. S TEERING B EHAVIOUR II Steering behaviours in game AI.
Blending & State Machines CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
CSE 380 – Computer Game Programming Pathfinding AI
Eyes for Relighting Extracting environment maps for use in integrating and relighting scenes (Noshino and Nayar)
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
CS 4731: Computer Graphics Lecture 19: Shadows Emmanuel Agu.
Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
CS 450: Computer Graphics 2D TRANSFORMATIONS
Week 1 - Friday.  What did we talk about last time?  C#  SharpDX.
Games Development 2 Entity / Architecture Review CO3301 Week
1 CO Games Development 1 Week 5 Deriving a "look at" function + Graph Theory Gareth Bellaby.
Introduction to 3D Computer Graphics and Virtual Reality McConnell text.
Collision and Animation Systems in Games Jani Kajala Lead Programmer / Chief Technology Officer, Pixelgene Ltd (0)
Games Development 2 Resource Management CO3301 Week 3.
Introduction to Networked Graphics Part 3 of 5: Latency.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Maths and Technologies for Games Quaternions CO3303 Week 1.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
+ Speed and Velocity Describing Motion Speed Just as distance and displacement have distinctly different meanings (despite their similarities),
Math / Physics 101 GAM 376 Robin Burke Fall 2006.
Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Submitted by: Giorgio Tabarani, Christian Galinski Supervised by: Amir Geva CIS and ISL Laboratory, Technion.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Games Development 2 Component-Based Entities
Maths & Technologies for Games Animation: Practicalities CO3303 Week 3.
Games Development 2 Review & Revision Strategy CO3301 End of Semester 1.
Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.
Games Development 2 Overview & Entity IDs and Communication CO3301 Week 1.
Games Development Game Architecture: Entities CO2301 Games Development 1 Week 22.
Advanced Computer Graphics Shadow Techniques CO2409 Computer Graphics Week 20.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
Point Sprites Course Information CVG: Programming 4 My Name: Mark Walsh Website: Recommended.
Emerging Technologies for Games Deferred Rendering CO3303 Week 22.
Chipmunk Physics Remember that we talked about this a bit when we did collision handlers for the space ship integration task (SpritesActionsPhysicsSound).
Sky Boxes and Vector Math 2 Course Information CVG: Programming 4 My Name: Mark Walsh Website:
Games Development 1 Review / Revision CO2301 Games Development 1 Semester 2.
Computer Graphics Basic Maths for Graphics in C++ CO2409 Computer Graphics Week 4.
Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.
Computer Graphics Matrices
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
Advanced Games Development Game Physics CO2301 Games Development 1 Week 19.
1 CO Games Development 1 Week 4 Finite State Machines + Maths Gareth Bellaby.
Graphics for Games Particle Systems CO2301 Games Development 1 Week 23.
In mathematics and physics, a specific form of measurement is used to describe revolution and fractions of revolutions. In one revolution, a point on.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 6 Examples 1,
The Stingray Example Program CMT3311. Stingray - an example 2D game May be useful as a simple case study Most 2D games need to solve generic problems.
CGDD 4003 Character Animation. The Skeletal Hierarchy (aka the “rig”) Based on the concept of bones Each bone has exactly one parent Each bone has a transform.
Game Engine Architecture
Computer Graphics Basic Maths for Graphics in C++
Scene Manager Creates and places movable objects like lights and cameras so as to access them efficiently, e.g. for rendering. Loads and assembles world.
Games Development 2 semester 1 Review & Revision
Deferred Lighting.
GAM 325/425: Applied 3D Geometry
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Steering behaviours in game AI
CO1301: Games Concepts Lecture 22 Particle Systems
Advanced Games Development Game Physics
Computer Graphics Material Colours and Lighting
CO Games Concepts Week 22 Particle systems
Games Development Game Architecture: Entities
Games Development 1 Review / Revision
Emerging Technologies for Games Review & Revision Strategy
Games Development 2 Entity / Architecture Review
Presentation transcript:

Games Development 2 Entity Update & Rendering CO3301 Week 2, Part 1

Entity Update Each entity (type) has a its own update function, which is called periodically –Maybe every frame –Perhaps less frequently in the case of distant, non-visible or less important entities The update function defines the entity behaviour: –Receive and process messages Update internal state based on these –Perform decision making / AI to decide what to do –Send messages to other entities –Perform movement & rotation –Set and play animations, update health, etc.

Scene Update to Entity Update Contrast use of entity update with our previous use of models in TL-Engine Models are just graphical - contain no behaviour Model behaviour was typically controlled in a single global “Scene Update” function –No attempt to encapsulate behaviour –Becomes a bloated, hard to maintain function Using entity-based Update is another shift of functionality towards a generalised game engine –However, we will retain “SceneUpdate” to do certain global update work, e.g. manage user/system input

Pros and Cons Using separate Entity Update functions: –Entity behaviour (code) and entity state (data) collected together within each entity and encapsulated for OO benefits –Easier to maintain in this form, especially for a team –Easier to comprehend behaviour of each entity type, wimpler to add scripted entity behaviour –However, overall game behaviour is distributed, can get unexpected interaction –Messaging between entities can be long-winded All behaviour in SceneUpdate: –Global function easy to find and work with –But ultimately clumsy and bloated – team unfriendly –Model state tends to become a set of globals

Entity Rendering We also give each entity a render function This is called every frame –Provided the entity is a renderable type and visible Typically, the entity passes its current position / animation / textures etc. to its entity template –The template class can render any one of its own entities given these specifics –Recall that the template stores the mesh This is fairly similar to model/mesh rendering

Pre / Post Rendering Modern engines often perform one or more passes of pre or post-rendering E.g. entities might have a PreRender function –Called for all (visible) entities prior to the main rendering calls Different purposes for different entities: –A models blends its animations to get the final matrices for rendering –Cameras calculate their view/projection matrix –Lights perform a shadow rendering pass (dynamic shadow mapping) –Many entities might do nothing

Games Development 2 Entity Update Example Targeting: Turning and Movement CO3301 Week 2, Part 2

Contents Forward Movement to a Target Turning –Dot product method –Turning Speed Acceleration / Deceleration Practicalities

Forward Movement to a Target Have an entity that needs to reach a target point However, the entity can’t move freely: –Has a forward velocity - can accelerate / decelerate –Can also turn –In a ground-based situation, can only turn left or right Like a car driving towards a target

Forward Movement to a Target Need an entity update function - each update we need to know: –Whether to turn left or right, and by how much –Whether to accelerate or decelerate Want to reach the target swiftly –But avoid excessively large turning circles –Worst case – circling around the target

Assumptions and Required Info To start, assume entity is on a 2D flat surface Need to know: –Entity position and target position –Entity local Z & X-axes (facing and rightward directions) Local X & Z axes can be found in world matrix –Or if local X unavailable: In 2D: If Z = (a,b), then X = (b, -a) in a left handed system In 3D: Use cross products (targeting - discussed elsewhere)

First normalise X & Z axes if necessary Then normalise vector from source to target (T) Consider angles α and β using dot products: Turning – Dot Product Method

First consider β, it can tell us which way to turn to face the target: –If β < 90° then target is to the right –If β > 90° the target is to the left Now when β 0, so: Turning – Dot Product Method

Now consider α, it indicates how much to turn to face the target Note: α will always be positive & so won’t indicate the direction (left/right) to rotate, hence the last slide cos -1 is the inverse cosine and can be performed in C++ using the acos function

Turning Overview Overview of this turning method: –Entity rotated around Y axis to turn towards the target –Get normalised vectors X, Z and T –Determine direction to rotate first: –Then determine angle to rotate to face target: –But should we rotate by α in the entity update?

Turning Speed No, we want to turn gradually to face the target –Don’t want to snap instantly to face it Set a maximum turn speed for the entity and limit turning in each update by this value –I.e. turn by min(turn speed, α ) –The turn speed can be a setting in the entity template Can consider angular acceleration / deceleration –Acceleration to max turn speed when starting to turn –Deceleration to 0 when almost facing target Similar to the movement acceleration / deceleration that follows

Acceleration / Deceleration When to accelerate and decelerate? Simple (breakneck) approach: –The stopping distance is the distance covered before stopping if we apply maximum deceleration –If entity is further from its target than stopping distance then apply maximum acceleration –Otherwise maximum deceleration If the current speed (not velocity) is s and max deceleration d, then: Stopping Distance = s 2 / 2d –Since average speed while stopping = s / 2 –And time to stop = s / d

Practicalities Use this method for static or dynamic tracking –When tracking a moving object, consider tracking a point in front of it (depending on its speed) Method needs tweaking: –Won’t target perfectly – so stop when within a certain range – use the length of the target vector –The stopping distance as given doesn’t quite match algorithm, should be s 2 / 2d – s / 2 Needs careful insertion into a timed game loop: –Only use update time when applying movement / turning, don’t alter angle / stopping distance formulae

Further Development This is a very basic method, which can easily be refined / altered for more realism: Angular acceleration / deceleration Decelerate to make a sharp turns (when α is large) –Adapt the acceleration algorithm to consider α Or even smarter acceleration / deceleration / maximum speed based on distance and manoeuvrability of target Adapt to 3D space – use cross products, see Space Game entity code shortly or Van Verth p39