XNA L02–Basic Matrices and Transformations

95
Mohammad Shaker mohammadshaker.com @ZGTRShaker 2011, 2012, 2013, 2014 XNA Game Development L02 – Transformations and Basic Matrices

Transcript of XNA L02–Basic Matrices and Transformations

Page 1: XNA L02–Basic Matrices and Transformations

Mohammad Shakermohammadshaker.com

@ZGTRShaker2011, 2012, 2013, 2014

XNA Game DevelopmentL02 – Transformations and Basic Matrices

Page 2: XNA L02–Basic Matrices and Transformations

3D World

Page 3: XNA L02–Basic Matrices and Transformations

3D World

Page 4: XNA L02–Basic Matrices and Transformations

3D World

Page 5: XNA L02–Basic Matrices and Transformations

XNA Matrices

Page 6: XNA L02–Basic Matrices and Transformations

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

Basic Matrices View, Projection and World Matrices

Page 8: XNA L02–Basic Matrices and Transformations

Basic Matrices

• View, Projection and World Matrices

Page 9: XNA L02–Basic Matrices and Transformations

RULE

Page 10: XNA L02–Basic Matrices and Transformations

RULETO SEE A 3D SCENE YOU SHOULD SET UP:

Page 11: XNA L02–Basic Matrices and Transformations

RULETO SEE A 3D SCENE YOU SHOULD SET UP:

CAMERA

Page 12: XNA L02–Basic Matrices and Transformations

RULETO SEE A 3D SCENE YOU SHOULD SET UP:

CAMERA

PROJECTION

Page 13: XNA L02–Basic Matrices and Transformations

RULETO SEE A 3D SCENE YOU SHOULD SET UP:

CAMERA

PROJECTION

WORLD MATRIX

Page 14: XNA L02–Basic Matrices and Transformations

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

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

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

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

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

Camera (View) Matrix

Page 20: XNA L02–Basic Matrices and Transformations

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

View Matrices

Matrix.CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector);

Page 22: XNA L02–Basic Matrices and Transformations

View Matrices

Matrix.CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector);

Page 23: XNA L02–Basic Matrices and Transformations

View Matrices

Matrix.CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector);

Page 24: XNA L02–Basic Matrices and Transformations

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

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

Projection Matrix

Page 27: XNA L02–Basic Matrices and Transformations

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

Projection Matrices

Page 29: XNA L02–Basic Matrices and Transformations

Projection Matrices

The Difference?!

Page 30: XNA L02–Basic Matrices and Transformations

Projection Matrices

The Difference?!perspective

Page 31: XNA L02–Basic Matrices and Transformations

Projection Matrices

The Difference?!perspective orthographic

Page 32: XNA L02–Basic Matrices and Transformations

Projection Matrices

Page 33: XNA L02–Basic Matrices and Transformations

Projection Matrices

Page 34: XNA L02–Basic Matrices and Transformations

Projection Matrices

Page 35: XNA L02–Basic Matrices and Transformations

Projection Matrices

Realistic?perspective orthographic

Page 36: XNA L02–Basic Matrices and Transformations

Projection Matrices

• Projection Matries

Realistic?perspective orthographic

Page 37: XNA L02–Basic Matrices and Transformations

Projection Matrices

Architecture?perspective orthographic

Page 38: XNA L02–Basic Matrices and Transformations

Projection Matrices

Architecture?perspective orthographic

Page 39: XNA L02–Basic Matrices and Transformations

Projection Matrices

Usability?perspective orthographic

Page 40: XNA L02–Basic Matrices and Transformations

Projection Matrices

Usability?perspective orthographic

Page 41: XNA L02–Basic Matrices and Transformations

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

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

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

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

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

Perspective Projections

• PerspectiveFieldOfView

Matrix.CreatePerspectiveFieldOfView(float fieldOfView,

float aspectRatio,

float nearPlaneDistance,

float farPlaneDistance);

Page 47: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspectiveFieldOfView(float fieldOfView,

float aspectRatio,

float nearPlaneDistance,

float farPlaneDistance);

Page 48: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspectiveFieldOfView(float fieldOfView,

float aspectRatio,

float nearPlaneDistance,

float farPlaneDistance);

Page 49: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspectiveFieldOfView(float fieldOfView,

float aspectRatio,

float nearPlaneDistance,

float farPlaneDistance);

Page 50: XNA L02–Basic Matrices and Transformations

Perspective Projections

• Perspective projections

Matrix.CreatePerspectiveFieldOfView(float fieldOfView,

float aspectRatio,

float nearPlaneDistance,

float farPlaneDistance);

Page 51: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspectiveFieldOfView(float fieldOfView,

float aspectRatio,

float nearPlaneDistance,

float farPlaneDistance);

Page 52: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspectiveFieldOfView(float fieldOfView,

float aspectRatio,

float nearPlaneDistance,

float farPlaneDistance);

Page 53: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspective(

float width,

float height,

float nearPlaneDistance, float farPlaneDistance);

Page 54: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspective(

float width,

float height,

float nearPlaneDistance, float farPlaneDistance);

Page 55: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspective(

float width,

float height,

float nearPlaneDistance, float farPlaneDistance);

Page 56: XNA L02–Basic Matrices and Transformations

Perspective Projections

Matrix.CreatePerspectiveOffCenter(

float left,

float right,

float bottom,

float top,

float nearPlaneDistance, float farPlaneDistance);

Page 57: XNA L02–Basic Matrices and Transformations

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

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

World MatrixEach Object in 3D Has Its own World Matrix

Page 60: XNA L02–Basic Matrices and Transformations

World Matrix

Page 61: XNA L02–Basic Matrices and Transformations

World Matrix

• Example

• Let’s assume that the coordinates of the triangle vertices are as follows:

Page 62: XNA L02–Basic Matrices and Transformations

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

World Matrix

Page 64: XNA L02–Basic Matrices and Transformations

World Matrix

Page 65: XNA L02–Basic Matrices and Transformations

Identity

Scale

Rotate

Orbit

Translate

Page 66: XNA L02–Basic Matrices and Transformations

Transformations

• Load Identity Matrix

Matrix.Identity();

Identity

Scale

Rotate

Orbit

Translate

Page 67: XNA L02–Basic Matrices and Transformations

Transformations

• Create scale matrix

Matrix.CreateScale(float scaleAmount);

Identity

Scale

Rotate

Orbit

Translate

Page 68: XNA L02–Basic Matrices and Transformations

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

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

Transformations

• Create an Orbit matrix?!

Identity

Scale

Rotate

Orbit

Translate

Page 71: XNA L02–Basic Matrices and Transformations

Transformations

• Create an Orbit matrix?!

It’s just

“Translate then Rotate”Identity

Scale

Rotate

Orbit

Translate

Page 72: XNA L02–Basic Matrices and Transformations

Transformations

• Create a translation matrix:

Matrix.CreateTranslation(Vector3 position);

Identity

Scale

Rotate

Orbit

Translate

Page 73: XNA L02–Basic Matrices and Transformations

Transformations

• Multiple World Transformations

Page 74: XNA L02–Basic Matrices and Transformations

Transformations

• Multiple World Transformations

Page 75: XNA L02–Basic Matrices and Transformations

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

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

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

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

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

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

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

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

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

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

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

Test’em live!Souvenir, 9:03 AM, Tuesday, Aug.16th-2011 still awake :S

Page 87: XNA L02–Basic Matrices and Transformations

Custom Matrices

Page 88: XNA L02–Basic Matrices and Transformations

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

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

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

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

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

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

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

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);