Re: [Algorithms] Dummie Matrix math questions
Brought to you by:
vexxed72
From: Richard F. <ra...@gm...> - 2008-02-07 13:56:35
|
you can think of a view matrix as just being a model matrix of your camera, and the reason you use the inverse of it is that you're trying to transform the scene by the camera's model matrix, but the camera is the other way up/down the scene graph. consider this: "object" is a child of "transform", is a child of "scene root", "camera" is a child of "scene root" to render "object", you need to get each vertex of "object", multiply each of them by the transforms "down" the chain . First by "object"'s model matrix, then down to "transform", then you reach the scene root (which you might have as a transform, but not normally as you'll see in a moment), but to get to the camera you have to go "up" (using the inverse matrix instead) of "camera" so you apply the inverse camera after you've built your "world" representation using the idea that a inverse multiply is a divide, you can figure it through like this V * object * transform * root / root / camera as you can see, the root scene transform is unimportant because it cancels immediately, leaving you with: V * object * transform / camera and this is why you need to use the inverse camera local matrix to build your renderer camera transform. On Feb 7, 2008 1:42 PM, Bruno Sanches <bcs...@gm...> wrote: > I will verify that when I arrive at home, because thinking again, I belive > my code at home is wrong, because now it makes sense why using the inverse > matrix its works :). Two days investigating this and havent figured out > this! > > So, it appears that for the view, I will need to use the invert matrix > after fixing the code, thats weird to me, does anyone knows a tutorial / doc > that explain the math behind view matrix? > > Thank you! > Bruno Sanches > > On 2/7/08, Oscar Forth <os...@tr...> wrote: > > > > Well either you wrote it twice wrong in your original mail ... or you > > wrote it correctly both times. > > > > Anyway, I still think its because GL and DX matrices are transposes of > > each other ... an invert of a simple rotation matrix is the transpose of > > that matrix. > > > > View matrices are odd beasts ... they are not constructed like a > > standard object matrix. They aren't interchangeable ... > > > > Hope thats some help. > > > > > > ----- Original Message ----- > > *From:* Bruno Sanches <bcs...@gm...> > > *To:* Game Development Algorithms<gda...@li...> > > *Sent:* Thursday, February 07, 2008 12:28 PM > > *Subject:* Re: [Algorithms] Dummie Matrix math questions > > > > > > Sorry Oscar, I typed it wrong when writing the email, the object code > > uses the same code from camera to extract the axis. > > > > I am not sure if something with my math is wrong. The most strange for > > me is that for the camera, when I get the fwd vector and use it to move the > > camera, everything goes fine, but for objects, I need to get the fwd vector > > from the inverse matrix. > > > > I am not understanding why I need to do that, because I was expecting > > the camera to behave like any other object. > > > > Thank you > > > > Bruno Sanches > > > > > > On 2/7/08, Oscar Forth <os...@tr...> wrote: > > > > > > Sounds like the difference between GL and DX row/column ordering. > > > > > > Under DX it should be > > > > > > fwd.x = objectMatrix._11; > > > fwd.y = objectMatrix._12; > > > fwd.z = objectMatrix._13; > > > > > > Don't get confused by the two ... > > > > > > Sorry if thats a bit of a platform specific answer admins! > > > > > > ----- Original Message ----- > > > *From:* Bruno Sanches <bcs...@gm...> > > > *To:* Game Development Algorithms<gda...@li...> > > > *Sent:* Thursday, February 07, 2008 12:07 PM > > > *Subject:* [Algorithms] Dummie Matrix math questions > > > > > > > > > > > > Hello Folks, > > > > > > I am reading this list emails (and learning a lot) from some time and > > > I would like to ask some help with basic 3d transformations that is giving a > > > lot of headaches for me on last days (and nights)... > > > > > > On the framework that I am working (d3d9) I have a basic scene graph > > > system, each node has a transformation matrix. > > > > > > On rendering, I have a code (pseudo code) like this: > > > > > > Vec3 fwd; > > > > > > fwd.x = cameraMatrix._11; > > > fwd.y = cameraMatrix._21; > > > fwd.z = cameraMatrix._31; > > > > > > //My coordinate system, x is forward, y is right, Z is up (right hand > > > with Z pointing up) > > > Vec3 origin = cameraOrigin; > > > Vec3 at = origin + fwd; > > > > > > Vec3 up; > > > up.x = cameraMatrix._13; > > > up.x = cameraMatrix._23; > > > up.x = cameraMatrix._33; > > > > > > D3DXMATRIX viewMat; > > > D3DXMatrixLookAtRH(&viewMat, cameraOrigin, &at, &up); > > > > > > screen->SetViewTransform(viewMat); > > > > > > After setting up the camera transformation like above, I go rendering > > > my objects: > > > > > > for each object > > > { > > > D3DXMATRIX mat = object.matrix; > > > screen->SetWorldTransform(mat); > > > > > > DrawObject(); > > > } > > > > > > And everything works fine. > > > > > > But, now I am trying to move a object forward, and this is where my > > > problems start, for moving my objects, I do: > > > > > > void moveObject(float dist) > > > { > > > Vec3 fwd; > > > > > > fwd.x = objectMatrix._11; > > > fwd.y = objectMatrix._21; > > > fwd.z = objectMatrix._31; > > > > > > fwd *= dist; > > > > > > objectOrigin += fwd; > > > } > > > > > > This appears to work, but I found out that the objects matrix appears > > > to be inverted, they will move on very strange directions, if on the above > > > function I use a invert matrix, everything works fine! I don't know what I > > > am missing here, because I was expecting the above function to work without > > > using the inverse matrix. > > > > > > I have similar code on opengl few years ago and it worked. Does anyone > > > has any clue what is going on? Or at least, is this expected? :) > > > > > > Please note for all math, I am using d3dx math functions. > > > > > > Thank you for your help! > > > > > > Regards > > > Bruno Sanches > > > > > > ------------------------------ > > > > > > > > > ------------------------------------------------------------------------- > > > This SF.net email is sponsored by: Microsoft > > > Defy all challenges. Microsoft(R) Visual Studio 2008. > > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > > > > ------------------------------ > > > > > > _______________________________________________ > > > GDAlgorithms-list mailing list > > > GDA...@li... > > > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > > > Archives: > > > > > > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list > > > > > > > > > > > > ------------------------------------------------------------------------- > > > This SF.net email is sponsored by: Microsoft > > > Defy all challenges. Microsoft(R) Visual Studio 2008. > > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > _______________________________________________ > > > GDAlgorithms-list mailing list > > > GDA...@li... > > > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > > > Archives: > > > > > > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list > > > > > > > ------------------------------ > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio 2008. > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > > ------------------------------ > > > > _______________________________________________ > > GDAlgorithms-list mailing list > > GDA...@li... > > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > > Archives: > > > > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list > > > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio 2008. > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > _______________________________________________ > > GDAlgorithms-list mailing list > > GDA...@li... > > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > > Archives: > > > > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list > -- fabs(); Just because the world is full of people that think just like you, doesn't mean the other ones can't be right. |