CO1301: Games Concepts Lecture 21 Timing + Quads + Numbers

Slides:



Advertisements
Similar presentations
16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.
Advertisements

9.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
22-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
COMP 175: Computer Graphics March 24, 2015
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
1 CO Games Concepts Week 20 Matrices continued Gareth Bellaby.
Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
CGMB214: Introduction to Computer Graphics
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
How a Computer Processes Information. Java – Numbering Systems OBJECTIVE - Introduction to Numbering Systems and their relation to Computer Problems Review.
Data Representation The storage of Text Numbers Graphics.
Point Sprites Course Information CVG: Programming 4 My Name: Mark Walsh Website: Recommended.
Sky Boxes and Vector Math 2 Course Information CVG: Programming 4 My Name: Mark Walsh Website:
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Computer Graphics Basic Maths for Graphics in C++ CO2409 Computer Graphics Week 4.
Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.
Basic Java Syntax Comments Basic data types Operators and assignment.
Graphics for Games Particle Systems CO2301 Games Development 1 Week 23.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Model Optimization Wed Nov 16th 2016 Garrett Morrison.
Computer Graphics Basic Maths for Graphics in C++
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
CO1301: Games ts 2015 Lecture 6 Vectors Dr Nick Mitchell (Room CM 224)
Topics Designing a Program Input, Processing, and Output
Week 7 - Wednesday CS361.
Lesson #6 Modular Programming and Functions.
Lesson #6 Modular Programming and Functions.
Image-Based Rendering
Object Oriented Programming
Assignment and Arithmetic expressions
Place Value and Mental Calculation
Modified from Sharon Guffy
Deferred Lighting.
Data Structures Mohammed Thajeel To the second year students
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Topic 3d Representation of Real Numbers
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Lesson #6 Modular Programming and Functions.
Common Classification Tasks
Fitting Curve Models to Edges
CS1S467 GUI Programming Lecture 3 Variables 2.
CO1301: Games Concepts Lecture 13 Basic Trigonometry
07/12/2018 Starter L.O. To be able to Solve a quadratic by factorising
KS4 Mathematics A6 Quadratic equations.
Variables Title slide variables.
EEL 3705 / 3705L Digital Logic Design
Games Development Practices Sound Effects
CO1301: Games Concepts Lecture 22 Particle Systems
Chapter 3 Operators and Expressions
Lesson #6 Modular Programming and Functions.
Continuous Growth and the Natural Exponential Function
SSEA Computer Science: Track A
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Introduction to Primitives
Introduction to Primitives
Floating Point Numbers
Computer Graphics Introduction to Shaders
CO Games Concepts Week 12 Collision Detection
Topic 3d Representation of Real Numbers
CO Games Concepts Week 22 Particle systems
Using billboards within games
Animation Translation.
Week 11 - Monday CS361.
Presentation transcript:

CO1301: Games Concepts Lecture 21 Timing + Quads + Numbers Dr Nick Mitchell (Room CM 226) email: npmitchell@uclan.ac.uk Material originally prepared by Gareth Bellaby

Topic 1: Timing The use of an absolute value for movement each frame is obviously flawed - the speed of your game depends on the speed of the computer. Things would get much worse if you introduced any more complex calculations which require time, e.g. acceleration. The solution is to take time into account.

Games Development 1 There are different ways to accomplish timing We are just introducing one approach in this module. More detail next year with Laurent. See Games Development 1, Week 14: "Overview, Timing and the Game Loop". In this module you are using the variable time approach.

Variable Time The approach is to discover how long it took the last frame to render. Adjust the timings in the current frame. The TL-Engine has a command Timer() Timer() returns the amount of time in seconds since it was last called. Call it once per frame: at the beginning of the frame before you do any processing. This obtains the frame time. The frame time is the time taken to process 1 frame. Frames per second (FPS) or frame rate is: frame rate = 1 / frame time

Variable Time Need to multiply all time dependent variables through by the adjustment. Movement is a dependent variable. So it rotation, so is acceleration... There may well be others. Measure everything in units per second. Record the frame time (the time taken to render the previous frame). Multiply all measurements by the frame time.

Variable Time Example An object is moving at a velocity of 5 units per second. A particularly slow computer takes 0.1 seconds to render a frame. The frame time is 0.1 seconds. movement = 5 * 0.1 = 0.5 The object moves 0.5 units per frame. Each frame takes 1/10th second to render. So over the course of 1 second it will indeed move 5 units.

