00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00094
00095
00096
00097
00098
00099
00100
00101
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;
00114 if(fread(&size,sizeof(long),1,fp) != 1) break;
00115 if(strcmp(buffer,"INFO") == 0){
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){
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){
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 {
00143 for(lp=0L; lp < size; ++lp) fread(&c,1,1,fp);
00144 }
00145 }
00146 fclose(fp);
00147 return 0;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
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
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;
00203 else if(PRMaxis == 1) axis=2;
00204 else if(PRMaxis == 2) axis=0;
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 }