Professional Documents
Culture Documents
Nhap-Mon-Phat-Trien-Game - 04.-Transformation - (Cuuduongthancong - Com)
Nhap-Mon-Phat-Trien-Game - 04.-Transformation - (Cuuduongthancong - Com)
Nhap-Mon-Phat-Trien-Game - 04.-Transformation - (Cuuduongthancong - Com)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Objectives
Understand transformation
Apply transformation in large world rendering
CuuDuongThanCong.com https://fb.com/tailieudientucntt
World vs view port coordinate
systems
world
view port
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Matrix & transformation review
Matrix addition
Dot product
Matrix multiplication
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Transformation
1 0
5 10 = 5 -10 Flip Y
0 -1
-1 0
5 10 = -5 10 Flip X
0 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Transformation
Translate cannot be specified by 1x2 & 2x2 matrices
Solution: add dummy cells
Affine transformation (i.e. transforms that does not
affect the dimensions of the objects)
1 0 0
x y 1 = x+10 y+20 1
0 1 0
10 20 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Transformation
Matrices can be multiplied to specify a serie
of transformations (in reverse order)
Translate Flip Y
1 0 0 1 0 0 1 0 0
0 1 0 0 -1 0 = 0 -1 0
20 15 1 0 0 1 20 -15 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Transformation
Matrices can be multiplied to specify a serie
of transformations (in reverse order)
x x+20
-y 20
- y - 15
15
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Transformation
Matrices can be multiplied to specify a serie
of transformations (in reverse order)
P 1 0 0
x y 1 0 -1 0 = x+20 -y-15 1
20 -15 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
World vs view port coordinate
systems
world
view port
Transform the view port coordinate “back” to the wanted world coordinate
CuuDuongThanCong.com https://fb.com/tailieudientucntt
World vs view port coordinate
systems
world
view port
CuuDuongThanCong.com https://fb.com/tailieudientucntt
World vs view port coordinate
systems
world
view port
CuuDuongThanCong.com https://fb.com/tailieudientucntt
World vs view port coordinate
systems
world
view port
x0 , y0
xw , yw
Flip Y Translate
1 0 0 1 0 0 1 0 0
0 -1 0 0 1 0 = 0 -1 0
0 0 1 -x0 y0 1 -x0 y0 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
World to view port transformation
x0 , y0 xw – x0
- yw + y0
xw , yw
P 1 0 0
xw yw 1 0 -1 0 = xw- x0 -yw+y0 1
-x0 y0 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
World to view port transformation
1 0 0 0
0 -1 0 0
0 0 1 0
-x0 y0 0 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Rotate?
x0 , y0
xw , yw
D3DXMatrixAffineTransformation2D
D3DXMatrixMultiply
_SpriteHandler->Draw(
_Image,
&srect,
NULL,
&position,
D3DCOLOR_ARGB(Alpha,255,255,255)
);
CuuDuongThanCong.com https://fb.com/tailieudientucntt