home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Graphics / sKulpt / skulpt-src / File-DirectX.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-28  |  4.3 KB  |  169 lines

  1. #define STRICT
  2.  
  3. // Includes standard Windows
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <memory.h>
  10. #include <stdio.h>
  11.  
  12. // Includes D3D
  13. #define  D3D_OVERLOADS
  14. #include <ddraw.h>
  15. #include <d3d.h>
  16. #include <d3dx.h>
  17.  
  18. // Includes utilitaires D3D
  19. #include "d3dmath.h"
  20. #include "d3dutil.h"
  21. #include "D3DEnum.h"
  22.  
  23. // Ids Resources
  24. #include "resource.h"
  25.  
  26. // Constantes
  27. #include "const.h"
  28.  
  29. // Types
  30. #include "types.h"
  31.  
  32. // Variables globales projet
  33. #include "vars.h"
  34.  
  35. // Prototypes fonctions autres modules
  36. #include "proto.h"
  37.  
  38. // Macros
  39. #include "macros.h"
  40.  
  41. void vSaveDirectX(void)
  42. {
  43.     int iTriangle, iMtrl;
  44.     static TCHAR sFileName[512];
  45.     FILE* hFile;
  46.  
  47. #ifndef _AMIGA_
  48.     static TCHAR sInitialDir[512] = "";
  49.     TCHAR sCurrentName[512] = "*.x";
  50.  
  51.     // Récupérer le directory courant
  52.     GetCurrentDirectory(sizeof(sInitialDir), sInitialDir);
  53.  
  54.     // Préparer une structure OPENFILENAME
  55.     OPENFILENAME sOFName = { sizeof(OPENFILENAME), NULL, NULL,
  56.                          "Fichiers Scènes DirectX (*.x)\0*.x\0\0",
  57.                          NULL, 0, 1, sCurrentName, 512, sFileName, 512,
  58.                          sInitialDir, "Ouvrir un fichier scène DirectX", 0, 0, 1,
  59.                          ".x", 0, NULL, NULL };
  60.  
  61.     // Choisir un fichier
  62.     if(!GetOpenFileName(&sOFName))
  63.         return;
  64.  
  65.     // Stocker le nom du directory pour le prochain appel
  66.     strcpy(sInitialDir, sCurrentName);
  67. #else
  68.     strcpy(sFileName, "#?.x");
  69.     if (!FSelect("Ouvrir...", sFileName))
  70.         return;
  71. #endif
  72.  
  73.     hFile = fopen(sFileName, "w");
  74.     if (!hFile)
  75.     {
  76.         vTrace("Pb ouverture fichier %s", sFileName);
  77.         return;
  78.     }
  79.  
  80.     vTrace("*** Fichier scène ouvert : %s", sFileName);
  81.  
  82.     // Garbage collecter
  83.     vCollect();
  84.  
  85.     // Créer le header
  86.     fprintf(hFile, "xof 0303txt 0032\n\nHeader {\n1;\n0;\n1;\n}\n\n");
  87.  
  88.     // Faire la liste des materials
  89.     for (iMtrl = 0 ; iMtrl < iMtrlFirstAvailable ; iMtrl ++)
  90.     {
  91.         D3DMATERIAL7 *hmtrl = &(Materials[iMtrl].mtrl);
  92.         fprintf(hFile, "Material Material_%d {\n%f, %f, %f, %f;;\n%f;\n%f, %f, %f;;\n%f, %f, %f;;\n}\n\n",
  93.             iMtrl,
  94.             hmtrl -> diffuse.r, hmtrl -> diffuse.g, hmtrl -> diffuse.b, hmtrl -> diffuse.a,
  95.             hmtrl -> power,
  96.             hmtrl -> specular.r, hmtrl -> specular.g, hmtrl -> specular.b,
  97.               hmtrl -> emissive.r, hmtrl -> emissive.g, hmtrl -> emissive.b
  98.             );
  99.     }
  100.  
  101.     // Entête frame
  102.     fprintf(hFile, "Frame __sKulpt {\n");
  103.     fprintf(hFile, "FrameTransformMatrix {\n");    
  104.     fprintf(hFile, "1.000000,0.000000,0.000000,0.000000;,\n");
  105.     fprintf(hFile, "0.000000,1.000000,0.000000,0.000000;,\n");
  106.     fprintf(hFile, "0.000000,0.000000,1.000000,0.000000;,\n");
  107.     fprintf(hFile, "0.000000,2.396835,0.000000,1.000000;;\n");
  108.     fprintf(hFile, "}\n\n");
  109.  
  110.     // Entête mesh
  111.     fprintf(hFile, "Mesh __sKulptShape {\n");
  112.  
  113.     // Vertices
  114.     fprintf(hFile, "%d;\n", iVertFirstAvailable);
  115.     for (int iVert = 0 ; iVert < iVertFirstAvailable ; iVert++)
  116.     {
  117.         fprintf(hFile, "%f;%f;%f;",
  118.             Vertices[iVert].vPoint.x, Vertices[iVert].vPoint.y, Vertices[iVert].vPoint.z);
  119.         if (iVert == iVertFirstAvailable - 1)
  120.             fprintf(hFile, ";\n\n");
  121.         else
  122.             fprintf(hFile, ",\n");
  123.     }
  124.  
  125.     // Triangles
  126.     fprintf(hFile, "%d;\n", iTriaFirstAvailable);
  127.     for (iTriangle = 0 ; iTriangle < iTriaFirstAvailable ; iTriangle++)
  128.     {
  129.         fprintf(hFile, "3;%d,%d,%d;",
  130.             Triangles[iTriangle].iSommets[0], Triangles[iTriangle].iSommets[1], Triangles[iTriangle].iSommets[2]);
  131.         if (iTriangle == iTriaFirstAvailable - 1)
  132.             fprintf(hFile, ";\n\n");
  133.         else
  134.             fprintf(hFile, ",\n");
  135.     }
  136.  
  137.     // Mesh Materials
  138.     fprintf(hFile, "MeshMaterialList {\n%d;\n%d;\n", iMtrlFirstAvailable, iTriaFirstAvailable);
  139.     for (iTriangle = 0 ; iTriangle < iTriaFirstAvailable ; iTriangle++)
  140.     {
  141.         fprintf(hFile, "%d", Triangles[iTriangle].iMtrl);
  142.         if (iTriangle == iTriaFirstAvailable - 1)
  143.             fprintf(hFile, ";;\n");
  144.         else
  145.             fprintf(hFile, ",\n");
  146.     }
  147.     for (iMtrl = 0 ; iMtrl < iMtrlFirstAvailable ; iMtrl++)
  148.         fprintf(hFile, "{Material_%d}\n", iMtrl);
  149.     fprintf(hFile, "}\n\n");
  150.  
  151.     // Fin de mesh
  152.     fprintf(hFile, "}\n\n");
  153.  
  154.     // fin de frame
  155.     fprintf(hFile, "}\n\n");
  156.  
  157.     // Animationset
  158.     fprintf(hFile, "AnimationSet skulpt_animset {\n");
  159.     fprintf(hFile, "}\n");
  160.  
  161.  
  162.     fclose(hFile);
  163. }
  164.  
  165. void vLoadDirectX(void)
  166. {
  167. }
  168.  
  169.