Thread: .x file format

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    62

    .x file format

    I am programming a 3D game. I develop the meshes using Blender and export .x files from it. I have to parse the .x file and write it's data into a file that has a bit different structure, so my program gets the data a little bit faster. Because of it I need to know the meaning of the following detail in .x file format.

    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_001 {
    
      FrameTransformMatrix {
        0.965900,-0.258800,0.000000,0.000000,
        0.258800,0.965900,0.000000,0.000000,
        0.000000,0.000000,1.000000,0.000000,
        3.023400,5.487700,1.262100,1.000000;;
      }
    I don't understand the first part of it at all. I understand the second part a bit.
    In my parser program I use the second part in the following way:

    Code:
    fscanf(x_file, "%f,%f,%f,%f,\n", &kord_x, &kord_temp, &kord_temp, &kord_temp);
    				fscanf(x_file, "%f,%f,%f,%f,\n", &kord_temp, &kord_y, &kord_temp, &kord_temp);
    				fscanf(x_file, "%f,%f,%f,%f;;\n", &kord_temp, &kord_temp, &kord_z, &kord_temp);
    Code:
    for(int j=0; j<vertex_count[i]-1; j++)
    				{
    					x[j]=x[j]*kord_x;
    					y[j]=y[j]*kord_y;
    					z[j]=z[j]*kord_z;
    				}
    So I use the transformation to get the true size of the mesh into coordinates.

    My question is: what are the other things and are they something important?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I'm pretty sure what you have isn't going to work. This is a 4x4 transformation matrix, and in good DirectX style, it's been transposed so it can be multiplied by a row vector on the left. So that FrameTransformMatrix would do something like
    Code:
    new_x = 0.965900*old_x + 0.258800*old_y + 0.000000*old_z + 3.023400*old_w;
    ... and so on for y and z and w.
    Last edited by tabstop; 06-10-2008 at 10:35 AM.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    what is 'w'?
    I know only x, y and z.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You can get some idea here.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    Quote Originally Posted by tabstop View Post
    I'm pretty sure what you have isn't going to work. This is a 4x4 transformation matrix, and in good DirectX style, it's been transposed so it can be multiplied by a row vector on the left. So that FrameTransformMatrix would do something like
    Code:
    new_x = 0.965900*old_x + 0.258800*old_y + 0.000000*old_z + 3.023400*old_w;
    ... and so on for y and z and w.
    I don't get it. Why should y and z coordinates matter in x coordinates?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by fighter92 View Post
    I don't get it. Why should y and z coordinates matter in x coordinates?
    If you were to make, oh, a 15 degree turn to the left, things will move; and the larger their y-value (in other words, the farther away they are from the point of rotation, which is you), the more they will move.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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;;
      }
    This is the root of the bone hierarchy.

    Code:
    Frame Cube_001 {
      FrameTransformMatrix {
        0.965900,-0.258800,0.000000,0.000000,
        0.258800,0.965900,0.000000,0.000000,
        0.000000,0.000000,1.000000,0.000000,
        3.023400,5.487700,1.262100,1.000000;;
    This represents one transformation or one keyframe for the cube. A better example would be to load tiny.x which is supplied in the Direct3D samples in the SDK. You will see a hierarchy that has nested keyframes as well as bone names. You will also find the index buffer as well as the vertex buffer or the vertices for the mesh. I would recommend looking in the SDK concerning the .x file format. Each type of matrix has a code which tells you what type of matrix it is and what type of transformation will be used. Everything in X file format is nested. This means that your file gets ugly fast. Using the X file you can create your own templates which basically means you can redefine X file appropriate to your needs.

    There is far more information than what you have posted here and all of it is very important. You should also know that the default mesh viewer that comes with the SDK does NOT do skinned meshes properly. The vertex blending completely falls apart. You will need to download a newer version that supports indexed skinning, however, this version lacks some of the bells and whistles of the default X model viewer.

    Forgive the code tags but the forum would not accept quotes.

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    I think I understand. But if I don't want to load the rotation from .x file and define it myself, my code should work, right?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM