FreeWRL / FreeX3D 4.3.0
Component_CAD.c
1/*
2
3
4X3D Rendering Component
5
6*/
7
8
9/****************************************************************************
10 This file is part of the FreeWRL/FreeX3D Distribution.
11
12 Copyright 2013 John Alexander Stewart
13
14 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Lesser Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
26****************************************************************************/
27
28
29
30#include <config.h>
31#include <system.h>
32#include <display.h>
33#include <internal.h>
34
35#include <libFreeWRL.h>
36
37#include "../vrml_parser/Structs.h"
38#include "../vrml_parser/CRoutes.h"
39#include "../main/headers.h"
40#include "../opengl/Frustum.h"
41#include "../opengl/Material.h"
42#include "../opengl/OpenGL_Utils.h"
43#include "Component_Shape.h"
44#include "../scenegraph/RenderFuncs.h"
45#include "../scenegraph/Polyrep.h"
46#include "Children.h"
47
48
49/************************************************************************/
50/* */
51/* CADFace */
52/* */
53/************************************************************************/
54
55void child_CADFace (struct X3D_CADFace *node) {
56 if (node->shape != NULL) render_node(node->shape);
57}
58
59/************************************************************************/
60/* */
61/* CADAssembly */
62/* */
63/************************************************************************/
64
65/* prep_CADAssembly - we need this so that distance (and, thus, distance sorting) works for CADAssembly */
66/* refer to prep_Group for detailed explanations */
67void prep_CADAssembly (struct X3D_CADAssembly *node) {
68 COMPILE_IF_REQUIRED
69 RECORD_DISTANCE
70
71}
72
73/*child_CADAssembly - check with child_Group for detailed explanations */
74void child_CADAssembly (struct X3D_CADAssembly *node) {
75 CHILDREN_COUNT
76 //LOCAL_LIGHT_SAVE
77
78 RETURN_FROM_CHILD_IF_NOT_FOR_ME
79
80 /* do we have a DirectionalLight for a child? */
81 //LOCAL_LIGHT_CHILDREN(node->_sortedChildren);
82 prep_sibAffectors((struct X3D_Node*)node,&node->__sibAffectors);
83
84 normalChildren(node->_sortedChildren);
85
86 //LOCAL_LIGHT_OFF
87 prep_sibAffectors((struct X3D_Node*)node,&node->__sibAffectors);
88}
89
90/* we compile the CADAssembly so that children are not continuously sorted */
91void compile_CADAssembly (struct X3D_CADAssembly *node) {
92 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
93 /*
94 {
95 int i;
96 ConsoleMessage ("compile_CADAssembly, rootNode is %p",rootNode());
97 for (i=0; i<node->children.n; i++) ConsoleMessage ("compile_CADAssembly %p, c %d is %p",node,i,node->children.p[i]);
98 for (i=0; i<node->_sortedChildren.n; i++) ConsoleMessage ("compile_CADAssembly %p, sc %d is %p",node,i,node->_sortedChildren.p[i]);
99 }
100 */
101 MARK_NODE_COMPILED
102
103}
104
105/************************************************************************/
106/* */
107/* CADLayer */
108/* */
109/************************************************************************/
110
111
112/* render nodes. If visible is < children, just render the children (according to spec 32.4.3) */
113
114void child_CADLayer (struct X3D_CADLayer *node) {
115 int i;
116 for (i=0; i<node->children.n; i++) {
117 if (i >= node->visible.n) render_node(node->children.p[i]);
118 else if (node->visible.p[i]) render_node(node->children.p[i]);
119 }
120}
121
122/************************************************************************/
123/* */
124/* CADPart */
125/* */
126/************************************************************************/
127
128void prep_CADPart (struct X3D_CADPart *node) {
129 COMPILE_IF_REQUIRED
130
131 /* rendering the viewpoint means doing the inverse transformations in reverse order (while poping stack),
132 * so we do nothing here in that case -ncoder */
133
134 /* printf ("prep_Transform, render_hier vp %d geom %d light %d sens %d blend %d prox %d col %d\n",
135 render_vp,render_geom,render_light,render_sensitive,render_blend,render_proximity,render_collision); */
136
137 /* do we have any geometry visible, and are we doing anything with geometry? */
138 OCCLUSIONTEST
139
140 if(!renderstate()->render_vp) {
141 /* do we actually have any thing to rotate/translate/scale?? */
142 if (node->__do_anything) {
143
144 FW_GL_PUSH_MATRIX();
145
146 /* TRANSLATION */
147 if (node->__do_trans)
148 FW_GL_TRANSLATE_F(node->translation.c[0],node->translation.c[1],node->translation.c[2]);
149
150 /* CENTER */
151 if (node->__do_center)
152 FW_GL_TRANSLATE_F(node->center.c[0],node->center.c[1],node->center.c[2]);
153
154
155 /* ROTATION */
156 if (node->__do_rotation) {
157 FW_GL_ROTATE_RADIANS(node->rotation.c[3], node->rotation.c[0],node->rotation.c[1],node->rotation.c[2]);
158 }
159
160 /* SCALEORIENTATION */
161 if (node->__do_scaleO) {
162 FW_GL_ROTATE_RADIANS(node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
163 }
164
165 /* SCALE */
166 if (node->__do_scale)
167 FW_GL_SCALE_F(node->scale.c[0],node->scale.c[1],node->scale.c[2]);
168
169 /* REVERSE SCALE ORIENTATION */
170 if (node->__do_scaleO)
171 FW_GL_ROTATE_RADIANS(-node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
172
173 /* REVERSE CENTER */
174 if (node->__do_center)
175 FW_GL_TRANSLATE_F(-node->center.c[0],-node->center.c[1],-node->center.c[2]);
176 }
177
178
179 RECORD_DISTANCE
180 }
181 }
182
183
184void child_CADPart (struct X3D_CADPart *node) {
185 //LOCAL_LIGHT_SAVE
186 CHILDREN_COUNT
187 OCCLUSIONTEST
188
189 RETURN_FROM_CHILD_IF_NOT_FOR_ME
190
191 /* any children at all? */
192 if (nc==0) return;
193
194 /* do we have a local light for a child? */
195 //LOCAL_LIGHT_CHILDREN(node->_sortedChildren);
196 prep_sibAffectors((struct X3D_Node*)node,&node->__sibAffectors);
197
198 /* now, just render the non-directionalLight children */
199
200 /* printf ("Transform %d, flags %d, render_sensitive %d\n",
201 node,node->_renderFlags,render_sensitive); */
202
203 #ifdef CHILDVERBOSE
204 printf ("transform - doing normalChildren\n");
205 #endif
206
207 normalChildren(node->_sortedChildren);
208
209 #ifdef CHILDVERBOSE
210 printf ("transform - done normalChildren\n");
211 #endif
212
213 //LOCAL_LIGHT_OFF
214 prep_sibAffectors((struct X3D_Node*)node,&node->__sibAffectors);
215}
216
217void compile_CADPart (struct X3D_CADPart *node) {
218 INITIALIZE_EXTENT;
219
220 /* printf ("changed Transform for node %u\n",node); */
221 node->__do_center = verify_translate ((GLfloat *)node->center.c);
222 node->__do_trans = verify_translate ((GLfloat *)node->translation.c);
223 node->__do_scale = verify_scale ((GLfloat *)node->scale.c);
224 node->__do_rotation = verify_rotate ((GLfloat *)node->rotation.c);
225 node->__do_scaleO = verify_rotate ((GLfloat *)node->scaleOrientation.c);
226
227 node->__do_anything = (node->__do_center ||
228 node->__do_trans ||
229 node->__do_scale ||
230 node->__do_rotation ||
231 node->__do_scaleO);
232
233 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
234 MARK_NODE_COMPILED
235}
236
237void fin_CADPart (struct X3D_CADPart *node) {
238 OCCLUSIONTEST
239
240 if(!renderstate()->render_vp) {
241 if (node->__do_anything) {
242 FW_GL_POP_MATRIX();
243
244 } else {
245 /*Rendering the viewpoint only means finding it, and calculating the reverse WorldView matrix.*/
246 if((node->_renderFlags & VF_Viewpoint) == VF_Viewpoint) {
247 FW_GL_TRANSLATE_F(((node->center).c[0]),((node->center).c[1]),((node->center).c[2])
248 );
249 FW_GL_ROTATE_RADIANS(((node->scaleOrientation).c[3]),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
250 );
251 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]))
252 );
253 FW_GL_ROTATE_RADIANS(-(((node->scaleOrientation).c[3])),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
254 );
255 FW_GL_ROTATE_RADIANS(-(((node->rotation).c[3])),((node->rotation).c[0]),((node->rotation).c[1]),((node->rotation).c[2])
256 );
257 FW_GL_TRANSLATE_F(-(((node->center).c[0])),-(((node->center).c[1])),-(((node->center).c[2]))
258 );
259 FW_GL_TRANSLATE_F(-(((node->translation).c[0])),-(((node->translation).c[1])),-(((node->translation).c[2]))
260 );
261 }
262 }
263 }
264}
265
266
267/************************************************************************/
268/* */
269/* IndexedQuadSet */
270/* */
271/************************************************************************/
272
273
274void render_IndexedQuadSet (struct X3D_IndexedQuadSet *node) {
275 COMPILE_POLY_IF_REQUIRED( node->coord, node->fogCoord, node->color, node->normal, node->texCoord)
276 CULL_FACE(node->solid)
277 render_polyrep(node);
278}
279
280/************************************************************************/
281/* */
282/* QuadSet */
283/* */
284/* */
285/************************************************************************/
286
287void render_QuadSet (struct X3D_QuadSet *node) {
288 COMPILE_POLY_IF_REQUIRED(node->coord, node->fogCoord, node->color, node->normal, node->texCoord)
289 CULL_FACE(node->solid)
290 render_polyrep(node);
291}
292