CSCE 552 Spring 2011 Math By Jijun Tang. Languages C/C++ Java Script: Flash, Python, LISP, etc. C# XNA for PC and Xbox.

Slides:



Advertisements
Similar presentations
CS 450: COMPUTER GRAPHICS LINEAR ALGEBRA REVIEW SPRING 2015 DR. MICHAEL J. REALE.
Advertisements

Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin.
Trigonometry A brief review. 1.4 Trigonometry.
Chapter 3 Vectors.
Maths for Computer Graphics
How do games work? Game Workshop July 4, Parts Sprites/pictures Map/background Music/sounds Player character Enemies Objects.
Chapter 4.1 Mathematical Concepts
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
CSCE 590E Spring 2007 Game Architecture and Math By Jijun Tang.
1 Geometry A line in 3D space is represented by  S is a point on the line, and V is the direction along which the line runs  Any point P on the line.
Now Playing: My Mathematical Mind Spoon From Gimme Fiction Released May 10, 2005.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Computer Graphics CSC 630 Lecture 2- Linear Algebra.
CSci 6971: Image Registration Lecture 2: Vectors and Matrices January 16, 2004 Prof. Chuck Stewart, RPI Dr. Luis Ibanez, Kitware Prof. Chuck Stewart, RPI.
Chapter 2: Vectors Ian Parberry University of North Texas Fletcher Dunn Valve Software 3D Math Primer for Graphics and Game Development.
Copyright © 2014 John Wiley & Sons, Inc. All rights reserved.
Chapter 3.6 Game Architecture. 2 Overall Architecture The code for modern games is highly complex With code bases exceeding a million lines of code, a.
Chapter 3.4 Programming Fundamentals. 2 Data Structures Arrays – Elements are adjacent in memory (great cache consistency) – They never grow or get reallocated.
Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
Vectors and scalars A scalar quantity can be described by a single number, with some meaningful unit 4 oranges 20 miles 5 miles/hour 10 Joules of energy.
Vectors and Scalars Vector and scalar quantities Adding vectors geometrically Components Unit Vectors Dot Products Cross Products pps by C Gliniewicz.
Chapter 3: VECTORS 3-2 Vectors and Scalars 3-2 Vectors and Scalars
VECTORS AND THE GEOMETRY OF SPACE Vectors VECTORS AND THE GEOMETRY OF SPACE In this section, we will learn about: Vectors and their applications.
Scalar and Vector Fields
Matrices and Determinants
VECTORS AND THE GEOMETRY OF SPACE 12. VECTORS AND THE GEOMETRY OF SPACE So far, we have added two vectors and multiplied a vector by a scalar.
2IV60 Computer Graphics Basic Math for CG
Basics of Linear Algebra A review?. Matrix  Mathematical term essentially corresponding to an array  An arrangement of numbers into rows and columns.
Chapter Languages, Programming and Architecture.
Mathematical Fundamentals
Phys211C1V p1 Vectors Scalars: a physical quantity described by a single number Vector: a physical quantity which has a magnitude (size) and direction.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Graphics CSE 581 – Interactive Computer Graphics Mathematics for Computer Graphics CSE 581 – Roger Crawfis (slides developed from Korea University slides)
6.837 Linear Algebra Review Patrick Nichols Thursday, September 18, 2003.
1 February 24 Matrices 3.2 Matrices; Row reduction Standard form of a set of linear equations: Chapter 3 Linear Algebra Matrix of coefficients: Augmented.
Patrick Nichols Thursday, September 18, Linear Algebra Review.
Chapter 4.1 Mathematical Concepts
Vectors and the Geometry of Space
Vectors. Vectors and Direction Vectors are quantities that have a size and a direction. Vectors are quantities that have a size and a direction. A quantity.
CSCE 552 Spring 2011 Math By Jijun Tang. Layered.
H.Melikyan/12001 Vectors Dr.Hayk Melikyan Departmen of Mathematics and CS
Forces in 2D Chapter Vectors Both magnitude (size) and direction Magnitude always positive Can’t have a negative speed But can have a negative.
Vectors and the Geometry of Space 9. Vectors 9.2.
CSCE 552 Spring 2009 Programming Fundamentals By Jijun Tang.
CHAPTER 5 FORCES IN TWO DIMENSIONS
VECTORS. A vector is a quantity that has both magnitude and direction. It is represented by an arrow. The length of the vector represents the magnitude.
Introduction to Matrices and Vectors Sebastian van Delden USC Upstate
Engineering Mechanics: Statics Chapter 2: Force Vectors Chapter 2: Force Vectors.
Presented by: S. K. Pandey PGT Physics K. V. Khandwa Kinematics Vectors.
Chapter 3.6 Game Architecture. 2 Overall Architecture The code for modern games is highly complex (can easily exceed 1M LOC) The larger your program,
Vector components and motion. There are many different variables that are important in physics. These variables are either vectors or scalars. What makes.
Chun-Yuan Lin Mathematics for Computer Graphics 2015/12/15 1 CG.
CSCE 552 Fall 2012 Language and Programming By Jijun Tang.
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Physics and Physical Measurement Topic 1.3 Scalars and Vectors.
Physics 141Mechanics Lecture 3 Vectors Motion in 2-dimensions or 3-dimensions has to be described by vectors. In mechanics we need to distinguish two types.
Computer Graphics Mathematical Fundamentals Lecture 10 Taqdees A. Siddiqi
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry "Old Henry And His Old Aunt" Defined using right triangle  x y h.
Matrices, Vectors, Determinants.
Graphics Graphics Korea University kucg.korea.ac.kr Mathematics for Computer Graphics 고려대학교 컴퓨터 그래픽스 연구실.
CSCE 552 Spring 2009 Game Architecture and Math By Jijun Tang.
Lecture 1 Linear algebra Vectors, matrices. Linear algebra Encyclopedia Britannica:“a branch of mathematics that is concerned with mathematical structures.
Vectors Chapter 3 Copyright © 2014 John Wiley & Sons, Inc. All rights reserved.
Language and Programming
Game Architecture Rabin is a good overview of everything to do with Games A lot of these slides come from the 1st edition CS 4455.
Chapter 3 Vectors September 17, 2018 Chap 3.
Math review - scalars, vectors, and matrices
Game Programming Algorithms and Techniques
Presentation transcript:

