beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks

Post on 13-Feb-2017

38 Views

Category:

Engineering

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Beginning Direct3D Game Programming:Mathematics 6

Transformsjintaeks@gmail.com

Division of Digital Contents, DongSeo University.April 2016

2D Rotation: Do you remember the answer?

2

We can rewrite this in matrix form as follows.

3

Solution for this in different way When a point P is rotated about θ, we assume that axis

is rotated about θ. We assume that rotated x and y-axis about θ is x' and y'-

axis.

4

Now, the new point P' is a point on (cosθ, sinθ) x-axis, and (-sinθ, cosθ) y-axis.

So, p'=px(cosθ, sinθ)+py(-sinθ, cosθ)

Caution When a vector P is in the left side of the matrix, the ma-

trix must be transposed.

5

2D Transformations 2D Translation

2×3 augmented matrix

6

We can add a dummy linear equation.

It constructs the linear system of 3 linear equations.

Now, we get:

7

2D Rotation Transform

2D Scaling Transform

8

Linear Transformations Suppose that we have established a 3D coordinate sys-

tem C consisting of an origin and three coordinate axes, in which a point P has the coordinates x, y, z .

This constitutes a linear transformation from C to C′ and can be written in matrix form as follows

9

Assuming the transformation is invertible, the linear transformation from C′ to C is given by

We need to combine the 3×3 matrix and translation vector T into a single 4× 4 transformation matrix.

10

Orthogonal Matrices Most 3×3 matrices arising in computer graphics applica-

tions are orthogonal. An orthogonal matrix is simply one whose inverse is equal to its transpose.

If the n × n matrix M is orthogonal, then M preserves lengths and angles.

11

Handedness In three dimensions, a basis for a coordinate system

given by the 3D vectors V1, V2, and V3 possesses a property called handedness.

A left-handed basis is one for which (V1×V2)⋅V3 < 0.– in LHS V1×V2=-V3

• Left-handed coordinates on the leftRight-handed coordinates on the right.

12

Cross Product

13

The cross product of two three-dimensional vectors, also known as the vector product, returns a new vec-tor that is perpendicular to both of the vectors being multiplied together.

• The cross-product in respect to a left-handed coordi-nate system.

Coordinate Systems in Direct3D

• Direct3D uses a left-handed coordinate system. If you are porting an application that is based on a right-handed coordinate system, you must make two changes to the data passed to Direct3D.

14

Scaling Transforms To scale a vector P by a factor of a, we simply calculate

P′ = aP. In three dimensions, this operation can also be expressed as the matrix product.

15

Nonuniform Scaling A Diagonal entries are not necessarily all equal.

16

Rotation Transforms We can find 3×3 matrices that rotate a coordinate sys-

tem through an angle θ about the x, y, or z axis..

17

2D Rotation: Do you remember the answer?

18

We can rewrite this in matrix form as follows.

The matrix Rz(θ ) that performs a rotation through the angle θ about the z axis is thus given by

19

Solution for this in different way When a point P is rotated about θ, we assume that axis

is rotated about θ. We assume that rotated x and y-axis about θ is x' and y'-

axis.

20

Now, the new point P' is a point on (cosθ, sinθ) x-axis, and (-sinθ, cosθ) y-axis.

So, p'=px(cosθ, sinθ)+py(-sinθ, cosθ)

Caution When a vector P is in the left side of the matrix, the ma-

trix must be transposed.

21

Similarly, we can derive the following 3×3 matrices Rx(θ ) and Ry(θ ) that perform rotations through an angle θ about the x and y axes, respectively:

22

Rotation about an Arbitrary Axis

Combining these terms and setting c = cosθ and s = sinθ gives us the following formula for the matrix RA(θ) that rotates a vector through an angle θ about the axis A.

23

Translation To transform a point P from one coordinate system to

another, we usually find ourselves performing the opera-tion

P′ =MP + T where M is some invertible 3×3 matrix and T is a 3D

translation vector. Fortunately, there is a compact and elegant way to rep-

resent these transforms within a single mathematical entity.

24

