Sign in to follow this  

Unity (view)Matrix questions

This topic is 2874 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Similar Content

    • By loyalsheep
      Hey guys!
      Check out the trailer of Airavat. It's a minimalist, space survival game (and hard, very hard) 
      Download on GooglePlay: Airavat
       
    • By anomalystudiospt
      Hey, we are new around here!
      Our team spent the last year developing a prototype game called Rise of The Fey, a game that focuses on a dramatic story with a fast paced gameplay.
      Rise of The Fey is a third-person action-adventure RPG set within a fantasy world called Perrah. In Rise you control Kall, a young spaunian looking for revenge after the death of his beloved.

      We would appreciate if you could take a look at our stuff, tell us what you think and possibly help us out on Indiegogo.
      The prototype is in portuguese, sorry about that!
      Have a good one!
    • By juglar
      Hi guys, we are developing a game called BiteOff! based on Zombies topic. BiteOff! is based on a game strategy mechanics, free to play, where the player has a bunch of zombies and he can distribute them along the map landscape to be able to bite and transform all humans into each level. Humans are controlled by artificial intelligence and they differ each other on capabilities based on different weapons that give them three different levels of aggressiveness to defend against the zombies. The zombies are also presented in three types and they are differentiated by their attack, speed, strength and resistance abilities. Through different achievements, (time to eat all humans, score, among others) the player can access four extra skills that can enhance your attack in real time on next levels as power-ups.
      We are launching a crowdfunding campaign in kickico and we need some helps please visit us on the crowdfunding page https://www.kickico.com/es/campaigns/17824/biteoff-the-videogame 
      Twitter @biteoffthegame
      Facebook
      Clickme!
      Website 
      Clickme!
    • By Lord McMutton
      The world of Ethios is held aloft by massive trees known as the Pillars.
  • Popular Now