home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / MEDIT.LZH / RENDEXEC.CPP < prev    next >
C/C++ Source or Header  |  1996-06-17  |  3KB  |  117 lines

  1. #include <owl\owlpch.h>
  2. #pragma hdrstop
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <dos.h>
  6. #include <cstring.h>
  7. #include <dir.h>
  8. #include "matrix.h"
  9. #include "suflib.h"
  10. #include "parts.h"
  11. #include "profile.h"
  12. #include "motion.h"
  13. #include "mecha.h"
  14. #include "files.h"
  15.  
  16. #include "log.h"
  17.  
  18. static char *indfile = "_temp1.ind";
  19. static char *frmfile = "_temp.frm";
  20. static char *cRend   = "rendwin.exe";
  21. static char *cWire   = "wireview.exe";
  22.  
  23. void WireView(Motion *motion, CameraMotion *camera, Vector& light)
  24. {
  25.     char str[128];
  26.     sprintf(str, "%s%s", tempdir.c_str(), frmfile);
  27.     Motion::FileWrite(motion, camera, light, str);
  28.     sprintf(str, "%s%s %s%s", pathdir.c_str(), cWire, tempdir.c_str(), frmfile);
  29.     WinExec(str, SW_SHOW);
  30. }
  31.  
  32. #define MAXPARTS 1024
  33.  
  34. void RendNowMotion(Motion *motion, CameraMotion *camera, Vector& light, int frame)
  35. {
  36.     Object *objlist[MAXPARTS];
  37.     int nobj = 0;
  38.     char str[128];
  39.     FILE *fp;
  40.     FILE *frmfp;
  41.     sprintf(str, "%s%s", tempdir.c_str(), indfile);
  42.     if ((fp = fopen(str, "w")) == NULL) {
  43.         return;
  44.     }
  45.     sprintf(str, "%s%s", tempdir.c_str(), frmfile);
  46.     if ((frmfp = fopen(str, "w")) == NULL) {
  47.         fclose(fp);
  48.         return;
  49.     }
  50.  
  51.     fprintf(frmfp,
  52.         "/*                            Motion Editor\n"
  53.         "                                  Version 1.00γ\n"
  54.         "Frame: %d\n"
  55.         "*/\n", frame);
  56.  
  57.     fprintf(frmfp, "fram\n{\n"
  58.         "\tlight pal( rgb ( 1.00 1.00 1.00 ) %4.0lf %4.0lf %4.0lf)\n",
  59.             100.0 * light.x, 100.0 * light.y, 100.0 * light.z);
  60.  
  61.     fprintf(frmfp,
  62.             "\t{\tmov ( %5.0lf %5.0lf %5.0lf ) "
  63.             "rotz( %7.3lf ) roty( %7.3lf ) rotx( %7.3lf ) "
  64.             "eye deg ( %d ) }\n",
  65.         camera->position.x, camera->position.y, camera->position.z,
  66.         rad(camera->rotation.z), rad(camera->rotation.y), rad(camera->rotation.x),
  67.         int(rad(camera->angle)+0.5)
  68.         );
  69.  
  70.     fprintf(fp, "%s\n", atrfile.c_str());
  71.     fprintf(fp, "%s%s\n", tempdir.c_str(), frmfile);
  72.     for (Motion *m = motion; m != NULL; m = m->next) {
  73.         if (m->beginframe <= frame && frame <= m->endframe) {
  74.             m->GetName(str);
  75.             fprintf(frmfp,
  76.                 "  {\t/*%s*/\n"
  77.                 "\tmov ( %5.0lf %5.0lf %5.0lf ) "
  78.                 "rotz( %7.3lf ) roty( %7.3lf ) rotx( %7.3lf ) "
  79.                 "scal( %7.3lf %7.3lf %7.3lf )\n",
  80.                 str,
  81.                 m->position.x, m->position.y, m->position.z,
  82.                 rad(m->rotation.z), rad(m->rotation.y), rad(m->rotation.x),
  83.                 m->scale.x, m->scale.y, m->scale.z);
  84.             for (Parts *p = m->mecha->parts; p != NULL; p = p->next) {
  85.                 p->PartsWrite(frmfp, NULL, 0);
  86.                 for (int no = 0; no < nobj; ++no) {
  87.                     if (objlist[no] == p->object) {
  88.                         break;
  89.                     }
  90.                 }
  91.                 if (no == nobj) {
  92.                     objlist[nobj++] = p->object;
  93.                     char *f = p->object->filename;
  94.                     if (strncmpi(f, simplepartsdir.c_str(), simplepartsdir.length()) == 0) {
  95.                         fprintf(fp, "%s%s\n", partsdir.c_str(), f+simplepartsdir.length());
  96.                     } else if (f[1] == ':' || f[0] == '\\') {
  97.                         fprintf(fp, "%s\n", f);
  98.                     } else {
  99.                         fprintf(fp, "%s%s\n", partsdir.c_str(), f);
  100.                     }
  101.                 }
  102.             }
  103.             fprintf(frmfp, "  }\n");
  104.         }
  105.     }
  106.     fprintf(frmfp, "}\n");
  107.     if (rendoption == "") {
  108.         fprintf(fp, "-c512x384 -n -g\n");
  109.     } else {
  110.         fprintf(fp, "%s\n", rendoption.c_str());
  111.     }
  112.     fclose(fp);
  113.     fclose(frmfp);
  114.     sprintf(str, "%s%s @%s%s", pathdir.c_str(), cRend, tempdir.c_str(), indfile);
  115.     WinExec(str, SW_SHOW);
  116. }
  117.