05. vectors

16
Video Game Development: Vectors A. Babadi 1 of 16 In The Name Of God Video Game Development Amin Babadi Department of Electrical and Computer Engineering Isfahan University of Technology Spring 2015 Vectors

Upload: amin-babadi

Post on 18-Aug-2015

57 views

Category:

Engineering


1 download

TRANSCRIPT

Video Game Development: Vectors A. Babadi 1 of 16

In The Name Of God

Video Game Development

Amin Babadi

Department of Electrical and Computer Engineering

Isfahan University of Technology

Spring 2015

Vectors

Video Game Development: Vectors A. Babadi 2 of 16

Outline

What is a game engine?

Vector definition

The dot product

Vector projection

The cross product

Video Game Development: Vectors A. Babadi 3 of 16

Game Engine

A game engine is a software designed for the creation and development of video games.

The core functionality typically provided by a game engine includes: o A rendering engine,

o A physics engine,

o Scripting support,

o Multi-threading support,

o Animation support,

o Etc.

More about game engines comes in next lectures.

Video Game Development: Vectors A. Babadi 4 of 16

Game Engine

Examples of well-known game engines: o CryEngine,

o Unreal Engine,

o Gamebyro,

o Unity,

o Wintermute Engine,

o XNA Game Studio,

o Game Maker.

Video Game Development: Vectors A. Babadi 5 of 16

Vectors

Vectors are of fundamental importance in any game engine.

They mainly are used for representing points in space and spatial directions. o But for now, we make no distinction between vectors representing

points and vectors representing directions, nor do we concern ourselves with how vectors are transformed from one coordinate system to another.

Video Game Development: Vectors A. Babadi 6 of 16

Vector Properties

We usually restrict ourselves to vectors defined by n-tuples of real numbers, where n is typically 2, 3, or 4.

𝑉 = 𝑣1, 𝑣2, … , 𝑣𝑛

The numbers 𝑣𝑖 are called the components of the vector 𝑉.

𝑉 may also be represented by a 𝑛 Γ— 1 matrix:

𝑉 =

𝑣1𝑣2:𝑣𝑛

= 𝑣1 𝑣2 … 𝑣𝑛𝑇

The components can usually be labeled with the name of the axis to which they correspond.

𝑃 = 𝑝π‘₯ , 𝑝𝑦, 𝑝𝑧

Video Game Development: Vectors A. Babadi 7 of 16

Vector Properties

𝛼𝑉 = 𝑉𝛼 = 𝛼𝑣1, 𝛼𝑣2, … , 𝛼𝑣𝑛 𝑃 + 𝑄 = 𝑝1 + π‘ž1, 𝑝2 + π‘ž2, … , 𝑝𝑛 + π‘žπ‘›

𝑉 = 𝑣𝑖2

𝑛

𝑖=1

If 𝑉 = 1, 𝑉 is called a unit vector. If 𝑉 > 0, 𝑉 can be converted to a unit vector. This operation is called normalization.

𝑉′ =1

𝑉𝑉

Video Game Development: Vectors A. Babadi 8 of 16

The Dot Product

The dot product of two vectors supplies a measure of the similarity (or difference) between the directions in which the two vectors point.

𝑃. 𝑄 = 𝑄. 𝑃 = π‘π‘–π‘žπ‘–

𝑛

𝑖=1

It is also known as the scalar product or inner product, and is one of the most heavily used operations in 3D graphics.

𝑃. 𝑄 may also be expressed as the matrix product:

𝑃𝑇𝑄 = 𝑝1 𝑝2 … 𝑝𝑛

π‘ž1π‘ž2:π‘žπ‘›

Video Game Development: Vectors A. Babadi 9 of 16

The Dot Product

𝑃. 𝑄 = 𝑃 𝑄 cos 𝛼

The dot product is related to the angle between two vectors.

Video Game Development: Vectors A. Babadi 10 of 16

The Dot Product

The sign of the dot product tells us whether two vectors lie on the same side or on opposite sides of a plane.

Video Game Development: Vectors A. Babadi 11 of 16

The Dot Product

Vectors whose dot product yields zero are called orthogonal (or perpendicular) vectors.

We define the zero vector 𝟎 = 0,0,… , 0 to be orthogonal to every vector 𝑃.

Video Game Development: Vectors A. Babadi 12 of 16

cos 𝛼 =π‘₯

𝑃⇒ π‘₯ = 𝑃 cos 𝛼 =

𝑃. 𝑄

𝑄

We now have this formula for the projection of 𝑃 onto 𝑄:

π‘π‘Ÿπ‘œπ‘—π‘„π‘ƒ =𝑃.𝑄

𝑄 2𝑄

Projecting Vectors

𝛼

𝑃

𝑄

π‘₯

Video Game Development: Vectors A. Babadi 13 of 16

The Cross Product

The cross product (vector product) of two 3D vectors, returns a new vector that is perpendicular to both of the vectors being multiplied together.

𝑃 Γ— 𝑄 =

𝑖 𝑗 π‘˜π‘π‘₯ 𝑝𝑦 π‘π‘§π‘žπ‘₯ π‘žπ‘¦ π‘žπ‘§

= π‘π‘¦π‘žπ‘§ βˆ’ π‘π‘§π‘žπ‘¦, π‘π‘§π‘žπ‘₯ βˆ’ 𝑝π‘₯π‘žπ‘§, 𝑝π‘₯π‘žπ‘¦ βˆ’ π‘π‘¦π‘žπ‘₯

Video Game Development: Vectors A. Babadi 14 of 16

The Cross Product

Theorem: 𝑃 Γ— 𝑄 . 𝑃 = 𝑃 Γ— 𝑄 .𝑄 = 0

The right hand rule provides an easy way for determining in which direction the cross product points.

Video Game Development: Vectors A. Babadi 15 of 16

The Cross Product

Theorem: 𝑃 Γ— 𝑄 = 𝑃 𝑄 sin 𝛼

The right hand rule provides an easy way for determining in which direction the cross product points.

Video Game Development: Vectors A. Babadi 16 of 16

References

Lengyel’s textbook,

Wikipedia, and

Some other sources on the Internet.