twistdos.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 1.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <conio.h>
00027 #include <string.h>
00028 #include <math.h>
00029 
00030 #define double float
00031 
00032 #if __ZTC__
00033 #include "\x-32vm\include\x32.h"
00034 #ifndef max
00035 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00036 #endif
00037 #endif
00038 
00039 #if __WATCOMC__
00040 #include "\x-32vm\include\x32.h"
00041 #endif
00042 
00043 typedef struct {
00044  long pos[3];
00045 } vertex;
00046 
00047 typedef struct {
00048  long nvert;
00049  long ltime;
00050  long vmin[3];
00051  long vmax[3];
00052  long origin[3];
00053  double time;
00054 } sfxinfo;
00055 
00056 char     *PrmList=NULL;
00057 vertex   *Vlist=NULL;
00058 sfxinfo  *SFXinfo=NULL,SFX;
00059 
00060 char WriteFXfile(char *fname);
00061 void ExecuteEffect(void);
00062 char ReadFXfile(char *fname);
00063 void SetUpEffect(void);
00064 
00065 int main(int argc, char *argv[]){
00066  if(argc < 2){
00067    printf("Procedural animation program.\n");
00068    exit(-1);
00069  }
00070  if(strcmp(argv[1],"$$") == 0){
00071    unsigned long i;
00072    printf("Ram based effect\n");
00073    i=atol(argv[2]);
00074    SFXinfo=(sfxinfo *)((unsigned int)_x32_zero_base_ptr +
00075                     ((i & 0xFFFF0000) >> 12) + (i & 0xFFFF));
00076    i=atol(argv[3]);
00077    PrmList=(char *)((unsigned int)_x32_zero_base_ptr +
00078                     ((i & 0xFFFF0000) >> 12) + (i & 0xFFFF));
00079    i=atol(argv[4]);
00080    Vlist=(vertex *)((unsigned int)_x32_zero_base_ptr +
00081                     ((i & 0xFFFF0000) >> 12) + (i & 0xFFFF));
00082    ExecuteEffect();
00083  }
00084  else{
00085 //   printf("File based effect\n");
00086    if(ReadFXfile(argv[1]) != 0) exit(-1);
00087    ExecuteEffect();
00088    if(WriteFXfile(argv[1]) != 0) exit(-1);
00089  }
00090  exit(0);
00091 }
00092 
00093 /* FNAME is the name of the temporary file that the EVI render module
00094    produces. The path for this file is passed to your program as its first
00095    argument.
00096    This function returns 0 if the temporary file was successfully opened,
00097    and all its data read in. Error return values are listed below :
00098 
00099                  -1 : Could not open file.
00100                  -2 : Out of memory.
00101                  -3 : Error in vertex (VERT) chunk (file corrupted ?).
00102 
00103 */
00104 char ReadFXfile(char *fname){
00105  FILE *fp;
00106  long size, lp,nv,tl;
00107  short i, j;
00108  char buffer[16], c;
00109  for(i=0; i<16; ++i)buffer[i]=0;
00110  fp=fopen(fname,"rb");
00111  if(fp == NULL) return(-1);
00112  while(1){
00113   if(fread(buffer,sizeof(char),4,fp) != 4) break;  /* Read chunk title */
00114   if(fread(&size,sizeof(long),1,fp) != 1) break;   /* Read chunk length */
00115   if(strcmp(buffer,"INFO") == 0){             /* Read INFO chunk */
00116    fread(&SFX.nvert,sizeof(long),1,fp);
00117    fread(&SFX.ltime,sizeof(long),1,fp);
00118    fread(&SFX.vmin,sizeof(long),3,fp);
00119    fread(&SFX.vmax,sizeof(long),3,fp);
00120    fread(&SFX.origin,sizeof(long),3,fp);
00121    SFX.time=(double)SFX.ltime/1000.0;
00122    SFXinfo = &SFX;
00123   }
00124   else if(strcmp(buffer,"PRMS") == 0){        /* Read Parameter PRMS chunk */
00125    PrmList = (char *)malloc((size+1L)*(long)sizeof(char));
00126    if(PrmList == NULL){
00127     fclose(fp); return(-2);
00128    }
00129    fread(PrmList,sizeof(char),size,fp);
00130   }
00131   else if(strcmp(buffer,"VERT") == 0){          /* Read vertex VERT chunk */
00132    nv = SFXinfo->nvert;
00133    Vlist = (vertex *)malloc((nv+1L) * (long)sizeof(vertex));
00134    if(Vlist == NULL){
00135     fclose(fp); return(-2);
00136    }
00137    for(lp=0L; lp < nv; lp++) for(j=0; j < 3; j++){
00138     if(fread(&tl,sizeof(long),1,fp) != 1){ fclose(fp); return(-3); }
00139     Vlist[lp].pos[j] = tl;
00140    }
00141   }
00142   else {                        /* Chunk not recognized - so it is skipped */
00143    for(lp=0L; lp < size; ++lp) fread(&c,1,1,fp);
00144   }
00145  }
00146  fclose(fp);
00147  return 0;
00148 }
00149 
00150 /* FNAME is the temporary file that the EVI render module produces.
00151    The path for this file is passed to your program as its first
00152    argument.
00153    VERTICES is a pointer to the start of the vertex array to be written out.
00154    Give NULL as a value for this parameter if you do not wish to write out
00155    vertices.
00156    This function returns 0 if the temporary file was successfully opened,
00157    and all the data written out. Error return values are listed below :
00158 
00159                  -1 : Could not open file.
00160                  -2 : Could not write vertices (disk full ?).
00161                  NOTE: -2 is a fatal error and you should abandon your
00162                  special effect and return control to the renderer. Since
00163                  not all of the vertex positions can be written, none are
00164                  written and the temporary comunications file is
00165                  automatically deleted.
00166 
00167 */
00168 char WriteFXfile(char *fname){
00169  FILE *fo;
00170  long size, lp,tl;
00171  short j;
00172  fo=fopen(fname,"wb");
00173  if(fo == NULL) return(-1);
00174  fprintf(fo,"VERT");
00175  size=(long)SFXinfo->nvert * (long)sizeof(long) * (long)3;
00176  fwrite(&size,sizeof(long),1,fo);
00177  for(lp=0L; lp < SFXinfo->nvert; lp++){
00178   for(j=0; j < 3; j++){
00179    tl=Vlist[lp].pos[j];
00180    if(fwrite(&tl,sizeof(long),1,fo) != 1){
00181     fclose(fo); remove(fname); return(-2);
00182    }
00183   }
00184  }
00185  fclose(fo);
00186  return 0;
00187 }
00188 /*******************************************************************\
00189 |                Code that define the effects                       |
00190 \*******************************************************************/
00191 
00192 void ExecuteEffect(void)
00193 {
00194  double h,d,t,x,y;
00195  long i;
00196  short val;
00197  double PRMangle=60, angle, ang;
00198  char PRMaxis, axis, paxis, paxis2, buffer[128], type;
00199  sscanf(PrmList,"%s %d %d %d",buffer,&PRMaxis,&type,&val);
00200  PRMangle=(double)val;
00201  t=SFXinfo->time;
00202  if(PRMaxis == 3) axis=1;         /* F / B */
00203  else if(PRMaxis == 1) axis=2;    /* U / D */
00204  else if(PRMaxis == 2) axis=0;    /* L / R */
00205  if(axis == 0){      paxis = 1; paxis2 = 2; }
00206  else if(axis == 2){ paxis = 1; paxis2 = 0; }
00207  else if(axis == 1){ paxis = 0; paxis2 = 2; }
00208  if(type == 2) t = 1.00 - t;
00209  t = -1.00 * (t*t) + 2.00 * t;
00210  angle=(PRMangle * PI/180) * t;
00211  for(i=0L; i < SFXinfo->nvert; i++){
00212   h=(double)(Vlist[i].pos[axis] - SFXinfo->vmin[axis]) /
00213     (double)(SFXinfo->vmax[axis] - SFXinfo->vmin[axis]);
00214   ang=angle * h;
00215   x=Vlist[i].pos[paxis]; y=Vlist[i].pos[paxis2];
00216   Vlist[i].pos[paxis]=(double)x*(double)cos(ang)-(double)y*(double)sin(ang);
00217   Vlist[i].pos[paxis2]=(double)y*(double)cos(ang)+(double)x*(double)sin(ang);
00218  }
00219 }
Generated on Tue Jan 28 06:18:30 2014 for OpenFX by  doxygen 1.6.3