7 float x
[5000],y
[5000],z
[5000];
8 float xb
[5000],yb
[5000],zb
[5000];
16 int load3d(char *filename
)
23 if (!(file
=KDPloadFile(filename
)))
25 if (KDPgetMlong(&file
[0])!=0x33445257)
27 pointo
=KDPgetMlong(&file
[6]);
28 numf
=KDPgetMword(&file
[10])+1;
29 nump
=KDPgetMword(&file
[pointo
])+1;
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;
62 void project(float zx
)
71 sx
[i
]=(int)((xb
[i
]*256)/zz
)+160;
72 sy
[i
]=(int)((yb
[i
]*256)/zz
)+100;
78 void rotate(float rx
,float ry
,float rz
)
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
;
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
)
109 float da
=0,db
=0,dc
=0;
118 printf("usage: scaletest <3dobj>\n");
122 if(load3d(argv
[1])==0)
124 printf("hmm...\n");return 0;
127 KDPpalRange( 0, 0, 0,
130 KDPpalRange(150,180,220,
134 pal
[1][i
]=pal
[0][i
]/2;
135 KDPreadBMP("bmp/cir.bmp",0,tex
);
142 while(mouse
.button
!=3)
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;}
161 KDPsp256(sx
[i
],sy
[i
],(int)(size
[i
]),tex
,vmem
);