test.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("Envisage 3D procedural animation program.\n");
00068    exit(-1);
00069  }
00070  if(strcmp(argv[1],"$$") == 0){
00071    unsigned long i;
00072 //printf("Ram based\n");
00073 //printf("%s %s %s\n",argv[2],argv[3],argv[4]);
00074    i=atol(argv[2]);
00075    SFXinfo=(sfxinfo *)((unsigned int)_x32_zero_base_ptr +
00076                     ((i & 0xFFFF0000) >> 12) + (i & 0xFFFF));
00077    i=atol(argv[3]);
00078    PrmList=(char *)((unsigned int)_x32_zero_base_ptr +
00079                     ((i & 0xFFFF0000) >> 12) + (i & 0xFFFF));
00080    i=atol(argv[4]);
00081    Vlist=(vertex *)((unsigned int)_x32_zero_base_ptr +
00082                     ((i & 0xFFFF0000) >> 12) + (i & 0xFFFF));
00083 //printf("Vertices %ld ltime %ld  time %f\n",SFXinfo->nvert,SFXinfo->ltime,
00084 //        SFXinfo->time);
00085 //printf("Max and min %ld %ld   %ld %ld   %ld %ld\n",
00086 //SFXinfo->vmax[0],SFXinfo->vmin[0],
00087 //SFXinfo->vmax[1],SFXinfo->vmin[1],
00088 //SFXinfo->vmax[2],SFXinfo->vmin[2]);
00089 //if(PrmList != NULL)printf("[%s]\n",PrmList);
00090 //getch();
00091    ExecuteEffect();
00092  }
00093  else{
00094    if(ReadFXfile(argv[1]) != 0) exit(-1);
00095    ExecuteEffect();
00096    if(WriteFXfile(argv[1]) != 0) exit(-1);
00097  }
00098  exit(0);
00099 }
00100 
00101 /* FNAME is the name of the temporary file that the EVI render module
00102    produces. The path for this file is passed to your program as its first
00103    argument.
00104    This function returns 0 if the temporary file was successfully opened,
00105    and all its data read in. Error return values are listed below :
00106 
00107                  -1 : Could not open file.
00108                  -2 : Out of memory.
00109                  -3 : Error in vertex (VERT) chunk (file corrupted ?).
00110 
00111 */
00112 char ReadFXfile(char *fname){
00113  FILE *fp;
00114  long size, lp,nv,tl;
00115  short i, j;
00116  char buffer[16], c;
00117  for(i=0; i<16; ++i)buffer[i]=0;
00118  fp=fopen(fname,"rb");
00119  if(fp == NULL) return(-1);
00120  while(1){
00121   if(fread(buffer,sizeof(char),4,fp) != 4) break;  /* Read chunk title */
00122   if(fread(&size,sizeof(long),1,fp) != 1) break;   /* Read chunk length */
00123   if(strcmp(buffer,"INFO") == 0){             /* Read INFO chunk */
00124    fread(&SFX.nvert,sizeof(long),1,fp);
00125    fread(&SFX.ltime,sizeof(long),1,fp);
00126    fread(&SFX.vmin,sizeof(long),3,fp);
00127    fread(&SFX.vmax,sizeof(long),3,fp);
00128    fread(&SFX.origin,sizeof(long),3,fp);
00129    SFX.time=(double)SFX.ltime/1000.0;
00130    SFXinfo = &SFX;
00131   }
00132   else if(strcmp(buffer,"PRMS") == 0){        /* Read Parameter PRMS chunk */
00133    PrmList = (char *)malloc((size+1L)*(long)sizeof(char));
00134    if(PrmList == NULL){
00135     fclose(fp); return(-2);
00136    }
00137    fread(PrmList,sizeof(char),size,fp);
00138   }
00139   else if(strcmp(buffer,"VERT") == 0){          /* Read vertex VERT chunk */
00140    nv = SFXinfo->nvert;
00141    Vlist = (vertex *)malloc((nv+1L) * (long)sizeof(vertex));
00142    if(Vlist == NULL){
00143     fclose(fp); return(-2);
00144    }
00145    for(lp=0L; lp < nv; lp++) for(j=0; j < 3; j++){
00146     if(fread(&tl,sizeof(long),1,fp) != 1){ fclose(fp); return(-3); }
00147     Vlist[lp].pos[j] = tl;
00148    }
00149   }
00150   else {                        /* Chunk not recognized - so it is skipped */
00151    for(lp=0L; lp < size; ++lp) fread(&c,1,1,fp);
00152   }
00153  }
00154  fclose(fp);
00155  return 0;
00156 }
00157 
00158 /* FNAME is the temporary file that the EVI render module produces.
00159    The path for this file is passed to your program as its first
00160    argument.
00161    VERTICES is a pointer to the start of the vertex array to be written out.
00162    Give NULL as a value for this parameter if you do not wish to write out
00163    vertices.
00164    This function returns 0 if the temporary file was successfully opened,
00165    and all the data written out. Error return values are listed below :
00166 
00167                  -1 : Could not open file.
00168                  -2 : Could not write vertices (disk full ?).
00169                  NOTE: -2 is a fatal error and you should abandon your
00170                  special effect and return control to the renderer. Since
00171                  not all of the vertex positions can be written, none are
00172                  written and the temporary comunications file is
00173                  automatically deleted.
00174 
00175 */
00176 char WriteFXfile(char *fname){
00177  FILE *fo;
00178  long size, lp,tl;
00179  short j;
00180  fo=fopen(fname,"wb");
00181  if(fo == NULL) return(-1);
00182  fprintf(fo,"VERT");
00183  size=(long)SFXinfo->nvert * (long)sizeof(long) * (long)3;
00184  fwrite(&size,sizeof(long),1,fo);
00185  for(lp=0L; lp < SFXinfo->nvert; lp++){
00186   for(j=0; j < 3; j++){
00187    tl=Vlist[lp].pos[j];
00188    if(fwrite(&tl,sizeof(long),1,fo) != 1){
00189     fclose(fo); remove(fname); return(-2);
00190    }
00191   }
00192  }
00193  fclose(fo);
00194  return 0;
00195 }
00196 /*******************************************************************\
00197 |                Code that define the effects                       |
00198 \*******************************************************************/
00199 
00200 void ExecuteEffect(void){
00201  double amplitude,wavelength,displacement,distance;
00202  long i;
00203  double PRMfreq, PRMwavelength;
00204  char axis, *cp;
00205  wavelength=max((double)(SFXinfo->vmax[1]-SFXinfo->vmin[1]),1.0) / 12.0;
00206  amplitude=wavelength/24;
00207  for(i=0L; i < SFXinfo->nvert; i++){
00208   distance=sqrt((double)Vlist[i].pos[0]*(double)Vlist[i].pos[0] +
00209                 (double)Vlist[i].pos[1]*(double)Vlist[i].pos[1]);
00210   displacement=amplitude*cos(PI*2*(SFXinfo->time-distance/wavelength));
00211   Vlist[i].pos[2] += (long)displacement;
00212  }
00213 }
00214 
Generated on Tue Jan 28 06:18:32 2014 for OpenFX by  doxygen 1.6.3