## Re: [Algorithms] Dummie Matrix math questions

 Re: [Algorithms] Dummie Matrix math questions From: Jon Watte - 2008-02-07 18:38:55 ```Direct3D uses row vectors on left. Thus, the "X" basis vector lives in the first row, not first column. For more information, see http://www.mindcontrol.org/~hplus/graphics/matrix-layout.html Cheers, / h+ Bruno Sanches wrote: > > 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 > GDAlgorithms-list@... > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list -- -- Go is to Western chess what philosophy is to double entry accounting. ```