File: sardrawhuman.c

package info (click to toggle)
searchandrescue 0.8.2-10
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,656 kB
  • ctags: 6,111
  • sloc: ansic: 89,072; cpp: 7,691; sh: 90; makefile: 80
file content (999 lines) | stat: -rw-r--r-- 23,916 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
#include <math.h>
#include <sys/types.h>

#ifdef __MSW__
# include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>

#include "gw.h"
#include "stategl.h"
#include "obj.h"
#include "objutils.h"
#include "sar.h"
#include "sardraw.h"
#include "sardrawdefs.h"
#include "config.h"


void SARDrawHumanIterate(
	sar_dc_struct *dc,
	float height, float mass,
	sar_human_flags flags,
	const sar_color_struct *palette,	/* Human colors */
	int water_ripple_tex_num,
	sar_grad_anim_t anim_pos
);
void SARDrawHuman(
	sar_dc_struct *dc, sar_object_struct *obj_ptr,
	sar_object_human_struct *human
);


/*
 *	Called by SARDrawHuman() to draw one human.
 *
 *	All inputs assumed valid.
 */
void SARDrawHumanIterate(
	sar_dc_struct *dc,
	float height, float mass,
	sar_human_flags flags,
	const sar_color_struct *palette,	/* Human colors */
	int water_ripple_tex_num,
	sar_grad_anim_t anim_pos
)
{
	gw_display_struct *display = dc->display;
	state_gl_struct *state = &display->state_gl;
	const sar_option_struct *opt = dc->option;
	sar_scene_struct *scene = dc->scene;
	StateGLBoolean lighting = state->lighting;
	GLenum shade_model_mode = state->shade_model_mode;
	StateGLBoolean texture_2d_state = state->texture_2d;
	float anim_coeff = (float)anim_pos /
	    (float)((sar_grad_anim_t)-1);

	float torso_angle;
	float left_bisep_angle, right_bisep_angle;
	float left_shoulder_angle, right_shoulder_angle;
	float left_trisep_angle, right_trisep_angle;
	float left_hip_to_thigh_angle, right_hip_to_thigh_angle;
	float left_knee_to_calv_angle, right_knee_to_calv_angle;

	float thigh_len = 0.3f;
	float calv_len = 0.4f;
	float torso_len = 0.8f;
	float bisep_len = 0.3f;
	float trisep_len = 0.4f;
	float base_to_torso = 0.0f;	/* Ground to bottom of torso
					 * (calculated later).
					 */
	float streatcher_height = 0.8f;	/* Ground to bed of streatcher. */

	const sar_color_struct *c;
	Boolean draw_shadow_std = False;

/* Macro to set the color pointed to by c.  The color must be specifying
 * a color on the human's body, because dc->flir will be checked and if
 * it is True then the color will be brightened.
 */
#define SET_BODY_COLOR					\
{ if(dc->flir) {						\
 float g = (float)(((c->r + c->g + c->b) / 3.0) / 2.0);	\
 glColor4f(0.5f + g, 1.0f, 0.5f + g, 1.0f);		\
} else {						\
 glColor4f(c->r, c->g, c->b, c->a);			\
} }

	/* Set up gl states. */
	if(dc->flir)
	    StateGLDisable(state, GL_LIGHTING);
	StateGLDisable(state, GL_TEXTURE_2D);
	V3DTextureSelect(NULL);
	StateGLShadeModel(state, opt->gl_shade_model);

	/* Calculate angles of body parts. Note that all zero radians
	 * indicates human is standing upright with hands to side.
	 */
	if(flags & SAR_HUMAN_FLAG_LYING)
	{
	    torso_angle = (float)(1.5 * PI);
	    left_shoulder_angle = (float)(0.0 * PI);
	    right_shoulder_angle = (float)(0.0 * PI);
	    left_bisep_angle = (float)(0.0 * PI);
	    right_bisep_angle = (float)(0.0 * PI);
	    left_trisep_angle = (float)(0.0 * PI);
	    right_trisep_angle = (float)(0.0 * PI);
	    left_hip_to_thigh_angle = (float)(0.0 * PI);
	    right_hip_to_thigh_angle = (float)(0.0 * PI);
	    left_knee_to_calv_angle = (float)(0.0 * PI);
	    right_knee_to_calv_angle = (float)(0.0 * PI);

	    base_to_torso = thigh_len + calv_len;

	    if(flags & SAR_HUMAN_FLAG_ON_STREATCHER)
	    {
		/* Some translating will be done later. */
	    }
	}
	else if(flags & SAR_HUMAN_FLAG_SIT)
	{
	    /* Sitting base at tush. */
	    torso_angle = (float)(0.0 * PI);
	    left_shoulder_angle = (float)(0.0 * PI);
	    right_shoulder_angle = (float)(0.0 * PI);
	    left_bisep_angle = (float)(0.0 * PI);
	    right_bisep_angle = (float)(0.0 * PI);
	    left_trisep_angle = (float)(1.75 * PI);
	    right_trisep_angle = (float)(1.75 * PI);
	    left_hip_to_thigh_angle = (float)(1.5 * PI);
	    right_hip_to_thigh_angle = (float)(1.5 * PI);
	    left_knee_to_calv_angle = (float)(0.5 * PI);
	    right_knee_to_calv_angle = (float)(0.5 * PI);

	    base_to_torso = 0.0f;
	}
	else if(flags & SAR_HUMAN_FLAG_SIT_DOWN)
	{
	    torso_angle = (float)(0.0 * PI);
	    left_shoulder_angle = (float)(0.0 * PI);
	    right_shoulder_angle = (float)(0.0 * PI);
	    left_bisep_angle = (float)(0.0 * PI);
	    right_bisep_angle = (float)(0.0 * PI);
	    left_trisep_angle = (float)(1.75 * PI);
	    right_trisep_angle = (float)(1.75 * PI);
	    left_hip_to_thigh_angle = (float)(1.5 * PI);
	    right_hip_to_thigh_angle = (float)(1.5 * PI);
	    left_knee_to_calv_angle = (float)(0.0 * PI);
	    right_knee_to_calv_angle = (float)(0.0 * PI);

	    base_to_torso = 0.0f;
	}
	else if(flags & SAR_HUMAN_FLAG_SIT_UP)
	{
	    /* Sitting base at feet. */
	    torso_angle = (float)(0.0 * PI);
	    left_shoulder_angle = (float)(0.0 * PI);
	    right_shoulder_angle = (float)(0.0 * PI);
	    left_bisep_angle = (float)(0.0 * PI);
	    right_bisep_angle = (float)(0.0 * PI);
	    left_trisep_angle = (float)(1.75 * PI);
	    right_trisep_angle = (float)(1.75 * PI);
	    left_hip_to_thigh_angle = (float)(1.5 * PI);
	    right_hip_to_thigh_angle = (float)(1.5 * PI); 
	    left_knee_to_calv_angle = (float)(0.5 * PI);
	    right_knee_to_calv_angle = (float)(0.5 * PI);
	
	    base_to_torso = calv_len;
	}
	else if(flags & SAR_HUMAN_FLAG_DIVER_CATCHER)
	{
	    /* Diver catching victim, used for hoist rescue end drawing. */
	    torso_angle = (float)(0.0 * PI);
	    left_shoulder_angle = (float)(0.1 * PI);
	    right_shoulder_angle = (float)(1.9 * PI);
	    left_bisep_angle = (float)(1.8 * PI);
	    right_bisep_angle = (float)(1.8 * PI);
	    left_trisep_angle = (float)(1.8 * PI);   
	    right_trisep_angle = (float)(1.8 * PI);
	    left_hip_to_thigh_angle = (float)(1.9 * PI);
	    right_hip_to_thigh_angle = (float)(1.9 * PI);
	    left_knee_to_calv_angle = (float)(0.2 * PI); 
	    right_knee_to_calv_angle = (float)(0.2 * PI);

	    /* If gripped it implies on end of rescue hoist rope. */
	    if(flags & SAR_HUMAN_FLAG_GRIPPED)
		base_to_torso = torso_len;
	    else if(flags & SAR_HUMAN_FLAG_IN_WATER)
		base_to_torso = torso_len * -0.92f;
	    else
		base_to_torso = thigh_len + calv_len;
	}
	/* Run should be checked last since lying and setting have
	 * precidence.
	 */
	else if(flags & SAR_HUMAN_FLAG_RUN)
	{
	    if(anim_coeff > 0.5f)
		anim_coeff = (1.0f - anim_coeff) / 0.5f;
	    else
		anim_coeff = anim_coeff / 0.5f;

	    torso_angle = (float)(0.1 * PI);
	    left_shoulder_angle = (float)(0.0 * PI);
	    right_shoulder_angle = (float)(0.0 * PI);
	    if(flags & SAR_HUMAN_FLAG_PUSHING)
	    {
		left_bisep_angle = (float)(1.7 * PI);
		right_bisep_angle = (float)(1.7 * PI);
		left_trisep_angle = (float)(1.6 * PI);
		right_trisep_angle = (float)(1.6 * PI);
	    }
	    else
	    {
		left_bisep_angle = (float)(
		    (1.7 + (0.35 * (1.0 - anim_coeff))) * PI
		);
		right_bisep_angle = (float)(
		    (1.7 + (0.35 * anim_coeff)) * PI
		);
		left_trisep_angle = (float)(
		    (1.6 + (0.15 * (1.0 - anim_coeff))) * PI
		);
		right_trisep_angle = (float)(
		    (1.6 + (0.15 * anim_coeff)) * PI
		);
	    }
	    left_hip_to_thigh_angle = (float)(
		(0.2 - (0.5 * anim_coeff)) * PI
	    );
	    right_hip_to_thigh_angle = (float)(
		(0.2 - (0.5 * (1.0 - anim_coeff))) * PI
	    );
	    left_knee_to_calv_angle = (float)(0.2 * PI);
	    right_knee_to_calv_angle = (float)(0.2 * PI);

	    base_to_torso = thigh_len + calv_len;

	    draw_shadow_std = True;
	}
	/* All else assume just standing. */
	else
	{
	    /* Standing in water? */
	    if(flags & SAR_HUMAN_FLAG_IN_WATER)
	    {
		/* Standing in water, arms fore and moving. */
		if(anim_coeff > 0.5f)
		    anim_coeff = (float)((1.0 - anim_coeff) / 0.5);
		else
		    anim_coeff = (float)(anim_coeff / 0.5);

		torso_angle = (float)(0.0 * PI);
		left_shoulder_angle = (float)((0.4 * anim_coeff) * PI);
		right_shoulder_angle = (float)((2 - (0.4 * anim_coeff)) * PI);
		left_bisep_angle = (float)(1.5 * PI);
		right_bisep_angle = (float)(1.5 * PI);
		left_trisep_angle = (float)(0.0 * PI);
	        right_trisep_angle = (float)(0.0 * PI);
		left_hip_to_thigh_angle = (float)(0.0 * PI);
		right_hip_to_thigh_angle = (float)(0.0 * PI);
		left_knee_to_calv_angle = (float)(0.0 * PI);
		right_knee_to_calv_angle = (float)(0.0 * PI);

		/* Since in water, move torso down. */
		base_to_torso = torso_len * -0.92f;
	    }
	    else
	    {
		/* Standing on ground and aware? */
		if((flags & SAR_HUMAN_FLAG_NEED_RESCUE) &&
		   (flags & SAR_HUMAN_FLAG_AWARE)
		)
		{
		    /* Need rescue and aware that rescuer is
		     * near by, move arms fore and wave.
		     */
		    if(anim_coeff > 0.5f)
			anim_coeff = (float)((1.0 - anim_coeff) / 0.5);
		    else
			anim_coeff = (float)(anim_coeff / 0.5);

		    torso_angle = (float)(0.0 * PI);
		    left_shoulder_angle = (float)(
			(0.7 + (0.4 * anim_coeff)) * PI
		    );
		    right_shoulder_angle = (float)(
			(1.3 - (0.4 * anim_coeff)) * PI
		    );
		    left_bisep_angle = (float)(0.0 * PI);
		    right_bisep_angle = (float)(0.0 * PI);
		    left_trisep_angle = (float)(0.0 * PI);
		    right_trisep_angle = (float)(0.0 * PI);
		    left_hip_to_thigh_angle = (float)(0.0 * PI);
		    right_hip_to_thigh_angle = (float)(0.0 * PI);
		    left_knee_to_calv_angle = (float)(0.0 * PI);
		    right_knee_to_calv_angle = (float)(0.0 * PI);

		    base_to_torso = thigh_len + calv_len;
		}
		else
		{
		    /* Just standing on ground. */
		    torso_angle = (float)(0.0 * PI);
		    left_shoulder_angle = (float)(0.0 * PI);
		    right_shoulder_angle = (float)(0.0 * PI);
		    left_bisep_angle = (float)(0.0 * PI);
		    right_bisep_angle = (float)(0.0 * PI);
		    left_trisep_angle = (float)(0.0 * PI);
		    right_trisep_angle = (float)(0.0 * PI);
		    left_hip_to_thigh_angle = (float)(0.0 * PI);
		    right_hip_to_thigh_angle = (float)(0.0 * PI);
		    left_knee_to_calv_angle = (float)(0.0 * PI);
		    right_knee_to_calv_angle = (float)(0.0 * PI);

		    base_to_torso = thigh_len + calv_len;
		}
		draw_shadow_std = True;
	    }
	}

	/* At this point the human's appendage length and rotation
	 * values have now been set up.
	 */

	/* Draw shadow? */
	if(draw_shadow_std)
	{
	    float theta, r = 0.5f;
	    StateGLBoolean lighting = state->lighting;
	    StateGLBoolean depth_mask_flag = state->depth_mask_flag;
	    GLenum shade_model_mode = state->shade_model_mode;

	    /* Set up GL states. */
	    if(lighting)
		StateGLDisable(state, GL_LIGHTING);
	    StateGLEnable(state, GL_BLEND);
	    StateGLDisable(state, GL_ALPHA_TEST);
	    StateGLDepthMask(state, GL_FALSE);
	    StateGLEnable(state, GL_POLYGON_OFFSET_FILL);
	    StateGLBlendFunc(
		state, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
	    );
	    StateGLPolygonOffset(
		state,
		(GLfloat)opt->gl_polygon_offset_factor, -1.0f
	    );
	    StateGLShadeModel(state, GL_FLAT);

	    glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
	    glBegin(GL_TRIANGLE_FAN);
	    glNormal3f(0.0f, 1.0f, 0.0f);
	    for(theta = 2.0f; theta > 0.0f; theta -= 0.25f)
		glVertex3f(
		    (float)(r * sin(theta * PI)),
		    0.0f,
		    (float)-(r * cos(theta * PI))
		);
	    glEnd();

	    /* Restore GL states. */
	    if(lighting)
		StateGLEnable(state, GL_LIGHTING);
	    StateGLDisable(state, GL_POLYGON_OFFSET_FILL);
	    StateGLDisable(state, GL_BLEND);
	    StateGLDepthMask(state, depth_mask_flag);
	    StateGLEnable(state, GL_ALPHA_TEST);
	    StateGLShadeModel(state, shade_model_mode);
	}

	/* Draw streatcher? */
	if(flags & SAR_HUMAN_FLAG_ON_STREATCHER)
	{
	    float x = 0.35f, y = 1.05f;
	    float h = streatcher_height - 0.1f, hl = 0.1f;

	    glColor4f(0.8f, 0.8f, 0.8f, 1.0f);

	    /* Bed of streatcher. */
	    glBegin(GL_QUADS);
	    {
		glNormal3f(0.0f, 1.0f, 0.0f);
		glVertex3f(x, h, -y);
		glVertex3f(-x, h, -y);
		glVertex3f(-x, h, y);
		glVertex3f(x, h, y);

		glNormal3f(0.0f, -1.0f, 0.0f);
		glVertex3f(-x, h, -y);
		glVertex3f(x, h, -y);
		glVertex3f(x, h, y);
		glVertex3f(-x, h, y);
	    }
	    glEnd();

	    glColor4f(0.7f, 0.7f, 0.7f, 1.0f);

	    /* Left grids. */
	    glBegin(GL_LINE_LOOP);
	    {
		glNormal3f(-1.0f, 0.0f, 0.0f);
		glVertex3f(-x, hl, -y);
		glVertex3f(-x, h, y);
		glVertex3f(-x, hl, y);
		glVertex3f(-x, h, -y);
	    }
	    glEnd();

	    /* Right grids. */
	    glBegin(GL_LINE_LOOP);  
	    {
		glNormal3f(1.0, 0.0, 0.0);
		glVertex3f(x, hl, -y);
		glVertex3f(x, h, y);
		glVertex3f(x, hl, y);
		glVertex3f(x, h, -y);
	    }
	    glEnd();


	    glColor4f(0.1f, 0.1f, 0.1f, 1.0f);

	    /* Simple square wheels. */
	    glBegin(GL_QUADS);
	    {
		glNormal3f(-1.0f, 0.0f, 0.0f);
		glVertex3f(-x, 0.0f, -y);
		glVertex3f(-x, 0.0f, -(y - 0.1f));
		glVertex3f(-x, hl, -(y - 0.1f));
		glVertex3f(-x, hl, -y);
	    }
	    glEnd();

	    glBegin(GL_QUADS);        
	    {
		glNormal3f(-1.0f, 0.0f, 0.0f);
		glVertex3f(-x, hl, y);
		glVertex3f(-x, hl, (y - 0.1f));
		glVertex3f(-x, 0.0f, (y - 0.1f)); 
		glVertex3f(-x, 0.0f, y);
	    }
	    glEnd();

	    glBegin(GL_QUADS);
	    {
		glNormal3f(1.0f, 0.0f, 0.0f);
		glVertex3f(x, 0.0f, -y);
		glVertex3f(x, hl, -y);
		glVertex3f(x, hl, -(y - 0.1f));
		glVertex3f(x, 0.0f, -(y - 0.1f));
	    }
	    glEnd();

	    glBegin(GL_QUADS);
	    {
		glNormal3f(1.0f, 0.0f, 0.0f);
		glVertex3f(x, 0.0f, (y - 0.1f));
		glVertex3f(x, hl, (y - 0.1f));
		glVertex3f(x, hl, y);
		glVertex3f(x, 0.0f, y);
	    }
	    glEnd();
	}

	/* Begin drawing human. */

	/* Torso. */
	glPushMatrix();
	{
	    /* Check if on streatcher, if so translate up. */
	    if(flags & SAR_HUMAN_FLAG_ON_STREATCHER)  
	    {
		/* Push on extra matrix and move up (matrix poped later). */
		glPushMatrix();
		glTranslatef(
		    0.0f,
		    streatcher_height,
		    -(base_to_torso + 0.2f)
		);
	    }

	    /* Move to base of torso (the tush). */
	    glRotatef(
		(GLfloat)-SFMRadiansToDegrees(torso_angle),
		1.0f, 0.0f, 0.0f
	    );
	    glTranslatef(0.0f, base_to_torso, 0.0f);

	    /* Move to center of torso and draw torso. */
	    glPushMatrix();
	    {
		/* Hips of torso. */
		c = &palette[SAR_HUMAN_COLOR_HIPS];
		SET_BODY_COLOR
		glBegin(GL_QUADS);
		{
	            SARDrawBoxBaseNS(
			0.45f * torso_len,
			0.25f * torso_len,
			0.10f * torso_len,
			True
		    );
		}
		glEnd();


		glTranslatef(0.0f, 0.10f * torso_len, 0.0f);

		/* Upper torso. */
		c = &palette[SAR_HUMAN_COLOR_TORSO];
		SET_BODY_COLOR
		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.45f * torso_len,
			0.25f * torso_len,
			0.90f * torso_len,
			False
		    );
		}
		glEnd();
	    }
	    glPopMatrix();
	    /* Back to base of torso. */

	    /* Draw left leg. */
	    glPushMatrix();
	    {
		/* Thigh. */
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(left_hip_to_thigh_angle),
		    1.0f, 0.0f, 0.0f
		);
		glTranslatef(-0.16f * torso_len, 0.0f, 0.0f);

		c = &palette[SAR_HUMAN_COLOR_LEGS];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.5f * thigh_len,
			0.5f * thigh_len,
			-thigh_len,
			True
		    );
		}
		glEnd();

		/* Calv. */
		glTranslatef(0.0f, -thigh_len, 0.0f);
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(left_knee_to_calv_angle),
		    1.0f, 0.0f, 0.0f
		);

		/* Use same color as for thighs. */

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.3f * calv_len,
			0.3f * calv_len,
			-calv_len,
			True
		    );
		}
		glEnd();

		/* Feet. */
		glTranslatef(0.0f, -calv_len, -0.05f);

		c = &palette[SAR_HUMAN_COLOR_FEET];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.1f,
			0.2f,
			-0.1f,
			True
		    );
		}
		glEnd();
	    }
	    glPopMatrix();
	    /* Back to base of torso. */

	    /* Draw right leg. */
	    glPushMatrix();
	    {
		/* Thigh. */
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(right_hip_to_thigh_angle),
		    1.0f, 0.0f, 0.0f
		);
		glTranslatef(0.16f * torso_len, 0.0f, 0.0f);

		c = &palette[SAR_HUMAN_COLOR_LEGS];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.5f * thigh_len,
			0.5f * thigh_len,
			-thigh_len,
			True
		    );  
		}
		glEnd();   
		
		/* Calv. */
		glTranslatef(0.0f, -thigh_len, 0.0f);
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(right_knee_to_calv_angle),
		    1.0f, 0.0f, 0.0f
		);

		/* Use same color as for thighs. */

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.3f * calv_len,
			0.3f * calv_len,
			-calv_len,
			True
		    );
		}
		glEnd();

		/* Feet. */
		glTranslatef(0.0f, -calv_len, -0.05f);

		c = &palette[SAR_HUMAN_COLOR_FEET];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.1f,
			0.2f,
			-0.1f,
			True
		    );
		}
		glEnd();
	    }
	    glPopMatrix();
	    /* Back to base of torso. */

	    /* Move to shoulders. */
	    glTranslatef(0.0f, 0.95f * torso_len, 0.0f);

	    /* Draw left arm. */
	    glPushMatrix();
	    {
		/* Bisep and shoulder. */
		glTranslatef(
		    (-0.225f * torso_len) + (-0.25f * bisep_len),
		    0.0f,
		    0.0f
		);
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(left_bisep_angle),
		    1.0f, 0.0f, 0.0f
		);
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(left_shoulder_angle),
		    0.0f, 0.0f, 1.0f
		);

		c = &palette[SAR_HUMAN_COLOR_ARMS];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.5f * bisep_len,
			0.5f * bisep_len,
			-bisep_len,
			True
		    );
		}
		glEnd();

		/* Trisep. */
		glTranslatef(0.0f, -bisep_len, 0.0f);
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(left_trisep_angle),
		    1.0f, 0.0f, 0.0f
		);

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.28f * trisep_len,
			0.28f * trisep_len,
			-trisep_len,
			True
		    );
		}
		glEnd();


		/* Hand. */
		glTranslatef(0.0f, -trisep_len, 0.0f);

		c = &palette[SAR_HUMAN_COLOR_HANDS];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(0.2f, 0.1f, -0.2f, True);
		}
		glEnd();
	    }
	    glPopMatrix();
	    /* Back to shoulders. */

	    /* Draw right arm. */
	    glPushMatrix();
	    {
		/* Bisep. */
		glTranslatef(
		    (0.225f * torso_len) + (0.25f * bisep_len),
		    0.0f,
		    0.0f
		);
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(right_bisep_angle),
		    1.0f, 0.0f, 0.0f
		);
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(right_shoulder_angle),
		    0.0f, 0.0f, 1.0f
		);

		c = &palette[SAR_HUMAN_COLOR_ARMS];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.5f * bisep_len,
			0.5f * bisep_len,
			-bisep_len,
			True
		    );
		}
		glEnd();

		/* Trisep. */
		glTranslatef(0.0f, -bisep_len, 0.0f);
		glRotatef(
		    (GLfloat)-SFMRadiansToDegrees(right_trisep_angle),
		    1.0f, 0.0f, 0.0f
		);

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(
			0.28f * trisep_len,
			0.28f * trisep_len,
			-trisep_len,
			True
		    );
		}
		glEnd();


		/* Hand. */
		glTranslatef(0.0f, -trisep_len, 0.0f);

		c = &palette[SAR_HUMAN_COLOR_HANDS];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(0.2f, 0.1f, -0.2f, True);
		}
		glEnd();
	    }
	    glPopMatrix();
	    /* Back to shoulders. */


	    /* Head. */
	    glTranslatef(0.0f, 0.05f * torso_len, 0.0f);

	    c = &palette[SAR_HUMAN_COLOR_FACE];
	    SET_BODY_COLOR

	    glBegin(GL_QUADS);
	    {
		SARDrawBoxBaseNS(0.18f, 0.18f, 0.25f, False);
	    }
	    glEnd();


	    /* Hair. */
	    glPushMatrix();
	    {
		glTranslatef(0.0f, 0.25f, 0.0f);

		c = &palette[SAR_HUMAN_COLOR_HAIR];
		SET_BODY_COLOR

		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(0.18f, 0.18f, 0.1f, False);
		}
		glEnd();
	    }
	    glPopMatrix();
	    /* Back of head hair. */
	    glPushMatrix();
	    {
		glTranslatef(0.0f, 0.05f, -(-0.09f - 0.03f));
		glBegin(GL_QUADS);
		{
		    SARDrawBoxBaseNS(0.18f, 0.06f, 0.25f, True);
		}
		glEnd();
	    }
	    glPopMatrix();


	    /* Check if on streatcher, if so we need to pop one matrix
	     * level that was added for translation up on to streatcher.
	     */
	    if(flags & SAR_HUMAN_FLAG_ON_STREATCHER)
	    {
		glPopMatrix();
	    }
	}
	glPopMatrix();

	/* Re-enable GL_TEXTURE_2D as needed. */
	if(texture_2d_state)
	    StateGLEnable(state, GL_TEXTURE_2D);

	/* Draw water ripples if in water. */
	if(flags & SAR_HUMAN_FLAG_IN_WATER)
	{
	    GLboolean depth_mask_flag;
	    int tex_num, frame_num;
	    v3d_texture_ref_struct *t;
	    float hr = 5.0;	/* Half ripple radius. */


	    tex_num = water_ripple_tex_num;
	    if(SARIsTextureAllocated(scene, tex_num) &&
	       opt->textured_objects
	    )
	    {
		t = scene->texture_ref[tex_num];

		/* Select frame by animation, re-update anim_coeff. */
		anim_coeff = (float)anim_pos /
		    (float)((sar_grad_anim_t)-1);

		frame_num = (int)(anim_coeff * t->total_frames);
		if(frame_num >= t->total_frames)
		    frame_num = t->total_frames - 1;
		if(frame_num < 0)
		    frame_num = 0;
		V3DTextureSelectFrame(t, frame_num);

		glColor4f(1.0f, 1.0f, 1.0f, 0.5f);

		StateGLEnable(state, GL_BLEND);
		StateGLDisable(state, GL_ALPHA_TEST);
		depth_mask_flag = state->depth_mask_flag;
		StateGLDepthMask(state, GL_FALSE);
		StateGLEnable(state, GL_POLYGON_OFFSET_FILL);
		StateGLBlendFunc(
		    state, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
		);
		StateGLPolygonOffset(
		    state,
		    (GLfloat)opt->gl_polygon_offset_factor, -1.0f
		);

		glBegin(GL_QUADS);
		{
		    glNormal3f(0, 1, 0);
		    glTexCoord2d(0, 1 - 0);
		    glVertex3f(-hr, 0, hr);
		    glTexCoord2d(1, 1 - 0);
		    glVertex3f(hr, 0, hr);
		    glTexCoord2d(1, 1 - 1);
		    glVertex3f(hr, 0, -hr);
		    glTexCoord2d(0, 1 - 1);
		    glVertex3f(-hr, 0, -hr);
		}
		glEnd();

		StateGLDisable(state, GL_POLYGON_OFFSET_FILL);
		StateGLDisable(state, GL_BLEND);
		StateGLDepthMask(state, depth_mask_flag);
		StateGLEnable(state, GL_ALPHA_TEST);
	    }
	}

	/* Restore GL states. */
	if(lighting)
	    StateGLEnable(state, GL_LIGHTING);
	StateGLShadeModel(state, shade_model_mode);