CSCE 552 Spring 2011 Math By Jijun Tang

Languages C/C++ Java Script: Flash, Python, LISP, etc. C# XNA for PC and Xbox

Data Structures: Array Elements are adjacent in memory (great cache consistency)  Requires continuous memory space They never grow or get reallocated  Use dynamic incremental array concept  GCC has a remalloc function In C++ there's no check for going out of bounds  Use vector if possible  Keep in mind of checking boundaries Inserting and deleting elements in the middle is expensive

Lists

Hash Table

Stack/Queue/Priority Queue

Bits

Inheritance Models “is-a” relationship Extends behavior of existing classes by making minor changes Do not overuse, if possible, use component systerm UML diagram representing inheritance

Component Systems Component system organization

Object Factory Creates objects by name Pluggable factory allows for new object types to be registered at runtime Extremely useful in game development for passing messages, creating new objects, loading games, or instantiating new content after game ships

Singleton Implements a single instance of a class with global point of creation and access For example, GUI Don't overuse it!!!

Adapter Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces Real interface

Observer Allows objects to be notified of specific events with minimal coupling to the source of the event Two parts  subject and observer

Ad-hoc

Modular

DAG

Layered

Overview: Initialization/Shutdown The initialization step prepares everything that is necessary to start a part of the game The shutdown step undoes everything the initialization step did, but in reverse order

Initialization/Shutdown Resource Acquisition Is Initialization  A useful rule to minimalize mismatch errors in the initialization and shutdown steps  Means that creating an object acquires and initializes all the necessary resources, and destroying it destroys and shuts down all those resources Optimizations  Fast shutdown  Warm reboot

Overview: Main Game Loop Games are driven by a game loop that performs a series of tasks every frame Some games have separate loops for the front and the game itself Other games have a unified main loop Must finish a loop within second

Tasks of Main Game Loop Handling time Gathering player input Networking Simulation Collision detection and response Object updates Rendering Other miscellaneous tasks

Sample Game Loop

Main Game Loop Structure  Hard-coded loops  Multiple game loops: for each major game state  Consider steps as tasks to be iterated through Coupling  Can decouple the rendering step from simulation and update steps  Results in higher frame rate, smoother animation, and greater responsiveness  Implementation is tricky and can be error-prone

Execution Order of Main Loop Most of the time it doesn't matter In some situations, execution order is important Can help keep player interaction seamless Can maximize parallelism Exact ordering depends on hardware

Example (Open Source Rail Simulator) Simulator = new Simulator(settings, args[0]); if (args.Length == 1) Simulator.SetActivity(args[0]); else Simulator.SetExplore(args[0], args[1], args[2], args[3], args[4]); Simulator.Start(); Viewer = new Viewer3D(Simulator); Viewer.Initialize(); Viewer.Run(); //Frame Updates Here Simulator.Stop(); //Check if exit condition met

Math

Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h

Applied Trigonometry Angles measured in radians Full circle contains 2  radians

Applied Trigonometry Sine and cosine used to decompose a point into horizontal and vertical components  r cos  r sin  r x y

Trigonometry

Trigonometric identities

Inverse trigonometric functions Return angle for which sin, cos, or tan function produces a particular value If sin  = z, then  = sin -1 z If cos  = z, then  = cos -1 z If tan  = z, then  = tan -1 z

arcs