Variability The timing is maintained between computers. The slow computer takes 0.1 seconds to render a frame. A faster machine takes 0.02 seconds to render it. On the slow machine the frame time is 0.1 5 * 0.1 = 0.5 units per frame One the faster machine the frame time is 0.02 5 * 0.02 = 0.1 units per frame

Variability The slower machine renders 1 frame for every 5 frames of the faster machine so the object moves the same distance in the same time on both machines. The method copes with variability of frame processing. Our calculations will always be relative to the amount of time taken to render the previous frame, with the measurement taken at the beginning of the current frame, therefore uneven timing will be automatically dealt with.

Units The 3D world has abstract units built into it. We talk about moving 1 unit per frame. However, the units could represent anything. A unit could be 1 centimetre, 1 metre, 1 kilometre, and so on. It is necessary to decide what units you are working in. The modelling packages also set up measurements and this will allow you to determine speeds, distances, etc. It particularly important when talking about velocities, acceleration, etc. in your program.

Topic 2: Quads Short for "quadrilateral”: A four sided polygon. "Quad" is a common phrase for a simple rectangle. It is the simplest 4 sided polygon. A quad has no depth. A quad is made up of two triangles.

Quads A simple shape which can be constructed on-the-fly on the CPU or GPU. A texture can mapped onto the quad. Not to be confused with a sprite. A sprite is a 2D image. Uses screen coordinates. It is separate from the 3D world.

Billboards Quads can be used for "billboards". A billboard is a simple technique whereby a 2D texture painted onto a quad and used to give the illusion of 3D. One use is a set of billboards placed in a pattern in order to give the illusion of "bulk" or complexity e.g. a complex object such as the twigs and leaves of a tree. The example on the next slide is from GTA IV. The quads will placed on different planes.

Billboards

Billboards Billboards can also be used for imposters. A 2D model is used in place of a 3D model, e.g. the billboarding for trees in the distance or for clouds. In this case the quad is always oriented towards the camera.

Imposters

Particle systems Billboards are also used for particle systems. A particle system is a graphics technique in which an effect is modelled as a set of discrete particles, e.g. fire, smoke, rain. A particle system is typically made up of lots of particles (hundreds, even millions). It is expensive to render so many 3D models. Typically billboards are used instead. The quad is always oriented towards the camera and so the illusion of depth and 3 dimensionality is maintained. The number of particles means that duplication goes unnoticed.

Particle systems "Building a Million Particle System", Lutz Latta http://www.2ld.de/gdc2004/MegaParticlesSlides.pdf

Note This approach is being superseded and modified. DirectX now has "point sprite" as a primitive type. A point sprite is a quad generated on-the-fly on the graphics card. Increased processing power means that billboarding is less necessary. Techniques such as "instancing" used in place of (or alongside) billboards.

Topic 3Numbers Mathematics distinguishes between several types of number: Natural Numbers (non-negative whole numbers) 0,1,2…, only positive numbers Integers 0,1,-1,2,-2,3,-3…, (+ve or -ve whole numbers) Real numbers 0.02, -3.455, 124.0, 0.33333, any number written with a decimal point (possibly infinitely long) As well as others… A single number (in any form) is called a scalar .

Numbers in C++ Equivalent types of number in C++: int - integers (+ve or –ve) unsigned int - whole numbers (+ve only) float - real numbers Each type has finite storage Exact amount depends on the compiler They have limitations not present in maths: Maximum and minimum values e.g. typical int (4-bytes) has max/min of ±2 billion So large values may be out of range for an int

Floating point concerns Floating point numbers cannot all be accurately represented. The float and double data types rarely hold exactly the numbers you assign or would expect them to. Calculations can cause difference to magnify i.e. error propagation. Difference will be greater for larger values. Never use ==, except for small integers.

Test against zero Always assume a margin of error, e.g. test against a range: -epsilon < x < epsilon, where epsilon is a small number. For example, a test against zero. const float kfEpsilon = 0.5e-6f; bool IsZero( const float x ) { return fabs( x ) < kfEpsilon; }

Number conversion C++ can automatically convert number types But doesn’t always: 5 / 10 = 0, Correct: The compiler usually issues a warning when it does perform a conversion, e.g. Don’t ignore warnings – ensure it is what you want float / double are rounded down to int f = 5.0 / 10.0; // Correct int i = 9.0/10.0; // Warning likely (i = 0)

Number conversion To round to the nearest int: N.B. 0.5 is a double, 0.5f is a float In order to convert number types you use casting. The modern C++ casting style is: int NearInt = MyFloat + 0.5f; float f = static_cast<float>(MyInteger);