9 float x
[5000],y
[5000],z
[5000];
10 float xb
[5000],yb
[5000],zb
[5000];
12 int sx
[5000],sy
[5000];
13 int fac1
[5000],fac2
[5000],fac3
[5000];
20 LONG rad1
[5000],rad2
[5000];
21 LONG zsrt1
[5000],zsrt2
[5000];
29 void radix(int byte
, LONG N
,LONG
*source
,LONG
*dest
,LONG
*srts
,LONG
*srtd
)
35 memset(count
,0,sizeof(count
));
36 for(i
=0;i
<N
;i
++) count
[(source
[i
]>>(byte
*8))& 0xff]++;
38 for(i
=1;i
<256;i
++) index
[i
]=index
[i
-1]+count
[i
-1];
41 w
=index
[(source
[i
]>>(byte
*8))& 0xff]++;
47 void radixsort(LONG
*source
,LONG
*temp
, LONG N
, LONG
*srts
,LONG
*srtd
)
49 radix(0,N
,source
,temp
,srts
,srtd
);
50 radix(1,N
,temp
,source
,srtd
,srts
);
51 radix(2,N
,source
,temp
,srts
,srtd
);
52 radix(3,N
,temp
,source
,srtd
,srts
);
58 int load3d(char *filename
)
68 x[i]=(10000-(float)(rand()%20000))/1000;
69 y[i]=(10000-(float)(rand()%20000))/1000;
70 z[i]=(10000-(float)(rand()%20000))/1000;
73 if (!(file
=KDPloadFile(filename
)))
75 if (KDPgetMlong(&file
[0])!=0x33445257)
77 pointo
=KDPgetMlong(&file
[6]);
78 numf
=KDPgetMword(&file
[10])+1;
79 nump
=KDPgetMword(&file
[pointo
])+1;
84 fac1
[i
]=KDPgetMword(&file
[faceo
]);
86 fac2
[i
]=KDPgetMword(&file
[faceo
]);
88 fac3
[i
]=KDPgetMword(&file
[faceo
]);
94 x
[i
]=(float)KDPgetMword(&file
[pointo
])/1000;
95 y
[i
]=(float)KDPgetMword(&file
[pointo
+2])/1000;
96 z
[i
]=(float)KDPgetMword(&file
[pointo
+4])/1000;
115 printf("points:%d faces:%d \n",nump
,numf
);
123 void project(float zx
)
132 sx
[i
]=(int)((xb
[i
]*256)/zz
)+160;
133 sy
[i
]=(int)((yb
[i
]*256)/zz
)+100;
139 void rotate(float rx
,float ry
,float rz
)
147 sx
=sin(rx
);cx
=cos(rx
);
148 sy
=sin(ry
);cy
=cos(ry
);
149 sz
=sin(rz
);cz
=cos(rz
);
150 xx
=cy
*cz
; xy
=cy
*sz
; xz
=-sy
;
151 yx
=sx
*sy
*cz
-cx
*sz
; yy
=sx
*sy
*sz
+cx
*cz
; yz
=sx
*cy
;
152 zx
=cx
*sy
*cz
+sx
*sz
; zy
=cx
*sy
*sz
-sx
*cz
; zz
=cx
*cy
;
155 xb
[i
]=x
[i
]*xx
+ y
[i
]*xy
+ z
[i
]*xz
;
156 yb
[i
]=x
[i
]*yx
+ y
[i
]*yy
+ z
[i
]*yz
;
157 zb
[i
]=x
[i
]*zx
+ y
[i
]*zy
+ z
[i
]*zz
;
162 void pset(int x
,int y
,UBYTE c
,UBYTE
*vmem
)
165 if((x
<0) || (x
>319) || (y
<0) || (y
>199)) return;
167 vmem
[o
]=ctab
[vmem
[o
]+c
];
170 void pset2(int x
,int y
,UBYTE c
,UBYTE
*vmem
)
173 if((x
<0) || (x
>318) || (y
<0) || (y
>198)) return;
175 vmem
[o
]=ctab
[vmem
[o
]+c
];
176 vmem
[o
+1]=ctab
[vmem
[o
+1]+c
];
177 vmem
[o
+320]=ctab
[vmem
[o
+320]+c
];
178 vmem
[o
+321]=ctab
[vmem
[o
+321]+c
];
181 void sub(UBYTE
*vmem
)
189 void addbuffers(UBYTE
*vmem
)
192 UBYTE
*v0
,*v1
,*v2
,*v3
,*v4
;
200 *(v0
++)=(*(v1
++)+*(v2
++)+*(v3
++)+*(v4
++))>>2;
203 void addbuffers8(UBYTE
*vmem
)
206 UBYTE
*v0
,*v1
,*v2
,*v3
,*v4
,*v5
,*v6
,*v7
,*v8
;
219 *(v0
++)=(*(v1
++)+*(v2
++)+*(v3
++)+*(v4
++)+*(v5
++)+*(v6
++)+*(v7
++)+*(v8
++))>>3;
221 void addbuffers16(UBYTE
*vmem
)
224 UBYTE
*v0
,*v1
,*v2
,*v3
,*v4
,*v5
,*v6
,*v7
,*v8
,*v9
,*v10
,*v11
,*v12
,*v13
,*v14
,*v15
,*v16
;
246 *(v0
++)=(*(v1
++)+*(v2
++)+*(v3
++)+*(v4
++)+*(v5
++)+*(v6
++)+*(v7
++)+*(v8
++)+*(v9
++)+*(v10
++)+*(v11
++)+*(v12
++)+*(v13
++)+*(v14
++)+*(v15
++)+*(v16
++))>>4;
249 int main(int argc
,char **argv
)
269 printf("usage: motionblur <3dobj>\n");
275 if(i
>255) ctab
[i
]=255;
283 if(!(load3d(argv
[1])))
297 KDPreadBMP("bmp/brush1.bmp",pal
,sp1
);
302 KDPpalRange(50,150,255,
314 KDPreadBMP("bmp/cir.bmp",0,tex
);
315 //for(i=0;i<256*256;i++)
316 //tex[i]=KDPcoltab[tex[i]+10];
317 while(mouse
.button
!=3)
321 dc
+=(float)mouse
.yspeed
/500;
322 db
+=(float)mouse
.xspeed
/500;
327 da
+=(float)mouse
.xspeed
/500;
336 speed
+=(float)mouse
.xspeed
/500;
337 dz
=(float)mouse
.yspeed
/50;
342 if(tel
==1) flip
=1-flip
;
345 for(frm
=0;frm
<16;frm
++)
357 if(x
[i
]<-10) x
[i
]=10;
358 if(x
[i
]>10) x
[i
]=-10;
361 project(zx
);//+((float)(frm-4)/2));
366 KDPsp256(sx
[i
],sy
[i
],size
[i
],tex
,vme
[frm
]);
371 /*for(i=0;i<nump;i++)
374 if(x[i]<-10) x[i]=10;
375 if(x[i]>10) x[i]=-10;
388 KDPwriteBMP("bmp/test.bmp",pal
,vmem
,320,200);
389 secs
=(float)(time2
-time1
)/(float)CLOCKS_PER_SEC
;
390 printf("frames: %d time:%f fps:%f\n",frame
,secs
,(float)frame
/secs
);