Thread: transform matrix

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    10

    transform matrix

    I use a program that reads the content of .x file and stores it into a file that my game uses to load graphic data. I have problems calculating points using the two transformation matrices that are in my .x file.

    .x matrices:
    Code:
    Frame RootFrame {
    
      FrameTransformMatrix {
        1.000000,0.000000,0.000000,0.000000,
        0.000000,1.000000,0.000000,0.000000,
        0.000000,0.000000,-1.000000,0.000000,
        0.000000,0.000000,0.000000,1.000000;;
      }
    Frame Cube_005 {
    
      FrameTransformMatrix {
        0.115300,0.000000,0.192300,0.000000,
        -0.000000,0.224200,-0.000000,0.000000,
        -0.192300,-0.000000,0.115300,0.000000,
        6.861500,0.000000,0.187800,1.000000;;
      }
    In Microsoft documentation I found the way I should calculate the points, but it seems that either I don't understand it correctly or it just doesn't work:
    Transforms (Direct3D 9)


    Here's the thing I do:
    Code:
    x=x*1.0+y*0.0+z*0.0+0.0;
    x=x*0.1153+y*0.0+z*(-0.1923)+6.8615;
    
    y=x*0.0+y*1.0+z*0.0+0.0;
    y=x*0.0+y*0.2242+z*0.0+0.0;
    
    z=x*0.0+y*0.0+z*(-1.0)+0.0;
    z=x*0.1923+y*0.0+z*0.1153+0.1878;
    Of course in code I don't use constant, I just put them in so it would be more clear.

    What do I do wrong?

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Why are you manually transforming vertices? The D3DX math libraries were programmed by Intel/AMD respectively and are very fast. What is it that you are trying to do?

    Your translation is:
    x = 6.8615f
    y = 0.0f
    z = 0.1878f

    To transform a vector by a matrix in D3D:

    result.x = v.x * matrix(0,0) + v.y * matrix (1,0) + v.z * matrix(2,0) + matrix(3,0);
    result.y = v.x * matrix(0,1) + v.y * matrix(1,1) + v.z * matrix(2,1) + matrix(3,1);
    result.z = v.y * matrix(0,2) + v.y * matrix(1,2) + v.z * matrix(2,2) + matrix(3,2);


    Or use D3DXVec3TransformCoord(), D3DXVec3TransformNormal() or one of the array-based equivalent functions.
    But if you are using hardware transform and lighting you just create your scaling, translation, and rotation matrices and set the world transform. Then you draw the object.

    It looks as if you are trying to load a skinned mesh in an X file. You can use D3DX to load the mesh with and without hierarchy. Check the DX SDK.
    Last edited by VirtualAce; 06-13-2009 at 11:56 AM.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    10
    Thanks Bubba, one of my problems was solved with D3DXVec3TransformCoord(), but another remained. The mesh is now in the right size, but it has somehow wrong rotation. But when I open that .x file in DirectX Viewer it is rotated correctly. I'm quite out of ideas. Are there any other things than transform matrix that can cause such things?

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    In order to correctly load the data you will need to use the D3DX functions. This will extract the D3DXFRAME information for you which will have the correct data. If not then you must manually extract the data. The X file format is heavily documented and widely available both in the SDK and on the web.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM
  4. Matrix Reloaded Questions (SPOILERS_
    By Xei in forum A Brief History of Cprogramming.com
    Replies: 73
    Last Post: 10-19-2003, 02:21 PM