# Unity (view)Matrix questions

## Recommended Posts

Hey, i'm reading tutorials and learning from codes on how to setup different sorts of cameras in XNA. Like Forst Person, Flight Cam, Free Orbit etc. But the example i'm following is using matrices in a way that i really don't understand. In this case he makes changes to the viewMatrix. I know how a matrix looks like and that its a 4x4 matrix. But i have no idea what the elements in a veiwMatrix represent. Take this code for example:
//cam setup
eye = Vector3.Zero;
target = Vector3.Zero;
targetYAxis = Vector3.Up;

xAxis = Vector3.UnitX; //1,0,0
yAxis = Vector3.UnitY; //0,1,0
zAxis = Vector3.UnitZ; //0,0,1
/////////////////////////////////////////////////////

viewMatrix.M11 = xAxis.X;
viewMatrix.M21 = xAxis.Y;
viewMatrix.M31 = xAxis.Z;
Vector3.Dot(ref xAxis, ref eye, out viewMatrix.M41);
viewMatrix.M41 = -viewMatrix.M41;

viewMatrix.M12 = yAxis.X;
viewMatrix.M22 = yAxis.Y;
viewMatrix.M32 = yAxis.Z;
Vector3.Dot(ref yAxis, ref eye, out viewMatrix.M42);
viewMatrix.M42 = -viewMatrix.M42;

viewMatrix.M13 = zAxis.X;
viewMatrix.M23 = zAxis.Y;
viewMatrix.M33 = zAxis.Z;
Vector3.Dot(ref zAxis, ref eye, out viewMatrix.M43);
viewMatrix.M43 = -viewMatrix.M43;

viewMatrix.M14 = 0.0f;
viewMatrix.M24 = 0.0f;
viewMatrix.M34 = 0.0f;
viewMatrix.M44 = 1.0f;


Can someone explain what is happening here? I can see he's changing the viewMatrix to this: 1 0 0 0 0 1 0 0 0 0 1 0 ? ? ? 1 Then he does the DOT product for each axis, x,y,z to see how much degrees it has moved?? And WHY is he altering the M41, M42 and M43 of the matrix?? Does it really matters which part he stores that data in? What would've happend if he stored it in M14, M24, 34, wouldn't that be the same? Hoping someone can clearify this for me. Thanks for any help.

##### Share on other sites
Well, what ways of using matrics do you currently understand?

Are you familiar with the idea of using matrices to represent transformations?

##### Share on other sites
I know how it can be done in XNA. Well sort of. But i'm not really sure how to transformation is exactly done. Like i said in my example, he's doing a transformation on the fields 'M41, M42 and M43' in the matrix. Why there..??

Well guess i don't know enough about them yet. I'll try to read more about this. But if you guys want to give me a good explanation aswell, feel free to do so :)

I also just ordered this book:
3D Math Primer for Graphics and Game Development

The reviews say that it's a pretty good book to give a good basic understanding about matrices and quaternions etc.

##### Share on other sites
honestly basic matrix math is very simple.

there are many ways of visualizing what a matrix times a vector is. The two most useful to me are a change of basis, and another which tells you basically how much your vector is along each row vector in the matrix.

[c1x c2x c3x vx
c1y c2y c3y * vy
c1z c2z c3z] vz
=
vx*[c1] + vy*[c2] + vz*[c3]

the column vectors of the matrix become the new basis vectors. So if you want to rotate a vector about an axis, you rotate its coordinate frame and put its column vectors into the matrix.

v = [vx, vy, vz]

[r1x r1y r1z vx
r2x r2y r2z * vy
r3x r3y r3z] vz

= [ dot(v, r1),
dot(v, r2),
dot(v, r3)]

in this case we see you can view the matrix multiplication by dot products of the row vectors of the matrix and the vector you are multiplying. If your rows form an orthonormal basis, what you have done is calculated an inverse for the matrix formed by making the rows into columns.

[/source]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628320
• Total Posts
2982056
• ### Similar Content

• Hi,
I am an indie game developer from Taiwan.
This is my game” Wo Yao Da”, which is on sale on Steam now.
Wo Yao Da video
Wo Yao Da is a third-person ARPG game, in which the player plays as a tribe warrior and a mysterious weirdo, adventuring in the world of gremlins.

The tribe warrior is good at using knife, spear, bow and arquebus, and his prototype is the warriors from the Gaoshan Tribe (high mountain tribe) in Taiwan in the early 19th century.

While the prototype of the mysterious weirdo is the founder of a “special” and new religion. He created a series of “Buddha dance.”
STAR WARS 莊圓大師
再掉槍啊
【莊圓大師 ： 對十方世界的復仇】1080p高畫質正式中文預告片，全球搶先上映！(HD)
He does behave rather differently and in the game, the player attack just like whatever he does in real life, such as rolling on the ground over and over and over… oh yes, that Buddha Dance too, which is something you don’t want to miss.
I did refer to objects in history for the costumes and buildings, but the story plot is a work of fiction. Please take it lightly and have fun.

The gremlins in this game looks like this:

Thank you.
Steam Page: Wo Yao Da 我要大
• By Hilster
Hello 2D Artists,
I've started making a 2D Puzzle Adventure game for mobile and I'm looking for someone who would want in on creating assets for the game. The core of the programming is pretty much complete, you can walk within the grid laid out and push boxes, when there is an object on top of a pressure pad it will activate the linked objects or if there is one object with multiple linked pressure pads it requires you to activate all points for the object to become active.

The level iteration for the game is quick and simple, a Photoshop file that is made of individual pixels that represents objects is put into the game and it creates the level out of those pixels with the assigned objects.
The objects that need sprites created so far is the character, box, pressure pad, door, trap door, the walls, the stairs and the tiled background.
I intend to add more objects so the amount I'd like to add will be extended.
My motivations for posting here is to have something that looks nice to be able to display on my portfolio, so if you're looking for a working game that you can place your art into and improve the look of your portfolio then we're in business.

• Hi
I have set up my TcpClient to connect to my server and that works fine. But i am a bit confused how i read messages from the network stream with it continuously running via async, without ever closing the connection ?
My TcpClient Manager class has: