35 #include <libFreeWRL.h>
37 #include "../vrml_parser/Structs.h"
38 #include "../vrml_parser/CRoutes.h"
39 #include "../main/headers.h"
41 #include "../opengl/OpenGL_Utils.h"
42 #include "../opengl/Frustum.h"
43 #include "../opengl/Material.h"
45 #include "LinearAlgebra.h"
47 #include "../scenegraph/RenderFuncs.h"
53 node->__do_center = verify_translate ((GLfloat *)node->center.c);
54 node->__do_trans = verify_translate ((GLfloat *)node->translation.c);
55 node->__do_scale = verify_scale ((GLfloat *)node->scale.c);
56 node->__do_rotation = verify_rotate ((GLfloat *)node->rotation.c);
57 node->__do_scaleO = verify_rotate ((GLfloat *)node->scaleOrientation.c);
59 node->__do_anything = (node->__do_center ||
62 node->__do_rotation ||
65 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
71 void compile_Group(
struct X3D_Group *node) {
72 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
85 void prep_Group (
struct X3D_Group *node) {
122 if(!renderstate()->render_vp) {
124 if (node->__do_anything) {
129 if (node->__do_trans)
130 FW_GL_TRANSLATE_F(node->translation.c[0],node->translation.c[1],node->translation.c[2]);
133 if (node->__do_center)
134 FW_GL_TRANSLATE_F(node->center.c[0],node->center.c[1],node->center.c[2]);
137 if (node->__do_rotation) {
138 FW_GL_ROTATE_RADIANS(node->rotation.c[3], node->rotation.c[0],node->rotation.c[1],node->rotation.c[2]);
142 if (node->__do_scaleO) {
143 FW_GL_ROTATE_RADIANS(node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
148 if (node->__do_scale)
149 FW_GL_SCALE_F(node->scale.c[0],node->scale.c[1],node->scale.c[2]);
152 if (node->__do_scaleO)
153 FW_GL_ROTATE_RADIANS(-node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
156 if (node->__do_center)
157 FW_GL_TRANSLATE_F(-node->center.c[0],-node->center.c[1],-node->center.c[2]);
169 if(!renderstate()->render_vp) {
170 if (node->__do_anything) {
175 if((node->_renderFlags & VF_Viewpoint) == VF_Viewpoint) {
176 FW_GL_TRANSLATE_F(((node->center).c[0]),((node->center).c[1]),((node->center).c[2])
178 FW_GL_ROTATE_RADIANS(((node->scaleOrientation).c[3]),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
180 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]))
182 FW_GL_ROTATE_RADIANS(-(((node->scaleOrientation).c[3])),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
184 FW_GL_ROTATE_RADIANS(-(((node->rotation).c[3])),((node->rotation).c[0]),((node->rotation).c[1]),((node->rotation).c[2])
186 FW_GL_TRANSLATE_F(-(((node->center).c[0])),-(((node->center).c[1])),-(((node->center).c[2]))
188 FW_GL_TRANSLATE_F(-(((node->translation).c[0])),-(((node->translation).c[1])),-(((node->translation).c[2]))
198 int wc = node->whichChoice;
203 if(node->children.n){
204 pp = node->children.p;
205 n = node->children.n;
206 }
else if(node->choice.n){
211 if(wc >= 0 && wc < n){
231 void sib_prep_LocalFog(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
232 void sib_prep_DirectionalLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
233 void sib_prep_SpotlLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
234 void sib_prep_PointLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
235 void sib_prep_ClipPlane(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
236 void sib_prep_Effect(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
239 switch(sibAffector->_nodeType){
240 case NODE_DirectionalLight:
241 sib_prep_DirectionalLight(parent,sibAffector);
break;
243 sib_prep_SpotlLight(parent,sibAffector);
break;
244 case NODE_PointLight:
245 sib_prep_PointLight(parent,sibAffector);
break;
247 sib_prep_LocalFog(parent,sibAffector);
break;
249 sib_prep_ClipPlane(parent,sibAffector);
break;
251 sib_prep_Effect(parent,sibAffector);
break;
257 void sib_fin_LocalFog(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
258 void sib_fin_DirectionalLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
259 void sib_fin_SpotlLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
260 void sib_fin_PointLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
261 void sib_fin_ClipPlane(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
265 switch(sibAffector->_nodeType){
266 case NODE_DirectionalLight:
267 sib_fin_DirectionalLight(parent,sibAffector);
break;
269 sib_fin_SpotlLight(parent,sibAffector);
break;
270 case NODE_PointLight:
271 sib_fin_PointLight(parent,sibAffector);
break;
273 sib_fin_LocalFog(parent,sibAffector);
break;
275 sib_fin_ClipPlane(parent,sibAffector);
break;
277 sib_fin_Effect(parent,sibAffector);
break;
285 for(j=0;j<affectors->n;j++){
286 struct X3D_Node *sa = affectors->p[j];
294 for(jj=0;jj<affectors->n;jj++){
298 j = affectors->n - jj - 1;
299 sa = affectors->p[j];
309 RETURN_FROM_CHILD_IF_NOT_FOR_ME
312 if NODE_NEEDS_COMPILING {
313 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
320 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
323 normalChildren(node->_sortedChildren);
326 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
330 void child_Group (
struct X3D_Group *node) {
350 RETURN_FROM_CHILD_IF_NOT_FOR_ME
355 if (rs->render_geom) {
356 if (node->_renderFlags & VF_HideLeft && (viewer_iside() == 0) ) {
359 if (node->_renderFlags & VF_HideRight && (viewer_iside() == 1) ) {
364 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
372 printf (
"child_Group, children.n %d sortedChildren.n %d\n",node->children.n, node->_sortedChildren.n);
374 printf (
"child_Group, this %p rf %x isProto %d\n",node,node->_renderFlags, node->FreeWRL__protoDef);
377 for (x=0; x<nc; x++) {
378 xx = X3D_NODE(node->_sortedChildren.p[x]);
380 printf (
" %d: ch %p type %s dist %f\n",x, node->_sortedChildren.p[x],stringNodeType(xx->_nodeType),xx->_dist);
381 else printf (
" chiuld %d null\n",x);
383 for (x=0; x<nc; x++) {
384 xx = X3D_NODE(node->_sortedChildren.p[x]);
386 printf (
" %d: sch %p type %s dist %f\n",x, node->_sortedChildren.p[x],stringNodeType(xx->_nodeType),xx->_dist);
387 else printf (
" chiuld %d null\n",x);
403 normalChildren(node->_sortedChildren);
408 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
418 RETURN_FROM_CHILD_IF_NOT_FOR_ME
423 if (rs->render_geom) {
424 if (node->_renderFlags & VF_HideLeft && (viewer_iside() == 0) ) {
427 if (node->_renderFlags & VF_HideRight && (viewer_iside() == 1) ) {
434 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
449 printf (
"transform - doing normalChildren\n");
452 normalChildren(node->_sortedChildren);
455 printf (
"transform - done normalChildren\n");
459 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
465 char ciflag_get(
int flags,
int index){
466 char *cflags = (
char *)(&flags);
467 return cflags[index];
469 int ciflag_set(
int flags,
char flag,
int index ){
470 char *cflags = (
char *)(&flags);
471 cflags[index] = flag;
474 void prep_Proto (
struct X3D_Proto *node) {
475 if(0)printf(
"in prep_proto\n");
476 load_externProtoInstance(node);
481 void compile_Proto(
struct X3D_Proto *node) {
483 if(0)printf(
"in compile_proto\n");
484 pflag = ciflag_get(node->__protoFlags,2);
487 REINITIALIZE_SORTED_NODES_FIELD(node->__children,node->_sortedChildren);
494 void child_Proto (
struct X3D_Proto *node) {
496 unsigned char sceneflag;
497 int renderFirstProtoChildOnlyAsPerSpecs;
499 if(0)printf(
"in child_proto\n");
501 nc = node->__children.n;
517 RETURN_FROM_CHILD_IF_NOT_FOR_ME
526 printf (
"child_Group, children.n %d sortedChildren.n %d\n",node->children.n, node->_sortedChildren.n);
528 printf (
"child_Group, this %p rf %x isProto %d\n",node,node->_renderFlags, node->FreeWRL__protoDef);
531 for (x=0; x<nc; x++) {
532 xx = X3D_NODE(node->_sortedChildren.p[x]);
534 printf (
" %d: ch %p type %s dist %f\n",x, node->_sortedChildren.p[x],stringNodeType(xx->_nodeType),xx->_dist);
535 else printf (
" chiuld %d null\n",x);
537 for (x=0; x<nc; x++) {
538 xx = X3D_NODE(node->_sortedChildren.p[x]);
540 printf (
" %d: sch %p type %s dist %f\n",x, node->_sortedChildren.p[x],stringNodeType(xx->_nodeType),xx->_dist);
541 else printf (
" chiuld %d null\n",x);
549 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
568 sceneflag = ciflag_get(node->__protoFlags,2);
569 renderFirstProtoChildOnlyAsPerSpecs = TRUE;
572 normalChildren(node->_sortedChildren);
574 if(renderFirstProtoChildOnlyAsPerSpecs && (renderstate()->render_geom || renderstate()->render_blend)) {
576 (node->__children).n = 1;
577 normalChildren(node->__children);
578 (node->__children).n = nc;
582 normalChildren(node->__children);
587 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);