forked from gitpan/FreeWRL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVRMLFunc.xs
More file actions
6183 lines (5621 loc) · 158 KB
/
VRMLFunc.xs
File metadata and controls
6183 lines (5621 loc) · 158 KB
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
1000
/* VRMLFunc.c generated by VRMLC.pm. DO NOT MODIFY, MODIFY VRMLC.pm INSTEAD */
/* Code here comes almost verbatim from VRMLC.pm */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include "OpenGL/OpenGL.m"
#define offset_of(p_type,field) ((unsigned int)(&(((p_type)NULL)->field)-NULL))
#define TC(a,b) glTexCoord2f(a,b)
#ifdef M_PI
#define PI M_PI
#else
#define PI 3.141592653589793
#endif
/* Faster trig macros (thanks for Robin Williams) */
#define DECL_TRIG1 float t_aa, t_ab, t_sa, t_ca, t_sa1, t_ca1;
#define INIT_TRIG1(div) t_aa = sin(PI/(div)); t_aa *= 2*t_aa; t_ab = sin(2*PI/(div));
#define START_TRIG1 t_sa = 0; t_ca = 1;
#define UP_TRIG1 t_sa1 = t_sa; t_sa -= t_sa*t_aa - t_ca * t_ab; t_ca -= t_ca * t_aa + t_sa1 * t_ab;
#define SIN1 t_sa
#define COS1 t_ca
#define DECL_TRIG2 float t2_aa, t2_ab, t2_sa, t2_ca, t2_sa1, t2_ca1;
#define INIT_TRIG2(div) t2_aa = sin(PI/(div)); t2_aa *= 2*t2_aa; t2_ab = sin(2*PI/(div));
#define START_TRIG2 t2_sa = 0; t2_ca = 1;
#define UP_TRIG2 t2_sa1 = t2_sa; t2_sa -= t2_sa*t2_aa - t2_ca * t2_ab; t2_ca -= t2_ca * t2_aa + t2_sa1 * t2_ab;
#define SIN2 t2_sa
#define COS2 t2_ca
D_OPENGL;
/* Rearrange to take advantage of headlight when off */
int curlight = 0;
int nlightcodes = 7;
int lightcode[7] = {
GL_LIGHT1,
GL_LIGHT2,
GL_LIGHT3,
GL_LIGHT4,
GL_LIGHT5,
GL_LIGHT6,
GL_LIGHT7,
};
int nextlight() {
if(curlight == nlightcodes) { return -1; }
return lightcode[curlight++];
}
struct VRML_Virt {
void (*prep)(void *);
void (*rend)(void *);
void (*children)(void *);
void (*fin)(void *);
void (*rendray)(void *);
void (*mkpolyrep)(void *);
void (*light)(void *);
/* And get float coordinates : Coordinate, Color */
/* XXX Relies on MFColor repr.. */
struct SFColor *(*get3)(void *, int *); /* Number in int */
struct SFVec2f *(*get2)(void *, int *); /* Number in int */
char *name;
};
/* Internal representation of IndexedFaceSet, Extrusion & ElevationGrid:
* set of triangles.
* done so that we get rid of concave polygons etc.
*/
struct VRML_PolyRep { /* Currently a bit wasteful, because copying */
int _change;
int ntri; /* number of triangles */
int *cindex; /* triples (per triangle) */
float *coord; /* triples (per point) */
int *colindex; /* triples (per triangle) */
float *color; /* triples or null */
int *norindex;
float *normal; /* triples or null */
};
struct Multi_Float { int n; float *p; };
struct SFRotation {
float r[4]; };
struct Multi_Rotation { int n; struct SFRotation *p; };
struct Multi_Vec3f { int n; struct SFColor *p; };
struct Multi_Int32 { int n; int *p; };
struct Multi_Node { int n; void * *p; };
struct SFColor {
float c[3]; };
struct Multi_Color { int n; struct SFColor *p; };
struct Multi_String { int n; SV * *p; };
struct SFVec2f {
float c[2]; };
struct Multi_Vec2f { int n; struct SFVec2f *p; };
/* and now the structs for the nodetypes */
struct VRML_PointLight {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
float radius;
struct SFColor location;
struct SFColor direction;
struct SFColor attenuation;
int on;
struct SFColor color;
float ambientIntensity;
float intensity;
};
struct VRML_DirectionalLight {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct SFColor direction;
int on;
float ambientIntensity;
struct SFColor color;
float intensity;
};
struct VRML_Sphere {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
float radius;
};
struct VRML_Coordinate {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Vec3f point;
};
struct VRML_FontStyle {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
SV *style;
struct Multi_String family;
SV *language;
float spacing;
int horizontal;
int topToBottom;
float size;
int leftToRight;
struct Multi_String justify;
};
struct VRML_Normal {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Vec3f vector;
};
struct VRML_Box {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct SFColor size;
};
struct VRML_Billboard {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Node children;
struct SFColor axisOfRotation;
struct SFColor bboxCenter;
struct SFColor bboxSize;
};
struct VRML_ElevationGrid {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
int zDimension;
int colorPerVertex;
struct Multi_Float height;
void *normal;
float creaseAngle;
int solid;
float xSpacing;
int xDimension;
int normalPerVertex;
void *color;
float zSpacing;
};
struct VRML_Extrusion {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
int convex;
struct Multi_Vec2f scale;
int beginCap;
float creaseAngle;
int solid;
int endCap;
struct Multi_Rotation orientation;
int ccw;
struct Multi_Vec2f crossSection;
struct Multi_Vec3f spine;
};
struct VRML_Switch {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Node choice;
int whichChoice;
};
struct VRML_ImageTexture {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
SV *__data;
struct Multi_String url;
int __depth;
int repeatS;
int repeatT;
int __x;
int __y;
};
struct VRML_TextureCoordinate {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Vec2f point;
};
struct VRML_IndexedFaceSet {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Int32 texCoordIndex;
struct Multi_Int32 normalIndex;
int convex;
int colorPerVertex;
void *coord;
struct Multi_Int32 colorIndex;
void *texCoord;
void *normal;
float creaseAngle;
int solid;
int ccw;
struct Multi_Int32 coordIndex;
void *color;
};
struct VRML_Background {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
int __y_left;
SV *__data_left;
int __depth_back;
struct Multi_String backUrl;
int __depth_top;
struct Multi_String topUrl;
int __y_back;
int __depth_bottom;
SV *__data_back;
int __x_top;
struct Multi_String bottomUrl;
int __y_top;
int __y_bottom;
float bindTime;
SV *__data_bottom;
int __depth_right;
int __x_right;
int isBound;
int __y_right;
struct Multi_Float groundAngle;
struct Multi_Color skyColor;
SV *__data_front;
int __x_left;
int __x_back;
int set_bind;
SV *__data_top;
int __x_bottom;
struct Multi_Color groundColor;
struct Multi_String rightUrl;
SV *__data_right;
int __depth_front;
struct Multi_String frontUrl;
int __depth_left;
struct Multi_String leftUrl;
struct Multi_Float skyAngle;
int __x_front;
int __y_front;
};
struct VRML_Text {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
void *fontStyle;
int __rendersub;
struct Multi_Float length;
float maxExtent;
struct Multi_String string;
};
struct VRML_Cone {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
float height;
float bottomRadius;
int side;
int bottom;
};
struct VRML_Viewpoint {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
float fieldOfView;
SV *description;
int isBound;
struct SFColor position;
int set_bind;
float bindTime;
int jump;
struct SFRotation orientation;
};
struct VRML_TextureTransform {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
float rotation;
struct SFVec2f scale;
struct SFVec2f center;
struct SFVec2f translation;
};
struct VRML_Group {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Node children;
struct SFColor bboxCenter;
struct SFColor bboxSize;
};
struct VRML_ProximitySensor {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct SFColor center;
int __hit;
struct SFColor __t1;
struct SFRotation __t2;
struct SFRotation orientation_changed;
int isActive;
float exitTime;
struct SFColor size;
int enabled;
float enterTime;
struct SFColor position_changed;
};
struct VRML_Material {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
float transparency;
struct SFColor emissiveColor;
float shininess;
struct SFColor diffuseColor;
struct SFColor specularColor;
float ambientIntensity;
};
struct VRML_Appearance {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
void *texture;
void *textureTransform;
void *material;
};
struct VRML_Shape {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
void *appearance;
void *geometry;
};
struct VRML_IndexedLineSet {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
int colorPerVertex;
void *coord;
void *color;
struct Multi_Int32 colorIndex;
struct Multi_Int32 coordIndex;
};
struct VRML_PointSet {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
void *color;
void *coord;
};
struct VRML_Cylinder {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
float radius;
float height;
int top;
int side;
int bottom;
};
struct VRML_Anchor {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Node children;
struct Multi_String parameter;
struct Multi_String url;
SV *description;
struct SFColor bboxCenter;
struct SFColor bboxSize;
};
struct VRML_Transform {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct SFRotation rotation;
struct SFColor center;
struct SFRotation scaleOrientation;
struct SFColor bboxSize;
struct SFColor scale;
struct Multi_Node children;
struct SFColor bboxCenter;
struct SFColor translation;
};
struct VRML_SpotLight {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct SFColor direction;
float beamWidth;
float ambientIntensity;
float intensity;
float radius;
struct SFColor location;
struct SFColor attenuation;
int on;
float cutOffAngle;
struct SFColor color;
};
struct VRML_LOD {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Node level;
struct SFColor center;
struct Multi_Float range;
};
struct VRML_Color {
/***/ struct VRML_Virt *v;
/*s*/ int _sens;
/*t*/ int _hit;
/*a*/ int _change;
/*n*/ int _dlchange;
/*d*/ GLuint _dlist;
/*a*/ int _dl2change;
/*r*/ GLuint _dl2ist;
/*d*/ void *_intern;
/***/
struct Multi_Color color;
};
int verbose;
int reverse_trans;
int render_vp;
int render_geom;
int render_light;
int render_sensitive;
int horiz_div; int vert_div;
int vp_dist = 200000;
int cur_hits=0;
/* These two points define a ray in window coordinates */
struct pt {GLdouble x,y,z;};
struct pt r1 = {0,0,-1},r2 = {0,0,0},r3 = {0,1,0};
struct pt t_r1,t_r2,t_r3; /* transformed ray */
void *hypersensitive = 0; int hyperhit = 0;
struct pt hyper_r1,hyper_r2; /* Transformed ray for the hypersensitive node */
GLint viewport[4] = {-1,-1,2,2};
/* These three points define 1. hitpoint 2., 3. two different tangents
* of the surface at hitpoint (to get transformation correctly */
/* All in window coordinates */
struct pt hp, ht1, ht2;
double hpdist; /* distance in ray: 0 = r1, 1 = r2, 2 = 2*r2-r1... */
struct currayhit {
void *node; /* What node hit at that distance? */
GLdouble modelMatrix[16]; /* What the matrices were at that node */
GLdouble projMatrix[16];
} rh,rph,rhhyper;
/* used to test new hits */
/* defines for raycasting: */
#define APPROX(a,b) (fabs(a-b)<0.00000001)
#define NORMAL_VECTOR_LENGTH_TOLERANCE 0.00001
/* (test if the vector part of a rotation is normalized) */
#define IS_ROTATION_VEC_NOT_NORMAL(rot) ( \
fabs(1-sqrt(rot.r[0]*rot.r[0]+rot.r[1]*rot.r[1]+rot.r[2]*rot.r[2])) \
>NORMAL_VECTOR_LENGTH_TOLERANCE \
)
/* defines for raycasting: */
#define XEQ (APPROX(t_r1.x,t_r2.x))
#define YEQ (APPROX(t_r1.y,t_r2.y))
#define ZEQ (APPROX(t_r1.z,t_r2.z))
/* xrat(a) = ratio to reach coordinate a on axis x */
#define XRAT(a) (((a)-t_r1.x)/(t_r2.x-t_r1.x))
#define YRAT(a) (((a)-t_r1.y)/(t_r2.y-t_r1.y))
#define ZRAT(a) (((a)-t_r1.z)/(t_r2.z-t_r1.z))
/* mratx(r) = x-coordinate gotten by multiplying by given ratio */
#define MRATX(a) (t_r1.x + (a)*(t_r2.x-t_r1.x))
#define MRATY(a) (t_r1.y + (a)*(t_r2.y-t_r1.y))
#define MRATZ(a) (t_r1.z + (a)*(t_r2.z-t_r1.z))
/* trat: test if a ratio is reasonable */
#undef TRAT
#define TRAT(a) 1
#undef TRAT
#define TRAT(a) ((a) > 0 && ((a) < hpdist || hpdist < 0))
#define VECSQ(a) VECPT(a,a)
#define VECPT(a,b) ((a).x*(b).x + (a).y*(b).y + (a).z*(b).z)
#define VECDIFF(a,b,c) {(c).x = (a).x-(b).x;(c).y = (a).y-(b).y;(c).z = (a).z-(b).z;}
#define VEC_FROM_CDIFF(a,b,r) {(r).x = (a).c[0]-(b).c[0];(r).y = (a).c[1]-(b).c[1];(r).z = (a).c[2]-(b).c[2];}
#define VECCP(a,b,c) {(c).x = (a).y*(b).z-(b).y*(a).z; (c).y = -((a).x*(b).z-(b).x*(a).z); (c).z = (a).x*(b).y-(b).x*(a).y;}
#define VECSCALE(a,c) {(a).x *= c; (a).y *= c; (a).z *= c;}
/* rotate a vector along one axis */
#define VECROTATE_X(c,angle) { \
/*(c).x = (c).x */ \
(c).y = cos(angle) * (c).y - sin(angle) * (c).z; \
(c).z = sin(angle) * (c).y + cos(angle) * (c).z; \
}
#define VECROTATE_Y(c,angle) { \
(c).x = cos(angle)*(c).x + + sin(angle) * (c).z; \
/*(c).y = (c).y */ \
(c).z = -sin(angle)*(c).x + cos(angle) * (c).z; \
}
#define VECROTATE_Z(c,angle) { \
(c).x = cos(angle)*(c).x - sin(angle) * (c).y; \
(c).y = sin(angle)*(c).x + cos(angle) * (c).y; \
/*(c).z = s (c).z; */ \
}
#define MATRIX_ROTATION_X(angle,m) {\
m[0][0]=1; m[0][1]=0; m[0][2]=0; \
m[1][0]=0; m[1][1]=cos(angle); m[1][2]=- sin(angle); \
m[2][0]=0; m[2][1]=sin(angle); m[2][2]=cos(angle); \
}
#define MATRIX_ROTATION_Y(angle,m) {\
m[0][0]=cos(angle); m[0][1]=0; m[0][2]=sin(angle); \
m[1][0]=0; m[1][1]=1; m[1][2]=0; \
m[2][0]=-sin(angle); m[2][1]=0; m[2][2]=cos(angle); \
}
#define MATRIX_ROTATION_Z(angle,m) {\
m[0][0]=cos(angle); m[0][1]=- sin(angle); m[0][2]=0; \
m[1][0]=sin(angle); m[1][1]=cos(angle); m[1][2]=0; \
m[2][0]=0; m[2][1]=0; m[2][2]=1; \
}
/* next matrix calculation comes from comp.graphics.algorithms FAQ */
/* the axis vector has to be normalized */
#define MATRIX_FROM_ROTATION(ro,m) { \
struct { double x,y,z,w ; } __q; \
double sinHalfTheta = sin(0.5*(ro.r[3]));\
double xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;\
__q.x = (ro.r[0])*sinHalfTheta;\
__q.y = (ro.r[1])*sinHalfTheta;\
__q.z = (ro.r[2])*sinHalfTheta;\
__q.w = cos(0.5*(ro.r[3]));\
xs = 2*__q.x; ys = 2*__q.y; zs = 2*__q.z;\
wx = __q.w*xs; wy = __q.w*ys; wz = __q.w*zs;\
xx = __q.x*xs; xy = __q.x*ys; xz = __q.x*zs;\
yy = __q.y*ys; yz = __q.y*zs; zz = __q.z*zs;\
m[0][0] = 1 - (yy + zz); m[0][1] = xy - wz; m[0][2] = xz + wy;\
m[1][0] = xy + wz; m[1][1] = 1 - (xx + zz);m[1][2] = yz - wx;\
m[2][0] = xz - wy; m[2][1] = yz + wx; m[2][2] = 1-(xx + yy);\
}
/* matrix multiplication */
#define VECMM(m,c) { \
double ___x=(c).x,___y=(c).y,___z=(c).z; \
(c).x= m[0][0]*___x + m[0][1]*___y + m[0][2]*___z; \
(c).y= m[1][0]*___x + m[1][1]*___y + m[1][2]*___z; \
(c).z= m[2][0]*___x + m[2][1]*___y + m[2][2]*___z; \
}
/* next define rotates vector c with rotation vector r and angle */
/* after section 5.8 of the VRML`97 spec */
#define VECROTATE(rx,ry,rz,angle,nc) { \
double ___x=(nc).x,___y=(nc).y,___z=(nc).z; \
double ___c=cos(angle), ___s=sin(angle), ___t=1-___c; \
(nc).x= (___t*((rx)*(rx))+___c) *___x \
+ (___t*(rx)*(ry) -___s*(rz))*___y \
+ (___t*(rx)*(rz) +___s*(ry))*___z ; \
(nc).y= (___t*(rx)*(ry) +___s*(rz))*___x \
+ (___t*((ry)*(ry))+___c) *___y \
+ (___t*(ry)*(rz) -___s*(rx))*___z ; \
(nc).z= (___t*(rx)*(rz) -___s*(ry))*___x \
+ (___t*(ry)*(rz) +___s*(rx))*___y \
+ (___t*((rz)*(rz))+___c) *___z ; \
}
/*
#define VECROTATE(rx,ry,rz,angle,c) { \
double ___c=cos(angle), ___s=sin(angle), ___t=1-___c; \
(c).x= (___t*((rx)*(rx))+___c) *(c).x \
+ (___t*(rx)*(ry) +___s*(rz))*(c).y \
+ (___t*(rx)*(rz) -___s*(ry))*(c).z ; \
(c).y= (___t*(rx)*(ry) -___s*(rz))*(c).x \
+ (___t*((ry)*(ry))+___c) *(c).y \
+ (___t*(ry)*(rz) +___s*(rx))*(c).z ; \
(c).z= (___t*(rx)*(rz) +___s*(ry))*(c).x \
+ (___t*(ry)*(rz) -___s*(rx))*(c).y \
+ (___t*((rz)*(rz))+ ___c) *(c).z ; \
}
*/
/* next define abbreviates VECROTATE with use of the SFRotation struct */
#define VECRROTATE(ro,c) VECROTATE((ro).r[0],(ro).r[1],(ro).r[2],(ro).r[3],c)
#define HIT rayhit
/* Sub, rather than big macro... */
void rayhit(float rat, float cx,float cy,float cz, float nx,float ny,float nz,
float tx,float ty, char *descr) {
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
GLdouble wx, wy, wz;
/* Real rat-testing */
if(verbose) printf("RAY HIT %s! %f (%f %f %f) (%f %f %f)\nR: (%f %f %f) (%f %f %f)\n",
descr, rat,cx,cy,cz,nx,ny,nz,
t_r1.x, t_r1.y, t_r1.z,
t_r2.x, t_r2.y, t_r2.z
);
if(rat<0 || (rat>hpdist && hpdist >= 0)) {
return;
}
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
gluProject(cx,cy,cz, modelMatrix, projMatrix, viewport,
&hp.x, &hp.y, &hp.z);
hpdist = rat;
rh=rph;
rhhyper=rph;
}
/* Call this when modelview and projection modified */
void upd_ray() {
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
gluUnProject(r1.x,r1.y,r1.z,modelMatrix,projMatrix,viewport,
&t_r1.x,&t_r1.y,&t_r1.z);
gluUnProject(r2.x,r2.y,r2.z,modelMatrix,projMatrix,viewport,
&t_r2.x,&t_r2.y,&t_r2.z);
gluUnProject(r3.x,r3.y,r3.z,modelMatrix,projMatrix,viewport,
&t_r3.x,&t_r3.y,&t_r3.z);
/* printf("Upd_ray: (%f %f %f)->(%f %f %f) == (%f %f %f)->(%f %f %f)\n",
r1.x,r1.y,r1.z,r2.x,r2.y,r2.z,
t_r1.x,t_r1.y,t_r1.z,t_r2.x,t_r2.y,t_r2.z);
*/
}
void *what_vp;
int render_anything; /* Turned off when we hit the viewpoint */
void render_node(void *node);
void render_polyrep(void *node,
int npoints, struct SFColor *points,
int ncolors, struct SFColor *colors,
int nnormals, struct SFColor *normals);
void regen_polyrep(void *node) ;
void calc_poly_normals_flat(struct VRML_PolyRep *rep);
void render_ray_polyrep(void *node,
int npoints, struct SFColor *points);
/*********************************************************************
* Code here is generated from the hashes in VRMLC.pm and VRMLRend.pm
*/
void PointLight_Light(void *nod_){ /* GENERATED FROM HASH LightC, MEMBER PointLight */
struct VRML_PointLight *this_ = (struct VRML_PointLight *)nod_;
{
if(((this_->on))) {
int light = nextlight();
if(light >= 0) {
float vec[4];
glEnable(light);
vec[0] = ((this_->direction).c[0]);
vec[1] = ((this_->direction).c[1]);
vec[2] = ((this_->direction).c[2]);
vec[3] = 1;
glLightfv(light, GL_SPOT_DIRECTION, vec);
vec[0] = ((this_->location).c[0]);
vec[1] = ((this_->location).c[1]);
vec[2] = ((this_->location).c[2]);
vec[3] = 1;
glLightfv(light, GL_POSITION, vec);
glLightf(light, GL_CONSTANT_ATTENUATION,
((this_->attenuation).c[0]));
glLightf(light, GL_LINEAR_ATTENUATION,
((this_->attenuation).c[1]));
glLightf(light, GL_QUADRATIC_ATTENUATION,
((this_->attenuation).c[2]));
vec[0] = ((this_->color).c[0]) * (this_->intensity);
vec[1] = ((this_->color).c[1]) * (this_->intensity);
vec[2] = ((this_->color).c[2]) * (this_->intensity);
vec[3] = 1;
glLightfv(light, GL_DIFFUSE, vec);
glLightfv(light, GL_SPECULAR, vec);
vec[0] *= (this_->ambientIntensity);
vec[1] *= (this_->ambientIntensity);
vec[2] *= (this_->ambientIntensity);
glLightfv(light, GL_AMBIENT, vec);
/* XXX */
glLightf(light, GL_SPOT_CUTOFF, 180);
}
}
}
}
void DirectionalLight_Light(void *nod_){ /* GENERATED FROM HASH LightC, MEMBER DirectionalLight */
struct VRML_DirectionalLight *this_ = (struct VRML_DirectionalLight *)nod_;
{
if(((this_->on))) {
int light = nextlight();
if(light >= 0) {
float vec[4];
glEnable(light);
vec[0] = -((this_->direction).c[0]);
vec[1] = -((this_->direction).c[1]);
vec[2] = -((this_->direction).c[2]);
vec[3] = 0;
glLightfv(light, GL_POSITION, vec);
vec[0] = ((this_->color).c[0]) * (this_->intensity);
vec[1] = ((this_->color).c[1]) * (this_->intensity);
vec[2] = ((this_->color).c[2]) * (this_->intensity);
vec[3] = 1;
glLightfv(light, GL_DIFFUSE, vec);
glLightfv(light, GL_SPECULAR, vec);
vec[0] *= (this_->ambientIntensity);
vec[1] *= (this_->ambientIntensity);