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);
71void compile_Group(
struct X3D_Group *node) {
72 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
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){
231void sib_prep_LocalFog(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
232void sib_prep_DirectionalLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
233void sib_prep_SpotlLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
234void sib_prep_PointLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
235void sib_prep_ClipPlane(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
237void sib_prep_TextureProjector(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
240 switch(sibAffector->_nodeType){
241 case NODE_DirectionalLight:
242 sib_prep_DirectionalLight(parent,sibAffector);
break;
244 sib_prep_SpotlLight(parent,sibAffector);
break;
245 case NODE_PointLight:
246 sib_prep_PointLight(parent,sibAffector);
break;
248 sib_prep_LocalFog(parent,sibAffector);
break;
250 sib_prep_ClipPlane(parent,sibAffector);
break;
252 sib_prep_Effect(parent,sibAffector);
break;
253 case NODE_TextureProjectorPerspective:
254 case NODE_TextureProjectorParallel:
255 sib_prep_TextureProjector(parent,sibAffector);
break;
261void sib_fin_LocalFog(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
262void sib_fin_DirectionalLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
263void sib_fin_SpotlLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
264void sib_fin_PointLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
265void sib_fin_ClipPlane(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
267void sib_fin_TextureProjector(
struct X3D_Node *parent,
struct X3D_Node *sibAffector);
270 switch(sibAffector->_nodeType){
271 case NODE_DirectionalLight:
272 sib_fin_DirectionalLight(parent,sibAffector);
break;
274 sib_fin_SpotlLight(parent,sibAffector);
break;
275 case NODE_PointLight:
276 sib_fin_PointLight(parent,sibAffector);
break;
278 sib_fin_LocalFog(parent,sibAffector);
break;
280 sib_fin_ClipPlane(parent,sibAffector);
break;
282 sib_fin_Effect(parent,sibAffector);
break;
283 case NODE_TextureProjectorPerspective:
284 case NODE_TextureProjectorParallel:
285 sib_fin_TextureProjector(parent,sibAffector);
break;
294 for(j=0;j<affectors->n;j++){
295 struct X3D_Node *sa = affectors->p[j];
303 for(jj=0;jj<affectors->n;jj++){
307 j = affectors->n - jj - 1;
308 sa = affectors->p[j];
318 RETURN_FROM_CHILD_IF_NOT_FOR_ME
321 if NODE_NEEDS_COMPILING {
322 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
329 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
332 normalChildren(node->_sortedChildren);
335 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
339void child_Group (
struct X3D_Group *node) {
359 RETURN_FROM_CHILD_IF_NOT_FOR_ME
364 if (rs->render_geom) {
365 if (node->_renderFlags & VF_HideLeft && (viewer_iside() == 0) ) {
368 if (node->_renderFlags & VF_HideRight && (viewer_iside() == 1) ) {
373 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
381printf (
"child_Group, children.n %d sortedChildren.n %d\n",node->children.n, node->_sortedChildren.n);
383 printf (
"child_Group, this %p rf %x isProto %d\n",node,node->_renderFlags, node->FreeWRL__protoDef);
386 for (x=0; x<nc; x++) {
387 xx = X3D_NODE(node->_sortedChildren.p[x]);
389 printf (
" %d: ch %p type %s dist %f\n",x, node->_sortedChildren.p[x],stringNodeType(xx->_nodeType),xx->_dist);
390 else printf (
" chiuld %d null\n",x);
392 for (x=0; x<nc; x++) {
393 xx = X3D_NODE(node->_sortedChildren.p[x]);
395 printf (
" %d: sch %p type %s dist %f\n",x, node->_sortedChildren.p[x],stringNodeType(xx->_nodeType),xx->_dist);
396 else printf (
" chiuld %d null\n",x);
412 normalChildren(node->_sortedChildren);
417 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
427 RETURN_FROM_CHILD_IF_NOT_FOR_ME
432 if (rs->render_geom) {
433 if (node->_renderFlags & VF_HideLeft && (viewer_iside() == 0) ) {
436 if (node->_renderFlags & VF_HideRight && (viewer_iside() == 1) ) {
447 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
460 printf (
"transform - doing normalChildren\n");
463 normalChildren(node->_sortedChildren);
466 printf (
"transform - done normalChildren\n");
470 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
476char ciflag_get(
int flags,
int index){
477 char *cflags = (
char *)(&flags);
478 return cflags[index];
480int ciflag_set(
int flags,
char flag,
int index ){
481 char *cflags = (
char *)(&flags);
482 cflags[index] = flag;
485void prep_Proto (
struct X3D_Proto *node) {
486 if(0)printf(
"in prep_proto\n");
487 load_externProtoInstance(node);
492void compile_Proto(
struct X3D_Proto *node) {
494 if(0)printf(
"in compile_proto\n");
495 pflag = ciflag_get(node->__protoFlags,2);
498 REINITIALIZE_SORTED_NODES_FIELD(node->__children,node->_sortedChildren);
506int isUnitSpecVersionOK(
int specversion);
507static int unitoption_scalescene = TRUE;
508void prep_unitscale (
struct X3D_Proto *ec) {
511 if(!renderstate()->render_vp) {
514 double parentfactor = 1.0;
515 parent = X3D_PROTO(ec->_executionContext);
518 if(isUnitSpecVersionOK(ec->__specversion)){
519 factor = ec->__unitlengthfactor;
522 if(isUnitSpecVersionOK(parent->__specversion))
523 parentfactor = parent->__unitlengthfactor;
526 if(unitoption_scalescene){
529 parentfactor = factor;
535 factor = factor / parentfactor;
537 FW_GL_SCALE_D(factor,factor,factor);
544void fin_unitscale (
struct X3D_Proto *ec) {
548 if(!renderstate()->render_vp) {
575void child_Proto (
struct X3D_Proto *node) {
577 unsigned char sceneflag;
578 int renderFirstProtoChildOnlyAsPerSpecs;
580 if(0)printf(
"in child_proto\n");
582 nc = node->__children.n;
598 RETURN_FROM_CHILD_IF_NOT_FOR_ME
600 prep_unitscale(node);
607printf (
"child_Group, children.n %d sortedChildren.n %d\n",node->children.n, node->_sortedChildren.n);
609 printf (
"child_Group, this %p rf %x isProto %d\n",node,node->_renderFlags, node->FreeWRL__protoDef);
612 for (x=0; x<nc; x++) {
613 xx = X3D_NODE(node->_sortedChildren.p[x]);
615 printf (
" %d: ch %p type %s dist %f\n",x, node->_sortedChildren.p[x],stringNodeType(xx->_nodeType),xx->_dist);
616 else printf (
" chiuld %d null\n",x);
618 for (x=0; x<nc; x++) {
619 xx = X3D_NODE(node->_sortedChildren.p[x]);
621 printf (
" %d: sch %p type %s dist %f\n",x, node->_sortedChildren.p[x],stringNodeType(xx->_nodeType),xx->_dist);
622 else printf (
" chiuld %d null\n",x);
630 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
649 sceneflag = ciflag_get(node->__protoFlags,2);
650 renderFirstProtoChildOnlyAsPerSpecs = TRUE;
653 normalChildren(node->_sortedChildren);
655 if(renderFirstProtoChildOnlyAsPerSpecs && (renderstate()->render_geom || renderstate()->render_blend)) {
657 (node->__children).n = 1;
658 normalChildren(node->__children);
659 (node->__children).n = nc;
663 normalChildren(node->__children);
668 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);