35 #include <libFreeWRL.h>
37 #include "../vrml_parser/Structs.h"
38 #include "../vrml_parser/CRoutes.h"
39 #include "../main/headers.h"
41 #include "../world_script/fieldSet.h"
42 #include "../x3d_parser/Bindable.h"
43 #include "Collision.h"
44 #include "quaternion.h"
46 #include "../opengl/Frustum.h"
47 #include "../opengl/Material.h"
48 #include "../opengl/OpenGL_Utils.h"
49 #include "../input/EAIHelpers.h"
52 #include "LinearAlgebra.h"
53 #include "Component_Shape.h"
54 #include "Component_Geospatial.h"
56 #include "../scenegraph/RenderFuncs.h"
57 #include "../ui/common.h"
110 #define MF_SF_TEMPS struct Multi_Vec3d mIN; struct Multi_Vec3d mOUT; struct Multi_Vec3d gdCoords;
111 #define FREE_MF_SF_TEMPS FREE_IF_NZ(gdCoords.p); FREE_IF_NZ(mOUT.p); FREE_IF_NZ(mIN.p);
114 #define INIT_MF_FROM_SF(myNode, myField) \
116 mIN.p = MALLOC(struct SFVec3d *, sizeof (struct SFVec3d)); \
117 mIN.p[0].c[0] = myNode-> myField .c[0];\
118 mIN.p[0].c[1] = myNode-> myField .c[1];\
119 mIN.p[0].c[2] = myNode-> myField .c[2];\
120 mOUT.n=0; mOUT.p = NULL; \
121 gdCoords.n=0; gdCoords.p = NULL;
123 #define MF_FIELD_IN_OUT &mIN, &mOUT, &gdCoords
124 #define COPY_MF_TO_SF(myNode, myField) \
125 myNode-> myField .c[0] = mOUT.p[0].c[0]; \
126 myNode-> myField .c[1] = mOUT.p[0].c[1]; \
127 myNode-> myField .c[2] = mOUT.p[0].c[2]; \
128 FREE_IF_NZ(mIN.p); FREE_IF_NZ(mOUT.p);
131 #define MOVE_TO_ORIGIN(me) GeoMove(X3D_GEOORIGIN(me->geoOrigin), &me->__geoSystem, &mIN, &mOUT, &gdCoords);
132 #define COMPILE_GEOSYSTEM(me) compile_geoSystem (me->_nodeType, &me->geoSystem, &me->__geoSystem);
134 #define RADIANS_PER_DEGREE (double)0.0174532925199432957692
135 #define DEGREES_PER_RADIAN (double)57.2957795130823208768
137 #define ENSURE_SPACE(variableInQuestion) \
139 if (variableInQuestion ->n < inCoords->n) { \
140 if (variableInQuestion ->p != NULL) { \
141 FREE_IF_NZ(variableInQuestion->p); \
143 variableInQuestion ->p = MALLOC(struct SFVec3d *, sizeof (struct SFVec3d) * inCoords->n); \
144 variableInQuestion ->n = inCoords->n; \
148 #define ELEVATION_OUT outc->p[i].c[elevation]
149 #define ELEVATION_IN inc->p[i].c[elevation]
150 #define EASTING_IN inc->p[i].c[easting]
151 #define NORTHING_IN inc->p[i].c[northing]
152 #define UTM_SCALE (double)0.9996
153 #define LATITUDE_OUT outc->p[i].c[latitude]
154 #define LONGITUDE_OUT outc->p[i].c[longitude]
155 #define LATITUDE_IN inc->p[i].c[latitude]
156 #define LONGITUDE_IN inc->p[i].c[longitude]
158 #define GC_X_OUT outc->p[i].c[0]
159 #define GC_Y_OUT outc->p[i].c[1]
160 #define GC_Z_OUT outc->p[i].c[2]
163 #define GEOSP_AA_A (double)6377563.396
164 #define GEOSP_AA_F (double)299.3249646
165 #define GEOSP_AM_A (double)6377340.189
166 #define GEOSP_AM_F (double)299.3249646
167 #define GEOSP_AN_A (double)6378160
168 #define GEOSP_AN_F (double)298.25
169 #define GEOSP_BN_A (double)6377483.865
170 #define GEOSP_BN_F (double)299.1528128
171 #define GEOSP_BR_A (double)6377397.155
172 #define GEOSP_BR_F (double)299.1528128
173 #define GEOSP_CC_A (double)6378206.4
174 #define GEOSP_CC_F (double)294.9786982
175 #define GEOSP_CD_A (double)6378249.145
176 #define GEOSP_CD_F (double)293.465
177 #define GEOSP_EA_A (double)6377276.345
178 #define GEOSP_EA_F (double)300.8017
179 #define GEOSP_EB_A (double)6377298.556
180 #define GEOSP_EB_F (double)300.8017
181 #define GEOSP_EC_A (double)6377301.243
182 #define GEOSP_EC_F (double)300.8017
183 #define GEOSP_ED_A (double)6377295.664
184 #define GEOSP_ED_F (double)300.8017
185 #define GEOSP_EE_A (double)6377304.063
186 #define GEOSP_EE_F (double)300.8017
187 #define GEOSP_EF_A (double)6377309.613
188 #define GEOSP_EF_F (double)300.8017
189 #define GEOSP_FA_A (double)6378155
190 #define GEOSP_FA_F (double)298.3
191 #define GEOSP_HE_A (double)6378200
192 #define GEOSP_HE_F (double)298.3
193 #define GEOSP_HO_A (double)6378270
194 #define GEOSP_HO_F (double)297
195 #define GEOSP_ID_A (double)6378160
196 #define GEOSP_ID_F (double)298.247
197 #define GEOSP_IN_A (double)6378388
198 #define GEOSP_IN_F (double)297
199 #define GEOSP_KA_A (double)6378245
200 #define GEOSP_KA_F (double)298.3
201 #define GEOSP_RF_A (double)6378137
202 #define GEOSP_RF_F (double)298.257222101
203 #define GEOSP_SA_A (double)6378160
204 #define GEOSP_SA_F (double)298.25
205 #define GEOSP_WD_A (double)6378135
206 #define GEOSP_WD_F (double)298.26
207 #define GEOSP_WE_A (double)6378137
208 #define GEOSP_WE_F (double)298.257223563
210 #define ELLIPSOID(typ) \
211 case typ: Gd_Gc(inCoords,outCoords,typ##_A, typ##_F,geoSystem->p[3], geoSystem->p[4]); break;
213 #define UTM_ELLIPSOID(typ) \
214 case typ: Utm_Gd (inCoords, gdCoords, typ##_A, typ##_F, geoSystem->p[3], geoSystem->p[2], TRUE); \
215 Gd_Gc(gdCoords,outCoords,typ##_A, typ##_F, geoSystem->p[3], geoSystem->p[4]); break;
217 #define GCC_X gcc->c[0]
218 #define GCC_Y gcc->c[1]
219 #define GCC_Z gcc->c[2]
220 #define GDC_LAT gdc->c[0]
221 #define GDC_LON gdc->c[1]
222 #define GDC_ELE gdc->c[2]
225 #define INITIALIZE_GEOSPATIAL(me) \
226 initializeGeospatial((struct X3D_GeoOrigin **) &me->geoOrigin);
228 #define CONVERT_BACK_TO_GD_OR_UTM(thisField) \
238 if (node->__geoSystem.n != 0) { \
239 struct SFVec3d gdCoords; \
241 if (node->__geoSystem.p[0] != GEOSP_GC) { \
243 bool dugsInterpretationOfSpecs = true; \
244 if(dugsInterpretationOfSpecs) \
246 retractOrigin((struct X3D_GeoOrigin *)node->geoOrigin, \
249 if (Viewer()->GeoSpatialNode != NULL) { \
250 retractOrigin((struct X3D_GeoOrigin *)Viewer()->GeoSpatialNode->geoOrigin, \
258 gccToGdc (&thisField, &gdCoords); \
259 memcpy (&thisField, &gdCoords, sizeof (struct SFVec3d)); \
264 if (node->__geoSystem.p[0] == GEOSP_GD) { \
266 if (!(node->__geoSystem.p[3])) { \
268 tmp = thisField.c[0]; \
269 thisField.c[0] = thisField.c[1]; \
270 thisField.c[1] = tmp; \
280 zone = node->__geoSystem.p[2]; \
281 gdToUtm(thisField.c[0], \
283 &zone, &easting, &northing); \
285 thisField.c[0] = northing; \
286 thisField.c[1] = easting; \
295 static int gcToGdInit = FALSE;
301 void calculateViewingSpeed(
void);
304 static double A, F, C, A2, C2, Eps2, Eps21, Eps25, C254, C2DA, CEE,
305 CE2, CEEps2, TwoCEE, tem, ARat1, ARat2, BRat1, BRat2, B1,B2,B3,B4,B5;
311 void *Component_Geospatial_constructor(){
316 void Component_Geospatial_init(
struct tComponent_Geospatial *t){
319 t->prv = Component_Geospatial_constructor();
330 {13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13},
331 {3,1,-2,-3,-3,-3,-1,3,1,5,9,11,19,27,31,34,33,34,33,34,28,23,17,13,9,4,4,1,-2,-2,0,2,3,2,1,1},
332 {2,2,1,-1,-3,-7,-14,-24,-27,-25,-19,3,24,37,47,60,61,58,51,43,29,20,12,5,-2,-10,-14,-12,-10,-14,-12,-6,-2,3,6,4},
333 {2,9,17,10,13,1,-14,-30,-39,-46,-42,-21,6,29,49,65,60,57,47,41,21,18,14,7,-3,-22,-29,-32,-32,-26,-15,-2,13,17,19,6},
334 {-8,8,8,1,-11,-19,-16,-18,-22,-35,-40,-26,-12,24,45,63,62,59,47,48,42,28,12,-10,-19,-33,-43,-42,-43,-29,-2,17,23,22,6,2},
335 {-12,-10,-13,-20,-31,-34,-21,-16,-26,-34,-33,-35,-26,2,33,59,52,51,52,48,35,40,33,-9,-28,-39,-48,-59,-50,-28,3,23,37,18,-1,-11},
336 {-7,-5,-8,-15,-28,-40,-42,-29,-22,-26,-32,-51,-40,-17,17,31,34,44,36,28,29,17,12,-20,-15,-40,-33,-34,-34,-28,7,29,43,20,4,-6},
337 {5,10,7,-7,-23,-39,-47,-34,-9,-10,-20,-45,-48,-32,-9,17,25,31,31,26,15,6,1,-29,-44,-61,-67,-59,-36,-11,21,39,49,39,22,10},
338 {13,12,11,2,-11,-28,-38,-29,-10,3,1,-11,-41,-42,-16,3,17,33,22,23,2,-3,-7,-36,-59,-90,-95,-63,-24,12,53,60,58,46,36,26},
339 {22,16,17,13,1,-12,-23,-20,-14,-3,14,10,-15,-27,-18,3,12,20,18,12,-13,-9,-28,-49,-62,-89,-102,-63,-9,33,58,73,74,63,50,32},
340 {36,22,11,6,-1,-8,-10,-8,-11,-9,1,32,4,-18,-13,-9,4,14,12,13,-2,-14,-25,-32,-38,-60,-75,-63,-26,0,35,52,68,76,64,52},
341 {51,27,10,0,-9,-11,-5,-2,-3,-1,9,35,20,-5,-6,-5,0,13,17,23,21,8,-9,-10,-11,-20,-40,-47,-45,-25,5,23,45,58,57,63},
342 {46,22,5,-2,-8,-13,-10,-7,-4,1,9,32,16,4,-8,4,12,15,22,27,34,29,14,15,15,7,-9,-25,-37,-39,-23,-14,15,33,34,45},
343 {21,6,1,-7,-12,-12,-12,-10,-7,-1,8,23,15,-2,-6,6,21,24,18,26,31,33,39,41,30,24,13,-2,-20,-32,-33,-27,-14,-2,5,20},
344 {-15,-18,-18,-16,-17,-15,-10,-10,-8,-2,6,14,13,3,3,10,20,27,25,26,34,39,45,45,38,39,28,13,-1,-15,-22,-22,-18,-15,-14,-10},
345 {-45,-43,-37,-32,-30,-26,-23,-22,-16,-10,-2,10,20,20,21,24,22,17,16,19,25,30,35,35,33,30,27,10,-2,-14,-23,-30,-33,-29,-35,-43},
346 {-61,-60,-61,-55,-49,-44,-38,-31,-25,-16,-6,1,4,5,4,2,6,12,16,16,17,21,20,26,26,22,16,10,-1,-16,-29,-36,-46,-55,-54,-59},
347 {-53,-54,-55,-52,-48,-42,-38,-38,-29,-26,-26,-24,-23,-21,-19,-16,-12,-8,-4,-1,1,4,4,6,5,4,2,-6,-15,-24,-33,-40,-48,-50,-53,-52},
348 {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30}
351 static double geoidCorrection(
double latitudeDeg,
double longitudeDeg)
362 int il, ip, il1, ip1;
363 double dl, dp, d00, d01, d10, d11, d;
365 il = (int)(longitudeDeg/10.0) + 18 -1;
366 ip = 18 - ((int)(latitudeDeg/10.0) + 9);
369 if(il1 > 35) il1 = 0;
372 d00 = (float)geoid[ip][il];
373 d01 = (float)geoid[ip1][il];
374 d10 = (float)geoid[ip][il1];
375 d11 = (float)geoid[ip1][il1];
377 dl = longitudeDeg - (-180.0 + (float)(il)*10.0);
378 dp = latitudeDeg - (90.0 - (float)(ip)*10.0);
383 d = (1.0 - dl)*(1.0 - dp)*d00 + (dl)*(1.0 - dp)*d10 + (1.0-dl)*(dp)*d01 + (dl)*(dp)*d11;
390 if (myGeoOrigin != NULL) {
391 if(myGeoOrigin->rotateYUp == TRUE)
396 vrmlrot_to_quaternion(&rq,myGeoOrigin->__rotyup.c[0], myGeoOrigin->__rotyup.c[1], myGeoOrigin->__rotyup.c[2], myGeoOrigin->__rotyup.c[3]);
398 quaternion_rotation((
struct point_XYZ *)temp.c, &rq, (
const struct point_XYZ *)gcCoords->c);
400 gcCoords->c[i] = temp.c[i];
402 gcCoords->c[0] += myGeoOrigin->__movedCoords.c[0];
403 gcCoords->c[1] += myGeoOrigin->__movedCoords.c[1];
404 gcCoords->c[2] += myGeoOrigin->__movedCoords.c[2];
410 static void Gd_Gc (
struct Multi_Vec3d *inc,
struct Multi_Vec3d *outc,
double radius,
double eccentricity,
int lat_first,
int geoid) {
413 double A2 = radius*radius;
414 double F = (double)(1/eccentricity);
415 double C = A*((double)1.0 - F);
417 double Eps2 = F*((double)2.0 - F);
418 double Eps25 = (double) 0.25 * Eps2;
433 printf (
"Gd_Gc, NOT lat first\n");
434 latitude = 1; longitude = 0;
438 if (outc->n < inc->n) {
440 outc->p = MALLOC(
struct SFVec3d *,
sizeof (
struct SFVec3d) * inc->n);
444 printf (
"Gd_Gc, have n of %d\n",inc->n);
447 for (i=0; i<inc->n; i++) {
449 printf (
"Gd_Gc, ining lat %lf long %lf ele %lf ",LATITUDE_IN, LONGITUDE_IN, ELEVATION_IN);
452 source_lat = RADIANS_PER_DEGREE * LATITUDE_IN;
453 source_lon = RADIANS_PER_DEGREE * LONGITUDE_IN;
456 printf (
"Source Latitude %lf Source Longitude %lf\n",source_lat, source_lon);
459 slat = sin(source_lat);
461 clat = cos(source_lat);
464 printf (
"slat %lf slat2 %lf clat %lf\n",slat, slat2, clat);
469 Rn = A / ( (.25 - Eps25 * slat2 + .9999944354799/4) + (.25-Eps25 * slat2)/(.25 - Eps25 * slat2 + .9999944354799/4));
471 RnPh = Rn + ELEVATION_IN;
473 RnPh += geoidCorrection(LATITUDE_IN,LONGITUDE_IN);
476 printf (
"Rn %lf RnPh %lf\n",Rn, RnPh);
479 GC_X_OUT = RnPh * clat * cos(source_lon);
480 GC_Y_OUT = RnPh * clat * sin(source_lon);
481 GC_Z_OUT = ((C2 / A2) * Rn + ELEVATION_IN) * slat;
484 printf (
"Gd_Gc, outing x %lf y %lf z %lf\n", GC_X_OUT, GC_Y_OUT, GC_Z_OUT);
490 static void Utm_Gd (
struct Multi_Vec3d *inc,
struct Multi_Vec3d *outc,
double radius,
double flatten,
int hemisphere_north,
int zone,
int northing_first) {
499 double F = 1.0/flatten;
500 double Eccentricity = (F) * (2.0-F);
511 double longitudeOrigin;
512 double myeccPrimeSquared;
514 double northingDRCT1;
516 double calcConstantTerm1;
517 double calcConstantTerm2;
518 double calcConstantTerm3;
519 double calcConstantTerm4;
522 if (!northing_first) { northing = 1; easting = 0; }
525 if (!northing_first) printf (
"UTM to GD, not northing first, flipping norhting and easting\n");
529 if (northing_first) printf (
"Utm_Gd: northing first\n");
else printf (
"Utm_Gd: NOT northing_first\n");
530 if (!hemisphere_north) printf (
"Utm_Gd: NOT hemisphere_north\n");
else printf (
"Utm_Gd: hemisphere_north\n");
535 if (outc->n < inc->n) {
537 outc->p = MALLOC(
struct SFVec3d *,
sizeof (
struct SFVec3d) * inc->n);
542 longitudeOrigin = (zone -1) * 6 - 180 + 3;
543 myeccPrimeSquared = Eccentricity/(((double) 1.0) - Eccentricity);
544 eccRoot = (((double)1.0) - sqrt (((
double)1.0) - Eccentricity))/
545 (((
double)1.0) + sqrt (((
double)1.0) - Eccentricity));
547 calcConstantTerm1 = ((double)1.0) -Eccentricity/
548 ((double)4.0) - ((double)3.0) *Eccentricity*Eccentricity/
549 ((double)64.0) -((double)5.0) *Eccentricity*Eccentricity*Eccentricity/((double)256.0);
551 calcConstantTerm2 = ((double)3.0) * eccRoot/((double)2.0) - ((double)27.0) *eccRoot*eccRoot*eccRoot/((double)32.0);
552 calcConstantTerm3 = ((double)21.0) * eccRoot*eccRoot/ ((double)16.0) - ((double)55.0) *eccRoot*eccRoot*eccRoot*eccRoot/ ((double)32.0);
553 calcConstantTerm4 = ((double)151.0) *eccRoot*eccRoot*eccRoot/ ((double)96.0);
556 printf (
"zone %d\n",zone);
557 printf (
"longitudeOrigin %lf\n",longitudeOrigin);
558 printf (
"myeccPrimeSquared %lf\n",myeccPrimeSquared);
559 printf (
"eccRoot %lf\n",eccRoot);
563 for(i=0;i<inc->n;i++) {
565 ELEVATION_OUT = ELEVATION_IN;
566 myEasting = EASTING_IN - 500000;
567 if (hemisphere_north) myNorthing = NORTHING_IN;
568 else myNorthing = NORTHING_IN - (double)10000000.0;
571 printf (
"myEasting %lf\n",myEasting);
572 printf (
"myNorthing %lf\n",myNorthing);
577 myNorthing= myNorthing / UTM_SCALE;
579 northingDRCT1 = myNorthing /(radius * calcConstantTerm1);
581 myphi1rad = northingDRCT1 +
582 calcConstantTerm2 * sin(((
double)2.0) *northingDRCT1)+
583 calcConstantTerm3 * sin(((
double)4.0) *northingDRCT1)+
584 calcConstantTerm4 * sin(((
double)6.0) *northingDRCT1);
586 myN1 = radius/sqrt(((
double)1.0) - Eccentricity * sin(myphi1rad) * sin (myphi1rad));
587 myT1 = tan(myphi1rad) * tan(myphi1rad);
588 myC1 = Eccentricity * cos(myphi1rad) * cos (myphi1rad);
589 myR1 = radius * (((double)1.0) - Eccentricity) / pow(((
double)1.0) - Eccentricity * sin(myphi1rad) * sin (myphi1rad), 1.5);
590 myD = myEasting/(myN1*UTM_SCALE);
592 Latitude = myphi1rad-(myN1*tan(myphi1rad)/myR1)*
593 (myD*myD/((
double)2.0) -
594 (((double)5.0) + ((double)3.0) *myT1+ ((double)10.0) *myC1-
595 ((double)4.0) *myC1*myC1- ((double)9.0) *myeccPrimeSquared)*
597 myD*myD*myD*myD/((
double)24.0) +(((double)61.0) +((double)90.0) *
598 myT1+((double)298.0) *myC1+ ((double)45.0) *myT1*myT1-
599 ((double)252.0) * myeccPrimeSquared- ((double)3.0) *myC1*myC1)*myD*myD*myD*myD*myD*myD/((
double)720.0));
602 Longitude = (myD-(((double)1.0)+((double)2.0)*myT1+myC1)*myD*myD*myD/((
double)6.0)+(((double)5.0) - ((double)2.0) *myC1+
603 ((double)28.0) *myT1-((double)3.0) *myC1*myC1+
604 ((double)8.0) *myeccPrimeSquared+((double)24.0) *myT1*myT1)*myD*myD*myD*myD*myD/120)/cos(myphi1rad);
608 LATITUDE_OUT = Latitude * DEGREES_PER_RADIAN;
609 LONGITUDE_OUT = longitudeOrigin + Longitude * DEGREES_PER_RADIAN;
624 printf (
"utmtogd\tnorthing %lf easting %lf ele %lf\n\tlat %lf long %lf ele %lf\n", NORTHING_IN, EASTING_IN, ELEVATION_IN, LATITUDE_OUT, LONGITUDE_OUT, ELEVATION_IN);
642 gdCoords->n=0; gdCoords->p=NULL;
645 ENSURE_SPACE(outCoords)
646 ENSURE_SPACE(gdCoords)
649 switch (geoSystem->p[0]) {
652 switch (geoSystem->p[1]) {
676 default: printf ("unknown Gd_Gc: %s\n", stringGEOSPATIALType(geoSystem->p[1]));
681 gdCoords->n = inCoords->n;
684 if (geoSystem->p[1] != GEOSP_WE) {
686 for (i=0; i<outCoords->n; i++) {
687 gccToGdc (&outCoords->p[i], &gdCoords->p[i]);
691 memcpy (gdCoords->p, inCoords->p, sizeof (
struct SFVec3d) * inCoords->n);
693 if(geoSystem->p[4] == TRUE)
694 for(i=0;i<gdCoords->n;i++)
695 gdCoords->p[i].c[2] += geoidCorrection(gdCoords->p[i].c[1-geoSystem->p[3]],gdCoords->p[i].c[geoSystem->p[3]]);
700 for (i=0; i< inCoords->n; i++) {
701 outCoords->p[i].c[0] = inCoords->p[i].c[0];
702 outCoords->p[i].c[1] = inCoords->p[i].c[1];
703 outCoords->p[i].c[2] = inCoords->p[i].c[2];
706 gccToGdc (&inCoords->p[i], &gdCoords->p[i]);
714 switch (geoSystem->p[1]) {
715 UTM_ELLIPSOID(GEOSP_AA)
716 UTM_ELLIPSOID(GEOSP_AM)
717 UTM_ELLIPSOID(GEOSP_AN)
718 UTM_ELLIPSOID(GEOSP_BN)
719 UTM_ELLIPSOID(GEOSP_BR)
720 UTM_ELLIPSOID(GEOSP_CC)
721 UTM_ELLIPSOID(GEOSP_CD)
722 UTM_ELLIPSOID(GEOSP_EA)
723 UTM_ELLIPSOID(GEOSP_EB)
724 UTM_ELLIPSOID(GEOSP_EC)
725 UTM_ELLIPSOID(GEOSP_ED)
726 UTM_ELLIPSOID(GEOSP_EE)
727 UTM_ELLIPSOID(GEOSP_EF)
728 UTM_ELLIPSOID(GEOSP_FA)
729 UTM_ELLIPSOID(GEOSP_HE)
730 UTM_ELLIPSOID(GEOSP_HO)
731 UTM_ELLIPSOID(GEOSP_ID)
732 UTM_ELLIPSOID(GEOSP_IN)
733 UTM_ELLIPSOID(GEOSP_KA)
734 UTM_ELLIPSOID(GEOSP_RF)
735 UTM_ELLIPSOID(GEOSP_SA)
736 UTM_ELLIPSOID(GEOSP_WD)
737 UTM_ELLIPSOID(GEOSP_WE)
738 default: printf ("unknown Gd_Gc: %s\n", stringGEOSPATIALType(geoSystem->p[1]));
742 printf ("incorrect geoSystem field, %s\n",stringGEOSPATIALType(geoSystem->p[0]));
749 static
void initializeGeospatial (struct
X3D_GeoOrigin **nodeptr) {
754 printf (
"\ninitializing GeoSpatial code nodeptr %u\n",*nodeptr);
757 if (*nodeptr != NULL) {
758 if (X3D_GEOORIGIN(*nodeptr)->_nodeType != NODE_GeoOrigin) {
759 printf (
"expected a GeoOrigin node, but got a node of type %s\n",
760 stringNodeType(X3D_GEOORIGIN(*nodeptr)->_nodeType));
765 node = X3D_GEOORIGIN(*nodeptr);
770 if NODE_NEEDS_COMPILING {
771 compile_geoSystem (node->_nodeType, &node->geoSystem, &node->__geoSystem);
772 INIT_MF_FROM_SF(node,geoCoords)
773 moveCoords(&node->__geoSystem, MF_FIELD_IN_OUT);
774 COPY_MF_TO_SF(node, __movedCoords)
776 if(node->rotateYUp == TRUE)
782 vrmlrot_to_quaternion (&qz,0.0, 0.0, 1.0, RADIANS_PER_DEGREE*((
double)90.0 + gdCoords.p[0].c[1]));
785 printf (
"GeoOrient qz angle (deg) %lf angle (rad) %lf quat: %lf %lf %lf %lf\n",((
double)90.0 + gdCoords->c[1]),
786 RADIANS_PER_DEGREE*((
double)90.0 + gdCoords->c[1]),qz.x, qz.y, qz.z,qz.w);
789 vrmlrot_to_quaternion (&qx,1.0, 0.0, 0.0, RADIANS_PER_DEGREE*((
double)180.0 - gdCoords.p[0].c[0]));
792 printf (
"GeoOrient qx angle (deg) %lf angle (rad) %lf quat: %lf %lf %lf %lf\n",
793 ((
double)180.0 - gdCoords->c[0]), RADIANS_PER_DEGREE*((
double)180.0 - gdCoords->c[0]), qx.x, qx.y, qx.z,qx.w);
796 quaternion_add (&qr, &qx, &qz);
799 printf (
"GeoOrient qr %lf %lf %lf %lf\n",qr.x, qr.y, qr.z,qr.w);
802 quaternion_to_vrmlrot(&qr, &orient.c[0], &orient.c[1], &orient.c[2], &orient.c[3]);
804 node->__rotyup.c[i] = orient.c[i];
808 node->__rotyup.c[i] = 0.0;
809 node->__rotyup.c[1] = 1.0;
813 printf (
"initializeGeospatial, __movedCoords %lf %lf %lf, ryup %d, geoSystem %d %d %d %d\n",
814 node->__movedCoords.c[0],
815 node->__movedCoords.c[1],
816 node->__movedCoords.c[2],
818 node->__geoSystem.p[0],
819 node->__geoSystem.p[1],
820 node->__geoSystem.p[2],
821 node->__geoSystem.p[3]);
822 printf (
"initializeGeospatial, done\n\n");
839 printf (
"\nstart of GeoMove... %d coords\n",inCoords->n);
843 if (inCoords->n==0) {
return;}
844 if (outCoords->n < inCoords->n) {
845 if (outCoords->n!=0) {
846 FREE_IF_NZ(outCoords->p);
848 outCoords->p = MALLOC(
struct SFVec3d *,
sizeof (
struct SFVec3d) * inCoords->n);
849 outCoords->n = inCoords->n;
853 for (i=0; i<outCoords->n; i++) {
854 outCoords->p[i].c[0] = (double) 0.0; outCoords->p[i].c[1] = (double) 0.0; outCoords->p[i].c[2] = (double) 0.0;
858 for (i=0; i<outCoords->n; i++) {
859 printf (
"start of GeoMove, inCoords %d: %lf %lf %lf\n",i, inCoords->p[i].c[0], inCoords->p[i].c[1], inCoords->p[i].c[2]);
867 if (geoOrigin != NULL) {
868 if (X3D_GEOORIGIN(geoOrigin)->_nodeType != NODE_GeoOrigin) {
869 ConsoleMessage (
"GeoMove, expected a GeoOrigin, found a %s",stringNodeType(X3D_GEOORIGIN(geoOrigin)->_nodeType));
870 printf (
"GeoMove, expected a GeoOrigin, found a %s\n",stringNodeType(X3D_GEOORIGIN(geoOrigin)->_nodeType));
874 myOrigin = geoOrigin;
879 moveCoords(geoSystem, inCoords, outCoords, gdCoords);
882 for (i=0; i<outCoords->n; i++) {
885 printf (
"GeoMove, before subtracting origin %lf %lf %lf\n", outCoords->p[i].c[0], outCoords->p[i].c[1], outCoords->p[i].c[2]);
886 if (myOrigin != NULL) printf (
" ... origin %lf %lf %lf\n",myOrigin->__movedCoords.c[0], myOrigin->__movedCoords.c[1], myOrigin->__movedCoords.c[2]);
889 if (myOrigin != NULL) {
892 outCoords->p[i].c[0] -= myOrigin->__movedCoords.c[0];
893 outCoords->p[i].c[1] -= myOrigin->__movedCoords.c[1];
894 outCoords->p[i].c[2] -= myOrigin->__movedCoords.c[2];
895 if(myOrigin->rotateYUp == TRUE)
899 vrmlrot_to_quaternion(&rq,myOrigin->__rotyup.c[0], myOrigin->__rotyup.c[1], myOrigin->__rotyup.c[2], -myOrigin->__rotyup.c[3]);
902 quaternion_rotation((
struct point_XYZ *)temp.c, &rq, (
const struct point_XYZ *)outCoords->p[i].c);
903 outCoords->p[i].c[0] = temp.c[0];
904 outCoords->p[i].c[1] = temp.c[1];
905 outCoords->p[i].c[2] = temp.c[2];
910 printf (
"GeoMove, after subtracting origin %lf %lf %lf\n", outCoords->p[i].c[0], outCoords->p[i].c[1], outCoords->p[i].c[2]);
917 static void initializeGcToGdParams(
void) {
941 ARat1 =pow((A + 50005.0),2);
942 ARat2 =(ARat1) / pow((C+50005.0),2);
946 BRat1 =pow((A-10005.0),2);
947 BRat2 =(BRat1) / pow((C-10005.0),2);
950 B1=0.100225438677758E+01;
951 B2=-0.393246903633930E-04;
952 B3=0.241216653453483E+12;
953 B4=0.133733602228679E+14;
954 B5=0.984537701867943E+00;
961 double w2,w,z2,testu,testb,top,top2,rr,q,s12,rnn,s1,zp2,wp,wp2,cf,gee,alpha,cl,arg2,p,xarg,r2,r1,ro,
965 printf (
"gccToGdc input %lf %lf %lf\n",GCC_X, GCC_Y, GCC_Z);
969 if (!gcToGdInit) initializeGcToGdParams();
971 w2=GCC_X * GCC_X + GCC_Y * GCC_Y;
975 testu=w2 + ARat2 * z2;
976 testb=w2 + BRat2 * z2;
978 if ((testb > BRat1) && (testu < ARat1))
983 top= GCC_Z * (B1 + (B2 * w2 + B3) /
984 (B4 + w2 * B5 + z2));
1000 rnn = A / ( (.25 - Eps25*s12 + .9999944354799/4) + (.25-Eps25*s12)/(.25 - Eps25*s12 + .9999944354799/4));
1010 GDC_ELE = GCC_Z / s1 + (Eps21 * rnn);
1011 GDC_LAT = atan(top / w);
1012 GDC_LON = atan2(GCC_Y,GCC_X);
1017 wp2=GCC_X * GCC_X + GCC_Y * GCC_Y;
1021 gee=wp2 - (Eps21 * zp2) - CEEps2;
1022 alpha=cf / (gee*gee);
1023 cl=CEE * wp2 * alpha / gee;
1024 arg2=cl * (cl + 2.0);
1025 s1=1.0 + cl + sqrt(arg2);
1026 s=pow(s1,(1.0/3.0));
1027 p=alpha / (3.0 * pow(( s + (1.0/s) + 1.0),2));
1028 xarg= 1.0 + (TwoCEE * p);
1030 r2= -p * (2.0 * (1.0 - Eps2) * zp2 / ( q * ( 1.0 + q) ) + wp2);
1031 r1=(1.0 + (1.0 / q));
1037 ro = A * sqrt( .50 * (r1+r2));
1041 ro=ro - p * Eps2 * wp / ( 1.0 + q);
1044 arg = pow(( wp - roe),2) + zp2;
1045 v=sqrt(arg - Eps2 * zp2);
1046 zo=C2DA * GCC_Z / v;
1047 GDC_ELE = sqrt(arg) * (1.0 - C2DA / v);
1049 GDC_LAT = atan( top / wp );
1050 GDC_LON =atan2(GCC_Y,GCC_X);
1053 GDC_LAT *= DEGREES_PER_RADIAN;
1054 GDC_LON *= DEGREES_PER_RADIAN;
1060 static void gdToUtm(
double latitude,
double longitude,
int *zone,
double *easting,
double *northing) {
1061 #define DEG2RAD (PI/180.00)
1062 #define GEOSP_WE_INV 0.00669438
1067 double longOriginradian;
1077 *zone = (int) (((longitude + 180.0)/6.0) + 1);
1079 lat_radian = latitude * DEG2RAD;
1080 long_radian = longitude * DEG2RAD;
1082 longOrigin = (*zone - 1)*6 - 180 + 3;
1083 longOriginradian = longOrigin * DEG2RAD;
1084 eccentprime = GEOSP_WE_INV/(1-GEOSP_WE_INV);
1091 NNN = GEOSP_WE_A / sqrt(1-GEOSP_WE_INV * sin(lat_radian)*sin(lat_radian));
1092 TTT = tan(lat_radian) * tan(lat_radian);
1093 CCC = eccentprime * cos(lat_radian)*cos(lat_radian);
1094 AAA = cos(lat_radian) * (long_radian - longOriginradian);
1096 * ( ( 1 - GEOSP_WE_INV/4 - 3 * GEOSP_WE_INV * GEOSP_WE_INV/64
1097 - 5 * GEOSP_WE_INV * GEOSP_WE_INV * GEOSP_WE_INV/256
1099 - ( 3 * GEOSP_WE_INV/8 + 3 * GEOSP_WE_INV * GEOSP_WE_INV/32
1100 + 45 * GEOSP_WE_INV * GEOSP_WE_INV * GEOSP_WE_INV/1024
1101 ) * sin(2 * lat_radian)
1102 + ( 15 * GEOSP_WE_INV * GEOSP_WE_INV/256 +
1103 45 * GEOSP_WE_INV * GEOSP_WE_INV * GEOSP_WE_INV/1024
1104 ) * sin(4 * lat_radian)
1105 - ( 35 * GEOSP_WE_INV * GEOSP_WE_INV * GEOSP_WE_INV/3072
1106 ) * sin(6 * lat_radian)
1111 *easting = myScale*NNN*(AAA+(1-TTT+CCC)*AAA*AAA*AAA/6
1112 + (5-18*TTT+TTT*TTT+72*CCC-58*eccentprime)*AAA*AAA*AAA*AAA*AAA/120)
1115 *northing= myScale * ( MMM + NNN*tan(lat_radian) *
1116 ( AAA*AAA/2+(5-TTT+9*CCC+4*CCC*CCC)*AAA*AAA*AAA*AAA/24 + (61-58*TTT+TTT*TTT+600*CCC-330*eccentprime) * AAA*AAA*AAA*AAA*AAA*AAA/720));
1121 printf (
"gdToUtm: lat %lf long %lf zone %d -> easting %lf northing %lf\n",latitude, longitude, *zone,*easting, *northing);
1136 if (geoSystem->n > 0) {
1137 if (geoSystem->p[0] == GEOSP_GC) {
1139 printf (
"GeoOrient - simple GC, so no orient\n");
1146 if(((
struct X3D_GeoOrigin*)geoOrigin)->rotateYUp == TRUE)
return;
1150 printf (
"GeoOrient - gdCoords->c[0,1] is %f %f\n",gdCoords->c[0],gdCoords->c[1]);
1154 vrmlrot_to_quaternion (&qz,0.0, 0.0, 1.0, RADIANS_PER_DEGREE*((
double)90.0 + gdCoords->c[1]));
1157 printf (
"GeoOrient qz angle (deg) %lf angle (rad) %lf quat: %lf %lf %lf %lf\n",((
double)90.0 + gdCoords->c[1]),
1158 RADIANS_PER_DEGREE*((
double)90.0 + gdCoords->c[1]),qz.x, qz.y, qz.z,qz.w);
1161 vrmlrot_to_quaternion (&qx,1.0, 0.0, 0.0, RADIANS_PER_DEGREE*((
double)180.0 - gdCoords->c[0]));
1164 printf (
"GeoOrient qx angle (deg) %lf angle (rad) %lf quat: %lf %lf %lf %lf\n",
1165 ((
double)180.0 - gdCoords->c[0]), RADIANS_PER_DEGREE*((
double)180.0 - gdCoords->c[0]), qx.x, qx.y, qx.z,qx.w);
1168 quaternion_add (&qr, &qx, &qz);
1171 printf (
"GeoOrient qr %lf %lf %lf %lf\n",qr.x, qr.y, qr.z,qr.w);
1174 quaternion_to_vrmlrot(&qr, &orient->c[0], &orient->c[1], &orient->c[2], &orient->c[3]);
1177 printf (
"GeoOrient rotation %lf %lf %lf %lf\n",orient->c[0], orient->c[1], orient->c[2], orient->c[3]);
1196 indexT this_srf = INT_ID_UNDEFINED;
1197 indexT this_srf_ind = INT_ID_UNDEFINED;
1200 printf (
"start of compile_geoSystem\n");
1206 srf->p=MALLOC(
int *,
sizeof(
int) * 5);
1210 srf->p[0] = GEOSP_GD;
1211 srf->p[1] = GEOSP_WE;
1212 srf->p[2] = INT_ID_UNDEFINED;
1217 if (args->n==0)
return;
1220 for (i=0; i<args->n; i++) {
1222 indexT tc = findFieldInGEOSPATIAL(args->p[i]->strptr);
1224 if ((tc == GEOSP_GD) || (tc == GEOSP_GDC)) {
1225 this_srf = GEOSP_GD;
1227 }
else if ((tc == GEOSP_GC) || (tc == GEOSP_GCC)) {
1228 this_srf = GEOSP_GC;
1230 }
else if (tc == GEOSP_UTM) {
1231 this_srf = GEOSP_UTM;
1237 if (this_srf == INT_ID_UNDEFINED) {
1238 ConsoleMessage (
"geoSystem in node %s, must have GC, GD or UTM",stringNodeType(nodeType));
1242 srf->p[0] = (int) this_srf;
1244 if (this_srf == GEOSP_GC) {
1246 srf->p[1] = INT_ID_UNDEFINED;
1247 for (i=0; i<args->n; i++) {
1248 if (strcmp(
"northing_first",args->p[i]->strptr) == 0) { srf->p[3] = TRUE;
1249 }
else if (strcmp(
"easting_first",args->p[i]->strptr) == 0) { srf->p[3] = FALSE;
1250 }
else if (i!=this_srf_ind) ConsoleMessage (
"geoSystem GC parameter %s not allowed geospatial coordinates",args->p[i]->strptr);
1252 }
else if (this_srf == GEOSP_GD) {
1253 srf->p[1] = GEOSP_WE;
1258 for (i=0; i<args->n; i++) {
1260 if (strcmp(
"latitude_first", args->p[i]->strptr) == 0) {
1262 }
else if (strcmp(
"longitude_first", args->p[i]->strptr) == 0) {
1264 }
else if(strcmp (
"WGS84",args->p[i]->strptr) == 0){
1267 if (i!= this_srf_ind) {
1268 indexT tc = findFieldInGEOSPATIAL(args->p[i]->strptr);
1270 case INT_ID_UNDEFINED:
1276 ConsoleMessage(
"expected valid GC parameter in node %s",stringNodeType(nodeType));
1277 srf->p[1] = GEOSP_WE;
1281 srf->p[1] = (int) tc;
1294 for (i=0; i<args->n; i++) {
1295 if (i != this_srf_ind) {
1296 if (strcmp (
"S",args->p[i]->strptr) == 0) {
1298 }
else if (strcmp (
"N",args->p[i]->strptr) == 0) {
1300 }
else if (args->p[i]->strptr[0] ==
'Z') {
1302 sscanf(args->p[i]->strptr,
"Z%d",&zone);
1305 }
else if(strcmp (
"WGS84",args->p[i]->strptr) == 0){
1308 indexT tc = findFieldInGEOSPATIAL(args->p[i]->strptr);
1310 case INT_ID_UNDEFINED:
1316 ConsoleMessage(
"expected valid UTM Ellipsoid parameter in node %s",stringNodeType(nodeType));
1317 srf->p[1] = GEOSP_WE;
1321 srf->p[1] = (int)tc;
1329 printf (
"printf done compileGeoSystem\n");
1340 printf (
"compiling GeoCoordinate\n");
1345 mOUT.p = NULL; mOUT.n = 0;
1348 INITIALIZE_GEOSPATIAL(node)
1349 COMPILE_GEOSYSTEM(node)
1350 MOVE_TO_ORIGIN(node)
1353 FREE_IF_NZ(node->__movedCoords.p);
1354 node->__movedCoords.p = MALLOC (struct
SFVec3f *, sizeof (struct SFVec3f) * mOUT.n);
1355 for (i=0; i<mOUT.n; i++) {
1356 node->__movedCoords.p[i].c[0] = (float) mOUT.p[i].c[0];
1357 node->__movedCoords.p[i].c[1] = (
float) mOUT.p[i].c[1];
1358 node->__movedCoords.p[i].c[2] = (float) mOUT.p[i].c[2];
1360 printf (
"coord %d now is %f %f %f\n", i, node->__movedCoords.p[i].c[0],node->__movedCoords.p[i].c[1],node->__movedCoords.p[i].c[2]);
1363 node->__movedCoords.n = mOUT.n;
1365 FREE_IF_NZ(gdCoords.p);
1379 int checkX3DGeoElevationGridFields (
struct X3D_GeoElevationGrid *node,
float **points,
int *npoints) {
1393 float *texcoord = NULL;
1394 double myHeightAboveEllip = 0.0;
1397 nx = node->xDimension;
1398 xSp = node->xSpacing;
1399 nz = node->zDimension;
1400 zSp = node->zSpacing;
1401 height = node->height.p;
1402 nh = node->height.n;
1404 COMPILE_GEOSYSTEM(node)
1406 if (node->__geoSystem.n != 0) {
1407 mySRF = node->__geoSystem.p[0];
1413 rep = node->_intern;
1416 ntri = (nx && nz ? 2 * (nx-1) * (nz-1) : 0);
1422 printf (
"GeoElevationgrid: warning: x,y vs. height: %d * %d ne %d:\n", nx,nz,nh);
1424 printf (
"GeoElevationgrid: error: x,y vs. height: %d * %d ne %d:\n", nx,nz,nh);
1430 if ((nx < 2) || (nz < 2)) {
1431 printf (
"GeoElevationGrid: xDimension and zDimension less than 2 %d %d\n", nx,nz);
1439 if (!(node->texCoord)) {
1441 FREE_IF_NZ(rep->GeneratedTexCoords[0]);
1444 texcoord = rep->GeneratedTexCoords[0] = MALLOC (
float *,
sizeof (
float) * nquads * 12);
1451 newpoints = MALLOC (
float *,
sizeof (
float) * nz * nx * 3);
1453 FREE_IF_NZ(rep->actualCoord);
1454 rep->actualCoord = (
float *)newpoints;
1457 if (node->_coordIndex.n > 0) {FREE_IF_NZ(node->_coordIndex.p);}
1458 node->_coordIndex.p = MALLOC (
int *,
sizeof(
int) * nquads * 5);
1459 cindexptr = node->_coordIndex.p;
1461 node->_coordIndex.n = nquads * 5;
1463 *points = newpoints;
1464 *npoints = node->_coordIndex.n;
1467 printf (
"coordindex:\n");
1473 for (j = 0; j < (nz -1); j++) {
1474 for (i=0; i < (nx-1) ; i++) {
1476 printf (
" %d %d %d %d %d\n", j*nx+i, j*nx+i+nx, j*nx+i+nx+1, j*nx+i+1, -1);
1479 #ifdef WINDING_ELEVATIONGRID
1480 *cindexptr = j*nx+i; cindexptr++;
1481 *cindexptr = j*nx+i+nx; cindexptr++;
1482 *cindexptr = j*nx+i+nx+1; cindexptr++;
1483 *cindexptr = j*nx+i+1; cindexptr++;
1484 *cindexptr = -1; cindexptr++;
1486 *cindexptr = j*nx+i; cindexptr++;
1487 *cindexptr = j*nx+i+1; cindexptr++;
1488 *cindexptr = j*nx+i+nx+1; cindexptr++;
1489 *cindexptr = j*nx+i+nx; cindexptr++;
1490 *cindexptr = -1; cindexptr++;
1498 if (!(node->texCoord)) {
1501 for (j = 0; j < (nz -1); j++) {
1502 for (i=0; i < (nx-1) ; i++) {
1504 #ifdef WINDING_ELEVATIONGRID
1506 *texcoord = ((float) (i+0)/(nx-1)); texcoord++;
1507 *texcoord = ((float)(j+0)/(nz-1)); texcoord ++;
1509 *texcoord = ((float) (i+0)/(nx-1)); texcoord++;
1510 *texcoord = ((float)(j+1)/(nz-1)); texcoord ++;
1512 *texcoord = ((float) (i+1)/(nx-1)); texcoord++;
1513 *texcoord = ((float)(j+1)/(nz-1)); texcoord ++;
1516 *texcoord = ((float) (i+0)/(nx-1)); texcoord++;
1517 *texcoord = ((float)(j+0)/(nz-1)); texcoord ++;
1519 *texcoord = ((float) (i+1)/(nx-1)); texcoord++;
1520 *texcoord = ((float)(j+1)/(nz-1)); texcoord ++;
1522 *texcoord = ((float) (i+1)/(nx-1)); texcoord++;
1523 *texcoord = ((float)(j+0)/(nz-1)); texcoord ++;
1526 *texcoord = ((float) (i+0)/(nx-1)); texcoord++;
1527 *texcoord = ((float)(j+0)/(nz-1)); texcoord ++;
1529 *texcoord = ((float) (i+1)/(nx-1)); texcoord++;
1530 *texcoord = ((float)(j+0)/(nz-1)); texcoord ++;
1532 *texcoord = ((float) (i+1)/(nx-1)); texcoord++;
1533 *texcoord = ((float)(j+1)/(nz-1)); texcoord ++;
1536 *texcoord = ((float) (i+0)/(nx-1)); texcoord++;
1537 *texcoord = ((float)(j+0)/(nz-1)); texcoord ++;
1539 *texcoord = ((float) (i+1)/(nx-1)); texcoord++;
1540 *texcoord = ((float)(j+1)/(nz-1)); texcoord ++;
1542 *texcoord = ((float) (i+0)/(nx-1)); texcoord++;
1543 *texcoord = ((float)(j+1)/(nz-1)); texcoord ++;
1556 mIN.p = MALLOC (
struct SFVec3d *,
sizeof (
struct SFVec3d) * mIN.n);
1558 mOUT.n=0; mOUT.p = NULL;
1559 gdCoords.n=0; gdCoords.p = NULL;
1562 for (j=0; j<nz; j++) {
1563 for (i=0; i < nx; i++) {
1566 printf (
" %lf %lf %lf # (hei ind %d) point [%d, %d]\n",
1568 height[i+(j*nx)] * ((
double)node->yScale),
1576 if ((mySRF == GEOSP_GD) || (mySRF == GEOSP_UTM)) {
1580 mIN.p[i+(j*nx)].c[0] = zSp * j + node->geoGridOrigin.c[0];
1583 mIN.p[i+(j*nx)].c[1] =xSp * i + node->geoGridOrigin.c[1];
1586 mIN.p[i+(j*nx)].c[2] = (height[i+(j*nx)] *(node->yScale)) + node->geoGridOrigin.c[2]
1587 + myHeightAboveEllip;
1590 mIN.p[i+(j*nx)].c[0] = zSp * j + node->geoGridOrigin.c[0];
1592 mIN.p[i+(j*nx)].c[1] =xSp * i + node->geoGridOrigin.c[1];
1594 mIN.p[i+(j*nx)].c[2] = (height[i+(j*nx)] *(node->yScale)) + node->geoGridOrigin.c[2]
1595 + myHeightAboveEllip;
1602 printf (
"points before moving origin:\n");
1603 for (j=0; j<nz; j++) {
1604 for (i=0; i < nx; i++) {
1605 printf (
" %lf %lf %lf # lat/long/height before MOVE, index %d\n",mIN.p[i+(j*nx)].c[0],
1606 mIN.p[i+(j*nx)].c[1],mIN.p[i+(j*nx)].c[2],i+(j*nx));
1613 MOVE_TO_ORIGIN(node)
1618 printf (
"points:\n");
1621 for (j=0; j<nz; j++) {
1622 for (i=0; i < nx; i++) {
1624 newpoints[0] = (float) mOUT.p[i+(j*nx)].c[0];
1625 newpoints[1] = (float) mOUT.p[i+(j*nx)].c[1];
1626 newpoints[2] = (float) mOUT.p[i+(j*nx)].c[2];
1629 printf (
" %f %f %f # converted, index %d\n",newpoints[0],newpoints[1],newpoints[2],i+(j*nx));
1644 printf (
"compiling GeoElevationGrid\n");
1646 printf (
"compiling GeoElevationGrid\n");
1648 INITIALIZE_GEOSPATIAL(node)
1649 COMPILE_GEOSYSTEM(node)
1659 INITIALIZE_GEOSPATIAL(node)
1660 COMPILE_POLY_IF_REQUIRED (NULL, NULL, node->color, node->normal, node->texCoord)
1661 CULL_FACE(node->solid)
1662 render_polyrep(node);
1674 printf (
"compiling GeoLocation\n");
1678 INITIALIZE_GEOSPATIAL(node)
1679 COMPILE_GEOSYSTEM(node)
1680 INIT_MF_FROM_SF(node, geoCoords)
1681 MOVE_TO_ORIGIN(node)
1682 COPY_MF_TO_SF(node, __movedCoords)
1685 GeoOrient(node->geoOrigin, &node->__geoSystem, &gdCoords.p[0], &node->__localOrient);
1688 printf (
"compile_GeoLocation, orig coords %lf %lf %lf, moved %lf %lf %lf\n", node->geoCoords.c[0], node->geoCoords.c[1], node->geoCoords.c[2], node->__movedCoords.c[0], node->__movedCoords.c[1], node->__movedCoords.c[2]);
1689 printf (
" rotation is %lf %lf %lf %lf\n",
1690 node->__localOrient.c[0],
1691 node->__localOrient.c[1],
1692 node->__localOrient.c[2],
1693 node->__localOrient.c[3]);
1697 MARK_SFVEC3D_INOUT_EVENT(node->geoCoords, node->__oldgeoCoords, offsetof (
struct X3D_GeoLocation, geoCoords))
1700 MARK_MFNODE_INOUT_EVENT(node->children, node->__oldChildren, offsetof (struct
X3D_GeoLocation, children))
1702 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
1712 printf (
"compiled GeoLocation\n\n");
1719 INITIALIZE_GEOSPATIAL(node)
1738 RETURN_FROM_CHILD_IF_NOT_FOR_ME
1742 prep_sibAffectors((struct
X3D_Node*)node,&node->__sibAffectors);
1750 printf (
"GeoLocation - doing normalChildren\n");
1753 normalChildren(node->children);
1756 printf (
"GeoLocation - done normalChildren\n");
1760 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1766 INITIALIZE_GEOSPATIAL(node)
1778 if(!renderstate()->render_vp) {
1779 FW_GL_PUSH_MATRIX();
1782 FW_GL_TRANSLATE_D(node->__movedCoords.c[0], node->__movedCoords.c[1], node->__movedCoords.c[2]);
1786 FW_GL_ROTATE_RADIANS(node->__localOrient.c[3], node->__localOrient.c[0],node->__localOrient.c[1],node->__localOrient.c[2]);
1798 INITIALIZE_GEOSPATIAL(node)
1802 if(!renderstate()->render_vp) {
1805 if ((node->_renderFlags & VF_Viewpoint) == VF_Viewpoint) {
1806 FW_GL_ROTATE_RADIANS(-node->__localOrient.c[3], node->__localOrient.c[0],node->__localOrient.c[1],node->__localOrient.c[2]);
1807 FW_GL_TRANSLATE_D(-node->__movedCoords.c[0], -node->__movedCoords.c[1], -node->__movedCoords.c[2]);
1816 void add_node_to_broto_context(
struct X3D_Proto *currentContext,
struct X3D_Node *node);
1818 void deleteMallocedFieldValue(
int type,
union anyVrml *fieldPtr);
1822 if (childUrl->n > 0) {
1824 if (*childNode == NULL) {
1825 *childNode = createNewX3DNode(NODE_Inline);
1826 if(node->_executionContext)
1827 add_node_to_broto_context(X3D_PROTO(node->_executionContext),X3D_NODE(*childNode));
1828 ADD_PARENT(X3D_NODE(*childNode), X3D_NODE(node));
1831 deleteMallocedFieldValue(FIELDTYPE_MFString,(
union anyVrml*)&X3D_INLINE(*childNode)->url);
1832 X3D_INLINE(*childNode)->url.p = MALLOC(
struct Uni_String **,
sizeof(
struct Uni_String)*childUrl->n);
1833 for (i=0; i<childUrl->n; i++) {
1835 X3D_INLINE(*childNode)->url.p[i] = newASCIIString(childUrl->p[i]->strptr);
1838 X3D_INLINE(*childNode)->url.n = childUrl->n;
1839 X3D_INLINE(*childNode)->load = TRUE;
1843 #define UNLOAD_CHILD(childNode) \
1844 if (node->childNode != NULL) \
1845 X3D_INLINE(node->childNode)->load = FALSE;
1848 static void GeoLODchildren (
struct X3D_GeoLOD *node) {
1849 int load = node->__inRange;
1852 if (((node->__childloadstatus)==0) && (load)) {
1856 printf (
"GeoLODchildren - have to LOAD_CHILD for node %u (level %d)\n",node,p->geoLodLevel);
1859 LOAD_CHILD(node,&node->__child1Node,&node->child1Url);
1860 LOAD_CHILD(node,&node->__child2Node,&node->child2Url);
1861 LOAD_CHILD(node,&node->__child3Node,&node->child3Url);
1862 LOAD_CHILD(node,&node->__child4Node,&node->child4Url);
1868 node->__childloadstatus = 1;
1874 static void GeoUnLODchildren (
struct X3D_GeoLOD *node) {
1875 int load = node->__inRange;
1877 if (!(load) && ((node->__childloadstatus) != 0)) {
1880 printf (
"GeoLODloadChildren, removing children from node %u level %d\n",node,p->geoLodLevel);
1882 UNLOAD_CHILD(__child1Node)
1883 UNLOAD_CHILD(__child2Node)
1884 UNLOAD_CHILD(__child3Node)
1885 UNLOAD_CHILD(__child4Node)
1887 node->__childloadstatus = 0;
1892 static
void GeoLODrootUrl (struct
X3D_GeoLOD *node) {
1893 int load = node->__inRange == 0;
1896 if (((node->__rooturlloadstatus)==0) && (load)) {
1898 printf (
"GeoLODrootUrl - have to LOAD_CHILD for node %u\n",node);
1901 LOAD_CHILD(node,&node->__rootUrl, &node->rootUrl);
1904 node->__rooturlloadstatus = 1;
1909 static void GeoUnLODrootUrl (
struct X3D_GeoLOD *node) {
1910 int load = node->__inRange;
1912 if (!(load) && ((node->__rooturlloadstatus) != 0)) {
1914 printf (
"GeoLODloadChildren, removing rootUrl\n");
1916 node->__childloadstatus = 0;
1922 void compile_GeoLOD (
struct X3D_GeoLOD * node) {
1926 printf (
"compiling GeoLOD %u\n",node);
1930 INITIALIZE_GEOSPATIAL(node)
1931 COMPILE_GEOSYSTEM(node)
1932 INIT_MF_FROM_SF(node, center)
1933 MOVE_TO_ORIGIN(node)
1934 COPY_MF_TO_SF(node, __movedCoords)
1937 printf (
"compile_GeoLOD %u, orig coords %lf %lf %lf, moved %lf %lf %lf\n", node, node->center.c[0], node->center.c[1], node->center.c[2], node->__movedCoords.c[0], node->__movedCoords.c[1], node->__movedCoords.c[2]);
1939 printf (
"children.n %d childurl 1: %u 2: %u 3: %u 4: %u rootUrl: %u rootNode: %d\n",
1957 printf (
"compiled GeoLOD\n\n");
1963 void child_GeoLOD (
struct X3D_GeoLOD *node) {
1967 INITIALIZE_GEOSPATIAL(node)
1971 printf (
"child_GeoLOD %u (level %d), renderFlags %x render_hier vp %d geom %d light %d sens %d blend %d prox %d col %d\n",
1975 render_vp,render_geom,render_light,render_sensitive,render_blend,render_proximity,render_collision);
1979 if (node->__level == -1) node->__level = p->geoLodLevel;
1980 else if (node->__level != p->geoLodLevel) {
1981 printf (
"hmmm - GeoLOD %p was level %d, now %d\n",node,node->__level, p->geoLodLevel);
1985 if ( node->__inRange) {
1986 printf (
"GeoLOD %u (level %d) closer\n",node,p->geoLodLevel);
1988 printf (
"GeoLOD %u (level %d) farther away\n",node,p->geoLodLevel);
1994 if (!(node->__inRange)) {
1997 GeoUnLODchildren (node);
1999 if (node->rootNode.n != 0) {
2000 for (i=0; i<node->rootNode.n; i++) {
2002 printf (
"GeoLOD %u is rendering rootNode %u",node,node->rootNode.p[i]);
2003 if (node->rootNode.p[i]!=NULL) printf (
" (%s) ",stringNodeType(X3D_NODE(node->rootNode.p[i])->_nodeType));
2007 render_node (node->rootNode.p[i]);
2009 }
else if (node->rootUrl.n != 0) {
2012 GeoLODrootUrl (node);
2015 if (node->__rootUrl != NULL) {
2017 printf (
"GeoLOD %u is rendering rootUrl %u",node,node->__rootUrl);
2018 if (node->__rootUrl != NULL) printf (
" (%s) ", stringNodeType(X3D_NODE(node->__rootUrl)->_nodeType));
2022 render_node (node->__rootUrl);
2031 GeoLODchildren (node);
2034 GeoUnLODrootUrl (node);
2037 printf (
"rendering children at %d, they are: ",p->geoLodLevel);
2038 if (node->child1Url.n>0) printf (
" :%s: ",node->child1Url.p[0]->strptr);
2039 if (node->child2Url.n>0) printf (
" :%s: ",node->child2Url.p[0]->strptr);
2040 if (node->child3Url.n>0) printf (
" :%s: ",node->child3Url.p[0]->strptr);
2041 if (node->child4Url.n>0) printf (
" :%s: ",node->child4Url.p[0]->strptr);
2047 printf (
"GeoLOD %u is rendering children %u ", node, node->__child1Node);
2048 if (node->__child1Node != NULL) printf (
" (%s) ",stringNodeType(X3D_NODE(node->__child1Node)->_nodeType));
2049 printf (
" %u ", node->__child2Node);
2050 if (node->__child2Node != NULL) printf (
" (%s) ",stringNodeType(X3D_NODE(node->__child2Node)->_nodeType));
2051 printf (
" %u ", node->__child3Node);
2052 if (node->__child3Node != NULL) printf (
" (%s) ",stringNodeType(X3D_NODE(node->__child3Node)->_nodeType));
2053 printf (
" %u ", node->__child4Node);
2054 if (node->__child4Node != NULL) printf (
" (%s) ",stringNodeType(X3D_NODE(node->__child4Node)->_nodeType));
2058 if (node->__child1Node != NULL) render_node (node->__child1Node);
2059 if (node->__child2Node != NULL) render_node (node->__child2Node);
2060 if (node->__child3Node != NULL) render_node (node->__child3Node);
2061 if (node->__child4Node != NULL) render_node (node->__child4Node);
2073 printf (
"compiling GeoMetadata\n");
2086 printf (
"compiling GeoOrigin\n");
2089 ConsoleMessage (
"compiling GeoOrigin\n");
2091 COMPILE_GEOSYSTEM(node)
2095 node->__rotyup.c[0] = 0.0;
2096 node->__rotyup.c[1] = 1.0;
2102 MARK_SFVEC3D_INOUT_EVENT(node->geoCoords,node->__oldgeoCoords,offsetof (
struct X3D_GeoOrigin, geoCoords))
2115 printf (
"compiling GeoPositionInterpolator\n");
2119 mIN = node->keyValue;
2120 mOUT.p = NULL; mOUT.n = 0;
2123 INITIALIZE_GEOSPATIAL(node)
2124 COMPILE_GEOSYSTEM(node)
2125 MOVE_TO_ORIGIN(node)
2129 FREE_IF_NZ(node->__movedValue.p);
2130 node->__movedValue.p = mOUT.p;
2131 node->__movedValue.n = mOUT.n;
2133 FREE_IF_NZ(gdCoords.p);
2146 void do_GeoPositionInterpolator (
void *innode) {
2148 int kin, kvin, counter, tmp;
2152 if (!innode)
return;
2155 if (NODE_NEEDS_COMPILING) compile_GeoPositionInterpolator(node);
2156 kvin = node->__movedValue.n;
2157 kVs = node->__movedValue.p;
2163 if (node->__oldKeyValuePtr.p != node->keyValue.p) {
2165 node->__oldKeyValuePtr.p= node->keyValue.p;
2167 if (node->__oldKeyPtr.p != node->key.p) {
2169 node->__oldKeyPtr.p = node->key.p;
2174 printf(
"do_GeoPos: Position/Color interp, node %u kin %d kvin %d set_fraction %f\n",
2175 node, kin, kvin, node->set_fraction);
2179 if ((kvin == 0) || (kin == 0)) {
2180 node->value_changed.c[0] = (float) 0.0;
2181 node->value_changed.c[1] = (float) 0.0;
2182 node->value_changed.c[2] = (float) 0.0;
2183 node->geovalue_changed.c[0] = 0.0;
2184 node->geovalue_changed.c[1] = 0.0;
2185 node->geovalue_changed.c[2] = 0.0;
2189 if (kin>kvin) kin=kvin;
2192 if (node->set_fraction <= ((node->key).p[0])) {
2193 memcpy ((
void *)&node->geovalue_changed, (
void *)&kVs[0], sizeof (
struct SFVec3d));
2194 }
else if (node->set_fraction >= node->key.p[kin-1]) {
2195 memcpy ((
void *)&node->geovalue_changed, (
void *)&kVs[kvin-1], sizeof (
struct SFVec3d));
2198 counter = find_key(kin,((
float)(node->set_fraction)),node->key.p);
2199 for (tmp=0; tmp<3; tmp++) {
2200 node->geovalue_changed.c[tmp] =
2201 (node->set_fraction - node->key.p[counter-1]) /
2202 (node->key.p[counter] - node->key.p[counter-1]) *
2203 (kVs[counter].c[tmp] - kVs[counter-1].c[tmp]) + kVs[counter-1].c[tmp];
2208 CONVERT_BACK_TO_GD_OR_UTM(node->geovalue_changed)
2211 for (tmp=0;tmp<3;tmp++) node->value_changed.c[tmp] = (
float)node->geovalue_changed.c[tmp];
2214 printf (
"Pos/Col, new value (%f %f %f)\n",
2215 node->value_changed.c[0],node->value_changed.c[1],node->value_changed.c[2]);
2216 printf (
"geovalue_changed %lf %lf %lf\n",node->geovalue_changed.c[0], node->geovalue_changed.c[1], node->geovalue_changed.c[2]);
2228 printf (
"compiling GeoProximitySensor\n");
2232 INITIALIZE_GEOSPATIAL(node)
2233 COMPILE_GEOSYSTEM(node)
2234 INIT_MF_FROM_SF(node, geoCenter)
2235 MOVE_TO_ORIGIN(node)
2236 COPY_MF_TO_SF(node, __movedCoords)
2239 GeoOrient(node->geoOrigin, &node->__geoSystem, &gdCoords.p[0], &node->__localOrient);
2241 printf (
"compile_GeoProximitySensor, orig coords %lf %lf %lf, moved %lf %lf %lf\n", node->geoCenter.c[0], node->geoCenter.c[1], node->geoCenter.c[2], node->__movedCoords.c[0], node->__movedCoords.c[1], node->__movedCoords.c[2]);
2242 printf (
" rotation is %lf %lf %lf %lf\n",
2243 node->__localOrient.c[0],
2244 node->__localOrient.c[1],
2245 node->__localOrient.c[2],
2246 node->__localOrient.c[3]);
2252 MARK_SFVEC3D_INOUT_EVENT(node->geoCenter, node->__oldGeoCenter,offsetof (
struct X3D_GeoProximitySensor, geoCenter))
2260 printf (
"compiled GeoProximitySensor\n\n");
2274 static struct point_XYZ yvec = {0,0.05,0};
2275 static struct point_XYZ zvec = {0,0,-0.05};
2276 static struct point_XYZ zpvec = {0,0,0.05};
2278 struct point_XYZ t_zvec, t_yvec, t_orig, t_center;
2279 GLDOUBLE modelMatrix[16];
2280 GLDOUBLE projMatrix[16];
2281 GLDOUBLE view2prox[16];
2283 if(!((node->enabled)))
return;
2284 INITIALIZE_GEOSPATIAL(node)
2293 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelMatrix);
2295 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, projMatrix);
2296 FW_GLU_UNPROJECT(orig.x,orig.y,orig.z,modelMatrix,projMatrix,viewport,
2297 &t_orig.x,&t_orig.y,&t_orig.z);
2298 FW_GLU_UNPROJECT(zvec.x,zvec.y,zvec.z,modelMatrix,projMatrix,viewport,
2299 &t_zvec.x,&t_zvec.y,&t_zvec.z);
2300 FW_GLU_UNPROJECT(yvec.x,yvec.y,yvec.z,modelMatrix,projMatrix,viewport,
2301 &t_yvec.x,&t_yvec.y,&t_yvec.z);
2302 VECDIFF(t_zvec, t_orig, dr1r2);
2303 VECDIFF(t_yvec, t_orig, dr2r3);
2306 matinverseAFFINE(view2prox,modelMatrix);
2309 transform(&t_orig,&orig,view2prox);
2310 transform(&zvec,&zvec,view2prox);
2311 transform(&yvec,&yvec,view2prox);
2312 VECDIFF(zvec, t_orig, dr1r2);
2313 VECDIFF(yvec, t_orig, dr2r3);
2315 transform(&t_center,&orig, view2prox);
2323 cx = t_center.x - ((node->__movedCoords ).c[0]);
2324 cy = t_center.y - ((node->__movedCoords ).c[1]);
2325 cz = t_center.z - ((node->__movedCoords ).c[2]);
2327 if(((node->size).c[0]) == 0 || ((node->size).c[1]) == 0 || ((node->size).c[2]) == 0)
return;
2329 if(fabs(cx) > ((node->size).c[0])/2 ||
2330 fabs(cy) > ((node->size).c[1])/2 ||
2331 fabs(cz) > ((node->size).c[2])/2)
return;
2338 ((node->__t1).c[0]) = (float)t_center.x;
2339 ((node->__t1).c[1]) = (
float)t_center.y;
2340 ((node->__t1).c[2]) = (float)t_center.z;
2347 len = sqrt(VECSQ(dr1r2)); VECSCALE(dr1r2,1/len);
2348 len = sqrt(VECSQ(dr2r3)); VECSCALE(dr2r3,1/len);
2364 if(fabs(VECPT(dr1r2, dr2r3)) > 0.001) {
2365 printf (
"Sorry, can't handle unevenly scaled ProximitySensors yet :("
2366 "dp: %f v: (%f %f %f) (%f %f %f)\n", VECPT(dr1r2, dr2r3),
2367 dr1r2.x,dr1r2.y,dr1r2.z,
2368 dr2r3.x,dr2r3.y,dr2r3.z
2374 if(APPROX(dr1r2.z,1.0)) {
2376 ((node->__t2).c[0]) = (float) 0;
2377 ((node->__t2).c[1]) = (float) 0;
2378 ((node->__t2).c[2]) = (float) 1;
2379 ((node->__t2).c[3]) = (float) atan2(-dr2r3.x,dr2r3.y);
2380 }
else if(APPROX(dr2r3.y,1.0)) {
2382 ((node->__t2).c[0]) = (float) 0;
2383 ((node->__t2).c[1]) = (float) 1;
2384 ((node->__t2).c[2]) = (float) 0;
2385 ((node->__t2).c[3]) = (float) atan2(dr1r2.x,dr1r2.z);
2394 VECCP(nor1,nor2,ins);
2396 len = sqrt(VECSQ(ins)); VECSCALE(ins,1/len);
2399 VECCP(dr1r2,ins, nor1);
2400 VECCP(zpvec, ins, nor2);
2401 len = sqrt(VECSQ(nor1)); VECSCALE(nor1,1/len);
2402 len = sqrt(VECSQ(nor2)); VECSCALE(nor2,1/len);
2403 VECCP(nor1,nor2,ins);
2405 ((node->__t2).c[3]) = (float) -atan2(sqrt(VECSQ(ins)), VECPT(nor1,nor2));
2408 ((node->__t2).c[0]) = (float) ins.x;
2409 ((node->__t2).c[1]) = (
float) ins.y;
2410 ((node->__t2).c[2]) = (float) ins.z;
2423 void do_GeoProximitySensorTick(
void *ptr) {
2428 if (node->__oldEnabled != node->enabled) {
2429 node->__oldEnabled = node->enabled;
2432 if (!node->enabled)
return;
2437 if (!node->isActive) {
2439 printf (
"PROX - initial defaults\n");
2443 node->enterTime = TickTime();
2450 if (memcmp ((
void *) &node->position_changed,(
void *) &node->__t1,
sizeof(
struct SFColor))) {
2452 printf (
"PROX - position changed!!! \n");
2455 memcpy ((
void *) &node->position_changed,
2456 (
void *) &node->__t1,
sizeof(
struct SFColor));
2460 printf (
"do_GeoProximitySensorTick, position changed; it now is %lf %lf %lf\n",node->position_changed.c[0],
2461 node->position_changed.c[1], node->position_changed.c[2]);
2462 printf (
"nearPlane is %lf\n",Viewer.nearPlane);
2472 node->geoCoord_changed.c[0] = (double) node->position_changed.c[0];
2473 node->geoCoord_changed.c[1] = (
double) node->position_changed.c[1];
2474 node->geoCoord_changed.c[2] = (double) node->position_changed.c[2];
2480 node->geoCoord_changed.c[2] += Viewer()->nearPlane;
2484 printf (
"\ngeoCoord_changed as a GCC, %lf %lf %lf\n",
2485 node->geoCoord_changed.c[0],
2486 node->geoCoord_changed.c[1],
2487 node->geoCoord_changed.c[2]);
2490 CONVERT_BACK_TO_GD_OR_UTM(node->geoCoord_changed)
2492 if (memcmp ((
void *) &node->orientation_changed, (
void *) &node->__t2,
sizeof(
struct SFRotation))) {
2494 printf (
"PROX - orientation changed!!!\n ");
2497 memcpy ((
void *) &node->orientation_changed,
2498 (
void *) &node->__t2,
sizeof(
struct SFRotation));
2502 if (node->isActive) {
2504 printf (
"PROX - stopping\n");
2508 node->exitTime = TickTime();
2524 printf (
"compiling GeoTouchSensor\n");
2527 INITIALIZE_GEOSPATIAL(node)
2528 COMPILE_GEOSYSTEM(node)
2536 void do_GeoTouchSensor (
void *ptr,
int ev,
int but1,
int over) {
2545 printf (
"%lf: TS ",TickTime());
2546 if (ev==ButtonPress) printf (
"ButtonPress ");
2547 else if (ev==ButtonRelease) printf (
"ButtonRelease ");
2548 else if (ev==KeyPress) printf (
"KeyPress ");
2549 else if (ev==KeyRelease) printf (
"KeyRelease ");
2550 else if (ev==MotionNotify) printf (
"%lf MotionNotify ");
2551 else printf (
"ev %d ",ev);
2553 if (but1) printf (
"but1 TRUE ");
else printf (
"but1 FALSE ");
2554 if (over) printf (
"over TRUE ");
else printf (
"over FALSE ");
2560 if (node->__oldEnabled != node->enabled) {
2561 node->__oldEnabled = node->enabled;
2564 if (!node->enabled)
return;
2567 if ((ev == overMark) && (over != node->isOver)) {
2569 printf (
"TS %u, isOver changed %d\n",node, over);
2571 node->isOver = over;
2577 if (ev == ButtonPress) {
2581 printf (
"touchSens %u, butPress\n",node);
2584 node->touchTime = TickTime();
2587 }
else if (ev == ButtonRelease) {
2589 printf (
"touchSens %u, butRelease\n",node);
2597 memcpy ((
void *) &node->_oldhitPoint, (
void *) &tg->RenderFuncs.ray_save_posn,
sizeof(
struct SFColor));
2600 if ((APPROX(node->_oldhitPoint.c[0],node->hitPoint_changed.c[0])!= TRUE) ||
2601 (APPROX(node->_oldhitPoint.c[1],node->hitPoint_changed.c[1])!= TRUE) ||
2602 (APPROX(node->_oldhitPoint.c[2],node->hitPoint_changed.c[2])!= TRUE)) {
2605 printf (
"GeoTouchSens, hitPoint changed: %f %f %f\n",node->hitPoint_changed.c[0],
2606 node->hitPoint_changed.c[1], node->hitPoint_changed.c[2]);
2609 memcpy ((
void *) &node->hitPoint_changed, (
void *) &node->_oldhitPoint,
sizeof(
struct SFColor));
2613 node->hitGeoCoord_changed.c[0] = (double) node->hitPoint_changed.c[0];
2614 node->hitGeoCoord_changed.c[1] = (
double) node->hitPoint_changed.c[1];
2615 node->hitGeoCoord_changed.c[2] = (double) node->hitPoint_changed.c[2];
2621 node->hitGeoCoord_changed.c[2] += Viewer()->nearPlane;
2625 printf (
"\nhitGeoCoord_changed as a GCC, %lf %lf %lf\n",
2626 node->hitGeoCoord_changed.c[0],
2627 node->hitGeoCoord_changed.c[1],
2628 node->hitGeoCoord_changed.c[2]);
2631 CONVERT_BACK_TO_GD_OR_UTM(node->hitGeoCoord_changed)
2635 normalval.x = tg->RenderFuncs.hyp_save_norm[0];
2636 normalval.y = tg->RenderFuncs.hyp_save_norm[1];
2637 normalval.z = tg->RenderFuncs.hyp_save_norm[2];
2638 normalize_vector(&normalval);
2639 node->_oldhitNormal.c[0] = (float) normalval.x;
2640 node->_oldhitNormal.c[1] = (
float) normalval.y;
2641 node->_oldhitNormal.c[2] = (float) normalval.z;
2644 MARK_SFVEC3F_INOUT_EVENT(node->hitNormal_changed,node->_oldhitNormal,offsetof (
struct X3D_GeoTouchSensor, hitNormal_changed))
2663 printf (
"compileViewpoint is %u, its geoOrigin is %u \n",node, node->geoOrigin);
2664 if (node->geoOrigin!=NULL) printf (
"type %s\n",stringNodeType(X3D_GEOORIGIN(node->geoOrigin)->_nodeType));
2669 USE_SET_SFVEC3D_IF_CHANGED(set_position,position)
2670 USE_SET_SFROTATION_IF_CHANGED(set_orientation,orientation)
2673 INITIALIZE_GEOSPATIAL(node)
2674 COMPILE_GEOSYSTEM(node)
2675 INIT_MF_FROM_SF(node, position)
2676 MOVE_TO_ORIGIN(node)
2677 COPY_MF_TO_SF(node, __movedPosition)
2680 GeoOrient(node->geoOrigin, &node->__geoSystem, &gdCoords.p[0], &localOrient);
2683 vrmlrot_to_quaternion (&localQuat, localOrient.c[0], localOrient.c[1], localOrient.c[2], localOrient.c[3]);
2684 vrmlrot_to_quaternion (&relQuat, node->orientation.c[0], node->orientation.c[1], node->orientation.c[2], node->orientation.c[3]);
2687 quaternion_add (&combQuat, &relQuat, &localQuat);
2691 quaternion_to_vrmlrot(&combQuat, &orient.c[0], &orient.c[1], &orient.c[2], &orient.c[3]);
2692 for (i=0; i<4; i++) node->__movedOrientation.c[i] = (
float) orient.c[i];
2695 printf (
"compile_GeoViewpoint, final position %lf %lf %lf\n",node->__movedPosition.c[0],
2696 node->__movedPosition.c[1], node->__movedPosition.c[2]);
2698 printf (
"compile_GeoViewpoint, getLocalOrientation %lf %lf %lf %lf\n",localOrient.c[0],
2699 localOrient.c[1], localOrient.c[2], localOrient.c[3]);
2700 printf (
"compile_GeoViewpoint, initial orientation: %lf %lf %lf %lf\n",node->orientation.c[0],
2701 node->orientation.c[1], node->orientation.c[2], node->orientation.c[3]);
2702 printf (
"compile_GeoViewpoint, final rotation %lf %lf %lf %lf\n",node->__movedOrientation.c[0],
2703 node->__movedOrientation.c[1], node->__movedOrientation.c[2], node->__movedOrientation.c[3]);
2704 printf (
"compile_GeoViewpoint, elevation from the WGS84 ellipsoid is %lf\n",gdCoords.p[0].c[2]);
2712 MARK_SFFLOAT_INOUT_EVENT(node->fieldOfView, node->__oldFieldOfView, offsetof (
struct X3D_GeoViewpoint, fieldOfView))
2713 MARK_SFBOOL_INOUT_EVENT(node->headlight, node->__oldHeadlight, offsetof (struct
X3D_GeoViewpoint, headlight))
2714 MARK_SFBOOL_INOUT_EVENT(node->jump, node->__oldJump, offsetof (struct X3D_GeoViewpoint, jump))
2723 printf (
"compiled GeoViewpoint\n\n");
2726 struct X3D_Node *getActiveLayerBoundViewpoint();
2730 if (!renderstate()->render_vp)
return;
2732 if((
struct X3D_Node*)node == getActiveLayerBoundViewpoint() && !node->_donethispass){
2733 node->_donethispass = 1;
2735 INITIALIZE_GEOSPATIAL(node)
2747 printf (
"prep_GeoViewpoint called\n");
2751 FW_GL_ROTATE_RADIANS(-node->__movedOrientation.c[3],node->__movedOrientation.c[0],node->__movedOrientation.c[1],
2752 node->__movedOrientation.c[2]);
2754 FW_GL_TRANSLATE_D(-node->__movedPosition.c[0],-node->__movedPosition.c[1],-node->__movedPosition.c[2]);
2760 getCurrentPosInModel(FALSE);
2764 FW_GL_GETINTEGERV(GL_VIEWPORT, viewPort);
2765 if(viewPort[2] > viewPort[3]) {
2767 Viewer()->fieldofview = node->fieldOfView/3.1415926536*180;
2769 a1 = node->fieldOfView;
2770 a1 = atan2(sin(a1),viewPort[2]/((
float)viewPort[3]) * cos(a1));
2771 Viewer()->fieldofview = a1/3.1415926536*180;
2774 calculateViewingSpeed();
2776 printf (
"prep_GeoViewpoint, fieldOfView %f \n",node->fieldOfView);
2783 void calculateViewingSpeed() {
2788 gcCoords.c[0]= Viewer()->currentPosInModel.x;
2789 gcCoords.c[1] = Viewer()->currentPosInModel.y;
2790 gcCoords.c[2] = Viewer()->currentPosInModel.z;
2793 printf (
"calculateViewingSpeed, currentPosInModel %lf %lf %lf\n", gcCoords.c[0], gcCoords.c[1], gcCoords.c[2]);
2796 if (Viewer()->GeoSpatialNode != NULL) {
2798 INITIALIZE_GEOSPATIAL(Viewer()->GeoSpatialNode)
2809 if (Viewer()->GeoSpatialNode->__geoSystem.n>0) {
2812 if (Viewer()->GeoSpatialNode->__geoSystem.p[0] != GEOSP_GC) {
2820 printf (
"for GeoViewpoint :%s:\n",Viewer.GeoSpatialNode->description->strptr);
2821 printf (
"calculateViewingSpeed, currentPosInModel: %lf %lf %lf\n", gcCoords.c[0], gcCoords.c[1], gcCoords.c[2]);
2825 gccToGdc (&gcCoords, &gdCoords);
2828 printf (
"speed is calculated from geodetic height %lf %lf %lf\n",gdCoords.c[0], gdCoords.c[1], gdCoords.c[2]);
2832 Viewer()->speed = fabs(sqrt(gcCoords.c[0]*gcCoords.c[0] + gcCoords.c[1]*gcCoords.c[1] + gcCoords.c[2]*gcCoords.c[2])
2833 -GEOSP_WE_A) * Viewer()->GeoSpatialNode->speedFactor;
2834 if (Viewer()->speed < 1.0) Viewer()->speed=1.0;
2837 printf (
"height above center %f WGS84 ellipsoid is %lf\n",Viewer.speed,GEOSP_WE_A);
2845 set_naviWidthHeightStep(
2846 Viewer()->speed*0.25,
2847 Viewer()->speed*1.6,
2848 Viewer()->speed*0.25);
2854 static void calculateExamineModeDistance(
void) {
2858 Viewer()->doExamineModeDistanceCalculations = TRUE;
2867 if (!(node->isBound))
return;
2869 viewer = ViewerByLayerId(node->_layerId);
2871 INITIALIZE_GEOSPATIAL(node)
2877 printf (
"bind_GeoViewpoint, setting Viewer to %lf %lf %lf orient %f %f %f %f\n",node->__movedPosition.c[0],node->__movedPosition.c[1],
2878 node->__movedPosition.c[2],node->orientation.c[0],node->orientation.c[1],node->orientation.c[2],
2879 node->orientation.c[3]);
2880 printf (
" node %u fieldOfView %f\n",node,node->fieldOfView);
2883 viewer->GeoSpatialNode = node;
2885 viewer->Pos.x = node->__movedPosition.c[0];
2886 viewer->Pos.y = node->__movedPosition.c[1];
2887 viewer->Pos.z = node->__movedPosition.c[2];
2888 viewer->AntiPos.x = node->__movedPosition.c[0];
2889 viewer->AntiPos.y = node->__movedPosition.c[1];
2890 viewer->AntiPos.z = node->__movedPosition.c[2];
2894 vrmlrot_to_quaternion (&viewer->Quat,node->__movedOrientation.c[0],
2895 node->__movedOrientation.c[1],node->__movedOrientation.c[2],node->__movedOrientation.c[3]);
2897 vrmlrot_to_quaternion (&q_i,node->__movedOrientation.c[0],
2898 node->__movedOrientation.c[1],node->__movedOrientation.c[2],node->__movedOrientation.c[3]);
2899 quaternion_inverse(&(viewer->AntiQuat),&q_i);
2903 calculateViewingSpeed();
2905 calculateExamineModeDistance();
2906 setMenuStatusVP (node->description->strptr);
2919 printf (
"compiling GeoLocation\n");
2923 INITIALIZE_GEOSPATIAL(node)
2924 COMPILE_GEOSYSTEM(node)
2925 INIT_MF_FROM_SF(node, geoCenter)
2926 MOVE_TO_ORIGIN(node)
2927 COPY_MF_TO_SF(node, __movedCoords)
2930 GeoOrient(node->geoOrigin, &node->__geoSystem, &gdCoords.p[0], &node->__localOrient);
2932 MARK_SFVEC3D_INOUT_EVENT(node->geoCenter, node->__oldGeoCenter,offsetof (struct
X3D_GeoTransform, geoCenter))
2933 MARK_MFNODE_INOUT_EVENT(node->children, node->__oldChildren, offsetof (struct X3D_GeoTransform, children))
2938 node->__do_trans = verify_translate ((GLfloat *)node->translation.c);
2939 if (node->__do_trans) MARK_EVENT(X3D_NODE(node), offsetof (struct X3D_GeoTransform, translation));
2941 node->__do_scale = verify_scale ((GLfloat *)node->scale.c);
2942 if (node->__do_scale) MARK_EVENT(X3D_NODE(node), offsetof (struct X3D_GeoTransform, scale));
2944 node->__do_rotation = verify_rotate ((GLfloat *)node->rotation.c);
2945 if (node->__do_rotation) MARK_EVENT(X3D_NODE(node), offsetof (struct X3D_GeoTransform, rotation));
2947 node->__do_scaleO = verify_rotate ((GLfloat *)node->scaleOrientation.c);
2948 if (node->__do_scaleO) MARK_EVENT(X3D_NODE(node), offsetof (struct X3D_GeoTransform, scaleOrientation));
2953 printf (
"compile_GeoTransform, orig coords %lf %lf %lf, moved %lf %lf %lf\n", node->geoCoords.c[0], node->geoCoords.c[1], node->geoCoords.c[2], node->__movedCoords.c[0], node->__movedCoords.c[1], node->__movedCoords.c[2]);
2954 printf (
" rotation is %lf %lf %lf %lf\n",
2955 node->__localOrient.c[0],
2956 node->__localOrient.c[1],
2957 node->__localOrient.c[2],
2958 node->__localOrient.c[3]);
2961 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
2970 printf (
"compiled GeoTransform\n\n");
2978 INITIALIZE_GEOSPATIAL(node)
2990 if(!renderstate()->render_vp) {
2991 FW_GL_PUSH_MATRIX();
2995 if (node->__do_trans)
2996 FW_GL_TRANSLATE_F(node->translation.c[0],node->translation.c[1],node->translation.c[2]);
2999 FW_GL_TRANSLATE_D(node->__movedCoords.c[0], node->__movedCoords.c[1], node->__movedCoords.c[2]);
3004 FW_GL_ROTATE_RADIANS(node->__localOrient.c[3], node->__localOrient.c[0],node->__localOrient.c[1],node->__localOrient.c[2]);
3007 if (node->__do_rotation) {
3008 FW_GL_ROTATE_RADIANS(node->rotation.c[3], node->rotation.c[0],node->rotation.c[1],node->rotation.c[2]);
3012 if (node->__do_scaleO) {
3013 FW_GL_ROTATE_RADIANS(node->scaleOrientation.c[3], node->scaleOrientation.c[0],
3014 node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
3018 if (node->__do_scale)
3019 FW_GL_SCALE_F(node->scale.c[0],node->scale.c[1],node->scale.c[2]);
3022 if (node->__do_scaleO)
3023 FW_GL_ROTATE_RADIANS(-node->scaleOrientation.c[3], node->scaleOrientation.c[0],
3024 node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
3027 FW_GL_TRANSLATE_D(-node->__movedCoords.c[0], -node->__movedCoords.c[1], -node->__movedCoords.c[2]);
3035 INITIALIZE_GEOSPATIAL(node)
3039 if(!renderstate()->render_vp) {
3043 if((node->_renderFlags & VF_Viewpoint) == VF_Viewpoint) {
3044 FW_GL_TRANSLATE_D(((node->__movedCoords).c[0]),((node->__movedCoords).c[1]),((node->__movedCoords).c[2])
3046 FW_GL_ROTATE_RADIANS(node->scaleOrientation.c[3],node->scaleOrientation.c[0],node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
3047 FW_GL_SCALE_F((
float)1.0/(((node->scale).c[0])),(
float)1.0/(((node->scale).c[1])),(
float)1.0/(((node->scale).c[2]))
3049 FW_GL_ROTATE_RADIANS(-node->scaleOrientation.c[3],node->scaleOrientation.c[0],node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
3050 FW_GL_ROTATE_RADIANS(-(((node->rotation).c[3])),((node->rotation).c[0]),((node->rotation).c[1]),((node->rotation).c[2])
3052 FW_GL_TRANSLATE_D(-(((node->__movedCoords).c[0])),-(((node->__movedCoords).c[1])),-(((node->__movedCoords).c[2]))
3054 FW_GL_TRANSLATE_F(-(((node->translation).c[0])),-(((node->translation).c[1])),-(((node->translation).c[2]))
3063 INITIALIZE_GEOSPATIAL(node)
3066 RETURN_FROM_CHILD_IF_NOT_FOR_ME
3085 prep_sibAffectors((struct
X3D_Node*)node,&node->__sibAffectors);
3093 printf (
"transform - doing normalChildren\n");
3096 normalChildren(node->children);
3099 printf (
"transform - done normalChildren\n");
3103 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);