GLM Slide Set 4 04 GLM Vectors Operations

  • Slides: 15
Download presentation
GLM Slide Set 4. 04

GLM Slide Set 4. 04

GLM ■ Vectors – Operations – Functions ■ Matrices – Operations – Functions 2

GLM ■ Vectors – Operations – Functions ■ Matrices – Operations – Functions 2

Vectors ■ Different vector types: vec 2, vec 3, vec 4 ■ Objects of

Vectors ■ Different vector types: vec 2, vec 3, vec 4 ■ Objects of those types can be structured in different ways – Attributes x, y, z, w – Attributes r, g, b, a – By index ■ Objects take up minimal space in memory: 2 or 3 or 4 adjacent float values 3

Vector Operations ■ Component-wise operations: +, -, *, / ■ Scalar multiplication 4

Vector Operations ■ Component-wise operations: +, -, *, / ■ Scalar multiplication 4

5

5

6

6

Vector Functions ■ Length, dot product ■ Cross product of vec 3 ■ Apply

Vector Functions ■ Length, dot product ■ Cross product of vec 3 ■ Apply scalar functions componentwise 7

Dot Product ■ If v and u are both vec 4 then the dot

Dot Product ■ If v and u are both vec 4 then the dot product is ■ v. x*u. x + v. y*u. y + v. z*u. z + v. w*u. w ■ Many nice properties – v dotted with itself is the square of the length of v – If v and u are both of unit length, their dot product is the cosine of the angle between them 8

9

9

Cross Product ■ The cross product is defined only for vec 3 objects ■

Cross Product ■ The cross product is defined only for vec 3 objects ■ The cross product of two vectors is a vector also ■ The cross product of two vectors is perpendicular to both of them 10

(1, 1, 0) and (1, -1, 0) Cross and dot products 11

(1, 1, 0) and (1, -1, 0) Cross and dot products 11

Matrices ■ Many sizes supported but we will use mat 4 and, sometimes, mat

Matrices ■ Many sizes supported but we will use mat 4 and, sometimes, mat 3 ■ Indexing available to access elements if needed ■ Data stored compactly so easy to use with Open. GL functions 12

Matrix Operations ■ Add and subtract matrices using elementwise operations ■ Matrix multiplication –

Matrix Operations ■ Add and subtract matrices using elementwise operations ■ Matrix multiplication – Matrix times vector, for example, mat 4 times vec 4 – Matrix times matrix, for example, mat 4 times mat 4 13

Standard Matrices ■ Constructor will create a diagonal matrix given a value for the

Standard Matrices ■ Constructor will create a diagonal matrix given a value for the diagonal ■ Functions that will create a rotation/translation/scale transformation and multiply it by another transformation, returning the result – Typically we want to multiply these transformations once they are created in order to get the combined transformation 14

Matrix Functions ■ 15

Matrix Functions ■ 15