1 /* bzflag
2 * Copyright (c) 1993-2021 Tim Riker
3 *
4 * This package is free software; you can redistribute it and/or
5 * modify it under the terms of the license found in the file
6 * named COPYING that should have accompanied this file.
7 *
8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 */
12
13 #include "common.h"
14 // system headers
15 #include <assert.h>
16 #include <math.h>
17
18 // local implementation headers
19 #include "TankSceneNode.h"
20 #include "TankGeometryMgr.h"
21
22 using namespace TankGeometryUtils;
23
24
25 static int treadStyle = TankGeometryUtils::Covered;
26
27 // setup in setTreadStyle()
28 static int treadCount;
29 static float fullLength;
30 static float treadHeight;
31 static float treadInside;
32 static float treadOutside;
33 static float treadThickness;
34 static float treadWidth;
35 static float treadRadius;
36 static float treadYCenter;
37 static float treadLength;
38 static float treadTexCoordLen;
39 static float wheelRadius;
40 static float wheelWidth;
41 static float wheelSpacing;
42 static float wheelTexCoordLen;
43 static float casingWidth;
44 static float wheelInsideTexRad;
45 static float wheelOutsideTexRad;
46
47
setTreadStyle(int style)48 void TankGeometryUtils::setTreadStyle(int style)
49 {
50 if (style == TankGeometryUtils::Exposed)
51 {
52 fullLength = 6.0f;
53 treadHeight = 1.2f;
54 treadInside = 0.875f;
55 treadOutside = 1.4f;
56 treadStyle = TankGeometryUtils::Exposed;
57 }
58 else
59 {
60 fullLength = 5.4f;
61 treadHeight = 1.1f;
62 treadInside = 0.877f;
63 treadOutside = 1.38f;
64 treadStyle = TankGeometryUtils::Covered;
65 }
66
67 treadCount = 1;
68
69 treadThickness = 0.15f;
70 treadWidth = treadOutside - treadInside;
71 treadRadius = 0.5f * treadHeight;
72 treadYCenter = treadInside + (0.5f * treadWidth);
73 treadLength = (float)(((fullLength - treadHeight) * 2.0) +
74 (M_PI * treadHeight));
75 treadTexCoordLen = (float)treadCount;
76
77 wheelRadius = treadRadius - (0.7f * treadThickness);
78 wheelWidth = treadWidth * 0.9f;
79 wheelSpacing = (fullLength - treadHeight) / 3.0f;
80 wheelTexCoordLen = 1.0f;
81
82 casingWidth = treadWidth * 0.6f;
83
84 wheelInsideTexRad = 0.4f;
85 wheelOutsideTexRad = 0.5f;
86
87 return;
88 }
89
90
getWheelScale()91 float TankGeometryUtils::getWheelScale()
92 {
93 // degrees / meter
94 return (float)(360.0 / (treadHeight * M_PI));
95 }
96
getTreadScale()97 float TankGeometryUtils::getTreadScale()
98 {
99 // texcoords / meter
100 return treadTexCoordLen / treadLength;
101 }
102
getTreadTexLen()103 float TankGeometryUtils::getTreadTexLen()
104 {
105 // texcoords
106 return treadTexCoordLen;
107 }
108
109
buildCasing(float Yoffset)110 static int buildCasing(float Yoffset)
111 {
112 const float yLeft = Yoffset + (0.5f * casingWidth);
113 const float yRight = Yoffset - (0.5f * casingWidth);
114
115 glShadeModel(GL_FLAT);
116 {
117 const float xc = wheelSpacing * 1.5f;
118 const float zb = treadThickness;
119 const float zt = treadHeight - treadThickness;
120 const float ty = 0.25f; // effective, the texture scale factor
121 const float tx = (2.0f * ty) * (xc / (zt - zb));
122
123 // the left and right quad surface
124 {
125 // the right side
126 glBegin(GL_TRIANGLE_STRIP);
127 doNormal3f(0.0f, -1.0f, 0.0f);
128 doTexCoord2f(-tx, -ty);
129 doVertex3f(-xc, yRight, zb);
130 doTexCoord2f(+tx, -ty);
131 doVertex3f(+xc, yRight, zb);
132 doTexCoord2f(-tx, +ty);
133 doVertex3f(-xc, yRight, zt);
134 doTexCoord2f(+tx, +ty);
135 doVertex3f(+xc, yRight, zt);
136 glEnd();
137 // the left side
138 glBegin(GL_TRIANGLE_STRIP);
139 doNormal3f(0.0f, +1.0f, 0.0f);
140 doTexCoord2f(-tx, -ty);
141 doVertex3f(+xc, yLeft, zb);
142 doTexCoord2f(+tx, -ty);
143 doVertex3f(-xc, yLeft, zb);
144 doTexCoord2f(-tx, +ty);
145 doVertex3f(+xc, yLeft, zt);
146 doTexCoord2f(+tx, +ty);
147 doVertex3f(-xc, yLeft, zt);
148 glEnd();
149 }
150 }
151 glShadeModel(GL_SMOOTH);
152
153 return 4;
154 }
155
156
buildTread(float Yoffset,int divisions)157 static int buildTread(float Yoffset, int divisions)
158 {
159 int i;
160 const float divs = (float)((divisions / 2) * 2); // even number
161 const float divScale = 2.0f / divs;
162 const float astep = (float)((M_PI * 2.0) / divs);
163 const float yLeft = Yoffset + (0.5f * treadWidth);
164 const float yRight = Yoffset - (0.5f * treadWidth);
165 float x, z;
166 float tx;
167 // setup some basic texture coordinates
168 const float txScale = treadTexCoordLen / treadLength;
169 const float tx0 = 0.0f;
170 const float tx1 = (float)(txScale * (treadRadius * M_PI));
171 const float tx2 = (float)(txScale * ((treadRadius * M_PI) + (fullLength - treadHeight)));
172 const float tx3 = (float)(txScale * ((treadHeight * M_PI) + (fullLength - treadHeight)));
173 const float tx4 = treadTexCoordLen;
174 const float tyScale = 1.0f / (2.0f * (treadWidth + treadThickness));
175 const float ty0 = 0.0f;
176 const float ty1 = tyScale * treadWidth;
177 const float ty2 = tyScale * (treadWidth + treadThickness);
178 const float ty3 = tyScale * ((2.0f * treadWidth) + treadThickness);
179 const float ty4 = 1.0f;
180
181 // the outside of the tread
182 glBegin(GL_TRIANGLE_STRIP);
183 {
184 // first curve
185 for (i = 0; i < ((divisions / 2) + 1); i++)
186 {
187 const float ang = (float)((astep * (double)i) - (M_PI / 2.0));
188 const float cos_val = cosf(ang);
189 const float sin_val = sinf(ang);
190 doNormal3f(cos_val, 0.0f, sin_val);
191 tx = tx0 + ((tx1 - tx0) * ((float)i * divScale));
192 doTexCoord2f(tx, ty1);
193 x = (cos_val * treadRadius) + (wheelSpacing * 1.5f);
194 z = (sin_val * treadRadius) + treadRadius;
195 doVertex3f(x, yRight, z);
196 doTexCoord2f(tx, ty0);
197 doVertex3f(x, yLeft, z);
198 }
199 // top of the tread
200 doNormal3f(0.0f, 0.0f, 1.0f);
201 doTexCoord2f(tx2, ty1);
202 x = -wheelSpacing * 1.5f;
203 z = treadHeight;
204 doVertex3f(x, yRight, z);
205 doTexCoord2f(tx2, ty0);
206 doVertex3f(x, yLeft, z);
207 // second curve
208 for (i = 0; i < ((divisions / 2) + 1); i++)
209 {
210 const float ang = (float)((astep * (double)i) + (M_PI / 2.0));
211 const float cos_val = cosf(ang);
212 const float sin_val = sinf(ang);
213 doNormal3f(cos_val, 0.0f, sin_val);
214 tx = tx2 + ((tx3 - tx2) * ((float)i * divScale));
215 doTexCoord2f(tx, ty1);
216 x = (cos_val * treadRadius) - (wheelSpacing * 1.5f);
217 z = (sin_val * treadRadius) + treadRadius;
218 doVertex3f(x, yRight, z);
219 doTexCoord2f(tx, ty0);
220 doVertex3f(x, yLeft, z);
221 }
222 // bottom of the tread
223 doNormal3f(0.0f, 0.0f, -1.0f);
224 doTexCoord2f(tx4, ty1);
225 x = wheelSpacing * 1.5f;
226 z = 0.0f;
227 doVertex3f(x, yRight, z);
228 doTexCoord2f(tx4, ty0);
229 doVertex3f(x, yLeft, z);
230 }
231 glEnd();
232
233 // the inside of the tread
234 glBegin(GL_TRIANGLE_STRIP);
235 {
236 // first curve
237 for (i = 0; i < ((divisions / 2) + 1); i++)
238 {
239 const float ang = (float)((astep * (double)i) - (M_PI / 2.0));
240 const float cos_val = cosf(ang);
241 const float sin_val = sinf(ang);
242 doNormal3f(-cos_val, 0.0f, -sin_val);
243 tx = tx0 + ((tx1 - tx0) * ((float)i * divScale));
244 doTexCoord2f(tx, ty3);
245 x = (cos_val * (treadRadius - treadThickness)) + (wheelSpacing * 1.5f);
246 z = (sin_val * (treadRadius - treadThickness)) + treadRadius;
247 doVertex3f(x, yLeft, z);
248 doTexCoord2f(tx, ty2);
249 doVertex3f(x, yRight, z);
250 }
251 // top inside of the tread
252 doNormal3f(0.0f, 0.0f, -1.0f);
253 doTexCoord2f(tx2, ty3);
254 x = -wheelSpacing * 1.5f;
255 z = treadHeight - treadThickness;
256 doVertex3f(x, yLeft, z);
257 doTexCoord2f(tx2, ty2);
258 doVertex3f(x, yRight, z);
259 // second curve
260 for (i = 0; i < ((divisions / 2) + 1); i++)
261 {
262 const float ang = (float)((astep * (double)i) + (M_PI / 2.0));
263 const float cos_val = cosf(ang);
264 const float sin_val = sinf(ang);
265 doNormal3f(-cos_val, 0.0f, -sin_val);
266 tx = tx2 + ((tx3 - tx2) * ((float)i * divScale));
267 doTexCoord2f(tx, ty3);
268 x = (cos_val * (treadRadius - treadThickness)) - (wheelSpacing * 1.5f);
269 z = (sin_val * (treadRadius - treadThickness)) + treadRadius;
270 doVertex3f(x, yLeft, z);
271 doTexCoord2f(tx, ty2);
272 doVertex3f(x, yRight, z);
273 }
274 // bottom inside of the tread
275 doNormal3f(0.0f, 0.0f, 1.0f);
276 doTexCoord2f(tx4, ty3);
277 x = wheelSpacing * 1.5f;
278 z = treadThickness;
279 doVertex3f(x, yLeft, z);
280 doTexCoord2f(tx4, ty2);
281 doVertex3f(x, yRight, z);
282 }
283 glEnd();
284
285 glShadeModel(GL_FLAT);
286 {
287 // the right edge
288 doNormal3f(0.0f, -1.0f, 0.0f);
289 glBegin(GL_TRIANGLE_STRIP);
290 {
291 // first outside curve
292 for (i = 0; i < ((divisions / 2) + 1); i++)
293 {
294 const float ang = (float)((astep * (double)i) - (M_PI / 2.0));
295 const float cos_val = cosf(ang);
296 const float sin_val = sinf(ang);
297 tx = tx0 + ((tx1 - tx0) * ((float)i * divScale));
298 doTexCoord2f(tx, ty2);
299 x = (cos_val * (treadRadius - treadThickness)) + (wheelSpacing * 1.5f);
300 z = (sin_val * (treadRadius - treadThickness)) + treadRadius;
301 doVertex3f(x, yRight, z);
302 doTexCoord2f(tx, ty1);
303 x = (cos_val * treadRadius) + (wheelSpacing * 1.5f);
304 z = (sin_val * treadRadius) + treadRadius;
305 doVertex3f(x, yRight, z);
306 }
307 // top edge
308 doTexCoord2f(tx2, ty2);
309 x = -wheelSpacing * 1.5f;
310 z = treadHeight - treadThickness;
311 doVertex3f(x, yRight, z);
312 doTexCoord2f(tx2, ty1);
313 z = treadHeight;
314 doVertex3f(x, yRight, z);
315 // second outside curve
316 for (i = 0; i < ((divisions / 2) + 1); i++)
317 {
318 const float ang = (float)((astep * (double)i) + (M_PI / 2.0));
319 const float cos_val = cosf(ang);
320 const float sin_val = sinf(ang);
321 tx = tx2 + ((tx3 - tx2) * ((float)i * divScale));
322 doTexCoord2f(tx, ty2);
323 x = (cos_val * (treadRadius - treadThickness)) - (wheelSpacing * 1.5f);
324 z = (sin_val * (treadRadius - treadThickness)) + treadRadius;
325 doVertex3f(x, yRight, z);
326 doTexCoord2f(tx, ty1);
327 x = (cos_val * treadRadius) - (wheelSpacing * 1.5f);
328 z = (sin_val * treadRadius) + treadRadius;
329 doVertex3f(x, yRight, z);
330 }
331 // bottom edge
332 doTexCoord2f(tx4, ty2);
333 x = wheelSpacing * 1.5f;
334 z = treadThickness;
335 doVertex3f(x, yRight, z);
336 doTexCoord2f(tx4, ty1);
337 z = 0.0f;
338 doVertex3f(x, yRight, z);
339 }
340 glEnd();
341
342 // the left edge
343 doNormal3f(0.0f, +1.0f, 0.0f);
344 glBegin(GL_TRIANGLE_STRIP);
345 {
346 // first outside curve
347 for (i = 0; i < ((divisions / 2) + 1); i++)
348 {
349 const float ang = (float)((astep * (double)i) - (M_PI / 2.0));
350 const float cos_val = cosf(ang);
351 const float sin_val = sinf(ang);
352 tx = tx0 + ((tx1 - tx0) * ((float)i * divScale));
353 doTexCoord2f(tx, ty4);
354 x = (cos_val * treadRadius) + (wheelSpacing * 1.5f);
355 z = (sin_val * treadRadius) + treadRadius;
356 doVertex3f(x, yLeft, z);
357 doTexCoord2f(tx, ty3);
358 x = (cos_val * (treadRadius - treadThickness)) + (wheelSpacing * 1.5f);
359 z = (sin_val * (treadRadius - treadThickness)) + treadRadius;
360 doVertex3f(x, yLeft, z);
361 }
362 // top edge
363 doTexCoord2f(tx2, ty4);
364 x = -wheelSpacing * 1.5f;
365 z = treadHeight;
366 doVertex3f(x, yLeft, z);
367 doTexCoord2f(tx2, ty3);
368 z = treadHeight - treadThickness;
369 doVertex3f(x, yLeft, z);
370 // second outside curve
371 for (i = 0; i < ((divisions / 2) + 1); i++)
372 {
373 const float ang = (float)((astep * (double)i) + (M_PI / 2.0));
374 const float cos_val = cosf(ang);
375 const float sin_val = sinf(ang);
376 tx = tx2 + ((tx3 - tx2) * ((float)i * divScale));
377 doTexCoord2f(tx, ty4);
378 x = (cos_val * treadRadius) - (wheelSpacing * 1.5f);
379 z = (sin_val * treadRadius) + treadRadius;
380 doVertex3f(x, yLeft, z);
381 doTexCoord2f(tx, ty3);
382 x = (cos_val * (treadRadius - treadThickness)) - (wheelSpacing * 1.5f);
383 z = (sin_val * (treadRadius - treadThickness)) + treadRadius;
384 doVertex3f(x, yLeft, z);
385 }
386 // bottom edge
387 doTexCoord2f(tx4, ty4);
388 x = wheelSpacing * 1.5f;
389 z = 0.0f;
390 doVertex3f(x, yLeft, z);
391 doTexCoord2f(tx4, ty3);
392 z = treadThickness;
393 doVertex3f(x, yLeft, z);
394 }
395 glEnd();
396 }
397 glShadeModel(GL_SMOOTH);
398
399 return (2 * 4 * (divisions + 2));
400 }
401
402
buildWheel(const float pos[3],float angle,int divisions)403 static int buildWheel(const float pos[3], float angle, int divisions)
404 {
405 int i;
406 int tris = 0;
407 const float divs = (float)divisions;
408 const float astep = (float)((M_PI * 2.0) / (double)divs);
409 const float yLeft = pos[1] + (0.5f * wheelWidth);
410 const float yRight = pos[1] - (0.5f * wheelWidth);
411 float x, z;
412 float tx, ty;
413
414 // the edge loop
415 doNormal3f(0.0f, +1.0f, 0.0f);
416 glBegin(GL_TRIANGLE_STRIP);
417 {
418 for (i = 0; i < (divisions + 1); i++)
419 {
420 const float ang = astep * (float)i;
421 const float cos_val = cosf(ang);
422 const float sin_val = sinf(ang);
423 doNormal3f(cos_val, 0.0f, sin_val);
424 tx = 0.5f + (cosf(angle + ang) * wheelInsideTexRad);
425 ty = 0.5f + (sinf(angle + ang) * wheelInsideTexRad);
426 doTexCoord2f(tx, ty);
427 x = (cos_val * wheelRadius) + pos[0];
428 z = (sin_val * wheelRadius) + pos[2];
429 doVertex3f(x, yRight, z);
430 tx = 0.5f + (cosf(angle + ang) * wheelOutsideTexRad);
431 ty = 0.5f + (sinf(angle + ang) * wheelOutsideTexRad);
432 doTexCoord2f(tx, ty);
433 doVertex3f(x, yLeft, z);
434 }
435 }
436 glEnd();
437 tris += (2 * divisions);
438
439 glShadeModel(GL_FLAT);
440 {
441 // the left face
442 doNormal3f(0.0f, +1.0f, 0.0f);
443 glBegin(GL_TRIANGLE_FAN);
444 {
445 for (i = 0; i < divisions; i++)
446 {
447 const float ang = astep * (float)i;
448 const float cos_val = cosf(-ang);
449 const float sin_val = sinf(-ang);
450 tx = 0.5f + (cosf(angle - ang) * wheelInsideTexRad);
451 ty = 0.5f + (sinf(angle - ang) * wheelInsideTexRad);
452 doTexCoord2f(tx, ty);
453 x = (cos_val * wheelRadius) + pos[0];
454 z = (sin_val * wheelRadius) + pos[2];
455 doVertex3f(x, yLeft, z);
456
457 }
458 }
459 glEnd();
460 tris += (divisions - 2);
461
462 // the right face
463 doNormal3f(0.0f, -1.0f, 0.0f);
464 glBegin(GL_TRIANGLE_FAN);
465 {
466 for (i = 0; i < divisions; i++)
467 {
468 const float ang = astep * (float)i;
469 const float cos_val = cosf(+ang);
470 const float sin_val = sinf(+ang);
471 tx = 0.5f + (cosf(angle + ang) * 0.4f);
472 ty = 0.5f + (sinf(angle + ang) * 0.4f);
473 doTexCoord2f(tx, ty);
474 x = (cos_val * wheelRadius) + pos[0];
475 z = (sin_val * wheelRadius) + pos[2];
476 doVertex3f(x, yRight, z);
477 }
478 }
479 glEnd();
480 tris += (divisions - 2);
481 }
482 glShadeModel(GL_SMOOTH);
483
484 return tris;
485 }
486
487
buildHighLCasingAnim()488 int TankGeometryUtils::buildHighLCasingAnim()
489 {
490 int tris = 0;
491
492 tris += buildCasing(+treadYCenter);
493
494 if (treadStyle == TankGeometryUtils::Covered)
495 {
496 glShadeModel(GL_FLAT);
497 {
498 //draw the left tread cover
499 glBegin(GL_TRIANGLE_STRIP);
500 doNormal3f(0.984696f, 0.000000f, 0.174282f);
501 doTexCoord2f(-0.193f, 0.727f);
502 doVertex3f(3.000f, 0.875f, 0.770f);
503 doTexCoord2f(0.009f, 0.356f);
504 doVertex3f(3.000f, 1.400f, 0.770f);
505 doTexCoord2f(-0.164f, 0.679f);
506 doVertex3f(2.980f, 0.875f, 0.883f);
507 doTexCoord2f(-0.015f, 0.407f);
508 doVertex3f(2.980f, 1.400f, 0.883f);
509 doNormal3f(0.519720f, 0.000000f, 0.854336f);
510 doTexCoord2f(-0.134f, 0.666f);
511 doVertex3f(2.860f, 0.875f, 0.956f);
512 doTexCoord2f(-0.010f, 0.439f);
513 doVertex3f(2.860f, 1.400f, 0.956f);
514 doNormal3f(0.748075f, 0.000000f, 0.663614f);
515 doTexCoord2f(-0.102f, 0.647f);
516 doVertex3f(2.750f, 0.875f, 1.080f);
517 doTexCoord2f(-0.009f, 0.477f);
518 doVertex3f(2.750f, 1.400f, 1.080f);
519 doNormal3f(0.049938f, 0.000000f, 0.998752f);
520 doTexCoord2f(-0.041f, 0.675f);
521 doVertex3f(2.350f, 0.875f, 1.100f);
522 doTexCoord2f(0.048f, 0.512f);
523 doVertex3f(2.350f, 1.400f, 1.100f);
524 doNormal3f(0.455876f, 0.000000f, 0.890043f);
525 doTexCoord2f(0.033f, 0.684f);
526 doVertex3f(1.940f, 0.875f, 1.310f);
527 doTexCoord2f(0.095f, 0.570f);
528 doVertex3f(1.940f, 1.400f, 1.310f);
529 doNormal3f(0.003378f, 0.000000f, 0.999994f);
530 doTexCoord2f(0.468f, 0.920f);
531 doVertex3f(-1.020f, 0.875f, 1.320f);
532 doTexCoord2f(0.529f, 0.808f);
533 doVertex3f(-1.020f, 1.400f, 1.320f);
534 doNormal3f(0.178885f, 0.000000f, 0.983870f);
535 doTexCoord2f(0.536f, 0.949f);
536 doVertex3f(-1.460f, 0.875f, 1.400f);
537 doTexCoord2f(0.591f, 0.849f);
538 doVertex3f(-1.460f, 1.400f, 1.400f);
539 doNormal3f(0.006622f, 0.000000f, 0.999978f);
540 doTexCoord2f(0.759f, 1.070f);
541 doVertex3f(-2.970f, 0.875f, 1.410f);
542 doTexCoord2f(0.813f, 0.970f);
543 doVertex3f(-2.970f, 1.400f, 1.410f);
544 doNormal3f(-0.967641f, 0.000000f, -0.252333f);
545 doTexCoord2f(0.587f, 1.300f);
546 doVertex3f(-2.740f, 0.875f, 0.628f);
547 doTexCoord2f(0.917f, 0.700f);
548 doVertex3f(-2.740f, 1.400f, 0.628f);
549 doNormal3f(-0.426419f, 0.000000f, -0.904526f);
550 doTexCoord2f(0.375f, 1.300f);
551 doVertex3f(-1.620f, 0.875f, 0.500f);
552 doTexCoord2f(0.800f, 0.523f);
553 doVertex3f(-1.620f, 1.400f, 0.500f);
554 doNormal3f(0.000000f, 0.000000f, -1.000000f);
555 doTexCoord2f(-0.156f, 1.010f);
556 doVertex3f(1.990f, 0.875f, 0.500f);
557 doTexCoord2f(0.268f, 0.233f);
558 doVertex3f(1.990f, 1.400f, 0.500f);
559 doNormal3f(0.454326f, 0.000000f, -0.890835f);
560 doTexCoord2f(-0.246f, 0.896f);
561 doVertex3f(2.790f, 0.875f,0.608f);
562 doTexCoord2f(0.123f, 0.220f);
563 doVertex3f(2.790f, 1.400f,0.608f);
564 doNormal3f(0.978361f, 0.000000f, -0.206904f);
565 doTexCoord2f(-0.182f, 0.754f);
566 doVertex3f(2.860f, 0.875f, 0.739f);
567 doTexCoord2f(0.038f, 0.352f);
568 doVertex3f(2.860f, 1.400f, 0.739f);
569 doNormal3f(0.216192f, 0.000000f, -0.976351f);
570 doTexCoord2f(-0.193f, 0.727f);
571 doVertex3f(3.000f, 0.875f, 0.770f);
572 doTexCoord2f(0.009f, 0.356f);
573 doVertex3f(3.000f, 1.400f, 0.770f);
574 glEnd(); // 30 verts -> 28 tris
575 tris += 28;
576
577 glBegin(GL_TRIANGLE_FAN);
578 doNormal3f(0.000000f, -1.000000f, 0.000000f);
579 doTexCoord2f(0.587f, 1.300f);
580 doVertex3f(-2.740f, 0.875f, 0.628f);
581 doTexCoord2f(0.375f, 1.300f);
582 doVertex3f(-1.620f, 0.875f, 0.500f);
583 doTexCoord2f(0.468f, 0.920f);
584 doVertex3f(-1.020f, 0.875f, 1.320f);
585 doTexCoord2f(0.536f, 0.949f);
586 doVertex3f(-1.460f, 0.875f, 1.400f);
587 doTexCoord2f(0.759f, 1.070f);
588 doVertex3f(-2.970f, 0.875f, 1.410f);
589 glEnd(); // 5 verts -> 3 tris
590 tris += 3;
591
592 glBegin(GL_TRIANGLE_FAN);
593 doNormal3f(0.000000f, -1.000000f, 0.000000f);
594 doTexCoord2f(-0.156f, 1.010f);
595 doVertex3f(1.990f, 0.875f, 0.500f);
596 doTexCoord2f(-0.246f, 0.896f);
597 doVertex3f(2.790f, 0.875f,0.608f);
598 doTexCoord2f(-0.182f, 0.754f);
599 doVertex3f(2.860f, 0.875f, 0.739f);
600 doTexCoord2f(-0.102f, 0.647f);
601 doVertex3f(2.750f, 0.875f, 1.080f);
602 doTexCoord2f(-0.041f, 0.675f);
603 doVertex3f(2.350f, 0.875f, 1.100f);
604 doTexCoord2f(0.033f, 0.684f);
605 doVertex3f(1.940f, 0.875f, 1.310f);
606 doTexCoord2f(0.468f, 0.920f);
607 doVertex3f(-1.020f, 0.875f, 1.320f);
608 doTexCoord2f(0.375f, 1.300f);
609 doVertex3f(-1.620f, 0.875f, 0.500f);
610 glEnd(); // 8 verts -> 6 tris
611 tris += 6;
612
613 glBegin(GL_TRIANGLE_FAN);
614 doNormal3f(0.000000f, -1.000000f, 0.000000f);
615 doTexCoord2f(-0.182f, 0.754f);
616 doVertex3f(2.860f, 0.875f, 0.739f);
617 doTexCoord2f(-0.193f, 0.727f);
618 doVertex3f(3.000f, 0.875f, 0.770f);
619 doTexCoord2f(-0.164f, 0.679f);
620 doVertex3f(2.980f, 0.875f, 0.883f);
621 doTexCoord2f(-0.134f, 0.666f);
622 doVertex3f(2.860f, 0.875f, 0.956f);
623 doTexCoord2f(-0.102f, 0.647f);
624 doVertex3f(2.750f, 0.875f, 1.080f);
625 glEnd(); // 5 verts -> 3 tris
626 tris += 3;
627
628 glBegin(GL_TRIANGLE_FAN);
629 doNormal3f(0.000000f, 1.000000f, 0.000000f);
630 doTexCoord2f(0.917f, 0.700f);
631 doVertex3f(-2.740f, 1.400f, 0.628f);
632 doTexCoord2f(0.813f, 0.970f);
633 doVertex3f(-2.970f, 1.400f, 1.410f);
634 doTexCoord2f(0.591f, 0.849f);
635 doVertex3f(-1.460f, 1.400f, 1.400f);
636 doTexCoord2f(0.529f, 0.808f);
637 doVertex3f(-1.020f, 1.400f, 1.320f);
638 doTexCoord2f(0.800f, 0.523f);
639 doVertex3f(-1.620f, 1.400f, 0.500f);
640 glEnd(); // 5 verts -> 3 tris
641 tris += 3;
642
643 glBegin(GL_TRIANGLE_FAN);
644 doNormal3f(0.000000f, 1.000000f, 0.000000f);
645 doTexCoord2f(0.268f, 0.233f);
646 doVertex3f(1.990f, 1.400f, 0.500f);
647 doTexCoord2f(0.800f, 0.523f);
648 doVertex3f(-1.620f, 1.400f, 0.500f);
649 doTexCoord2f(0.529f, 0.808f);
650 doVertex3f(-1.020f, 1.400f, 1.320f);
651 doTexCoord2f(0.095f, 0.570f);
652 doVertex3f(1.940f, 1.400f, 1.310f);
653 doTexCoord2f(0.048f, 0.512f);
654 doVertex3f(2.350f, 1.400f, 1.100f);
655 doTexCoord2f(-0.009f, 0.477f);
656 doVertex3f(2.750f, 1.400f, 1.080f);
657 doTexCoord2f(0.038f, 0.352f);
658 doVertex3f(2.860f, 1.400f, 0.739f);
659 doTexCoord2f(0.123f, 0.220f);
660 doVertex3f(2.790f, 1.400f,0.608f);
661 glEnd(); // 8 verts -> 6 tris
662 tris += 6;
663
664 glBegin(GL_TRIANGLE_FAN);
665 doNormal3f(0.000000f, 1.000000f, 0.000000f);
666 doTexCoord2f(0.038f, 0.352f);
667 doVertex3f(2.860f, 1.400f, 0.739f);
668 doTexCoord2f(-0.009f, 0.477f);
669 doVertex3f(2.750f, 1.400f, 1.080f);
670 doTexCoord2f(-0.010f, 0.439f);
671 doVertex3f(2.860f, 1.400f, 0.956f);
672 doTexCoord2f(-0.015f, 0.407f);
673 doVertex3f(2.980f, 1.400f, 0.883f);
674 doTexCoord2f(0.009f, 0.356f);
675 doVertex3f(3.000f, 1.400f, 0.770f);
676 glEnd(); // 5 verts -> 3 tris
677 tris += 3;
678 }
679 glShadeModel(GL_SMOOTH);
680 }
681
682 return tris;
683 }
684
buildHighRCasingAnim()685 int TankGeometryUtils::buildHighRCasingAnim()
686 {
687 int tris = 0;
688
689 tris += buildCasing(-treadYCenter);
690
691 if (treadStyle == TankGeometryUtils::Covered)
692 {
693 glShadeModel(GL_FLAT);
694 {
695 //draw the right tread cover
696 glBegin(GL_TRIANGLE_STRIP);
697 doNormal3f(0.984696f, 0.000000f, 0.174282f);
698 doTexCoord2f(-0.295f, 0.041f);
699 doVertex3f(3.000f, -1.400f, 0.770f);
700 doTexCoord2f(0.045f, -0.208f);
701 doVertex3f(3.000f, -0.875f, 0.770f);
702 doTexCoord2f(-0.248f, 0.010f);
703 doVertex3f(2.980f, -1.400f, 0.883f);
704 doTexCoord2f(0.002f, -0.173f);
705 doVertex3f(2.980f, -0.875f, 0.883f);
706 doNormal3f(0.519720f, 0.000000f, 0.854336f);
707 doTexCoord2f(-0.216f, 0.011f);
708 doVertex3f(2.860f, -1.400f, 0.956f);
709 doTexCoord2f(-0.007f, -0.141f);
710 doVertex3f(2.860f, -0.875f, 0.956f);
711 doNormal3f(0.748075f, 0.000000f, 0.663614f);
712 doTexCoord2f(-0.179f, 0.008f);
713 doVertex3f(2.750f, -1.400f, 1.080f);
714 doTexCoord2f(-0.022f, -0.107f);
715 doVertex3f(2.750f, -0.875f, 1.080f);
716 doNormal3f(0.049938f, 0.000000f, 0.998752f);
717 doTexCoord2f(-0.136f, 0.059f);
718 doVertex3f(2.350f, -1.400f, 1.100f);
719 doTexCoord2f(0.014f, -0.050f);
720 doVertex3f(2.350f, -0.875f, 1.100f);
721 doNormal3f(0.455876f, 0.000000f, 0.890043f);
722 doTexCoord2f(-0.072f, 0.099f);
723 doVertex3f(1.940f, -1.400f, 1.310f);
724 doTexCoord2f(0.032f, 0.022f);
725 doVertex3f(1.940f, -0.875f, 1.310f);
726 doNormal3f(0.003378f, 0.000000f, 0.999994f);
727 doTexCoord2f(0.221f, 0.497f);
728 doVertex3f(-1.020f, -1.400f, 1.320f);
729 doTexCoord2f(0.324f, 0.422f);
730 doVertex3f(-1.020f, -0.875f, 1.320f);
731 doNormal3f(0.178885f, 0.000000f, 0.983870f);
732 doTexCoord2f(0.270f, 0.553f);
733 doVertex3f(-1.460f, -1.400f, 1.400f);
734 doTexCoord2f(0.362f, 0.486f);
735 doVertex3f(-1.460f, -0.875f, 1.400f);
736 doNormal3f(0.006622f, 0.000000f, 0.999978f);
737 doTexCoord2f(0.419f, 0.757f);
738 doVertex3f(-2.970f, -1.400f, 1.410f);
739 doTexCoord2f(0.511f, 0.690f);
740 doVertex3f(-2.970f, -0.875f, 1.410f);
741 doNormal3f(-0.967641f, 0.000000f, -0.252333f);
742 doTexCoord2f(0.165f, 0.896f);
743 doVertex3f(-2.740f, -1.400f, 0.628f);
744 doTexCoord2f(0.720f, 0.489f);
745 doVertex3f(-2.740f, -0.875f, 0.628f);
746 doNormal3f(-0.426419f, 0.000000f, -0.904526f);
747 doTexCoord2f(-0.026f, 0.803f);
748 doVertex3f(-1.620f, -1.400f, 0.500f);
749 doTexCoord2f(0.690f, 0.279f);
750 doVertex3f(-1.620f, -0.875f, 0.500f);
751 doNormal3f(0.000000f, 0.000000f, -1.000000f);
752 doTexCoord2f(-0.383f, 0.314f);
753 doVertex3f(1.990f, -1.400f, 0.500f);
754 doTexCoord2f(0.332f, -0.209f);
755 doVertex3f(1.990f, -0.875f, 0.500f);
756 doNormal3f(0.454326f, 0.000000f, -0.890835f);
757 doTexCoord2f(-0.415f, 0.172f);
758 doVertex3f(2.790f, -1.400f,0.608f);
759 doTexCoord2f(0.206f, -0.283f);
760 doVertex3f(2.790f, -0.875f,0.608f);
761 doNormal3f(0.978361f, 0.000000f, -0.206904f);
762 doTexCoord2f(-0.296f, 0.070f);
763 doVertex3f(2.860f, -1.400f, 0.739f);
764 doTexCoord2f(0.073f, -0.200f);
765 doVertex3f(2.860f, -0.875f, 0.739f);
766 doNormal3f(0.216192f, 0.000000f, -0.976351f);
767 doTexCoord2f(-0.295f, 0.041f);
768 doVertex3f(3.000f, -1.400f, 0.770f);
769 doTexCoord2f(0.045f, -0.208f);
770 doVertex3f(3.000f, -0.875f, 0.770f);
771 glEnd(); // 30 verts -> 28 tris
772 tris += 28;
773
774 glBegin(GL_TRIANGLE_FAN);
775 doNormal3f(0.000000f, -1.000000f, 0.000000f);
776 doTexCoord2f(0.165f, 0.896f);
777 doVertex3f(-2.740f, -1.400f, 0.628f);
778 doTexCoord2f(-0.026f, 0.803f);
779 doVertex3f(-1.620f, -1.400f, 0.500f);
780 doTexCoord2f(0.221f, 0.497f);
781 doVertex3f(-1.020f, -1.400f, 1.320f);
782 doTexCoord2f(0.270f, 0.553f);
783 doVertex3f(-1.460f, -1.400f, 1.400f);
784 doTexCoord2f(0.419f, 0.757f);
785 doVertex3f(-2.970f, -1.400f, 1.410f);
786 glEnd(); // 5 verts -> 3 tris
787 tris += 3;
788
789 glBegin(GL_TRIANGLE_FAN);
790 doNormal3f(0.000000f, -1.000000f, 0.000000f);
791 doTexCoord2f(-0.383f, 0.314f);
792 doVertex3f(1.990f, -1.400f, 0.500f);
793 doTexCoord2f(-0.415f, 0.172f);
794 doVertex3f(2.790f, -1.400f,0.608f);
795 doTexCoord2f(-0.296f, 0.070f);
796 doVertex3f(2.860f, -1.400f, 0.739f);
797 doTexCoord2f(-0.179f, 0.008f);
798 doVertex3f(2.750f, -1.400f, 1.080f);
799 doTexCoord2f(-0.136f, 0.059f);
800 doVertex3f(2.350f, -1.400f, 1.100f);
801 doTexCoord2f(-0.072f, 0.099f);
802 doVertex3f(1.940f, -1.400f, 1.310f);
803 doTexCoord2f(0.221f, 0.497f);
804 doVertex3f(-1.020f, -1.400f, 1.320f);
805 doTexCoord2f(-0.026f, 0.803f);
806 doVertex3f(-1.620f, -1.400f, 0.500f);
807 glEnd(); // 8 verts -> 6 tris
808 tris += 6;
809
810 glBegin(GL_TRIANGLE_FAN);
811 doNormal3f(0.000000f, -1.000000f, 0.000000f);
812 doTexCoord2f(-0.296f, 0.070f);
813 doVertex3f(2.860f, -1.400f, 0.739f);
814 doTexCoord2f(-0.295f, 0.041f);
815 doVertex3f(3.000f, -1.400f, 0.770f);
816 doTexCoord2f(-0.248f, 0.010f);
817 doVertex3f(2.980f, -1.400f, 0.883f);
818 doTexCoord2f(-0.216f, 0.011f);
819 doVertex3f(2.860f, -1.400f, 0.956f);
820 doTexCoord2f(-0.179f, 0.008f);
821 doVertex3f(2.750f, -1.400f, 1.080f);
822 glEnd(); // 5 verts -> 3 tris
823 tris += 3;
824
825 glBegin(GL_TRIANGLE_FAN);
826 doNormal3f(0.000000f, 1.000000f, 0.000000f);
827 doTexCoord2f(0.720f, 0.489f);
828 doVertex3f(-2.740f, -0.875f, 0.628f);
829 doTexCoord2f(0.511f, 0.690f);
830 doVertex3f(-2.970f, -0.875f, 1.410f);
831 doTexCoord2f(0.362f, 0.486f);
832 doVertex3f(-1.460f, -0.875f, 1.400f);
833 doTexCoord2f(0.324f, 0.422f);
834 doVertex3f(-1.020f, -0.875f, 1.320f);
835 doTexCoord2f(0.690f, 0.279f);
836 doVertex3f(-1.620f, -0.875f, 0.500f);
837 glEnd(); // 5 verts -> 3 tris
838 tris += 3;
839
840 glBegin(GL_TRIANGLE_FAN);
841 doNormal3f(0.000000f, 1.000000f, 0.000000f);
842 doTexCoord2f(0.332f, -0.209f);
843 doVertex3f(1.990f, -0.875f, 0.500f);
844 doTexCoord2f(0.690f, 0.279f);
845 doVertex3f(-1.620f, -0.875f, 0.500f);
846 doTexCoord2f(0.324f, 0.422f);
847 doVertex3f(-1.020f, -0.875f, 1.320f);
848 doTexCoord2f(0.032f, 0.022f);
849 doVertex3f(1.940f, -0.875f, 1.310f);
850 doTexCoord2f(0.014f, -0.050f);
851 doVertex3f(2.350f, -0.875f, 1.100f);
852 doTexCoord2f(-0.022f, -0.107f);
853 doVertex3f(2.750f, -0.875f, 1.080f);
854 doTexCoord2f(0.073f, -0.200f);
855 doVertex3f(2.860f, -0.875f, 0.739f);
856 doTexCoord2f(0.206f, -0.283f);
857 doVertex3f(2.790f, -0.875f,0.608f);
858 glEnd(); // 8 verts -> 6 tris
859 tris += 6;
860
861 glBegin(GL_TRIANGLE_FAN);
862 doNormal3f(0.000000f, 1.000000f, 0.000000f);
863 doTexCoord2f(0.073f, -0.200f);
864 doVertex3f(2.860f, -0.875f, 0.739f);
865 doTexCoord2f(-0.022f, -0.107f);
866 doVertex3f(2.750f, -0.875f, 1.080f);
867 doTexCoord2f(-0.007f, -0.141f);
868 doVertex3f(2.860f, -0.875f, 0.956f);
869 doTexCoord2f(0.002f, -0.173f);
870 doVertex3f(2.980f, -0.875f, 0.883f);
871 doTexCoord2f(0.045f, -0.208f);
872 doVertex3f(3.000f, -0.875f, 0.770f);
873 glEnd(); // 5 verts -> 3 tris
874 tris += 3;
875 }
876 glShadeModel(GL_SMOOTH);
877 }
878
879 return tris;
880 }
881
882
buildHighLTread(int divs)883 int TankGeometryUtils::buildHighLTread(int divs)
884 {
885 return buildTread(+treadYCenter, divs);
886 }
887
buildHighRTread(int divs)888 int TankGeometryUtils::buildHighRTread(int divs)
889 {
890 return buildTread(-treadYCenter, divs);
891 }
892
893
buildHighLWheel(int number,float angle,int divs)894 int TankGeometryUtils::buildHighLWheel(int number, float angle, int divs)
895 {
896 assert ((number >= 0) && (number < 4));
897 float pos[3];
898 pos[0] = wheelSpacing * (-1.5f + (float)number);
899 pos[1] = +treadYCenter;
900 pos[2] = treadRadius;
901 return buildWheel(pos, angle, divs);
902 }
903
buildHighRWheel(int number,float angle,int divs)904 int TankGeometryUtils::buildHighRWheel(int number, float angle, int divs)
905 {
906 assert ((number >= 0) && (number < 4));
907 float pos[3];
908 pos[0] = wheelSpacing * (-1.5f + (float)number);
909 pos[1] = -treadYCenter;
910 pos[2] = treadRadius;
911 return buildWheel(pos, angle, divs);
912 }
913
914
915 // Local Variables: ***
916 // mode: C++ ***
917 // tab-width: 4 ***
918 // c-basic-offset: 4 ***
919 // indent-tabs-mode: nil ***
920 // End: ***
921 // ex: shiftwidth=4 tabstop=4
922