1.    using System; 
2.    using System.Drawing; 
3.  
4.    namespace TankPocket 
5.    { 
6.   public class TDObject 
7.   { 
8.       public void Initialize(int object_type) 
9.       { 
10.  
11.        //  
12.        // ıԵ. 
           // Ҫʱٶ󣬲ҴСȷ 
13.  
14.        ObjectType = object_type; 
15.        int i; 
16.  
17.        if (object_type==1) 
18.        { 
19.          // Cube 
20.          tdshape = new tdpoint[24]; 
21.          i=0; 
22.          tdshape[i].x=   2   ; 
23.          tdshape[i].y= 2 ; 
24.          tdshape[i++].z= 2 ; 
25.          tdshape[i].x= -2 ; 
26.          tdshape[i].y= 2 ; 
27.          tdshape[i++].z= 2 ; 
28.          tdshape[i].x= -2 ; 
29.          tdshape[i].y= 2 ; 
30.          tdshape[i++].z= 2 ; 
31.          tdshape[i].x= -2 ; 
32.          tdshape[i].y= -2 ; 
33.          tdshape[i++].z= 2 ; 
34.          tdshape[i].x= -2 ; 
35.          tdshape[i].y= -2 ; 
36.          tdshape[i++].z= 2 ; 
37.          tdshape[i].x= 2 ; 
38.          tdshape[i].y= -2 ; 
39.          tdshape[i++].z= 2 ; 
40.          tdshape[i].x= 2 ; 
41.          tdshape[i].y= -2 ; 
42.          tdshape[i++].z= 2 ; 
43.          tdshape[i].x= 2 ; 
44.          tdshape[i].y= 2 ; 
45.          tdshape[i++].z= 2 ; 
46.          tdshape[i].x= 2 ; 
47.          tdshape[i].y= 2 ; 
48.          tdshape[i++].z= -2 ; 
49.          tdshape[i].x= -2 ; 
50.          tdshape[i].y= 2 ; 
51.          tdshape[i++].z= -2 ; 
52.          tdshape[i].x= -2 ; 
53.          tdshape[i].y= 2 ; 
54.          tdshape[i++].z= -2 ; 
55.          tdshape[i].x= -2 ; 
56.          tdshape[i].y= -2 ; 
57.          tdshape[i++].z= -2 ; 
58.          tdshape[i].x= -2 ; 
59.          tdshape[i].y= -2 ; 
60.          tdshape[i++].z= -2 ; 
61.          tdshape[i].x= 2 ; 
62.          tdshape[i].y= -2 ; 
63.          tdshape[i++].z= -2 ; 
64.          tdshape[i].x= 2 ; 
65.          tdshape[i].y= -2 ; 
66.          tdshape[i++].z= -2 ; 
67.          tdshape[i].x= 2 ; 
68.          tdshape[i].y= 2 ; 
69.          tdshape[i++].z= -2 ; 
70.          tdshape[i].x= 2 ; 
71.          tdshape[i].y= 2 ; 
72.          tdshape[i++].z= 2 ; 
73.          tdshape[i].x= 2 ; 
74.          tdshape[i].y= 2 ; 
75.          tdshape[i++].z= -2 ; 
76.          tdshape[i].x= -2 ; 
77.          tdshape[i].y= 2 ; 
78.          tdshape[i++].z= 2 ; 
79.          tdshape[i].x= -2 ; 
80.          tdshape[i].y= 2 ; 
81.          tdshape[i++].z= -2 ; 
82.          tdshape[i].x= -2 ; 
83.          tdshape[i].y= -2 ; 
84.          tdshape[i++].z= 2 ; 
85.          tdshape[i].x= -2 ; 
86.          tdshape[i].y= -2 ; 
87.          tdshape[i++].z= -2 ; 
88.          tdshape[i].x= 2 ; 
89.          tdshape[i].y= -2 ; 
90.          tdshape[i++].z= 2 ; 
91.          tdshape[i].x= 2 ; 
92.          tdshape[i].y= -2 ; 
93.          tdshape[i++].z= -2 ; 
94.      } 
95.    
96.      if (object_type==2) 
97.      { 
98.           // ̹
99.           // ̹! 
100.          tdshape = new tdpoint[34]; 
101.          i=0; 
102.          tdshape[i].x= 2 ; 
103.          tdshape[i].y= 0 ; 
104.          tdshape[i++].z= (float)1.5 ; 
105.          tdshape[i].x= -3 ; 
106.          tdshape[i].y= 0 ; 
107.          tdshape[i++].z= (float)1.5 ; 
108.          tdshape[i].x= -3 ; 
109.          tdshape[i].y= 0 ; 
110.          tdshape[i++].z= (float)1.5 ; 
111.          tdshape[i].x= -2 ; 
112.          tdshape[i].y= 1 ; 
113.          tdshape[i++].z= (float)1 ; 
114.          tdshape[i].x= -2 ; 
115.          tdshape[i].y= 1 ; 
116.          tdshape[i++].z= (float)1 ; 
117.          tdshape[i].x= 1 ; 
118.          tdshape[i].y= 1 ; 
119.          tdshape[i++].z= (float)1 ; 
120.          tdshape[i].x= 1 ; 
121.          tdshape[i].y= 1 ; 
122.          tdshape[i++].z= (float)1 ; 
123.          tdshape[i].x= 2 ; 
124.          tdshape[i].y= 0 ; 
125.          tdshape[i++].z= (float)1.5 ; 
126.          tdshape[i].x= 2 ; 
127.          tdshape[i].y= 0 ; 
128.          tdshape[i++].z= (float)-1.5 ; 
129.          tdshape[i].x= -3 ; 
130.          tdshape[i].y= 0 ; 
131.          tdshape[i++].z= (float)-1.5 ; 
132.          tdshape[i].x= -3 ; 
133.          tdshape[i].y= 0 ; 
134.          tdshape[i++].z= (float)-1.5 ; 
135.          tdshape[i].x= -2 ; 
136.          tdshape[i].y= 1 ; 
137.          tdshape[i++].z= (float)-1   ; 
138.          tdshape[i].x= -2 ; 
139.          tdshape[i].y= 1 ; 
140.          tdshape[i++].z= (float)-1   ; 
141.          tdshape[i].x= 1 ; 
142.          tdshape[i].y= 1 ; 
143.          tdshape[i++].z= (float)-1   ; 
144.          tdshape[i].x= 1 ; 
145.          tdshape[i].y= 1 ; 
146.          tdshape[i++].z= (float)-1   ; 
147.          tdshape[i].x= 2 ; 
148.          tdshape[i].y= 0 ; 
149.          tdshape[i++].z= (float)-1.5 ; 
150.          tdshape[i].x= 2 ; 
151.          tdshape[i].y= 0 ; 
152.          tdshape[i++].z= (float)1.5 ; 
153.          tdshape[i].x= 2 ; 
154.          tdshape[i].y= 0 ; 
155.          tdshape[i++].z= (float)-1.5 ; 
156.          tdshape[i].x= -3 ; 
157.          tdshape[i].y= 0 ; 
158.          tdshape[i++].z= (float)1.5 ; 
159.          tdshape[i].x= -3 ; 
160.          tdshape[i].y= 0 ; 
161.          tdshape[i++].z= (float)-1.5 ; 
162.          tdshape[i].x= -2 ; 
163.          tdshape[i].y= 1 ; 
164.          tdshape[i++].z= (float)1 ; 
165.          tdshape[i].x= -2 ; 
166.          tdshape[i].y= 1 ; 
167.          tdshape[i++].z= (float)-1   ; 
168.          tdshape[i].x= 1 ; 
169.          tdshape[i].y= 1 ; 
170.          tdshape[i++].z= (float)1 ; 
171.          tdshape[i].x= 1 ; 
172.          tdshape[i].y= 1 ; 
173.          tdshape[i++].z= (float)-1   ; 
174.          tdshape[i].x= 2 ; 
175.          tdshape[i].y= 0 ; 
176.          tdshape[i++].z= (float)1.5 ; 
177.          tdshape[i].x= 1 ; 
178.          tdshape[i].y= -2 ; 
179.          tdshape[i++].z= 0 ; 
180.          tdshape[i].x= 2 ; 
181.          tdshape[i].y= 0 ; 
182.          tdshape[i++].z= (float)-1.5 ; 
183.          tdshape[i].x= 1 ; 
184.          tdshape[i].y= -2 ; 
185.          tdshape[i++].z= 0 ; 
186.          tdshape[i].x= -3 ; 
187.          tdshape[i].y= 0 ; 
188.          tdshape[i++].z= (float)1.5 ; 
189.          tdshape[i].x= 1 ; 
190.          tdshape[i].y= -2 ; 
191.          tdshape[i++].z= 0 ; 
192.          tdshape[i].x= -3 ; 
193.          tdshape[i].y= 0 ; 
194.          tdshape[i++].z= (float)-1.5 ; 
195.          tdshape[i].x= 1 ; 
196.          tdshape[i].y= -2 ; 
197.          tdshape[i++].z= 0 ; 
198.          tdshape[i].x= 0 ; 
199.          tdshape[i].y=  (float)-1.5 ; 
200.          tdshape[i++].z= 0 ; 
201.          tdshape[i].x= -3 ; 
202.          tdshape[i].y=  (float)-1.5 ; 
203.          tdshape[i++].z= 0 ; 
204.      } 
205. 
206.       if (object_type==3) 
207.       { 
208.          // Flag
209.          // һСıǼ״. 
210. 
211.          tdshape = new tdpoint[4]; 
212.          tdshape[0].x=0; 
213.          tdshape[0].y=0; 
214.          tdshape[0].z=0; 
215.          tdshape[1].x=0; 
216.          tdshape[1].y=-2; 
217.          tdshape[1].z=0; 
218.          tdshape[2].x=1; 
219.          tdshape[2].y=(float)-1.5; 
220.          tdshape[2].z=0; 
221.          tdshape[3].x=0; 
222.          tdshape[3].y=-1; 
223.          tdshape[3].z=0; 
224.      } 
225.    } 
226.    
227.    public float GetX() 
228.    { 
229.        // һضXλ 
230.        return position_x; 
231.    } 
232.    
233.    public float GetZ() 
234.    { 
235.        // һضYλ 
236.        return position_z; 
237.    } 
238.    
239.    public void SetPosition(float x, float y, float z) 
240.    { 
241.        // һܿöλ 
242.        position_x = x; 
243.        position_y = y; 
244.        position_z = z; 
245.    } 
246. 
247.    public void Spin(float angle) 
248.    { 
249.        // ŶԼYת 
250. 
251.    
252.        float zz,xx; 
253. 
254.        // ͨЩһЩʱ 
255.        // Sin and Cosine values just the once.. 
256.        float sd=(float)Math.Sin(angle*3.141592654/180); 
257.        float cd=(float)Math.Cos(angle*3.141592654/180); 
258.    
259.        int j=0; 
260. 
261.        for (j=0;j<tdshape.GetLength(0);j++) 
262.        { 
263.            xx=(tdshape[j].x*cd)-(tdshape[j].z*sd); 
264.            zz=(tdshape[j].x*sd)+(tdshape[j].z*cd); 
265.            tdshape[j].z=zz;tdshape[j].x=xx; 
266.        } 
267.    } 
268.    
269.    public void Rotate(float angle) 
270.    { 
271.        // Χĵת 
272.        // ۲ߵӡ 
273.        // ת 
274. 
275.        float zz,xx; 
276.        float sd=(float)Math.Sin(angle*3.141592654/180); 
277.        float cd=(float)Math.Cos(angle*3.141592654/180); 
278. 
279.        xx=(position_x*cd)-(position_z*sd); 
280.        zz=(position_x*sd)+(position_z*cd); 
281.        position_z=zz;position_x=xx; 
282.    } 
283. 
284.    public void Move(float distance) 
285.    { 
286.        // ƶ 
287.    } 
288. 
289. 
290.     public void Draw(Graphics grfx) 
291.    { 
292.        // ק! 
293. 
294.        // ЩΪͼco-ords 
295.        float x1,y1,z1,x2,y2,z2; 
296.           // Щ͸co-ordinates 
297.        float px1,py1,px2,py2; 
298.        // "full"ܲͬ 
299.         Pen blackPen = new Pen(Color.Black); 
300. 
301.        // ڶѭе!
302.        for (int i=0;i<tdshape.GetLength(0);i+=2) 
303.        { 
304.            x1=tdshape[i].x+position_x; 
305.            y1=tdshape[i].y+position_y; 
306.            z1=tdshape[i].z+position_z; 
307.            x2=tdshape[i+1].x+position_x; 
308.            y2=tdshape[i+1].y+position_y; 
309.            z2=tdshape[i+1].z+position_z; 
310. 
311.            if ((z1>1) && (z2>1)) 
312.            { 
313.                px1=200*(x1/z1);py1=200*(y1/z1); 
314.                px2=200*(x2/z2);py2=200*(y2/z2); 
315. 
316.                if (!((px1<-HALFWIDTH) && (px2<-HALFWIDTH) 
317.                     ||(px1>HALFWIDTH) && (px2>HALFWIDTH))) 
318.     grfx.DrawLine(blackPen,(int)(100+px1),(int)(100+py1),
(int)(100+px2),(int)(100+py2 ));
319.            } 
320.        } 
321.    } 
322. 
323.    public TDObject() 
324.    { 
325.        // 
326.        // TODO:ӹ߼
327.        // 
328.    } 
329. 
330.    // Member 
331. 
332.    int ObjectType  = 0; // 0=cube, 1=tank, 2=saucer, 3=shell 
333.    int HALFWIDTH = 200; 
334.    int HALFHEIGHT = 200; 
335. 
336.    float position_x = 0;     // ⽫ɹ. 
337.    float position_y = 10;   // ͬʱҪ 
338.    float position_z = 30;   // ཫ ! 
339. 
340.    // ܹΪÿ洢co-ords  
341.    struct tdpoint 
342.    { 
343.        public float x; 
344.        public float y; 
345.        public float z; 
346.    } 
347.    
348.    // (tdpoint)һ(tdshape) 
349.    tdpoint [] tdshape; 
350.    } 
351.  } 