#undef SET_BODY_COLOR
}


/*
 *      Draws a human specified by the object obj_ptr.
 *
 *      The human substructure human should be the one on
 *      the object.
 *
 *      All inputs are assumed valid.
 */
void SARDrawHuman(
	sar_dc_struct *dc, sar_object_struct *obj_ptr,
	sar_object_human_struct *human
)
{
	/* Draw main human model for this call first, passing the
	 * given human object structure's values directly.
	 */
	SARDrawHumanIterate(
	    dc,
	    human->height, human->mass,
	    human->flags, human->color,
	    human->water_ripple_tex_num,
	    human->anim_pos
	);

	/* Draw assisting humans if any and as appropriate.
	 * Do not draw assisting humans if this human is being gripped
	 * (ie in a rescue basket).
	 */
	if((human->assisting_humans > 0) &&
	   !(human->flags & SAR_HUMAN_FLAG_GRIPPED)
	)
	{
	    int i;
	    sar_obj_flags_t flags;
	    float s = 0.8f;	/* Left/right spacing. */

	    /* Draw all assisting human objects, left and right. */
	    for(i = 0; i < human->assisting_humans; i++)
	    {
		glPushMatrix();
		{
		    /* Translate to the side and a bit behind. */
		    glTranslatef(s, 0.0f, 0.2f);

		    /* Set up `filtered' human flags that will be
		     * passed to the human draw itteration function.
		     * This is so that we don't pass all the flags, 
		     * because in some situations the human may be
		     * lying on a streatcher and the assisting humans
		     * need to be running.
		     */
		    flags = 0;
		    if(human->flags & SAR_HUMAN_FLAG_ALERT)
		        flags |= SAR_HUMAN_FLAG_ALERT;
		    if(human->flags & SAR_HUMAN_FLAG_AWARE)
			flags |= SAR_HUMAN_FLAG_AWARE;
		    if(human->flags & SAR_HUMAN_FLAG_IN_WATER)
			flags |= SAR_HUMAN_FLAG_IN_WATER;
		    if(human->flags & SAR_HUMAN_FLAG_RUN)
			flags |= SAR_HUMAN_FLAG_RUN;
		    if(human->flags & SAR_HUMAN_FLAG_PUSHING)
			flags |= SAR_HUMAN_FLAG_PUSHING;

		    /* Draw our human object as an assisting human,
		     * using the filtered human flags and the 
		     * assisting_human_color color palette
		     */
		    SARDrawHumanIterate(
			dc,
			human->height, human->mass,
			flags, human->assisting_human_color,
			human->water_ripple_tex_num,
			human->anim_pos
		    );
		}
		glPopMatrix();

		/* Shift spacing to other side. */
		s *= -1.0;
	    }
	}
}