fix detection of ssl in configure script.
[AROS-Contrib.git] / Demo / kdp / scaletest.c
blobc88c5d16734a4d4c1ecc4c9ee22ed8821a53de5c
1 #include <math.h>
3 #include "kdp.h"
4 #include "kdpgfx.h"
5 #include <stdlib.h>
7 float x[5000],y[5000],z[5000];
8 float xb[5000],yb[5000],zb[5000];
9 int sx[5000],sy[5000];
10 float size[5000];
12 UBYTE tex[256*256];
14 int nump,numf;
16 int load3d(char *filename)
18 UBYTE *file;
19 int pointo;
20 int i;
21 float xofs,yofs,zofs;
23 if (!(file=KDPloadFile(filename)))
24 return 0;
25 if (KDPgetMlong(&file[0])!=0x33445257)
26 return 0;
27 pointo=KDPgetMlong(&file[6]);
28 numf=KDPgetMword(&file[10])+1;
29 nump=KDPgetMword(&file[pointo])+1;
31 pointo+=2;
32 for(i=0;i<nump;i++)
34 x[i]=(float)KDPgetMword(&file[pointo])/1000;
35 y[i]=(float)KDPgetMword(&file[pointo+2])/1000;
36 z[i]=(float)KDPgetMword(&file[pointo+4])/1000;
37 pointo+=6;
39 xofs=0;yofs=0;zofs=0;
40 for(i=0;i<nump;i++)
42 xofs+=x[i];
43 yofs+=y[i];
44 zofs+=z[i];
46 xofs/=nump;
47 yofs/=nump;
48 zofs/=nump;
49 for(i=0;i<nump;i++)
51 x[i]-=xofs;
52 y[i]-=yofs;
53 z[i]-=zofs;
55 return 1;
62 void project(float zx)
64 int i;
65 float zz;
66 for(i=0;i<nump;i++)
68 zz=-(zb[i]-zx);
69 if (zz!=0)
71 sx[i]=(int)((xb[i]*256)/zz)+160;
72 sy[i]=(int)((yb[i]*256)/zz)+100;
73 size[i]=256/zz;
78 void rotate(float rx,float ry,float rz)
80 int i;
81 float xx,xy,xz;
82 float yx,yy,yz;
83 float zx,zy,zz;
84 float sx,sy,sz;
85 float cx,cy,cz;
86 sx=sin(rx);cx=cos(rx);
87 sy=sin(ry);cy=cos(ry);
88 sz=sin(rz);cz=cos(rz);
89 xx=cy*cz; xy=cy*sz; xz=-sy;
90 yx=sx*sy*cz-cx*sz; yy=sx*sy*sz+cx*cz; yz=sx*cy;
91 zx=cx*sy*cz+sx*sz; zy=cx*sy*sz-sx*cz; zz=cx*cy;
92 for(i=0;i<nump;i++)
94 xb[i]=x[i]*xx + y[i]*xy + z[i]*xz;
95 yb[i]=x[i]*yx + y[i]*yy + z[i]*yz;
96 zb[i]=x[i]*zx + y[i]*zy + z[i]*zz;
101 int main(int argc,char **argv)
103 KDPscreen screen;
104 KDPmouse mouse;
105 UBYTE *vmem;
106 UBYTE pal[2][256*3];
108 float a=0,b=0,c=0;
109 float da=0,db=0,dc=0;
110 int i;
111 float zx=20;
112 float m=1;
113 float speed=0;
114 float qx=0,qy=0;
116 if (argc < 2)
118 printf("usage: scaletest <3dobj>\n");
119 return 0;
122 if(load3d(argv[1])==0)
124 printf("hmm...\n");return 0;
127 KDPpalRange( 0, 0, 0,
128 150,180,220,
129 0,200,pal[0]);
130 KDPpalRange(150,180,220,
131 255,255,255,
132 200,255,pal[0]);
133 for(i=0;i<256;i++)
134 pal[1][i]=pal[0][i]/2;
135 KDPreadBMP("bmp/cir.bmp",0,tex);
136 if(KDPopen(&screen))
138 vmem=screen.vmem;
139 KDPgetMouse(&mouse);
140 KDPgetMouse(&mouse);
141 KDPsetPal(pal[0]);
142 while(mouse.button!=3)
144 if(mouse.button==0)
146 da+=(float)mouse.xspeed/500;
147 dc+=(float)mouse.yspeed/500;
149 if(mouse.button==1) {zx+=(float)mouse.yspeed/10;db+=(float)mouse.xspeed/500;}
150 if(mouse.button==2) {speed+=(float)mouse.yspeed/50;m+=(float)mouse.xspeed/50;da=0;db=0;dc=0;}
151 if(m<1) m=1;
152 a+=da;b+=db;c+=dc;
153 rotate(a,b,c);
154 project(zx);
155 qx+=0.03;
156 qy+=0.03;
160 for(i=0;i<nump;i++)
161 KDPsp256(sx[i],sy[i],(int)(size[i]),tex,vmem);
163 KDPwaitVr();
166 //KDPblur2(vmem);
167 KDPshow(vmem);
168 KDPcls(vmem);
169 KDPgetMouse(&mouse);
172 KDPclose(&screen);
173 return 0;