34 #include <libFreeWRL.h>
36 #include "../vrml_parser/Structs.h"
37 #include "../main/headers.h"
38 #include "../vrml_parser/CParseGeneral.h"
39 #include "../scenegraph/Vector.h"
40 #include "../vrml_parser/CFieldDecls.h"
41 #include "../vrml_parser/CParseParser.h"
42 #include "../vrml_parser/CParseLexer.h"
43 #include "../vrml_parser/CRoutes.h"
44 #include "../opengl/OpenGL_Utils.h"
46 #include "../scenegraph/quaternion.h"
47 #include "../scenegraph/Viewer.h"
48 #include "../scenegraph/Component_Shape.h"
49 #include "../scenegraph/Component_Geospatial.h"
50 #include "../scenegraph/RenderFuncs.h"
51 #include "../scenegraph/Component_ProgrammableShaders.h"
52 #include "../ui/common.h"
53 #include "../scenegraph/LinearAlgebra.h"
64 static void saveBGVert (
float *colptr,
float *pt,
int *vertexno,
float *col,
double dist,
double x,
double y,
double z) ;
66 void init_bindablestack(
bindablestack *bstack,
int layerId,
int nodetype){
67 bstack->background = newVector(
struct X3D_Node*, 2);
68 bstack->viewpoint = newVector(
struct X3D_Node*, 2);
69 bstack->fog = newVector(
struct X3D_Node*, 2);
70 bstack->navigation = newVector(
struct X3D_Node*, 2);
71 bstack->layerId = layerId;
72 loadIdentityMatrix(bstack->screenorientationmatrix);
73 loadIdentityMatrix(bstack->viewtransformmatrix);
74 loadIdentityMatrix(bstack->posorimatrix);
75 loadIdentityMatrix(bstack->stereooffsetmatrix[0]);
76 loadIdentityMatrix(bstack->stereooffsetmatrix[1]);
79 bstack->viewer = NULL;
80 bstack->nodetype = nodetype;
81 loadIdentityMatrix(bstack->pickraymatrix[0]);
82 loadIdentityMatrix(bstack->pickraymatrix[1]);
85 deleteVector(
struct X3D_Node*, bstack->background);
86 deleteVector(
struct X3D_Node*, bstack->viewpoint);
87 deleteVector(
struct X3D_Node*, bstack->fog);
88 deleteVector(
struct X3D_Node*, bstack->navigation);
89 FREE_IF_NZ(bstack->viewer);
95 void *Bindable_constructor(){
96 void *v = MALLOCV(
sizeof(
struct pBindable));
100 void Bindable_init(
struct tBindable *t){
108 t->prv = Bindable_constructor();
113 init_bindablestack(&p->bstack,0, NODE_Viewpoint);
115 p->naviinfo.width = 0.25;
116 p->naviinfo.height = 1.6;
117 p->naviinfo.step = 0.75;
118 t->naviinfo = &p->naviinfo;
122 void Bindable_clear(
struct tBindable *t){
129 for(i=0;i<vectorSize(t->bstacks);i++){
131 free_bindablestack(bstack);
132 if(i>0) FREE_IF_NZ(bstack);
141 for(i=0;i<vectorSize(tg->Bindable.bstacks);i++){
142 bstacktmp = vector_get(
bindablestack*,tg->Bindable.bstacks,i);
143 if(bstacktmp->layerId == layerId){
153 int layerId = bstack->layerId;
154 while(vectorSize(tg->Bindable.bstacks)<layerId+1)
156 vector_set(
bindablestack*,tg->Bindable.bstacks,layerId,bstack);
161 return getBindableStacksByLayer(tg,tg->Bindable.activeLayer);
163 int getBindableStacksCount(
ttglobal tg){
164 return vectorSize(tg->Bindable.bstacks);
166 void printStatsBindingStacks()
171 nstacks = getBindableStacksCount(tg);
172 for(i=0;i<nstacks;i++){
173 bstack = getBindableStacksByLayer(tg,i);
175 ConsoleMessage(
"Layer %d",i);
176 if(i == tg->Bindable.activeLayer)
177 ConsoleMessage(
" activeLayer");
178 ConsoleMessage(
":\n");
181 if(i == tg->Bindable.activeLayer)
183 ConsoleMessage(
"Layer %d%s:\n",i,al);
185 ConsoleMessage(
"%25s %d\n",
"Background stack count", vectorSize(bstack->background));
186 ConsoleMessage(
"%25s %d\n",
"Fog stack count", vectorSize(bstack->fog));
187 ConsoleMessage(
"%25s %d\n",
"Navigation stack count", vectorSize(bstack->navigation));
188 ConsoleMessage(
"%25s %d\n",
"Viewpoint stack count", vectorSize(bstack->viewpoint));
193 void set_naviWidthHeightStep(
double wid,
double hei,
double step) {
198 p->naviinfo.width = wid;
199 p->naviinfo.height = hei;
200 p->naviinfo.step = step;
213 viewer->speed = (double) node->speed;
214 if (node->avatarSize.n<2) {
215 printf (
"set_naviinfo, avatarSize smaller than expected\n");
217 set_naviWidthHeightStep ((
double)(node->avatarSize.p[0]),
218 (
double)(node->avatarSize.p[1]),
219 (
double)((node->avatarSize.p[2])));
223 svptr = node->type.p;
226 for (i=0; i<18; i++) viewer->oktypes[i] = FALSE;
230 for (i = 0; i < node->type.n; i++) {
232 typeptr = svptr[i]->strptr;
234 if (strcmp(typeptr,
"WALK") == 0) {
235 viewer->oktypes[VIEWER_WALK] = TRUE;
236 if (i==0) fwl_set_viewer_type0(viewer, VIEWER_WALK);
238 if (strcmp(typeptr,
"FLY") == 0) {
239 viewer->oktypes[VIEWER_FLY] = TRUE;
240 if (i==0) fwl_set_viewer_type0(viewer, VIEWER_FLY);
242 if (strcmp(typeptr,
"EXAMINE") == 0) {
243 viewer->oktypes[VIEWER_EXAMINE] = TRUE;
244 if (i==0) fwl_set_viewer_type0(viewer, VIEWER_EXAMINE);
246 if (strcmp(typeptr,
"NONE") == 0) {
247 viewer->oktypes[VIEWER_NONE] = TRUE;
248 if (i==0) fwl_set_viewer_type0(viewer, VIEWER_NONE);
250 if (strcmp(typeptr,
"EXFLY") == 0) {
251 viewer->oktypes[VIEWER_EXFLY] = TRUE;
252 if (i==0) fwl_set_viewer_type0(viewer, VIEWER_EXFLY);
254 if (strcmp(typeptr,
"EXPLORE") == 0) {
255 viewer->oktypes[VIEWER_EXPLORE] = TRUE;
256 if (i==0) fwl_set_viewer_type0(viewer, VIEWER_EXPLORE);
258 if (strcmp(typeptr,
"LOOKAT") == 0) {
259 viewer->oktypes[VIEWER_LOOKAT] = TRUE;
262 if (strcmp(typeptr,
"SPHERICAL") == 0) {
263 viewer->oktypes[VIEWER_SPHERICAL] = TRUE;
264 if (i==0) fwl_set_viewer_type0(viewer, VIEWER_SPHERICAL);
266 if (strcmp(typeptr,
"TURNTABLE") == 0) {
267 viewer->oktypes[VIEWER_TURNTABLE] = TRUE;
268 if (i == 0) fwl_set_viewer_type0(viewer, VIEWER_TURNTABLE);
270 if (strcmp(typeptr,
"DIST") == 0) {
271 viewer->oktypes[VIEWER_DIST] = TRUE;
272 if (i == 0) fwl_set_viewer_type0(viewer, VIEWER_DIST);
275 if (strcmp(typeptr,
"ANY") == 0) {
276 viewer->oktypes[VIEWER_EXAMINE] = TRUE;
277 viewer->oktypes[VIEWER_WALK] = TRUE;
278 viewer->oktypes[VIEWER_EXFLY] = TRUE;
279 viewer->oktypes[VIEWER_FLY] = TRUE;
280 viewer->oktypes[VIEWER_EXPLORE] = TRUE;
281 viewer->oktypes[VIEWER_LOOKAT] = TRUE;
282 viewer->oktypes[VIEWER_SPHERICAL] = TRUE;
283 viewer->oktypes[VIEWER_TURNTABLE] = TRUE;
284 viewer->oktypes[VIEWER_DIST] = TRUE;
285 if (i==0) fwl_set_viewer_type0(viewer, VIEWER_WALK);
288 viewer->headlight = node->headlight;
293 viewer->transitionTime = node->transitionTime;
295 if (viewer->transitionTime < 0.0) viewer->transitionTime = 0.0;
297 viewer->transitionType = VIEWER_TRANSITION_LINEAR;
298 if (node->transitionType.n > 0) {
299 if (strcmp(
"LINEAR", node->transitionType.p[0]->strptr) == 0) viewer->transitionType = VIEWER_TRANSITION_LINEAR;
300 else if (strcmp(
"TELEPORT", node->transitionType.p[0]->strptr) == 0) viewer->transitionType = VIEWER_TRANSITION_TELEPORT;
301 else if (strcmp(
"ANIMATE", node->transitionType.p[0]->strptr) == 0) viewer->transitionType = VIEWER_TRANSITION_ANIMATE;
303 ConsoleMessage (
"Unknown NavigationInfo transitionType :%s:",node->transitionType.p[0]->strptr);
310 int layerFromBindable(
struct X3D_Node *node){
312 switch(node->_nodeType){
314 layerId = X3D_VIEWPOINT(node)->_layerId;
break;
315 case NODE_OrthoViewpoint:
316 layerId = X3D_ORTHOVIEWPOINT(node)->_layerId;
break;
317 case NODE_GeoViewpoint:
318 layerId = X3D_GEOVIEWPOINT(node)->_layerId;
break;
319 case NODE_Background:
320 layerId = X3D_BACKGROUND(node)->_layerId;
break;
321 case NODE_TextureBackground:
322 layerId = X3D_TEXTUREBACKGROUND(node)->_layerId;
break;
324 layerId = X3D_FOG(node)->_layerId;
break;
325 case NODE_NavigationInfo:
326 layerId = X3D_NAVIGATIONINFO(node)->_layerId;
break;
334 void send_bind_to(
struct X3D_Node *node,
int value) {
339 layerId = layerFromBindable(node);
340 switch (node->_nodeType) {
341 case NODE_Background: {
343 bg->set_bind = value;
344 bind_node (node, getBindableStacksByLayer(tg,bg->_layerId)->background);
348 case NODE_TextureBackground: {
350 tbg->set_bind = value;
351 bind_node (node, getBindableStacksByLayer(tg,tbg->_layerId)->background);
355 case NODE_OrthoViewpoint: {
357 ovp->set_bind = value;
358 setMenuStatusVP(ovp->description->strptr);
359 bind_node (node, getBindableStacksByLayer(tg,ovp->_layerId)->viewpoint);
361 bind_OrthoViewpoint (ovp);
366 case NODE_Viewpoint: {
368 vp->set_bind = value;
369 setMenuStatusVP (vp->description->strptr);
370 bind_node (node, getBindableStacksByLayer(tg,vp->_layerId)->viewpoint);
377 case NODE_GeoViewpoint: {
379 gvp->set_bind = value;
380 setMenuStatusVP (gvp->description->strptr);
381 bind_node (node, getBindableStacksByLayer(tg,gvp->_layerId)->viewpoint);
383 bind_GeoViewpoint (gvp);
391 fg->set_bind = value;
392 bind_node (node, getBindableStacksByLayer(tg,fg->_layerId)->fog);
399 case NODE_NavigationInfo: {
401 nv->set_bind = value;
402 bind_node (node, getBindableStacksByLayer(tg,nv->_layerId)->navigation);
403 if (value==1) set_naviinfo(nv);
408 ConsoleMessage(
"send_bind_to, cant send a set_bind to %s %p!!\n",stringNodeType(node->_nodeType),node);
418 static size_t setBindofst(
void *node) {
421 switch (tn->_nodeType) {
422 case NODE_Background:
return offsetof(
struct X3D_Background, set_bind);
424 case NODE_Viewpoint:
return offsetof(
struct X3D_Viewpoint, set_bind);
427 case NODE_Fog:
return offsetof(
struct X3D_Fog, set_bind);
429 default: {printf (
"setBindoffst - huh? node type %d\n",tn->_nodeType); }
435 static size_t bindTimeoffst (
struct X3D_Node *node) {
436 X3D_NODE_CHECK(node);
438 switch (node->_nodeType) {
439 case NODE_Background:
return offsetof(
struct X3D_Background, bindTime);
441 case NODE_Viewpoint:
return offsetof(
struct X3D_Viewpoint, bindTime);
444 case NODE_Fog:
return offsetof(
struct X3D_Fog, bindTime);
446 default: {printf (
"bindTimeoffst - huh? node type %s\n",stringNodeType(node->_nodeType)); }
452 static size_t isboundofst(
void *node) {
458 X3D_NODE_CHECK(node);
460 switch (tn->_nodeType) {
461 case NODE_Background:
return offsetof(
struct X3D_Background, isBound);
463 case NODE_Viewpoint:
return offsetof(
struct X3D_Viewpoint, isBound);
466 case NODE_Fog:
return offsetof(
struct X3D_Fog, isBound);
468 default: {printf (
"isBoundoffst - huh? node type %s\n",stringNodeType(tn->_nodeType)); }
472 int removeNodeFromVector(
int iaction,
struct Vector *v,
struct X3D_Node *node);
473 void bind_node (
struct X3D_Node *node,
struct Vector *thisStack) {
478 isBoundPtr = offsetPointer_deref(
int*, node, isboundofst(node));
479 setBindPtr = offsetPointer_deref(
int*, node, setBindofst(node));
482 printf (
"bind_node, node %p (%s), set_bind %d isBound %d\n",node,stringNodeType(node->_nodeType),*setBindPtr,*isBoundPtr);
486 if (*isBoundPtr && (*setBindPtr != 0) ){
488 printf(
"%p already bound\n",node);
500 if (*setBindPtr == 1) {
509 MARK_EVENT (node, (
unsigned int) isboundofst(node));
512 offst = bindTimeoffst(node);
515 dp = offsetPointer_deref(
double*, node, offst);
517 MARK_EVENT (node, offst);
521 if (vectorSize(thisStack)>0) {
524 oldTOS = vector_back(
struct X3D_Node *,thisStack);
527 if (oldTOS == node)
return;
528 isBoundPtr = offsetPointer_deref(
int*, oldTOS, isboundofst(oldTOS));
529 setBindPtr = offsetPointer_deref(
int*, oldTOS, setBindofst(oldTOS));
532 MARK_EVENT (oldTOS, (
unsigned int) isboundofst(oldTOS));
536 vector_pushBack(
struct X3D_Node*,thisStack,node);
539 }
else if (*setBindPtr == 0) {
547 MARK_EVENT (node, (
unsigned int) isboundofst(node));
550 if (vectorSize(thisStack)>0) {
553 oldTOS = vector_back(
struct X3D_Node *,thisStack);
556 if (oldTOS != node) {
557 if(!removeNodeFromVector(0, thisStack, node)){
558 if (node->_nodeType == NODE_Viewpoint){
559 printf (
"can not pop from stack, not top (%p != %p)\n",node,oldTOS);
560 printf (
"%p Viewpoint, description :%s:\n",node,X3D_VIEWPOINT(node)->description->strptr);
561 printf (
"%p Viewpoint, description :%s:\n",oldTOS,X3D_VIEWPOINT(oldTOS)->description->strptr);
562 printf (
"oldTOS, isBound %d, setBindPtr %d\n",*(offsetPointer_deref(
int*, oldTOS, isboundofst(oldTOS))),
563 *(offsetPointer_deref(
int*, oldTOS, setBindofst(oldTOS))));
564 printf(
"and not found in stack\n");
571 vector_popBack(
struct X3D_Node *,thisStack);
572 removeNodeFromVector(0, thisStack, node);
573 if (vectorSize(thisStack)>0) {
575 oldTOS = vector_back(
struct X3D_Node *,thisStack);
578 isBoundPtr = offsetPointer_deref(
int*, oldTOS, isboundofst(oldTOS));
579 setBindPtr = offsetPointer_deref(
int*, oldTOS, setBindofst(oldTOS));
582 MARK_EVENT (oldTOS, (
unsigned int) isboundofst(oldTOS));
591 printf (
"setBindPtr %d\n",*setBindPtr);
597 void bind_Fog(
struct X3D_Fog *node){
617 void render_Fog_OLD (
struct X3D_Fog *node) {
618 #ifndef GL_ES_VERSION_2_0 // this should be handled in material shader
624 GLfloat fog_colour [4];
627 GLDOUBLE unit[16] = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
636 if (node->set_bind < 100) {
638 bind_node (X3D_NODE(node), getActiveBindableStacks(tg)->fog);
644 if(!node->isBound)
return;
645 if (node->visibilityRange <= 0.00001)
return;
647 fog_colour[0] = node->color.c[0];
648 fog_colour[1] = node->color.c[1];
649 fog_colour[2] = node->color.c[2];
650 fog_colour[3] = (float) 1.0;
652 fogptr = node->fogType->strptr;
653 foglen = node->fogType->len;
655 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, mod);
656 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, proj);
658 FW_GLU_UNPROJECT(0.0f,0.0f,0.0f,mod,proj,viewport,&x,&y,&z);
659 FW_GL_TRANSLATE_D(x,y,z);
661 FW_GLU_UNPROJECT(0.0f,0.0f,0.0f,mod,unit,viewport,&x,&y,&z);
663 FW_GLU_PROJECT(x+1,y,z,mod,unit,viewport,&x1,&y1,&z1);
664 sx = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
665 FW_GLU_PROJECT(x,y+1,z,mod,unit,viewport,&x1,&y1,&z1);
666 sy = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
667 FW_GLU_PROJECT(x,y,z+1,mod,unit,viewport,&x1,&y1,&z1);
668 sz = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
670 FW_GL_SCALE_D(sx,sy,sz);
674 FW_GL_FOGFV(GL_FOG_COLOR,fog_colour);
677 if (strcmp(
"LINEAR",fogptr)) {
679 FW_GL_FOGF(GL_FOG_DENSITY, (
float) (4.0)/ (node->visibilityRange));
680 FW_GL_FOGF(GL_FOG_END, (
float) (node->visibilityRange));
681 FW_GL_FOGI(GL_FOG_MODE, GL_EXP);
684 FW_GL_FOGF(GL_FOG_START, (
float) 1.0);
685 FW_GL_FOGF(GL_FOG_END, (
float) (node->visibilityRange));
686 FW_GL_FOGI(GL_FOG_MODE, GL_LINEAR);
702 static void saveBGVert (
float *colptr,
float *pt,
703 int *vertexno,
float *col,
double dist,
704 double x,
double y,
double z) {
706 memcpy (&colptr[*vertexno*3], col,
sizeof(
float)*3);
709 pt[*vertexno*3+0] = (float)(x*dist);
710 pt[*vertexno*3+1] = (float)(y*dist);
711 pt[*vertexno*3+2] = (float)(z*dist);
717 static void moveBackgroundCentre () {
720 GLDOUBLE unit[16] = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
727 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, mod);
729 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, proj);
731 FW_GLU_UNPROJECT(0.0f,0.0f,0.0f,mod,proj,viewport,&x,&y,&z);
732 FW_GL_TRANSLATE_D(x,y,z);
736 FW_GLU_UNPROJECT(0.0f,0.0f,0.0f,mod,unit,viewport,&x,&y,&z);
738 FW_GLU_PROJECT(x+1,y,z,mod,unit,viewport,&x1,&y1,&z1);
739 sx = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
740 FW_GLU_PROJECT(x,y+1,z,mod,unit,viewport,&x1,&y1,&z1);
741 sy = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
742 FW_GLU_PROJECT(x,y,z+1,mod,unit,viewport,&x1,&y1,&z1);
743 sz = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
746 FW_GL_SCALE_D(sx,sy,sz);
754 p.x = p.y = p.z = 0.0;
755 matinverseAFFINE(modi,mod);
756 transform(&p,&p,modi);
757 FW_GL_TRANSLATE_D(p.x,p.y,p.z);
764 transform(&q,&q,mod);
765 sx = 1.0/sqrt( q.x*q.x + q.y*q.y + q.z*q.z );
768 transform(&q,&q,mod);
769 sy = 1.0/sqrt( q.x*q.x + q.y*q.y + q.z*q.z );
772 transform(&q,&q,mod);
773 sz = 1.0/sqrt( q.x*q.x + q.y*q.y + q.z*q.z );
775 FW_GL_SCALE_D(sx,sy,sz);
781 static void recalculateBackgroundVectors(
struct X3D_Background *node) {
785 double va1, va2, ha1, ha2;
793 struct SFColor *skyCol;
int skyColCt;
794 struct SFColor *gndCol;
int gndColCt;
795 float *skyAng;
int skyAngCt;
796 float *gndAng;
int gndAngCt;
797 float *newPoints;
float *newColors;
798 double outsideRadius, insideRadius;
805 outsideRadius = DEFAULT_FARPLANE* 0.750;
806 insideRadius = DEFAULT_FARPLANE * 0.50;
813 if (node->_nodeType == NODE_Background) {
814 skyCol = node->skyColor.p;
815 gndCol = node ->groundColor.p;
816 skyColCt = node->skyColor.n;
817 gndColCt = node->groundColor.n;
818 skyAng = node->skyAngle.p;
819 gndAng = node ->groundAngle.p;
820 skyAngCt = node->skyAngle.n;
821 gndAngCt = node->groundAngle.n;
824 skyCol = tbnode->skyColor.p;
825 gndCol = tbnode ->groundColor.p;
826 skyColCt = tbnode->skyColor.n;
827 gndColCt = tbnode->groundColor.n;
828 skyAng = tbnode->skyAngle.p;
829 gndAng = tbnode ->groundAngle.p;
830 skyAngCt = tbnode->skyAngle.n;
831 gndAngCt = tbnode->groundAngle.n;
835 if ((skyColCt == 0) & (gndColCt == 0)) {
836 if (node->_nodeType == NODE_Background) {
839 FREE_IF_NZ (node->__points.p);
840 FREE_IF_NZ (node->__colours.p);
841 node->__quadcount = 0;
843 tbnode->_ichange = tbnode->_change;
846 FREE_IF_NZ (tbnode->__points.p);
847 FREE_IF_NZ (tbnode->__colours.p);
848 tbnode->__quadcount = 0;
859 estq += (skyColCt-1) * 20 + 20;
870 if(gndColCt == 1) estq += 40;
871 else if (gndColCt>0) estq += (gndColCt-1) * 20;
874 newPoints = MALLOC (GLfloat *,
sizeof (GLfloat) * estq * 3 * 6);
875 newColors = MALLOC (GLfloat *,
sizeof (GLfloat) * estq * 3 * 6);
884 for(h=0; h<hdiv; h++) {
885 ha1 = h * PI*2 / hdiv;
886 ha2 = (h+1) * PI*2 / hdiv;
887 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2)*sin(ha1));
888 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2)*sin(ha2));
889 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1)*sin(ha2));
890 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2)*sin(ha1));
891 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1)*sin(ha2));
892 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1) * sin(ha1));
910 for(v=0; v<(skyColCt-1); v++) {
913 if (skyAngCt>0) { va2 = skyAng[v];}
916 for(h=0; h<hdiv; h++) {
917 ha1 = h * PI*2 / hdiv;
918 ha2 = (h+1) * PI*2 / hdiv;
919 saveBGVert(newColors,newPoints, &actq,&c2->c[0],outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2) * sin(ha1));
920 saveBGVert(newColors,newPoints, &actq,&c2->c[0],outsideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2) * sin(ha2));
921 saveBGVert(newColors,newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1) * sin(ha2));
922 saveBGVert(newColors,newPoints, &actq,&c2->c[0],outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2) * sin(ha1));
923 saveBGVert(newColors,newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1) * sin(ha2));
924 saveBGVert(newColors,newPoints, &actq,&c1->c[0],outsideRadius, sin(va1) * cos(ha1), cos(va1), sin(va1) * sin(ha1));
931 if (va2 < (PI-0.01)) {
932 for(h=0; h<hdiv; h++) {
933 ha1 = h * PI*2 / hdiv;
934 ha2 = (h+1) * PI*2 / hdiv;
935 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(PI) * cos(ha1), cos(PI), sin(PI) * sin(ha1));
936 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(PI) * cos(ha2), cos(PI), sin(PI) * sin(ha2));
937 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(va2) * cos(ha2), cos(va2), sin(va2) * sin(ha2));
938 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(PI) * cos(ha1), cos(PI), sin(PI) * sin(ha1));
939 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(va2) * cos(ha2), cos(va2), sin(va2) * sin(ha2));
940 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(va2) * cos(ha1), cos(va2), sin(va2) * sin(ha1));
950 for(h=0; h<hdiv; h++) {
951 ha1 = h * PI*2 / hdiv;
952 ha2 = (h+1) * PI*2 / hdiv;
954 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI) * cos(ha1), cos(PI), sin(PI) * sin(ha1));
955 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI) * cos(ha2), cos(PI), sin(PI) * sin(ha2));
956 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI/2) * cos(ha2), cos(PI/2), sin(PI/2) * sin(ha2));
957 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI) * cos(ha1), cos(PI), sin(PI) * sin(ha1));
958 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI/2) * cos(ha2), cos(PI/2), sin(PI/2) * sin(ha2));
959 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI/2) * cos(ha1), cos(PI/2), sin(PI/2) * sin(ha1));
963 for(v=0; v<gndColCt-1; v++) {
966 if (v>=gndAngCt) va2 = PI;
967 else va2 = PI - gndAng[v];
969 for(h=0; h<hdiv; h++) {
970 ha1 = h * PI*2 / hdiv;
971 ha2 = (h+1) * PI*2 / hdiv;
973 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1)*sin(ha1));
974 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1)*sin(ha2));
975 saveBGVert(newColors,newPoints,&actq,&c2->c[0],insideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2)*sin(ha2));
976 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1)*sin(ha1));
977 saveBGVert(newColors,newPoints,&actq,&c2->c[0],insideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2)*sin(ha2));
978 saveBGVert(newColors,newPoints,&actq,&c2->c[0],insideRadius, sin(va2) * cos(ha1), cos(va2), sin(va2)*sin(ha1));
987 if (actq > (estq*6)) {
988 printf (
"Background quadcount error, %d > %d\n",
995 if (node->_nodeType == NODE_Background) {
1000 FREE_IF_NZ (node->__points.p);
1001 FREE_IF_NZ (node->__colours.p);
1002 node->__quadcount = actq;
1004 tbnode->_ichange = tbnode->_change;
1006 FREE_IF_NZ (tbnode->__points.p);
1007 FREE_IF_NZ (tbnode->__colours.p);
1008 tbnode->__quadcount = actq;
1016 float *npp = newPoints;
1017 float *ncp = newColors;
1020 if (node->_nodeType == NODE_Background) {
1021 if (node->__VBO == 0) glGenBuffers(1,(
unsigned int*) &node->__VBO);
1023 if (tbnode->__VBO == 0) glGenBuffers(1,(
unsigned int*) &tbnode->__VBO);
1032 for (i=0; i<actq; i++) {
1033 combinedBuffer[i].vert.c[0] = *npp; npp++;
1034 combinedBuffer[i].vert.c[1] = *npp; npp++;
1035 combinedBuffer[i].vert.c[2] = *npp; npp++;
1036 combinedBuffer[i].col.c[0] = *ncp; ncp++;
1037 combinedBuffer[i].col.c[1] = *ncp; ncp++;
1038 combinedBuffer[i].col.c[2] = *ncp; ncp++;
1039 combinedBuffer[i].col.c[3] = 1.0f;
1041 FREE_IF_NZ(newPoints);
1042 FREE_IF_NZ(newColors);
1045 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER,node->__VBO);
1046 glBufferData(GL_ARRAY_BUFFER,
sizeof (
struct MyVertex)*actq, combinedBuffer, GL_STATIC_DRAW);
1047 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER,0);
1050 FREE_IF_NZ(combinedBuffer);
1059 if (renderstate()->render_blend)
return;
1063 if (node->set_bind < 100) {
1064 bind_node (X3D_NODE(node), getActiveBindableStacks(tg)->background);
1068 if(!node->isBound)
return;
1070 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glDisable(GL_FOG);
1073 moveBackgroundCentre();
1075 if (NODE_NEEDS_COMPILING) {
1076 recalculateBackgroundVectors(node);
1084 FW_GL_SCALE_D (viewer->backgroundPlane, viewer->backgroundPlane, viewer->backgroundPlane);
1086 enableGlobalShader(getMyShader(COLOUR_MATERIAL_SHADER));
1088 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, node->__VBO);
1089 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1091 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
1092 FW_GL_VERTEX_POINTER(3, GL_FLOAT, (GLsizei)
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(0));
1093 FW_GL_COLOR_POINTER(4, GL_FLOAT, (GLsizei)
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(
sizeof(
struct SFVec3f)));
1096 sendArraysToGPU (GL_TRIANGLES, 0, node->__quadcount);
1098 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
1099 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1100 finishedWithGlobalShader();
1103 if (((node->backUrl).n>0) ||
1104 ((node->frontUrl).n>0) ||
1105 ((node->leftUrl).n>0) ||
1106 ((node->rightUrl).n>0) ||
1107 ((node->topUrl).n>0) ||
1108 ((node->bottomUrl).n>0)) {
1110 glEnable(GL_TEXTURE_2D);
1112 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,BackgroundVert);
1113 FW_GL_NORMAL_POINTER (GL_FLOAT,0,Backnorms);
1114 FW_GL_TEXCOORD_POINTER (2,GL_FLOAT,0,boxtex,0);
1116 enableGlobalShader(getMyShader(ONE_TEX_APPEARANCE_SHADER));
1119 loadBackgroundTextures(node);
1121 finishedWithGlobalShader();
1126 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glEnable(GL_FOG);
1135 if (renderstate()->render_blend)
return;
1140 if (node->set_bind < 100) {
1141 bind_node (X3D_NODE(node), getActiveBindableStacks(tg)->background);
1145 if(!node->isBound)
return;
1148 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glDisable(GL_FOG);
1151 moveBackgroundCentre();
1153 if NODE_NEEDS_COMPILING
1159 FW_GL_SCALE_D (viewer->backgroundPlane, viewer->backgroundPlane, viewer->backgroundPlane);
1162 enableGlobalShader(getMyShader(COLOUR_MATERIAL_SHADER));
1164 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, node->__VBO);
1165 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1167 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
1168 FW_GL_VERTEX_POINTER(3, GL_FLOAT,
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(0));
1169 FW_GL_COLOR_POINTER(4, GL_FLOAT,
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(
sizeof(
struct SFVec3f)));
1171 sendArraysToGPU (GL_TRIANGLES, 0, node->__quadcount);
1173 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
1174 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1175 finishedWithGlobalShader();
1178 if ((node->backTexture !=0) ||
1179 (node->frontTexture !=0) ||
1180 (node->leftTexture !=0) ||
1181 (node->rightTexture !=0) ||
1182 (node->topTexture !=0) ||
1183 (node->bottomTexture !=0)) {
1186 enableGlobalShader(getMyShader(ONE_TEX_APPEARANCE_SHADER));
1190 loadTextureBackgroundTextures(node);
1192 finishedWithGlobalShader();
1198 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glEnable (GL_FOG);