Translation P′ =MP + T Fortunately, there is a compact and elegant way to rep-

resent these transforms within a single mathematical entity.

25

26

P =M-1P' – M-1T We would therefore expect the inverse of the 4× 4 ma-

trix F to be

27

When a input vector is at left of a matrix. When a input vector is at left of a matrix, the translation

vector T will be located at bottom row.

28

Points and Directions Unlike points, direction vectors should remain invariant

under translation. To transform direction vectors using the same 4× 4

transformation matrices that we use to transform points, we extend direction vectors to four dimensions by set-ting the w coordinate to 0.

(x,y,z,w) (px,py,pz,0)

The upper left 3×3 portion of the matrix to affect the di-rection vector.

29

Linear Systems Matrices provide a compact and convenient way to rep-

resent systems of linear equations. For instance, the lin-ear system given by the equations

can be represented in matrix form as

30

The matrix preceding the vector x, y, z of unknowns is called the coefficient matrix, and the column vector on the right side of the equals sign is called the con-stant vector. Linear systems for which the constant vector is nonzero (like the example above) are called nonhomogeneous.

Linear systems for which every entry of the constant vector is zero are called homogeneous.– The Geometric meaning of homogeneous is all the 3-planes

meet at origin (0,0,0).31

The augmented matrix formed by concatenating the coefficient matrix and constant vector is

When the linear system is homogeneous, then the ma-trix cab be written like this

32

Homogeneous Matrix We will use 4x4 matrices to consistently represent

translation, scaling and rotation in 3D space.

In that case a14, a24 and a34 is always zero, when the in-put vector is at left of a matrix, this is a Homogeneous Matrix.

33

Transform Matrices in Direct3D You can transform any point (x,y,z) into another point

(x', y', z') by using a 4x4 matrix, as shown in the follow-ing equation.

34

35

Translation in Direct3D The following equation translates the point (x, y, z) to a

new point (x', y', z').

D3DXMATRIX Translate(const float dx, const float dy, const float dz) { D3DXMATRIX ret;

D3DXMatrixIdentity(&ret); ret(3, 0) = dx; ret(3, 1) = dy; ret(3, 2) = dz; return ret;} // End of Translate

Scaling in Direct3D The following equation scales the point (x, y, z) by arbi-

trary values in the x-, y-, and z-directions to a new point (x', y', z').

36

Rotations in Direct3D The following equation rotates the point (x, y, z) around

the x-axis, producing a new point (x', y', z').

37

D3DXMATRIX* WINAPI D3DXMatrixRotationX ( D3DXMATRIX *pOut, float angle ){ float sin, cos; sincosf(angle, &sin, &cos); // Determine sin and cos of angle

pOut->_11 = 1.0f; pOut->_12 = 0.0f; pOut->_13 = 0.0f; pOut->_14 = 0.0f; pOut->_21 = 0.0f; pOut->_22 = cos; pOut->_23 = sin; pOut->_24 = 0.0f; pOut->_31 = 0.0f; pOut->_32 = -sin; pOut->_33 = cos; pOut->_34 = 0.0f; pOut->_41 = 0.0f; pOut->_42 = 0.0f; pOut->_43 = 0.0f; pOut->_44 = 1.0f;

return pOut;}

The following equation rotates the point around the y-axis.

The following equation rotates the point around the z-axis.

38

Concatenating Matrices One advantage of using matrices is that you can com-

bine the effects of two or more matrices by multiplying them.

This means that, to rotate a model and then translate it to some location, you don't need to apply two matrices.

In this equation, C is the composite matrix being cre-ated, and M₁ through Mn are the individual matrices.

Use the D3DXMatrixMultiply function to perform matrix multiplication.

39

Win32 3D Cube Project

40

Step2

41

42

43

Step3: Matrix Rotation about x-axis

44

Projection Transform

45

46

47

48

References Lengyel, "Mathematics for 3D Game Programming and

Computer Graphics",3rd, 2011 https://msdn.microsoft.com/en-us/library/windows/deskt

op/bb206269(v=vs.85).aspx

49

top related