Jump to content

View more

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

World, View, and Projection Matrices

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Belos   Members   


Posted 20 June 2012 - 11:13 AM

I have quite the trouble with the world, view, and projection matrices. I understand how the world matrix works, but I don't know how to implement it can you give an example? also for the perspective projection I use the following method:
[source lang="csharp"] public static Matrix3D ProjectionMatrix(double angle, double aspect, double near, double far) { double size = near * Math.Tan(MathUtils.DegreeToRadian(angle) / 2.0); double left = -size, right = size, bottom = -size / aspect, top = size / aspect; Matrix3D m = new Matrix3D(new double[,] { {2*near/(right-left),0,(right + left)/(right - left),0}, {0,2*near/(top-bottom),(top+bottom)/(top-bottom),0}, {0,0,-(far+near)/(far-near),-(2 * far * near) / (far - near)}, {0,0,-1,0} }); return m; }[/source]is there anything wrong here?
and the last question how do I use the camera matrix?

Edited by Belos, 20 June 2012 - 11:17 AM.

#2 XNA-3D-101   Members   


Posted 20 June 2012 - 10:13 PM

I don't know if it will help you, but you might read my Matrix tutorial. It's written for XNA and XNA does a lot of work for setting up you matrices for you. I haven't had to think about manually loading a matrix in a long time.

Here's the tutorial:


It looks like you're working in C++ with DirectX. So, this may not be terribly helpful if you have to load your own matrices.

But Khan Academy has lessons on Matrices.

I swear that I saw a good video on YouTube on the subject of using Matrices in game creation the other day. I thought I book marked it, but apparently I didn't and I can't find it.

For 3D, you are going to be using 4 by 4 matrices.

The camera matrix (called a View Matrix in XNA) should store your camera position and facing.

Hopefully someone else will post something more helpful.

Post Script: Ah HA! I found it. I think this guy does a pretty good job of explaining how matrices are loaded for 3D games.

Edited by XNA-3D-101, 20 June 2012 - 10:18 PM.

#3 Belos   Members   


Posted 21 June 2012 - 07:28 AM

I used the following code to get the camera:

Matrix3D Camera
                Vector3D cameraZAxis = -this.LookDirection;

                Vector3D cameraXAxis = Vector3D.CrossProduct(this.UpDirection, cameraZAxis);

                Vector3D cameraYAxis = Vector3D.CrossProduct(cameraZAxis, cameraXAxis);

                Vector3D cameraPosition = (Vector3D)this.Position;
                double offsetX = -Vector3D.DotProduct(cameraXAxis, cameraPosition);
                double offsetY = -Vector3D.DotProduct(cameraYAxis, cameraPosition);
                double offsetZ = -Vector3D.DotProduct(cameraZAxis, cameraPosition);

                return new Matrix3D(new double[,]{{cameraXAxis.X, cameraYAxis.X, cameraZAxis.X, 0},
                                    {cameraXAxis.Y, cameraYAxis.Y, cameraZAxis.Y, 0},
                                    {cameraXAxis.Z, cameraYAxis.Z, cameraZAxis.Z, 0},
                                    {offsetX, offsetY, offsetZ, 1}});

The default camera matrix is
after I multiply the three matrices(the third is the model matrix) by the point and the resulting W in the point is very huge like -13000 Posted Image so I am very confused right now!!
the model matrix is
Can you tell me where I have gone wrong?
note: this is not xn

Edited by Belos, 21 June 2012 - 07:30 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.