XNA L02–Basic Matrices and Transformations
-
Upload
mohammad-shaker -
Category
Technology
-
view
432 -
download
1
Transcript of XNA L02–Basic Matrices and Transformations
![Page 1: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/1.jpg)
Mohammad Shakermohammadshaker.com
@ZGTRShaker2011, 2012, 2013, 2014
XNA Game DevelopmentL02 – Transformations and Basic Matrices
![Page 2: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/2.jpg)
3D World
![Page 3: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/3.jpg)
3D World
![Page 4: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/4.jpg)
3D World
![Page 5: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/5.jpg)
XNA Matrices
![Page 6: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/6.jpg)
XNA Matrices
• Matrix.CreateRotationX, Matrix.CreateRotationY, and Matrix.CreateRotationZ: Each
of these creates a rotation matrix for each of the axes.
• Matrix.Translation: Creates a translation matrix (one or more axes).
• Matrix.Scale: Creates a scale matrix (one or more axes).
• Matrix.CreateLookAt: Creates a view matrix used to position the camera, by setting
the 3D position of the camera, the 3D position it is facing, and which direction is “up”
for the camera.
• Matrix.CreatePerspectiveFieldOfView: Creates a projection matrix that uses a
perspective view.
![Page 7: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/7.jpg)
Basic Matrices View, Projection and World Matrices
![Page 8: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/8.jpg)
Basic Matrices
• View, Projection and World Matrices
![Page 9: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/9.jpg)
RULE
![Page 10: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/10.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
![Page 11: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/11.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA
![Page 12: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/12.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA
PROJECTION
![Page 13: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/13.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA
PROJECTION
WORLD MATRIX
![Page 14: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/14.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 15: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/15.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 16: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/16.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 17: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/17.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 18: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/18.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 19: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/19.jpg)
Camera (View) Matrix
![Page 20: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/20.jpg)
XNA Matrices
• Matrix.CreateRotationX, Matrix.CreateRotationY, and Matrix.CreateRotationZ: Each
of these creates a rotation matrix for each of the axes.
• Matrix.Translation: Creates a translation matrix (one or more axes).
• Matrix.Scale: Creates a scale matrix (one or more axes).
• Matrix.CreateLookAt: Creates a view matrix used to position the camera, by setting
the 3D position of the camera, the 3D position it is facing, and which direction is “up”
for the camera.
• Matrix.CreatePerspectiveFieldOfView: Creates a projection matrix that uses a
perspective view.
![Page 21: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/21.jpg)
View Matrices
Matrix.CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector);
![Page 22: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/22.jpg)
View Matrices
Matrix.CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector);
![Page 23: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/23.jpg)
View Matrices
Matrix.CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector);
![Page 24: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/24.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 25: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/25.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 26: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/26.jpg)
Projection Matrix
![Page 27: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/27.jpg)
XNA Matrices
• Matrix.CreateRotationX, Matrix.CreateRotationY, and Matrix.CreateRotationZ: Each
of these creates a rotation matrix for each of the axes.
• Matrix.Translation: Creates a translation matrix (one or more axes).
• Matrix.Scale: Creates a scale matrix (one or more axes).
• Matrix.CreateLookAt: Creates a view matrix used to position the camera, by setting
the 3D position of the camera, the 3D position it is facing, and which direction is “up”
for the camera.
• Matrix.CreatePerspectiveFieldOfView: Creates a projection matrix that uses a
perspective view.
![Page 28: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/28.jpg)
Projection Matrices
![Page 29: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/29.jpg)
Projection Matrices
The Difference?!
![Page 30: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/30.jpg)
Projection Matrices
The Difference?!perspective
![Page 31: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/31.jpg)
Projection Matrices
The Difference?!perspective orthographic
![Page 32: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/32.jpg)
Projection Matrices
![Page 33: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/33.jpg)
Projection Matrices
![Page 34: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/34.jpg)
Projection Matrices
![Page 35: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/35.jpg)
Projection Matrices
Realistic?perspective orthographic
![Page 36: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/36.jpg)
Projection Matrices
• Projection Matries
Realistic?perspective orthographic
![Page 37: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/37.jpg)
Projection Matrices
Architecture?perspective orthographic
![Page 38: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/38.jpg)
Projection Matrices
Architecture?perspective orthographic
![Page 39: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/39.jpg)
Projection Matrices
Usability?perspective orthographic
![Page 40: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/40.jpg)
Projection Matrices
Usability?perspective orthographic
![Page 41: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/41.jpg)
XNA Matrices
• Matrix.CreateRotationX, Matrix.CreateRotationY, and Matrix.CreateRotationZ: Each
of these creates a rotation matrix for each of the axes.
• Matrix.Translation: Creates a translation matrix (one or more axes).
• Matrix.Scale: Creates a scale matrix (one or more axes).
• Matrix.CreateLookAt: Creates a view matrix used to position the camera, by setting
the 3D position of the camera, the 3D position it is facing, and which direction is “up”
for the camera.
• Matrix.CreatePerspectiveFieldOfView: Creates a projection matrix that uses a
perspective view.
![Page 42: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/42.jpg)
Orthographic Projections
• An orthographic projection can be created with the following code:
Matrix.CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane);
![Page 43: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/43.jpg)
Orthographic Projections
• An orthographic projection can be created with the following code:
• Off-center orthogonal projection:
Matrix.CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane);
Matrix.CreateOrthographicOffCenter(float left,
float right,
float bottom,
float top,
float zNearPlane, float zFarPlane);
![Page 44: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/44.jpg)
Orthographic Projections
• Ummm ….
Matrix.CreateOrthographicOffCenter(-1, 1, -1, 1, 0.1f, 100f); Matrix.CreateOrthographic(2, 2, 0.1f, 100f);
![Page 45: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/45.jpg)
Orthographic Projections
• Ummm ….
Matrix.CreateOrthographicOffCenter(-1, 1, -1, 1, 0.1f, 100f); Matrix.CreateOrthographic(2, 2, 0.1f, 100f);
![Page 46: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/46.jpg)
Perspective Projections
• PerspectiveFieldOfView
Matrix.CreatePerspectiveFieldOfView(float fieldOfView,
float aspectRatio,
float nearPlaneDistance,
float farPlaneDistance);
![Page 47: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/47.jpg)
Perspective Projections
Matrix.CreatePerspectiveFieldOfView(float fieldOfView,
float aspectRatio,
float nearPlaneDistance,
float farPlaneDistance);
![Page 48: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/48.jpg)
Perspective Projections
Matrix.CreatePerspectiveFieldOfView(float fieldOfView,
float aspectRatio,
float nearPlaneDistance,
float farPlaneDistance);
![Page 49: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/49.jpg)
Perspective Projections
Matrix.CreatePerspectiveFieldOfView(float fieldOfView,
float aspectRatio,
float nearPlaneDistance,
float farPlaneDistance);
![Page 50: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/50.jpg)
Perspective Projections
• Perspective projections
Matrix.CreatePerspectiveFieldOfView(float fieldOfView,
float aspectRatio,
float nearPlaneDistance,
float farPlaneDistance);
![Page 51: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/51.jpg)
Perspective Projections
Matrix.CreatePerspectiveFieldOfView(float fieldOfView,
float aspectRatio,
float nearPlaneDistance,
float farPlaneDistance);
![Page 52: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/52.jpg)
Perspective Projections
Matrix.CreatePerspectiveFieldOfView(float fieldOfView,
float aspectRatio,
float nearPlaneDistance,
float farPlaneDistance);
![Page 53: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/53.jpg)
Perspective Projections
Matrix.CreatePerspective(
float width,
float height,
float nearPlaneDistance, float farPlaneDistance);
![Page 54: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/54.jpg)
Perspective Projections
Matrix.CreatePerspective(
float width,
float height,
float nearPlaneDistance, float farPlaneDistance);
![Page 55: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/55.jpg)
Perspective Projections
Matrix.CreatePerspective(
float width,
float height,
float nearPlaneDistance, float farPlaneDistance);
![Page 56: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/56.jpg)
Perspective Projections
Matrix.CreatePerspectiveOffCenter(
float left,
float right,
float bottom,
float top,
float nearPlaneDistance, float farPlaneDistance);
![Page 57: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/57.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 58: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/58.jpg)
RULETO SEE A 3D SCENE YOU SHOULD SET UP:
CAMERA (Singleton, for all objects)
PROJECTION (Singleton, for all objects)
WORLD MATRIX (For each object separately)
![Page 59: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/59.jpg)
World MatrixEach Object in 3D Has Its own World Matrix
![Page 60: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/60.jpg)
World Matrix
![Page 61: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/61.jpg)
World Matrix
• Example
• Let’s assume that the coordinates of the triangle vertices are as follows:
![Page 62: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/62.jpg)
World Matrix
• Example
• To translate 40 units over the y axis’s positive direction,all you need to do is to add 40
toeach y position, and you have the new coordinates for the vertices:
![Page 63: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/63.jpg)
World Matrix
![Page 64: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/64.jpg)
World Matrix
![Page 65: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/65.jpg)
Identity
Scale
Rotate
Orbit
Translate
![Page 66: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/66.jpg)
Transformations
• Load Identity Matrix
Matrix.Identity();
Identity
Scale
Rotate
Orbit
Translate
![Page 67: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/67.jpg)
Transformations
• Create scale matrix
Matrix.CreateScale(float scaleAmount);
Identity
Scale
Rotate
Orbit
Translate
![Page 68: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/68.jpg)
Transformations
• Create a matrix that rotates around the x-axis:
Matrix.CreateRotateX(float angleInRadians);
• Create a matrix that rotates around the y-axis:Matrix.CreateRotateY(float angleInRadians);
• Create a matrix that rotates around the z-axis:Matrix.CreateRotateZ(float angleInRadians);
Identity
Scale
Rotate
Orbit
Translate
![Page 69: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/69.jpg)
Transformations
• Create a matrix that rotates points around an arbitrary axis:
Matrix.CreateFromAxisAngle(Vector3 axis, float angleInRadians);
Identity
Scale
Rotate
Orbit
Translate
![Page 70: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/70.jpg)
Transformations
• Create an Orbit matrix?!
Identity
Scale
Rotate
Orbit
Translate
![Page 71: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/71.jpg)
Transformations
• Create an Orbit matrix?!
It’s just
“Translate then Rotate”Identity
Scale
Rotate
Orbit
Translate
![Page 72: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/72.jpg)
Transformations
• Create a translation matrix:
Matrix.CreateTranslation(Vector3 position);
Identity
Scale
Rotate
Orbit
Translate
![Page 73: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/73.jpg)
Transformations
• Multiple World Transformations
![Page 74: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/74.jpg)
Transformations
• Multiple World Transformations
![Page 75: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/75.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));Identity
Scale
Rotate
Orbit
Translate
![Page 76: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/76.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));Identity
Scale
Rotate
Orbit
Translate
![Page 77: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/77.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));Identity
Scale
Rotate
Orbit
Translate
![Page 78: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/78.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));Identity
Scale
Rotate
Orbit
Translate
![Page 79: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/79.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));
Matrix result =
Matrix.CreateTranslation(new Vector3(10, 0, 0)) *
Matrix.CreateRotationX(MathHelper.ToRadians(45));
Identity
Scale
Rotate
Orbit
Translate
![Page 80: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/80.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));
Matrix result =
Matrix.CreateTranslation(new Vector3(10, 0, 0)) *
Matrix.CreateRotationX(MathHelper.ToRadians(45));
Identity
Scale
Rotate
Orbit
Translate
![Page 81: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/81.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));
Matrix result =
Matrix.CreateTranslation(new Vector3(10, 0, 0)) *
Matrix.CreateRotationX(MathHelper.ToRadians(45));
Not the same!
Identity
Scale
Rotate
Orbit
Translate
![Page 82: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/82.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));
Matrix result =
Matrix.CreateTranslation(new Vector3(10, 0, 0)) *
Matrix.CreateRotationX(MathHelper.ToRadians(45));
Not the same!
Identity
Scale
Rotate
Orbit
Translate
![Page 83: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/83.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateRotationX(MathHelper.ToRadians(45)) *
Matrix.CreateTranslation(new Vector3(10, 0, 0));
Matrix result =
Matrix.CreateTranslation(new Vector3(10, 0, 0)) *
Matrix.CreateRotationX(MathHelper.ToRadians(45));
Not the same!
Identity
Scale
Rotate
Orbit
Translate
![Page 84: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/84.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateTranslation(new Vector3(10, 0, 0)) *
Matrix.CreateRotationX(MathHelper.ToRadians(45));
Identity
Scale
Rotate
Orbit
Translate
![Page 85: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/85.jpg)
Transformations
• Multiple World Transformations
Matrix result =
Matrix.CreateTranslation(new Vector3(10, 0, 0)) *
Matrix.CreateRotationX(MathHelper.ToRadians(45));
Identity
Scale
Rotate
Orbit
Translate
![Page 86: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/86.jpg)
Test’em live!Souvenir, 9:03 AM, Tuesday, Aug.16th-2011 still awake :S
![Page 87: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/87.jpg)
Custom Matrices
![Page 88: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/88.jpg)
Custom Matrices
Matrix customMatrix = new Matrix(
float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44);
![Page 89: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/89.jpg)
Custom Matrices
• Custom Matrices
Matrix customMatrix = new Matrix(
float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44);
customMatrix.M31 = 4;
![Page 90: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/90.jpg)
Basic Matrices - A Final Example
Vector3 cameraPosition = new Vector3(30.0f, 30.0f, 30.0f);
Vector3 cameraTarget = new Vector3(0.0f, 0.0f, 0.0f); // Look back at the origin
float fovAngle = MathHelper.ToRadians(45); // convert 45 degrees to radians
float aspectRatio = graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight;
float near = 0.01f; // the near clipping plane distance
float far = 100f; // the far clipping plane distance
Matrix world = Matrix.CreateTranslation(10.0f, 0.0f, 10.0f);
Matrix view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(fovAngle, aspectRatio, near, far);
![Page 91: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/91.jpg)
Basic Matrices - A Final Example
Vector3 cameraPosition = new Vector3(30.0f, 30.0f, 30.0f);
Vector3 cameraTarget = new Vector3(0.0f, 0.0f, 0.0f); // Look back at the origin
float fovAngle = MathHelper.ToRadians(45); // convert 45 degrees to radians
float aspectRatio = graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight;
float near = 0.01f; // the near clipping plane distance
float far = 100f; // the far clipping plane distance
Matrix world = Matrix.CreateTranslation(10.0f, 0.0f, 10.0f);
Matrix view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(fovAngle, aspectRatio, near, far);
![Page 92: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/92.jpg)
Basic Matrices - A Final Example
Vector3 cameraPosition = new Vector3(30.0f, 30.0f, 30.0f);
Vector3 cameraTarget = new Vector3(0.0f, 0.0f, 0.0f); // Look back at the origin
float fovAngle = MathHelper.ToRadians(45); // convert 45 degrees to radians
float aspectRatio = graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight;
float near = 0.01f; // the near clipping plane distance
float far = 100f; // the far clipping plane distance
Matrix world = Matrix.CreateTranslation(10.0f, 0.0f, 10.0f);
Matrix view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(fovAngle, aspectRatio, near, far);
![Page 93: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/93.jpg)
Basic Matrices - A Final Example
Vector3 cameraPosition = new Vector3(30.0f, 30.0f, 30.0f);
Vector3 cameraTarget = new Vector3(0.0f, 0.0f, 0.0f); // Look back at the origin
float fovAngle = MathHelper.ToRadians(45); // convert 45 degrees to radians
float aspectRatio = graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight;
float near = 0.01f; // the near clipping plane distance
float far = 100f; // the far clipping plane distance
Matrix world = Matrix.CreateTranslation(10.0f, 0.0f, 10.0f);
Matrix view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(fovAngle, aspectRatio, near, far);
![Page 94: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/94.jpg)
Basic Matrices - A Final Example
Vector3 cameraPosition = new Vector3(30.0f, 30.0f, 30.0f);
Vector3 cameraTarget = new Vector3(0.0f, 0.0f, 0.0f); // Look back at the origin
float fovAngle = MathHelper.ToRadians(45); // convert 45 degrees to radians
float aspectRatio = graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight;
float near = 0.01f; // the near clipping plane distance
float far = 100f; // the far clipping plane distance
Matrix world = Matrix.CreateTranslation(10.0f, 0.0f, 10.0f);
Matrix view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(fovAngle, aspectRatio, near, far);
![Page 95: XNA L02–Basic Matrices and Transformations](https://reader033.fdocuments.in/reader033/viewer/2022052619/5553b45fb4c905d9448b4c65/html5/thumbnails/95.jpg)
Basic Matrices - A Final Example
Vector3 cameraPosition = new Vector3(30.0f, 30.0f, 30.0f);
Vector3 cameraTarget = new Vector3(0.0f, 0.0f, 0.0f); // Look back at the origin
float fovAngle = MathHelper.ToRadians(45); // convert 45 degrees to radians
float aspectRatio = graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight;
float near = 0.01f; // the near clipping plane distance
float far = 100f; // the far clipping plane distance
Matrix world = Matrix.CreateTranslation(10.0f, 0.0f, 10.0f);
Matrix view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(fovAngle, aspectRatio, near, far);