Applied Trigonometry Law of sines Law of cosines Reduces to Pythagorean theorem when  = 90 degrees   b a c

Vectors and Scalars Scalars represent quantities that can be described fully using one value  Mass  Time  Distance Vectors describe a magnitude and direction together using multiple values

Examples of vectors Difference between two points  Magnitude is the distance between the points  Direction points from one point to the other Velocity of a projectile  Magnitude is the speed of the projectile  Direction is the direction in which it ’ s traveling A force is applied along a direction

Visualize Vectors The length represents the magnitude The arrowhead indicates the direction Multiplying a vector by a scalar changes the arrow ’ s length V 2V2V –V–V

Vectors Add and Subtraction Two vectors V and W are added by placing the beginning of W at the end of V Subtraction reverses the second vector V W V + W V W V V – W –W–W

High-Dimension Vectors An n-dimensional vector V is represented by n components In three dimensions, the components are named x, y, and z Individual components are expressed using the name as a subscript:

Add/Subtract Componentwise

Vector Magnitude The magnitude of an n-dimensional vector V is given by In three dimensions, this is

Vector Normalization A vector having a magnitude of 1 is called a unit vector Any vector V can be resized to unit length by dividing it by its magnitude: This process is called normalization

Matrices A matrix is a rectangular array of numbers arranged as rows and columns A matrix having n rows and m columns is an n  m matrix  At the right, M is a 2  3 matrix  If n = m, the matrix is a square matrix

Matrix Representation The entry of a matrix M in the i-th row and j-th column is denoted M ij For example,

Matrix Transpose The transpose of a matrix M is denoted M T and has its rows and columns exchanged:

Vectors and Matrices An n-dimensional vector V can be thought of as an n  1 column matrix: Or a 1  n row matrix:

Vectors and Matrices Product of two matrices A and B  Number of columns of A must equal number of rows of B  Entries of the product are given by  If A is a n  m matrix, and B is an m  p matrix, then AB is an n  p matrix

Vectors and Matrices Example matrix product

Vectors and Matrices Matrices are used to transform vectors from one coordinate system to another In three dimensions, the product of a matrix and a column vector looks like:

Identity Matrix I n For any n  n matrix M, the product with the identity matrix is M itself  I n M = M  MI n = M

Invertible An n  n matrix M is invertible if there exists another matrix G such that The inverse of M is denoted M -1

Properties of Inverse Not every matrix has an inverse A noninvertible matrix is called singular Whether a matrix is invertible can be determined by calculating a scalar quantity called the determinant

Determinant The determinant of a square matrix M is denoted det M or |M| A matrix is invertible if its determinant is not zero For a 2  2 matrix,

Determinant The determinant of a 3  3 matrix is

Inverse Explicit formulas exist for matrix inverses  These are good for small matrices, but other methods are generally used for larger matrices  In computer graphics, we are usually dealing with 2  2, 3  3, and a special form of 4  4 matrices

Inverse of 2x2 and 3x3 The inverse of a 2  2 matrix M is The inverse of a 3  3 matrix M is

4x4 A special type of 4  4 matrix used in computer graphics looks like  R is a 3  3 rotation matrix, and T is a translation vector

Inverse of 4x4

General Matrix Inverse (AB) -1 = B -1 A -1 A general nxn matrix can be inverted using methods such as  Gauss-Jordan elimination  Gaussian elimination  LU decomposition

Gauss-Jordan Elimination Gaussian Elimination

The Dot Product The dot product is a product between two vectors that produces a scalar The dot product between two n-dimensional vectors V and W is given by In three dimensions,

Dot Product Usage The dot product can be used to project one vector onto another  V W

Dot Product Properties The dot product satisfies the formula   is the angle between the two vectors  Dot product is always 0 between perpendicular vectors  If V and W are unit vectors, the dot product is 1 for parallel vectors pointing in the same direction, -1 for opposite

Self Dot Product The dot product of a vector with itself produces the squared magnitude Often, the notation V 2 is used as shorthand for V  V

The Cross Product The cross product is a product between two vectors the produces a vector The cross product only applies in three dimensions  The cross product is perpendicular to both vectors being multiplied together  The cross product between two parallel vectors is the zero vector (0, 0, 0)

Illustration The cross product satisfies the trigonometric relationship This is the area of the parallelogram formed by V and W  V W ||V|| sin 

Area and Cross Product The area A of a triangle with vertices P 1, P 2, and P 3 is thus given by

Rules Cross products obey the right hand rule  If first vector points along right thumb, and second vector points along right fingers,  Then cross product points out of right palm Reversing order of vectors negates the cross product:  Cross product is anticommutative

Rules in Figure

Formular The cross product between V and W is A helpful tool for remembering this formula is the pseudodeterminant (x, y, z) are unit vectors

Alternative The cross product can also be expressed as the matrix-vector product The perpendicularity property means