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"
45#include "../opengl/Textures.h"
47#include "../scenegraph/quaternion.h"
48#include "../scenegraph/Viewer.h"
49#include "../scenegraph/Component_Shape.h"
50#include "../scenegraph/Component_Geospatial.h"
51#include "../scenegraph/RenderFuncs.h"
52#include "../scenegraph/Component_ProgrammableShaders.h"
53#include "../ui/common.h"
54#include "../scenegraph/LinearAlgebra.h"
56void setup_projection();
62 struct SFColorRGBA col;
67static void saveBGVert (
float *colptr,
float *pt,
int *vertexno,
float *col,
double dist,
double x,
double y,
double z) ;
69void init_bindablestack(
bindablestack *bstack,
int layerId,
int nodetype){
70 bstack->background = newVector(
struct X3D_Node*, 2);
71 bstack->viewpoint = newVector(
struct X3D_Node*, 2);
72 bstack->fog = newVector(
struct X3D_Node*, 2);
73 bstack->navigation = newVector(
struct X3D_Node*, 2);
74 bstack->layerId = layerId;
75 loadIdentityMatrix(bstack->screenorientationmatrix);
76 loadIdentityMatrix(bstack->viewtransformmatrix);
77 loadIdentityMatrix(bstack->posorimatrix);
78 loadIdentityMatrix(bstack->stereooffsetmatrix[0]);
79 loadIdentityMatrix(bstack->stereooffsetmatrix[1]);
82 bstack->viewer = NULL;
83 bstack->nodetype = nodetype;
84 loadIdentityMatrix(bstack->pickraymatrix[0]);
85 loadIdentityMatrix(bstack->pickraymatrix[1]);
88 deleteVector(
struct X3D_Node*, bstack->background);
89 deleteVector(
struct X3D_Node*, bstack->viewpoint);
90 deleteVector(
struct X3D_Node*, bstack->fog);
91 deleteVector(
struct X3D_Node*, bstack->navigation);
92 FREE_IF_NZ(bstack->viewer);
98void *Bindable_constructor(){
99 void *v = MALLOCV(
sizeof(
struct pBindable));
103void Bindable_init(
struct tBindable *t){
111 t->prv = Bindable_constructor();
115 ppBindable p = (ppBindable)t->prv;
116 init_bindablestack(&p->bstack,0, NODE_Viewpoint);
118 p->naviinfo.width = 0.25;
119 p->naviinfo.height = 1.6;
120 p->naviinfo.step = 0.75;
121 t->naviinfo = &p->naviinfo;
125void Bindable_clear(
struct tBindable *t){
132 for(i=0;i<vectorSize(t->bstacks);i++){
134 free_bindablestack(bstack);
135 if(i>0) FREE_IF_NZ(bstack);
139bindablestack* getBindableStacksByLayer(ttglobal tg,
int layerId )
144 for(i=0;i<vectorSize(tg->Bindable.bstacks);i++){
145 bstacktmp = vector_get(
bindablestack*,tg->Bindable.bstacks,i);
146 if(bstacktmp->layerId == layerId){
156 int layerId = bstack->layerId;
157 while(vectorSize(tg->Bindable.bstacks)<layerId+1)
159 vector_set(
bindablestack*,tg->Bindable.bstacks,layerId,bstack);
164 return getBindableStacksByLayer(tg,tg->Bindable.activeLayer);
166int getBindableStacksCount(ttglobal tg){
167 return vectorSize(tg->Bindable.bstacks);
169void printStatsBindingStacks()
173 ttglobal tg = gglobal();
174 nstacks = getBindableStacksCount(tg);
175 for(i=0;i<nstacks;i++){
176 bstack = getBindableStacksByLayer(tg,i);
178 ConsoleMessage(
"Layer %d",i);
179 if(i == tg->Bindable.activeLayer)
180 ConsoleMessage(
" activeLayer");
181 ConsoleMessage(
":\n");
184 if(i == tg->Bindable.activeLayer)
186 ConsoleMessage(
"Layer %d%s:\n",i,al);
188 ConsoleMessage(
"%25s %d\n",
"Background stack count", vectorSize(bstack->background));
189 ConsoleMessage(
"%25s %d\n",
"Fog stack count", vectorSize(bstack->fog));
190 ConsoleMessage(
"%25s %d\n",
"Navigation stack count", vectorSize(bstack->navigation));
191 ConsoleMessage(
"%25s %d\n",
"Viewpoint stack count", vectorSize(bstack->viewpoint));
196void set_naviWidthHeightStep(
double wid,
double hei,
double step) {
198 ttglobal tg = gglobal();
199 p = (ppBindable)tg->Bindable.prv;
201 p->naviinfo.width = wid;
202 p->naviinfo.height = hei;
203 p->naviinfo.step = step;
214 X3D_Viewer *
viewer = ViewerByLayerId(node->_layerId);
216 viewer->speed = (double) node->speed;
217 if (node->avatarSize.n < 2) {
220 if(node->avatarSize.n == 1){
223 double avScale = (double)(node->avatarSize.p[0])/1.6;
224 set_naviWidthHeightStep (.25*avScale,1.6*avScale,.75*avScale);
227 set_naviWidthHeightStep ((
double)(node->avatarSize.p[0]),
228 (
double)(node->avatarSize.p[1]),
229 (
double)((node->avatarSize.p[2])));
233 svptr = node->type.p;
236 for (i=0; i<18; i++)
viewer->oktypes[i] = FALSE;
240 for (i = 0; i < node->type.n; i++) {
242 typeptr = svptr[i]->strptr;
244 if (strcmp(typeptr,
"WALK") == 0) {
245 viewer->oktypes[VIEWER_WALK] = TRUE;
246 if (i==0) fwl_set_viewer_type0(
viewer, VIEWER_WALK);
248 if (strcmp(typeptr,
"FLY") == 0) {
249 viewer->oktypes[VIEWER_FLY] = TRUE;
250 if (i==0) fwl_set_viewer_type0(
viewer, VIEWER_FLY);
252 if (strcmp(typeptr,
"EXAMINE") == 0) {
253 viewer->oktypes[VIEWER_EXAMINE] = TRUE;
254 if (i==0) fwl_set_viewer_type0(
viewer, VIEWER_EXAMINE);
256 if (strcmp(typeptr,
"NONE") == 0) {
257 viewer->oktypes[VIEWER_NONE] = TRUE;
258 if (i==0) fwl_set_viewer_type0(
viewer, VIEWER_NONE);
260 if (strcmp(typeptr,
"EXFLY") == 0) {
261 viewer->oktypes[VIEWER_EXFLY] = TRUE;
262 if (i==0) fwl_set_viewer_type0(
viewer, VIEWER_EXFLY);
264 if (strcmp(typeptr,
"EXPLORE") == 0) {
265 viewer->oktypes[VIEWER_EXPLORE] = TRUE;
266 if (i==0) fwl_set_viewer_type0(
viewer, VIEWER_EXPLORE);
268 if (strcmp(typeptr,
"LOOKAT") == 0) {
269 viewer->oktypes[VIEWER_LOOKAT] = TRUE;
272 if (strcmp(typeptr,
"SPHERICAL") == 0) {
273 viewer->oktypes[VIEWER_SPHERICAL] = TRUE;
274 if (i==0) fwl_set_viewer_type0(
viewer, VIEWER_SPHERICAL);
276 if (strcmp(typeptr,
"TURNTABLE") == 0) {
277 viewer->oktypes[VIEWER_TURNTABLE] = TRUE;
278 if (i == 0) fwl_set_viewer_type0(
viewer, VIEWER_TURNTABLE);
280 if (strcmp(typeptr,
"DIST") == 0) {
281 viewer->oktypes[VIEWER_DIST] = TRUE;
282 if (i == 0) fwl_set_viewer_type0(
viewer, VIEWER_DIST);
284 if (strcmp(typeptr,
"PAN") == 0) {
285 viewer->oktypes[VIEWER_PAN] = TRUE;
286 if (i == 0) fwl_set_viewer_type0(
viewer, VIEWER_PAN);
288 if (strcmp(typeptr,
"ZOOM") == 0) {
289 viewer->oktypes[VIEWER_ZOOM] = TRUE;
290 if (i == 0) fwl_set_viewer_type0(
viewer, VIEWER_ZOOM);
293 if (strcmp(typeptr,
"ANY") == 0) {
294 viewer->oktypes[VIEWER_EXAMINE] = TRUE;
295 viewer->oktypes[VIEWER_WALK] = TRUE;
296 viewer->oktypes[VIEWER_EXFLY] = TRUE;
297 viewer->oktypes[VIEWER_FLY] = TRUE;
298 viewer->oktypes[VIEWER_EXPLORE] = TRUE;
299 viewer->oktypes[VIEWER_LOOKAT] = TRUE;
300 viewer->oktypes[VIEWER_SPHERICAL] = TRUE;
301 viewer->oktypes[VIEWER_TURNTABLE] = TRUE;
302 viewer->oktypes[VIEWER_DIST] = TRUE;
303 viewer->oktypes[VIEWER_PAN] = TRUE;
304 viewer->oktypes[VIEWER_ZOOM] = TRUE;
305 if (i==0) fwl_set_viewer_type0(
viewer, VIEWER_WALK);
308 viewer->headlight = node->headlight;
313 viewer->transitionTime = node->transitionTime;
315 if (
viewer->transitionTime < 0.0)
viewer->transitionTime = 0.0;
317 viewer->transitionType = VIEWER_TRANSITION_LINEAR;
318 if (node->transitionType.n > 0) {
319 if (strcmp(
"LINEAR", node->transitionType.p[0]->strptr) == 0)
viewer->transitionType = VIEWER_TRANSITION_LINEAR;
320 else if (strcmp(
"TELEPORT", node->transitionType.p[0]->strptr) == 0)
viewer->transitionType = VIEWER_TRANSITION_TELEPORT;
321 else if (strcmp(
"ANIMATE", node->transitionType.p[0]->strptr) == 0)
viewer->transitionType = VIEWER_TRANSITION_ANIMATE;
323 ConsoleMessage (
"Unknown NavigationInfo transitionType :%s:",node->transitionType.p[0]->strptr);
330int layerFromBindable(
struct X3D_Node *node){
332 switch(node->_nodeType){
334 layerId = X3D_VIEWPOINT(node)->_layerId;
break;
335 case NODE_OrthoViewpoint:
336 layerId = X3D_ORTHOVIEWPOINT(node)->_layerId;
break;
337 case NODE_GeoViewpoint:
338 layerId = X3D_GEOVIEWPOINT(node)->_layerId;
break;
339 case NODE_Background:
340 layerId = X3D_BACKGROUND(node)->_layerId;
break;
341 case NODE_TextureBackground:
342 layerId = X3D_TEXTUREBACKGROUND(node)->_layerId;
break;
344 layerId = X3D_FOG(node)->_layerId;
break;
345 case NODE_NavigationInfo:
346 layerId = X3D_NAVIGATIONINFO(node)->_layerId;
break;
352static int reachable_new_way = 0;
353int is_reachable_new_way() {
354 return reachable_new_way;
357void send_bind_to(
struct X3D_Node *node,
int value) {
359 ttglobal tg = gglobal();
362 layerId = layerFromBindable(node);
363 switch (node->_nodeType) {
364 case NODE_Background: {
366 bg->set_bind = value;
367 bind_node (node, getBindableStacksByLayer(tg,bg->_layerId)->background);
371 case NODE_TextureBackground: {
373 tbg->set_bind = value;
374 bind_node (node, getBindableStacksByLayer(tg,tbg->_layerId)->background);
378 case NODE_OrthoViewpoint: {
380 ovp->set_bind = value;
382 setMenuStatusVP (ovp->description->strptr);
383 bind_node (node, getBindableStacksByLayer(tg,ovp->_layerId)->viewpoint);
385 bind_OrthoViewpoint(ovp);
390 case NODE_Viewpoint: {
392 vp->set_bind = value;
393 setMenuStatusVP (vp->description->strptr);
394 bind_node(node, getBindableStacksByLayer(tg, vp->_layerId)->viewpoint);
401 case NODE_GeoViewpoint: {
403 gvp->set_bind = value;
404 setMenuStatusVP(gvp->description->strptr);
405 bind_node(node, getBindableStacksByLayer(tg, gvp->_layerId)->viewpoint);
407 bind_GeoViewpoint(gvp);
415 fg->set_bind = value;
416 bind_node (node, getBindableStacksByLayer(tg,fg->_layerId)->fog);
423 case NODE_NavigationInfo: {
425 nv->set_bind = value;
426 bind_node (node, getBindableStacksByLayer(tg,nv->_layerId)->navigation);
427 if (value==1) set_naviinfo(nv);
432 ConsoleMessage(
"send_bind_to, cant send a set_bind to %s %p!!\n",stringNodeType(node->_nodeType),node);
442static size_t setBindofst(
void *node) {
445 switch (tn->_nodeType) {
446 case NODE_Background:
return offsetof(
struct X3D_Background, set_bind);
448 case NODE_Viewpoint:
return offsetof(
struct X3D_Viewpoint, set_bind);
451 case NODE_Fog:
return offsetof(
struct X3D_Fog, set_bind);
453 default: {printf (
"setBindoffst - huh? node type %d\n",tn->_nodeType); }
459static size_t bindTimeoffst (
struct X3D_Node *node) {
460 X3D_NODE_CHECK(node);
462 switch (node->_nodeType) {
463 case NODE_Background:
return offsetof(
struct X3D_Background, bindTime);
465 case NODE_Viewpoint:
return offsetof(
struct X3D_Viewpoint, bindTime);
468 case NODE_Fog:
return offsetof(
struct X3D_Fog, bindTime);
470 default: {printf (
"bindTimeoffst - huh? node type %s\n",stringNodeType(node->_nodeType)); }
476static size_t isboundofst(
void *node) {
482 X3D_NODE_CHECK(node);
484 switch (tn->_nodeType) {
485 case NODE_Background:
return offsetof(
struct X3D_Background, isBound);
487 case NODE_Viewpoint:
return offsetof(
struct X3D_Viewpoint, isBound);
490 case NODE_Fog:
return offsetof(
struct X3D_Fog, isBound);
492 default: {printf (
"isBoundoffst - huh? node type %s\n",stringNodeType(tn->_nodeType)); }
496int removeNodeFromVector(
int iaction,
struct Vector *v,
struct X3D_Node *node);
502 isBoundPtr = offsetPointer_deref(
int*, node, isboundofst(node));
503 setBindPtr = offsetPointer_deref(
int*, node, setBindofst(node));
506 printf (
"bind_node, node %p (%s), set_bind %d isBound %d\n",node,stringNodeType(node->_nodeType),*setBindPtr,*isBoundPtr);
510 if (*isBoundPtr && (*setBindPtr != 0) ){
512 printf(
"%p already bound\n",node);
524 if (*setBindPtr == 1) {
533 MARK_EVENT (node, (
unsigned int) isboundofst(node));
536 offst = bindTimeoffst(node);
539 dp = offsetPointer_deref(
double*, node, offst);
541 MARK_EVENT (node, offst);
545 if (vectorSize(thisStack)>0) {
548 oldTOS = vector_back(
struct X3D_Node *,thisStack);
551 if (oldTOS == node)
return;
552 isBoundPtr = offsetPointer_deref(
int*, oldTOS, isboundofst(oldTOS));
553 setBindPtr = offsetPointer_deref(
int*, oldTOS, setBindofst(oldTOS));
556 MARK_EVENT (oldTOS, (
unsigned int) isboundofst(oldTOS));
560 vector_pushBack(
struct X3D_Node*,thisStack,node);
563 }
else if (*setBindPtr == 0) {
571 MARK_EVENT (node, (
unsigned int) isboundofst(node));
574 if (vectorSize(thisStack)>0) {
577 oldTOS = vector_back(
struct X3D_Node *,thisStack);
580 if (oldTOS != node) {
581 if(!removeNodeFromVector(0, thisStack, node)){
582 if (node->_nodeType == NODE_Viewpoint){
585 printf (
"can not pop from stack, not top (%p != %p)\n",node,oldTOS);
586 printf (
"%p Viewpoint, description :%s:\n",node,X3D_VIEWPOINT(node)->description->strptr);
587 printf (
"%p Viewpoint, description :%s:\n",oldTOS,X3D_VIEWPOINT(oldTOS)->description->strptr);
588 printf (
"oldTOS, isBound %d, setBindPtr %d\n",*(offsetPointer_deref(
int*, oldTOS, isboundofst(oldTOS))),
589 *(offsetPointer_deref(
int*, oldTOS, setBindofst(oldTOS))));
590 printf(
"and not found in stack\n");
598 vector_popBack(
struct X3D_Node *,thisStack);
599 removeNodeFromVector(0, thisStack, node);
600 if (vectorSize(thisStack)>0) {
602 oldTOS = vector_back(
struct X3D_Node *,thisStack);
605 isBoundPtr = offsetPointer_deref(
int*, oldTOS, isboundofst(oldTOS));
606 setBindPtr = offsetPointer_deref(
int*, oldTOS, setBindofst(oldTOS));
609 MARK_EVENT (oldTOS, (
unsigned int) isboundofst(oldTOS));
618 printf (
"setBindPtr %d\n",*setBindPtr);
624void bind_Fog(
struct X3D_Fog *node){
644void render_Fog_OLD (
struct X3D_Fog *node) {
645 #ifndef GL_ES_VERSION_2_0
651 GLfloat fog_colour [4];
654 GLDOUBLE unit[16] = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
655 ttglobal tg = gglobal();
663 if (node->set_bind < 100) {
665 bind_node (X3D_NODE(node), getActiveBindableStacks(tg)->fog);
671 if(!node->isBound)
return;
672 if (node->visibilityRange <= 0.00001)
return;
674 fog_colour[0] = node->color.c[0];
675 fog_colour[1] = node->color.c[1];
676 fog_colour[2] = node->color.c[2];
677 fog_colour[3] = (float) 1.0;
679 fogptr = node->fogType->strptr;
680 foglen = node->fogType->len;
682 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, mod);
683 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, proj);
685 FW_GLU_UNPROJECT(0.0f,0.0f,0.0f,mod,proj,viewport,&x,&y,&z);
686 FW_GL_TRANSLATE_D(x,y,z);
688 FW_GLU_UNPROJECT(0.0f,0.0f,0.0f,mod,unit,viewport,&x,&y,&z);
690 FW_GLU_PROJECT(x+1,y,z,mod,unit,viewport,&x1,&y1,&z1);
691 sx = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
692 FW_GLU_PROJECT(x,y+1,z,mod,unit,viewport,&x1,&y1,&z1);
693 sy = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
694 FW_GLU_PROJECT(x,y,z+1,mod,unit,viewport,&x1,&y1,&z1);
695 sz = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
697 FW_GL_SCALE_D(sx,sy,sz);
701 FW_GL_FOGFV(GL_FOG_COLOR,fog_colour);
704 if (strcmp(
"LINEAR",fogptr)) {
706 FW_GL_FOGF(GL_FOG_DENSITY, (
float) (4.0)/ (node->visibilityRange));
707 FW_GL_FOGF(GL_FOG_END, (
float) (node->visibilityRange));
708 FW_GL_FOGI(GL_FOG_MODE, GL_EXP);
711 FW_GL_FOGF(GL_FOG_START, (
float) 1.0);
712 FW_GL_FOGF(GL_FOG_END, (
float) (node->visibilityRange));
713 FW_GL_FOGI(GL_FOG_MODE, GL_LINEAR);
729static void saveBGVert (
float *colptr,
float *pt,
730 int *vertexno,
float *col,
double dist,
731 double x,
double y,
double z) {
733 memcpy (&colptr[*vertexno*3], col,
sizeof(
float)*3);
736 pt[*vertexno*3+0] = (float)(x*dist);
737 pt[*vertexno*3+1] = (float)(y*dist);
738 pt[*vertexno*3+2] = (float)(z*dist);
744static void moveBackgroundCentre () {
747 GLDOUBLE unit[16] = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
751 ttglobal tg = gglobal();
754 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, mod);
756 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, proj);
758 FW_GLU_UNPROJECT(0.0f,0.0f,0.0f,mod,proj,viewport,&x,&y,&z);
759 FW_GL_TRANSLATE_D(x,y,z);
764 FW_GLU_UNPROJECT(0.0f,0.0f,0.0f,mod,unit,viewport,&x,&y,&z);
766 FW_GLU_PROJECT(x+1,y,z,mod,unit,viewport,&x1,&y1,&z1);
767 sx = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
768 FW_GLU_PROJECT(x,y+1,z,mod,unit,viewport,&x1,&y1,&z1);
769 sy = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
770 FW_GLU_PROJECT(x,y,z+1,mod,unit,viewport,&x1,&y1,&z1);
771 sz = 1/sqrt( x1*x1 + y1*y1 + z1*z1*4 );
774 FW_GL_SCALE_D(sx,sy,sz);
783 p.x = p.y = p.z = 0.0;
784 matinverseAFFINE(modi,mod);
785 transform(&p,&p,modi);
786 FW_GL_TRANSLATE_D(p.x,p.y,p.z);
793 transform(&q,&q,mod);
794 sx = 1.0/sqrt( q.x*q.x + q.y*q.y + q.z*q.z );
797 transform(&q,&q,mod);
798 sy = 1.0/sqrt( q.x*q.x + q.y*q.y + q.z*q.z );
801 transform(&q,&q,mod);
802 sz = 1.0/sqrt( q.x*q.x + q.y*q.y + q.z*q.z );
806 FW_GL_SCALE_D(sx,sy,sz);
812static void recalculateBackgroundVectors_old(
struct X3D_Background *node) {
816 double va1, va2, ha1, ha2;
824 struct SFColor *skyCol;
int skyColCt;
825 struct SFColor *gndCol;
int gndColCt;
826 float *skyAng;
int skyAngCt;
827 float *gndAng;
int gndAngCt;
828 float *newPoints;
float *newColors;
829 double outsideRadius, insideRadius;
840 outsideRadius = 1.001;
841 insideRadius = 1.0005;
844 if (node->_nodeType == NODE_Background) {
845 skyCol = node->skyColor.p;
846 gndCol = node ->groundColor.p;
847 skyColCt = node->skyColor.n;
848 gndColCt = node->groundColor.n;
849 skyAng = node->skyAngle.p;
850 gndAng = node ->groundAngle.p;
851 skyAngCt = node->skyAngle.n;
852 gndAngCt = node->groundAngle.n;
855 skyCol = tbnode->skyColor.p;
856 gndCol = tbnode ->groundColor.p;
857 skyColCt = tbnode->skyColor.n;
858 gndColCt = tbnode->groundColor.n;
859 skyAng = tbnode->skyAngle.p;
860 gndAng = tbnode ->groundAngle.p;
861 skyAngCt = tbnode->skyAngle.n;
862 gndAngCt = tbnode->groundAngle.n;
866 if ((skyColCt == 0) && (gndColCt == 0)) {
867 if (node->_nodeType == NODE_Background) {
870 FREE_IF_NZ (node->__points.p);
871 FREE_IF_NZ (node->__colours.p);
872 node->__quadcount = 0;
874 tbnode->_ichange = tbnode->_change;
877 FREE_IF_NZ (tbnode->__points.p);
878 FREE_IF_NZ (tbnode->__colours.p);
879 tbnode->__quadcount = 0;
890 estq += (skyColCt-1) * 20 + 20;
901 if(gndColCt == 1) estq += 40;
902 else if (gndColCt>0) estq += (gndColCt-1) * 20;
905 newPoints = MALLOC (GLfloat *,
sizeof (GLfloat) * estq * 3 * 6);
906 newColors = MALLOC (GLfloat *,
sizeof (GLfloat) * estq * 3 * 6);
913 for(v=0; v < 2; v++) {
914 for(h=0; h<hdiv; h++) {
915 ha1 = h * PI*2 / hdiv;
916 ha2 = (h+1) * PI*2 / hdiv;
917 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2)*sin(ha1));
918 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2)*sin(ha2));
919 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1)*sin(ha2));
920 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2)*sin(ha1));
921 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1)*sin(ha2));
922 saveBGVert (newColors, newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1) * sin(ha1));
940 for(v=0; v<(skyColCt-1); v++) {
943 if (skyAngCt>0) { va2 = skyAng[v];}
946 for(h=0; h<hdiv; h++) {
947 ha1 = h * PI*2 / hdiv;
948 ha2 = (h+1) * PI*2 / hdiv;
949 saveBGVert(newColors,newPoints, &actq,&c2->c[0],outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2) * sin(ha1));
950 saveBGVert(newColors,newPoints, &actq,&c2->c[0],outsideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2) * sin(ha2));
951 saveBGVert(newColors,newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1) * sin(ha2));
952 saveBGVert(newColors,newPoints, &actq,&c2->c[0],outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2) * sin(ha1));
953 saveBGVert(newColors,newPoints, &actq,&c1->c[0],outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1) * sin(ha2));
954 saveBGVert(newColors,newPoints, &actq,&c1->c[0],outsideRadius, sin(va1) * cos(ha1), cos(va1), sin(va1) * sin(ha1));
961 if (va2 < (PI-0.01)) {
962 for(h=0; h<hdiv; h++) {
963 ha1 = h * PI*2 / hdiv;
964 ha2 = (h+1) * PI*2 / hdiv;
965 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(PI) * cos(ha1), cos(PI), sin(PI) * sin(ha1));
966 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(PI) * cos(ha2), cos(PI), sin(PI) * sin(ha2));
967 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(va2) * cos(ha2), cos(va2), sin(va2) * sin(ha2));
968 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(PI) * cos(ha1), cos(PI), sin(PI) * sin(ha1));
969 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(va2) * cos(ha2), cos(va2), sin(va2) * sin(ha2));
970 saveBGVert(newColors,newPoints,&actq,&c2->c[0],outsideRadius, sin(va2) * cos(ha1), cos(va2), sin(va2) * sin(ha1));
980 for(h=0; h<hdiv; h++) {
981 ha1 = h * PI*2 / hdiv;
982 ha2 = (h+1) * PI*2 / hdiv;
984 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI) * cos(ha1), cos(PI), sin(PI) * sin(ha1));
985 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI) * cos(ha2), cos(PI), sin(PI) * sin(ha2));
986 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI/2) * cos(ha2), cos(PI/2), sin(PI/2) * sin(ha2));
987 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI) * cos(ha1), cos(PI), sin(PI) * sin(ha1));
988 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI/2) * cos(ha2), cos(PI/2), sin(PI/2) * sin(ha2));
989 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(PI/2) * cos(ha1), cos(PI/2), sin(PI/2) * sin(ha1));
993 for(v=0; v<gndColCt-1; v++) {
996 if (v>=gndAngCt) va2 = PI;
997 else va2 = PI - gndAng[v];
999 for(h=0; h<hdiv; h++) {
1000 ha1 = h * PI*2 / hdiv;
1001 ha2 = (h+1) * PI*2 / hdiv;
1003 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1)*sin(ha1));
1004 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1)*sin(ha2));
1005 saveBGVert(newColors,newPoints,&actq,&c2->c[0],insideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2)*sin(ha2));
1006 saveBGVert(newColors,newPoints,&actq,&c1->c[0],insideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1)*sin(ha1));
1007 saveBGVert(newColors,newPoints,&actq,&c2->c[0],insideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2)*sin(ha2));
1008 saveBGVert(newColors,newPoints,&actq,&c2->c[0],insideRadius, sin(va2) * cos(ha1), cos(va2), sin(va2)*sin(ha1));
1017 if (actq > (estq*6)) {
1018 printf (
"Background quadcount error, %d > %d\n",
1025 if (node->_nodeType == NODE_Background) {
1030 FREE_IF_NZ (node->__points.p);
1031 FREE_IF_NZ (node->__colours.p);
1032 node->__quadcount = actq;
1034 tbnode->_ichange = tbnode->_change;
1036 FREE_IF_NZ (tbnode->__points.p);
1037 FREE_IF_NZ (tbnode->__colours.p);
1038 tbnode->__quadcount = actq;
1046 float *npp = newPoints;
1047 float *ncp = newColors;
1050 if (node->_nodeType == NODE_Background) {
1051 if (node->__VBO == 0) glGenBuffers(1,(
unsigned int*) &node->__VBO);
1053 if (tbnode->__VBO == 0) glGenBuffers(1,(
unsigned int*) &tbnode->__VBO);
1062 for (i=0; i<actq; i++) {
1063 combinedBuffer[i].vert.c[0] = *npp; npp++;
1064 combinedBuffer[i].vert.c[1] = *npp; npp++;
1065 combinedBuffer[i].vert.c[2] = *npp; npp++;
1066 combinedBuffer[i].col.c[0] = *ncp; ncp++;
1067 combinedBuffer[i].col.c[1] = *ncp; ncp++;
1068 combinedBuffer[i].col.c[2] = *ncp; ncp++;
1069 combinedBuffer[i].col.c[3] = 1.0f;
1071 FREE_IF_NZ(newPoints);
1072 FREE_IF_NZ(newColors);
1075 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER,node->__VBO);
1076 glBufferData(GL_ARRAY_BUFFER,
sizeof (
struct MyVertex)*actq, combinedBuffer, GL_STATIC_DRAW);
1078 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER,0);
1081 FREE_IF_NZ(combinedBuffer);
1085static void recalculateBackgroundVectors(
struct X3D_Background *node) {
1089 double va1, va2, ha1, ha2;
1093 struct Multi_Color *skycolor, *groundcolor, *colours;
1101 struct SFColor *skyCol;
int skyColCt;
1102 struct SFColor *gndCol;
int gndColCt;
1103 float *skyAng;
int skyAngCt;
1104 float *gndAng;
int gndAngCt;
1105 float *newPoints;
float *newColors;
1106 double outsideRadius, insideRadius;
1118 outsideRadius = 1.001;
1119 insideRadius = 1.0005;
1122 if (node->_nodeType == NODE_Background) {
1123 skycolor = &node->skyColor;
1124 skyangle = &node->skyAngle;
1125 groundcolor = &node->groundColor;
1126 groundangle = &node->groundAngle;
1127 colours = &node->__colours;
1128 points = &node->__points;
1129 quadcount = &node->__quadcount;
1132 skycolor = &tbnode->skyColor;
1133 skyangle = &tbnode->skyAngle;
1134 groundcolor = &tbnode->groundColor;
1135 groundangle = &tbnode->groundAngle;
1136 colours = (
struct Multi_Color*)&tbnode->__colours;
1137 points = &tbnode->__points;
1138 quadcount = &tbnode->__quadcount;
1142 if ((skycolor->n == 0) && (groundcolor->n == 0)) {
1143 FREE_IF_NZ (points->p);
1144 FREE_IF_NZ (colours->p);
1146 if (node->_nodeType == NODE_Background) {
1149 tbnode->_ichange = tbnode->_change;
1154 if(skycolor->n && skycolor->n != skyangle->n +1){
1155 ConsoleMessage(
"warning Background: skyColor.n %d should have one more entry than skyAngle.n %d\n",skycolor->n,skyangle->n);
1157 if(groundcolor->n && groundcolor->n != groundangle->n +1){
1158 ConsoleMessage(
"warning Background: groundColor.n %d should have one more entry than groundAngle.n %d\n",groundcolor->n,groundangle->n);
1168 int s_vdiv = max(skyangle->n,2);
1169 if(skyangle->n > 0){
1170 if(skyangle->p[skyangle->n-1]< 1.57) s_vdiv += 1;
1171 if(skyangle->p[skyangle->n-1]< M_PI) s_vdiv += 1;
1173 int g_vdiv = groundangle->n > 0 ? groundangle->n : 0;
1174 g_vdiv = groundcolor->n == 1 ? 1 : g_vdiv;
1175 vdiv = s_vdiv + g_vdiv;
1179 newPoints = MALLOC (GLfloat *,
sizeof (GLfloat) * estq * 3 * 6);
1180 newColors = MALLOC (GLfloat *,
sizeof (GLfloat) * estq * 3 * 6);
1182 float *g_angle = MALLOC (
float *,
sizeof (
float) * (g_vdiv+1));
1183 float *s_angle = MALLOC (
float *,
sizeof (
float) * (s_vdiv+1));
1189 for(
int i=0;i<g_vdiv+1;i++){
1190 if(i==0) g_angle[i] = 0.0f;
1192 if(groundcolor->n == 1) g_angle[i] = M_PI/2.0f;
1193 else g_angle[i] = min(groundangle->p[i-1],M_PI/2.0f);
1195 if(groundcolor->n==1) veccopy3f(g_color[i].c,groundcolor->p[0].c);
1196 else veccopy3f(g_color[i].c,groundcolor->p[i].c);
1201 veccopy3f(lastcolor,skycolor->p[skycolor->n-1].c);
1202 for(
int i=0;i<s_vdiv+1;i++){
1203 if(i==0) s_angle[i] = 0.0f;
1204 else if(i-1<skyangle->n)
1205 s_angle[i] = skyangle->p[i-1];
1206 else if(i==s_vdiv) s_angle[i] = M_PI;
1207 else s_angle[i] = M_PI/2.0;
1208 veccopy3f(s_color[i].c,lastcolor);
1209 if(i < skycolor->n ){
1210 veccopy3f(s_color[i].c,skycolor->p[i].c);
1218 for(
int i=0; i < s_vdiv; i++) {
1222 c2 = s_color[i+1].c;
1224 for(h=0; h<hdiv; h++) {
1225 ha1 = h * PI*2 / hdiv;
1226 ha2 = (h+1) * PI*2 / hdiv;
1227 saveBGVert(newColors,newPoints, &actq,c2,outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2) * sin(ha1));
1228 saveBGVert(newColors,newPoints, &actq,c2,outsideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2) * sin(ha2));
1229 saveBGVert(newColors,newPoints, &actq,c1,outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1) * sin(ha2));
1230 saveBGVert(newColors,newPoints, &actq,c2,outsideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2) * sin(ha1));
1231 saveBGVert(newColors,newPoints, &actq,c1,outsideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1) * sin(ha2));
1232 saveBGVert(newColors,newPoints, &actq,c1,outsideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1) * sin(ha1));
1239 for(
int i=0; i<g_vdiv; i++) {
1240 va1 = M_PI - g_angle[i];
1241 va2 = M_PI - g_angle[i+1];
1243 c2 = g_color[i+1].c;
1244 for(h=0; h<hdiv; h++) {
1245 ha1 = h * PI*2 / hdiv;
1246 ha2 = (h+1) * PI*2 / hdiv;
1248 saveBGVert(newColors,newPoints,&actq,c1,insideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1)*sin(ha1));
1249 saveBGVert(newColors,newPoints,&actq,c1,insideRadius, sin(va1)*cos(ha2), cos(va1), sin(va1)*sin(ha2));
1250 saveBGVert(newColors,newPoints,&actq,c2,insideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2)*sin(ha2));
1251 saveBGVert(newColors,newPoints,&actq,c1,insideRadius, sin(va1)*cos(ha1), cos(va1), sin(va1)*sin(ha1));
1252 saveBGVert(newColors,newPoints,&actq,c2,insideRadius, sin(va2)*cos(ha2), cos(va2), sin(va2)*sin(ha2));
1253 saveBGVert(newColors,newPoints,&actq,c2,insideRadius, sin(va2)*cos(ha1), cos(va2), sin(va2)*sin(ha1));
1261 if (actq > (estq*6)) {
1262 printf (
"Background quadcount error, %d > %d\n",
1269 if (node->_nodeType == NODE_Background) {
1274 FREE_IF_NZ (node->__points.p);
1275 FREE_IF_NZ (node->__colours.p);
1276 node->__quadcount = actq;
1278 tbnode->_ichange = tbnode->_change;
1280 FREE_IF_NZ (tbnode->__points.p);
1281 FREE_IF_NZ (tbnode->__colours.p);
1282 tbnode->__quadcount = actq;
1290 float *npp = newPoints;
1291 float *ncp = newColors;
1294 if (node->_nodeType == NODE_Background) {
1295 if (node->__VBO == 0) glGenBuffers(1,(
unsigned int*) &node->__VBO);
1297 if (tbnode->__VBO == 0) glGenBuffers(1,(
unsigned int*) &tbnode->__VBO);
1306 for (i=0; i<actq; i++) {
1307 combinedBuffer[i].vert.c[0] = *npp; npp++;
1308 combinedBuffer[i].vert.c[1] = *npp; npp++;
1309 combinedBuffer[i].vert.c[2] = *npp; npp++;
1310 combinedBuffer[i].col.c[0] = *ncp; ncp++;
1311 combinedBuffer[i].col.c[1] = *ncp; ncp++;
1312 combinedBuffer[i].col.c[2] = *ncp; ncp++;
1313 combinedBuffer[i].col.c[3] = 1.0f;
1315 FREE_IF_NZ(newPoints);
1316 FREE_IF_NZ(newColors);
1319 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER,node->__VBO);
1320 glBufferData(GL_ARRAY_BUFFER,
sizeof (
struct MyVertex)*actq, combinedBuffer, GL_STATIC_DRAW);
1322 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER,0);
1325 FREE_IF_NZ(combinedBuffer);
1333 double va1, va2, ha1, ha2;
1337 struct Multi_Color* skycolor, * groundcolor, * colours;
1344 struct SFColor* skyCol;
int skyColCt;
1345 struct SFColor* gndCol;
int gndColCt;
1346 float* skyAng;
int skyAngCt;
1347 float* gndAng;
int gndAngCt;
1348 float* newPoints;
float* newColors;
1349 double outsideRadius, insideRadius;
1360 outsideRadius = 1.001;
1361 insideRadius = 1.0005;
1365 skycolor = &node->skyColor;
1366 skyangle = &node->skyAngle;
1367 groundcolor = &node->groundColor;
1368 groundangle = &node->groundAngle;
1370 points = &node->__points;
1371 quadcount = &node->__quadcount;
1375 if ((skycolor->n == 0) && (groundcolor->n == 0)) {
1376 FREE_IF_NZ(points->p);
1377 FREE_IF_NZ(colours->p);
1383 if (skycolor->n && skycolor->n != skyangle->n + 1) {
1384 ConsoleMessage(
"warning TextureBackground: skyColor.n %d should have one more entry than skyAngle.n %d\n", skycolor->n, skyangle->n);
1386 if (groundcolor->n && groundcolor->n != groundangle->n + 1) {
1387 ConsoleMessage(
"warning TextureBackground: groundColor.n %d should have one more entry than groundAngle.n %d\n", groundcolor->n, groundangle->n);
1397 int s_vdiv = max(skyangle->n, 2);
1398 if (skyangle->n > 0) {
1399 if (skyangle->p[skyangle->n - 1] < 1.57) s_vdiv += 1;
1400 if (skyangle->p[skyangle->n - 1] < M_PI) s_vdiv += 1;
1402 int g_vdiv = groundangle->n > 0 ? groundangle->n : 0;
1403 g_vdiv = groundcolor->n == 1 ? 1 : g_vdiv;
1404 vdiv = s_vdiv + g_vdiv;
1408 newPoints = MALLOC(GLfloat*,
sizeof(GLfloat) * estq * 3 * 6);
1409 newColors = MALLOC(GLfloat*,
sizeof(GLfloat) * estq * 3 * 6);
1411 float* g_angle = MALLOC(
float*,
sizeof(
float) * (g_vdiv + 1));
1412 float* s_angle = MALLOC(
float*,
sizeof(
float) * (s_vdiv + 1));
1418 for (
int i = 0; i < g_vdiv + 1; i++) {
1419 if (i == 0) g_angle[i] = 0.0f;
1421 if (groundcolor->n == 1) g_angle[i] = M_PI / 2.0f;
1422 else g_angle[i] = min(groundangle->p[i - 1], M_PI / 2.0f);
1424 if (groundcolor->n == 1) veccopy3f(g_color[i].c, groundcolor->p[0].c);
1425 else veccopy3f(g_color[i].c, groundcolor->p[i].c);
1430 veccopy3f(lastcolor, skycolor->p[skycolor->n - 1].c);
1431 for (
int i = 0; i < s_vdiv + 1; i++) {
1432 if (i == 0) s_angle[i] = 0.0f;
1433 else if (i - 1 < skyangle->n)
1434 s_angle[i] = skyangle->p[i - 1];
1435 else if (i == s_vdiv) s_angle[i] = M_PI;
1436 else s_angle[i] = M_PI / 2.0;
1437 veccopy3f(s_color[i].c, lastcolor);
1438 if (i < skycolor->n) {
1439 veccopy3f(s_color[i].c, skycolor->p[i].c);
1447 for (
int i = 0; i < s_vdiv; i++) {
1449 va2 = s_angle[i + 1];
1451 c2 = s_color[i + 1].c;
1453 for (h = 0; h < hdiv; h++) {
1454 ha1 = h * PI * 2 / hdiv;
1455 ha2 = (h + 1) * PI * 2 / hdiv;
1456 saveBGVert(newColors, newPoints, &actq, c2, outsideRadius, sin(va2) * cos(ha1), cos(va2), sin(va2) * sin(ha1));
1457 saveBGVert(newColors, newPoints, &actq, c2, outsideRadius, sin(va2) * cos(ha2), cos(va2), sin(va2) * sin(ha2));
1458 saveBGVert(newColors, newPoints, &actq, c1, outsideRadius, sin(va1) * cos(ha2), cos(va1), sin(va1) * sin(ha2));
1459 saveBGVert(newColors, newPoints, &actq, c2, outsideRadius, sin(va2) * cos(ha1), cos(va2), sin(va2) * sin(ha1));
1460 saveBGVert(newColors, newPoints, &actq, c1, outsideRadius, sin(va1) * cos(ha2), cos(va1), sin(va1) * sin(ha2));
1461 saveBGVert(newColors, newPoints, &actq, c1, outsideRadius, sin(va1) * cos(ha1), cos(va1), sin(va1) * sin(ha1));
1468 for (
int i = 0; i < g_vdiv; i++) {
1469 va1 = M_PI - g_angle[i];
1470 va2 = M_PI - g_angle[i + 1];
1472 c2 = g_color[i + 1].c;
1473 for (h = 0; h < hdiv; h++) {
1474 ha1 = h * PI * 2 / hdiv;
1475 ha2 = (h + 1) * PI * 2 / hdiv;
1477 saveBGVert(newColors, newPoints, &actq, c1, insideRadius, sin(va1) * cos(ha1), cos(va1), sin(va1) * sin(ha1));
1478 saveBGVert(newColors, newPoints, &actq, c1, insideRadius, sin(va1) * cos(ha2), cos(va1), sin(va1) * sin(ha2));
1479 saveBGVert(newColors, newPoints, &actq, c2, insideRadius, sin(va2) * cos(ha2), cos(va2), sin(va2) * sin(ha2));
1480 saveBGVert(newColors, newPoints, &actq, c1, insideRadius, sin(va1) * cos(ha1), cos(va1), sin(va1) * sin(ha1));
1481 saveBGVert(newColors, newPoints, &actq, c2, insideRadius, sin(va2) * cos(ha2), cos(va2), sin(va2) * sin(ha2));
1482 saveBGVert(newColors, newPoints, &actq, c2, insideRadius, sin(va2) * cos(ha1), cos(va2), sin(va2) * sin(ha1));
1490 if (actq > (estq * 6)) {
1491 printf(
"Background quadcount error, %d > %d\n",
1500 FREE_IF_NZ(node->__points.p);
1501 FREE_IF_NZ(node->__colours.p);
1502 node->__quadcount = actq;
1510 float* npp = newPoints;
1511 float* ncp = newColors;
1514 if (node->__VBO == 0) glGenBuffers(1, (
unsigned int*)&node->__VBO);
1522 for (i = 0; i < actq; i++) {
1523 combinedBuffer[i].vert.c[0] = *npp; npp++;
1524 combinedBuffer[i].vert.c[1] = *npp; npp++;
1525 combinedBuffer[i].vert.c[2] = *npp; npp++;
1526 combinedBuffer[i].col.c[0] = *ncp; ncp++;
1527 combinedBuffer[i].col.c[1] = *ncp; ncp++;
1528 combinedBuffer[i].col.c[2] = *ncp; ncp++;
1529 combinedBuffer[i].col.c[3] = 1.0f;
1531 FREE_IF_NZ(newPoints);
1532 FREE_IF_NZ(newColors);
1535 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, node->__VBO);
1536 glBufferData(GL_ARRAY_BUFFER,
sizeof(
struct MyVertex) * actq, combinedBuffer, GL_STATIC_DRAW);
1538 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
1541 FREE_IF_NZ(combinedBuffer);
1547 if (renderstate()->render_blend)
return;
1548 if(!node->isBound)
return;
1551 double viewi[16], mat[16], bmat[16];
1553 ttglobal tg = gglobal();
1555 bstack = getActiveBindableStacks(tg);
1556 matinverseAFFINE(viewi,bstack->viewmatrix);
1557 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX,mat);
1560 matmultiplyAFFINE(bmat, mat, viewi);
1561 matrixAFFINE2RotationMatrix(bstack->backgroundmatrix, bmat);
1566 if (renderstate()->render_blend)
return;
1567 if(!node->isBound)
return;
1570 double viewi[16], mat[16], bmat[16];
1572 ttglobal tg = gglobal();
1574 bstack = getActiveBindableStacks(tg);
1575 matinverseAFFINE(viewi,bstack->viewmatrix);
1576 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX,mat);
1579 matmultiplyAFFINE(bmat, mat, viewi);
1580 matrixAFFINE2RotationMatrix(bstack->backgroundmatrix, bmat);
1584 ttglobal tg = gglobal();
1586 X3D_Viewer *
viewer = Viewer();
1588 if (renderstate()->render_blend)
return;
1592 if (node->set_bind < 100) {
1593 bind_node (X3D_NODE(node), getActiveBindableStacks(tg)->background);
1597 if(!node->isBound)
return;
1599 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glDisable(GL_FOG);
1602 moveBackgroundCentre();
1604 if (NODE_NEEDS_COMPILING) {
1605 recalculateBackgroundVectors(node);
1618 glDisable(GL_DEPTH_TEST);
1619 enableGlobalShader(getMyShader(COLOUR_MATERIAL_SHADER));
1620 initialize_front_and_back_material_params();
1623 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1624 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, node->__VBO);
1625 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
1626 FW_GL_VERTEX_POINTER(3, GL_FLOAT, (GLsizei)
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(0));
1627 FW_GL_COLOR_POINTER(4, GL_FLOAT, (GLsizei)
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(
sizeof(
struct SFVec3f)));
1630 sendArraysToGPU (GL_TRIANGLES, 0, node->__quadcount);
1633 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
1634 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1635 finishedWithGlobalShader();
1638 if (((node->backUrl).n>0) ||
1639 ((node->frontUrl).n>0) ||
1640 ((node->leftUrl).n>0) ||
1641 ((node->rightUrl).n>0) ||
1642 ((node->topUrl).n>0) ||
1643 ((node->bottomUrl).n>0)) {
1645 glEnable(GL_TEXTURE_2D);
1647 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,BackgroundVert);
1648 FW_GL_NORMAL_POINTER (GL_FLOAT,0,Backnorms);
1649 FW_GL_TEXCOORD_POINTER (2,GL_FLOAT,0,boxtex,0);
1651 enableGlobalShader(getMyShader(ONE_TEX_APPEARANCE_SHADER));
1652 initialize_front_and_back_material_params();
1654 loadBackgroundTextures(node);
1656 finishedWithGlobalShader();
1658 glEnable(GL_DEPTH_TEST);
1663 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glEnable(GL_FOG);
1677void fw_gluPerspective_2(GLDOUBLE xcenter, GLDOUBLE fovy, GLDOUBLE aspect, GLDOUBLE zNear, GLDOUBLE zFar);
1678void fw_depth_slice_push(
double nearplane,
double farplane){
1698 double save_nearPlane, save_farPlane;
1699 X3D_Viewer *
viewer = Viewer();
1701 FW_GL_MATRIX_MODE(GL_PROJECTION);
1702 FW_GL_PUSH_MATRIX();
1704 save_nearPlane =
viewer->nearPlane;
1705 save_farPlane =
viewer->farPlane;
1706 viewer->nearPlane = nearplane;
1707 viewer->farPlane = farplane;
1709 viewer->nearPlane = save_nearPlane;
1710 viewer->farPlane = save_farPlane;
1712void fw_depth_slice_pop(){
1713 FW_GL_MATRIX_MODE(GL_PROJECTION);
1715 FW_GL_MATRIX_MODE(GL_MODELVIEW);
1721 ttglobal tg = gglobal();
1722 X3D_Viewer *
viewer = Viewer();
1724 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glDisable(GL_FOG);
1730 moveBackgroundCentre();
1735 double pp[3], mvmat[16], mvinv[16];
1737 ttglobal tg = gglobal();
1738 bstack = getActiveBindableStacks(tg);
1739 FW_GL_MATRIX_MODE(GL_MODELVIEW);
1740 FW_GL_PUSH_MATRIX();
1741 FW_GL_TRANSFORM_D(bstack->backgroundmatrix);
1747 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, mvmat);
1748 matinverseAFFINE(mvinv,mvmat);
1749 vecsetd(pp,0.0,0.0,0.0);
1750 transformAFFINEd(pp,pp,mvinv);
1751 FW_GL_TRANSLATE_D(pp[0],pp[1],pp[2]);
1754 double sx,sy,sz, q[3],p[3],d[3];
1756 vecsetd(p,0.0,0.0,0.0);
1757 transformAFFINEd(p,p,mvmat);
1758 vecsetd(q,1.0,0.0,0.0);
1759 transformAFFINEd(q,q,mvmat);
1760 sx = 1.0/veclengthd(vecdifd(d,q,p));
1761 vecsetd(q,0.0,1.0,0.0);
1762 transformAFFINEd(q,q,mvmat);
1763 sy = 1.0/veclengthd(vecdifd(d,q,p));
1764 vecsetd(q,0.0,0.0,1.0);
1765 transformAFFINEd(q,q,mvmat);
1766 sz = 1.0/veclengthd(vecdifd(d,q,p));
1768 FW_GL_SCALE_D(sx,sy,sz);
1774 FW_GL_MATRIX_MODE(GL_MODELVIEW);
1775 FW_GL_PUSH_MATRIX();
1776 FW_GL_LOAD_IDENTITY();
1779 double matA2BVVA[16],matBVVA2A[16];
1780 avatar2BoundViewpointVerticalAvatar(matA2BVVA,matBVVA2A);
1781 fw_glSetDoublev(GL_MODELVIEW_MATRIX,matBVVA2A);
1785 if (NODE_NEEDS_COMPILING) {
1786 recalculateBackgroundVectors(node);
1798 didPerspective = FALSE;
1809 FW_GL_SCALE_D (bgscale, bgscale, bgscale);
1812 GLclampd znear, zfar;
1813 fw_depth_slice_push(.1,100);
1814 didPerspective = TRUE;
1816 glDisable(GL_DEPTH_TEST);
1817 glDepthMask(GL_FALSE);
1818 initialize_front_and_back_material_params();
1819 enableGlobalShader(getMyShader(COLOUR_MATERIAL_SHADER));
1822 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1823 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, node->__VBO);
1824 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
1825 FW_GL_VERTEX_POINTER(3, GL_FLOAT, (GLsizei)
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(0));
1826 FW_GL_COLOR_POINTER(4, GL_FLOAT, (GLsizei)
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(
sizeof(
struct SFVec3f)));
1827 clear_textureUnit_used();
1828 clear_material_samplers();
1829 clear_materialparameters_per_draw_counts();
1832 sendArraysToGPU (GL_TRIANGLES, 0, node->__quadcount);
1835 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
1836 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1837 finishedWithGlobalShader();
1840 if (((node->backUrl).n>0) ||
1841 ((node->frontUrl).n>0) ||
1842 ((node->leftUrl).n>0) ||
1843 ((node->rightUrl).n>0) ||
1844 ((node->topUrl).n>0) ||
1845 ((node->bottomUrl).n>0)) {
1846 glEnable(GL_TEXTURE_2D);
1848 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,BackgroundVert);
1849 FW_GL_NORMAL_POINTER (GL_FLOAT,0,Backnorms);
1850 FW_GL_TEXCOORD_POINTER (2,GL_FLOAT,0,boxtex,0);
1852 enableGlobalShader(getMyShader(ONE_TEX_APPEARANCE_SHADER));
1855 loadBackgroundTextures(node);
1856 finishedWithGlobalShader();
1858 glDepthMask(GL_TRUE);
1859 glEnable(GL_DEPTH_TEST);
1862 FW_GL_MATRIX_MODE(GL_PROJECTION);
1864 FW_GL_MATRIX_MODE(GL_MODELVIEW);
1867 fw_depth_slice_pop();
1873 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glEnable(GL_FOG);
1878 ttglobal tg = gglobal();
1880 X3D_Viewer *
viewer = Viewer();
1882 if (renderstate()->render_blend)
return;
1887 if (node->set_bind < 100) {
1888 bind_node (X3D_NODE(node), getActiveBindableStacks(tg)->background);
1892 if(!node->isBound)
return;
1895 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glDisable(GL_FOG);
1898 moveBackgroundCentre();
1900 if NODE_NEEDS_COMPILING
1907 glDisable(GL_DEPTH_TEST);
1909 enableGlobalShader(getMyShader(COLOUR_MATERIAL_SHADER));
1911 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, node->__VBO);
1914 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
1915 FW_GL_VERTEX_POINTER(3, GL_FLOAT,
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(0));
1916 FW_GL_COLOR_POINTER(4, GL_FLOAT,
sizeof(
struct MyVertex), (GLfloat *)BUFFER_OFFSET(
sizeof(
struct SFVec3f)));
1918 sendArraysToGPU (GL_TRIANGLES, 0, node->__quadcount);
1920 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
1921 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
1922 finishedWithGlobalShader();
1925 if ((node->backTexture !=0) ||
1926 (node->frontTexture !=0) ||
1927 (node->leftTexture !=0) ||
1928 (node->rightTexture !=0) ||
1929 (node->topTexture !=0) ||
1930 (node->bottomTexture !=0)) {
1933 enableGlobalShader(getMyShader(ONE_TEX_APPEARANCE_SHADER));
1937 loadTextureBackgroundTextures(node);
1939 finishedWithGlobalShader();
1942 glEnable(GL_DEPTH_TEST);
1947 if (vectorSize(getActiveBindableStacks(tg)->fog) >0) glEnable (GL_FOG);
1967 ttglobal tg = gglobal();
1968 X3D_Viewer*
viewer = Viewer();
1970 if (vectorSize(getActiveBindableStacks(tg)->fog) > 0) glDisable(GL_FOG);
1976 moveBackgroundCentre();
1982 double pp[3], mvmat[16], mvinv[16];
1984 ttglobal tg = gglobal();
1985 bstack = getActiveBindableStacks(tg);
1986 FW_GL_MATRIX_MODE(GL_MODELVIEW);
1987 FW_GL_PUSH_MATRIX();
1988 FW_GL_TRANSFORM_D(bstack->backgroundmatrix);
1994 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, mvmat);
1995 matinverseAFFINE(mvinv, mvmat);
1996 vecsetd(pp, 0.0, 0.0, 0.0);
1997 transformAFFINEd(pp, pp, mvinv);
1998 FW_GL_TRANSLATE_D(pp[0], pp[1], pp[2]);
2001 double sx, sy, sz, q[3], p[3], d[3];
2003 vecsetd(p, 0.0, 0.0, 0.0);
2004 transformAFFINEd(p, p, mvmat);
2005 vecsetd(q, 1.0, 0.0, 0.0);
2006 transformAFFINEd(q, q, mvmat);
2007 sx = 1.0 / veclengthd(vecdifd(d, q, p));
2008 vecsetd(q, 0.0, 1.0, 0.0);
2009 transformAFFINEd(q, q, mvmat);
2010 sy = 1.0 / veclengthd(vecdifd(d, q, p));
2011 vecsetd(q, 0.0, 0.0, 1.0);
2012 transformAFFINEd(q, q, mvmat);
2013 sz = 1.0 / veclengthd(vecdifd(d, q, p));
2015 FW_GL_SCALE_D(sx, sy, sz);
2022 FW_GL_MATRIX_MODE(GL_MODELVIEW);
2023 FW_GL_PUSH_MATRIX();
2024 FW_GL_LOAD_IDENTITY();
2027 double matA2BVVA[16], matBVVA2A[16];
2028 avatar2BoundViewpointVerticalAvatar(matA2BVVA, matBVVA2A);
2029 fw_glSetDoublev(GL_MODELVIEW_MATRIX, matBVVA2A);
2033 if (NODE_NEEDS_COMPILING) {
2034 recalculateTextureBackgroundVectors(node);
2046 didPerspective = FALSE;
2057 FW_GL_SCALE_D(bgscale, bgscale, bgscale);
2061 GLclampd znear, zfar;
2062 fw_depth_slice_push(.1, 100);
2063 didPerspective = TRUE;
2065 glDisable(GL_DEPTH_TEST);
2066 glDepthMask(GL_FALSE);
2067 enableGlobalShader(getMyShader(COLOUR_MATERIAL_SHADER));
2071 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
2072 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, node->__VBO);
2073#define BUFFER_OFFSET(i) ((char *)NULL + (i))
2074 FW_GL_VERTEX_POINTER(3, GL_FLOAT, (GLsizei)
sizeof(
struct MyVertex), (GLfloat*)BUFFER_OFFSET(0));
2075 FW_GL_COLOR_POINTER(4, GL_FLOAT, (GLsizei)
sizeof(
struct MyVertex), (GLfloat*)BUFFER_OFFSET(
sizeof(
struct SFVec3f)));
2078 if (setupShaderB()) {
2079 sendArraysToGPU(GL_TRIANGLES, 0, node->__quadcount);
2082 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
2083 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
2084 finishedWithGlobalShader();
2088 if ((node->backTexture != 0) ||
2089 (node->frontTexture != 0) ||
2090 (node->leftTexture != 0) ||
2091 (node->rightTexture != 0) ||
2092 (node->topTexture != 0) ||
2093 (node->bottomTexture != 0)) {
2095 glEnable(GL_TEXTURE_2D);
2097 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,BackgroundVert);
2098 FW_GL_NORMAL_POINTER (GL_FLOAT,0,Backnorms);
2099 FW_GL_TEXCOORD_POINTER (2,GL_FLOAT,0,boxtex,0);
2101 enableGlobalShader(getMyShader(ONE_TEX_APPEARANCE_SHADER));
2103 loadTextureBackgroundTextures(node);
2105 finishedWithGlobalShader();
2108 glDepthMask(GL_TRUE);
2109 glEnable(GL_DEPTH_TEST);
2110 if (didPerspective) {
2112 FW_GL_MATRIX_MODE(GL_PROJECTION);
2114 FW_GL_MATRIX_MODE(GL_MODELVIEW);
2117 fw_depth_slice_pop();
2123 if (vectorSize(getActiveBindableStacks(tg)->fog) > 0) glEnable(GL_FOG);
2126void render_bound_background(){
2130 ttglobal tg = gglobal();
2131 if (vectorSize(getActiveBindableStacks(tg)->background) >0){
2132 struct X3D_Node * node = vector_back(
struct X3D_Node *,getActiveBindableStacks(tg)->background);
2133 switch(node->_nodeType){
2134 case NODE_Background:
2137 case NODE_TextureBackground: