7 float x
[5000],y
[5000],z
[5000];
8 float xb
[5000],yb
[5000],zb
[5000];
10 int fac1
[5000],fac2
[5000],fac3
[5000];
19 int load3d(char *filename
)
26 if (!(file
=KDPloadFile(filename
)))
28 if (KDPgetMlong(&file
[0])!=0x33445257)
30 pointo
=KDPgetMlong(&file
[6]);
31 numf
=KDPgetMword(&file
[10])+1;
32 nump
=KDPgetMword(&file
[pointo
])+1;
37 fac1
[i
]=KDPgetMword(&file
[faceo
]);
39 fac2
[i
]=KDPgetMword(&file
[faceo
]);
41 fac3
[i
]=KDPgetMword(&file
[faceo
]);
47 x
[i
]=(float)KDPgetMword(&file
[pointo
])/1000;
48 y
[i
]=(float)KDPgetMword(&file
[pointo
+2])/1000;
49 z
[i
]=(float)KDPgetMword(&file
[pointo
+4])/1000;
75 void project(float zx
)
84 sx
[i
]=(int)((xb
[i
]*256)/zz
)+160;
85 sy
[i
]=(int)((yb
[i
]*256)/zz
)+100;
90 void rotate(float rx
,float ry
,float rz
)
98 sx
=sin(rx
);cx
=cos(rx
);
99 sy
=sin(ry
);cy
=cos(ry
);
100 sz
=sin(rz
);cz
=cos(rz
);
101 xx
=cy
*cz
; xy
=cy
*sz
; xz
=-sy
;
102 yx
=sx
*sy
*cz
-cx
*sz
; yy
=sx
*sy
*sz
+cx
*cz
; yz
=sx
*cy
;
103 zx
=cx
*sy
*cz
+sx
*sz
; zy
=cx
*sy
*sz
-sx
*cz
; zz
=cx
*cy
;
106 xb
[i
]=x
[i
]*xx
+ y
[i
]*xy
+ z
[i
]*xz
;
107 yb
[i
]=x
[i
]*yx
+ y
[i
]*yy
+ z
[i
]*yz
;
108 zb
[i
]=x
[i
]*zx
+ y
[i
]*zy
+ z
[i
]*zz
;
113 void pset(int x
,int y
,UBYTE c
,UBYTE
*vmem
)
116 if((x
<0) || (x
>319) || (y
<0) || (y
>199)) return;
118 vmem
[o
]=ctab
[vmem
[o
]+c
];
121 void pset2(int x
,int y
,UBYTE c
,UBYTE
*vmem
)
124 if((x
<0) || (x
>318) || (y
<0) || (y
>198)) return;
126 vmem
[o
]=ctab
[vmem
[o
]+c
];
127 vmem
[o
+1]=ctab
[vmem
[o
+1]+c
];
128 vmem
[o
+320]=ctab
[vmem
[o
+320]+c
];
129 vmem
[o
+321]=ctab
[vmem
[o
+321]+c
];
132 void sub(UBYTE
*vmem
)
139 int main(int argc
,char **argv
)
155 printf("usage: wire <3dobj>\n");
161 if(i
>255) ctab
[i
]=255;
169 if(!(load3d(argv
[1])))
188 KDPsetColor(0,30,30,50);
189 while(mouse
.button
!=3)
193 dc
+=(float)mouse
.yspeed
/500;
194 db
+=(float)mouse
.xspeed
/500;
198 da
+=(float)mouse
.xspeed
/500;
207 zx
+=(float)mouse
.yspeed
/10;
217 KDPpset2(kl
,0,255,vmem
);
224 if ((zb
[ia
]<zx
) && (zb
[ib
]<zx
) && (zb
[ic
]<zx
))
226 KDPline2(sx
[ia
],sy
[ia
],sx
[ib
],sy
[ib
],kl
,vmem
);
227 KDPline2(sx
[ib
],sy
[ib
],sx
[ic
],sy
[ic
],kl
,vmem
);
228 KDPline2(sx
[ic
],sy
[ic
],sx
[ia
],sy
[ia
],kl
,vmem
);
238 secs
=(float)(time2
-time1
)/(float)CLOCKS_PER_SEC
;
239 printf("frames: %d time:%f fps:%f\n",frame
,secs
,(float)frame
/secs
);