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
57 prep_BBox((struct BBoxFields*)&node->bboxCenter);
58 if (node->shape != NULL) render_node(node->shape);
59 fin_BBox((struct X3D_Node*)node,(struct BBoxFields*)&node->bboxCenter,FALSE);
60
61}
62
63/************************************************************************/
64/* */
65/* CADAssembly */
66/* */
67/************************************************************************/
68
69/* prep_CADAssembly - we need this so that distance (and, thus, distance sorting) works for CADAssembly */
70/* refer to prep_Group for detailed explanations */
71void prep_CADAssembly (struct X3D_CADAssembly *node) {
72 COMPILE_IF_REQUIRED
73
74}
75
76/*child_CADAssembly - check with child_Group for detailed explanations */
77void child_CADAssembly (struct X3D_CADAssembly *node) {
78 CHILDREN_COUNT
79 RETURN_FROM_CHILD_IF_NOT_FOR_ME
80
81 prep_sibAffectors((struct X3D_Node*)node,&node->__sibAffectors);
82 prep_BBox((struct BBoxFields*)&node->bboxCenter);
83
84 normalChildren(node->_sortedChildren);
85
86 fin_BBox((struct X3D_Node*)node,(struct BBoxFields*)&node->bboxCenter,FALSE);
87 fin_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
117 prep_BBox((struct BBoxFields*)&node->bboxCenter);
118
119 // this kind of visiblility just blocks shape rendering, not picking or anything else// if(peek_group_visible())
120 for (i=0; i<node->children.n; i++) {
121 if (i >= node->visibles.n) render_node(node->children.p[i]);
122 else if (node->visibles.p[i])
123 render_node(node->children.p[i]);
124 }
125 fin_BBox((struct X3D_Node*)node,(struct BBoxFields*)&node->bboxCenter,FALSE);
126}
127
128/************************************************************************/
129/* */
130/* CADPart */
131/* */
132/************************************************************************/
133
134void prep_CADPart (struct X3D_CADPart *node) {
135 COMPILE_IF_REQUIRED
136
137 /* rendering the viewpoint means doing the inverse transformations in reverse order (while poping stack),
138 * so we do nothing here in that case -ncoder */
139
140 /* printf ("prep_Transform, render_hier vp %d geom %d light %d sens %d blend %d prox %d col %d\n",
141 render_vp,render_geom,render_light,render_sensitive,render_blend,render_proximity,render_collision); */
142
143 /* do we have any geometry visible, and are we doing anything with geometry? */
144 OCCLUSIONTEST
145
146 if(!renderstate()->render_vp) {
147 /* do we actually have any thing to rotate/translate/scale?? */
148 push_transform_local_identity();
149 if (node->__do_anything) {
150
151 FW_GL_PUSH_MATRIX();
152 FW_GL_PUSH_MATRIX(); //this is to get us a separate 4x4 matrix just for the stuff here
153 FW_GL_LOAD_IDENTITY(); // .. wehich we will save for child_Transform to propagate its bbox up to its extent
154
155 /* TRANSLATION */
156 if (node->__do_trans)
157 FW_GL_TRANSLATE_F(node->translation.c[0],node->translation.c[1],node->translation.c[2]);
158
159 /* CENTER */
160 if (node->__do_center)
161 FW_GL_TRANSLATE_F(node->center.c[0],node->center.c[1],node->center.c[2]);
162
163
164 /* ROTATION */
165 if (node->__do_rotation) {
166 FW_GL_ROTATE_RADIANS(node->rotation.c[3], node->rotation.c[0],node->rotation.c[1],node->rotation.c[2]);
167 }
168
169 /* SCALEORIENTATION */
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
174 /* SCALE */
175 if (node->__do_scale)
176 FW_GL_SCALE_F(node->scale.c[0],node->scale.c[1],node->scale.c[2]);
177
178 /* REVERSE SCALE ORIENTATION */
179 if (node->__do_scaleO)
180 FW_GL_ROTATE_RADIANS(-node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
181
182 /* REVERSE CENTER */
183 if (node->__do_center)
184 FW_GL_TRANSLATE_F(-node->center.c[0],-node->center.c[1],-node->center.c[2]);
185 {
186 double mat[16];
187
188 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX,mat); //we got our local transform saved
189 FW_GL_POP_MATRIX();
190 FW_GL_TRANSFORM_D(mat); //now apply the above to prep for child_Tranform
191 reset_transform_local(mat);
192 }
193
194 }
195 }
196}
197
198
199void child_CADPart (struct X3D_CADPart *node) {
200 CHILDREN_COUNT
201 OCCLUSIONTEST
202
203 RETURN_FROM_CHILD_IF_NOT_FOR_ME
204
205 /* any children at all? */
206 if (nc==0) return;
207
208 /* do we have a local light for a child? */
209 prep_sibAffectors((struct X3D_Node*)node,&node->__sibAffectors);
210
211 prep_BBox((struct BBoxFields*)&node->bboxCenter);
212 normalChildren(node->_sortedChildren);
213 fin_BBox((struct X3D_Node*)node,(struct BBoxFields*)&node->bboxCenter,TRUE);
214
215 fin_sibAffectors((struct X3D_Node*)node,&node->__sibAffectors);
216
217}
218
219void compile_CADPart (struct X3D_CADPart *node) {
220 INITIALIZE_EXTENT;
221
222 /* printf ("changed Transform for node %u\n",node); */
223 node->__do_center = verify_translate ((GLfloat *)node->center.c);
224 node->__do_trans = verify_translate ((GLfloat *)node->translation.c);
225 node->__do_scale = verify_scale ((GLfloat *)node->scale.c);
226 node->__do_rotation = verify_rotate ((GLfloat *)node->rotation.c);
227 node->__do_scaleO = verify_rotate ((GLfloat *)node->scaleOrientation.c);
228
229 node->__do_anything = (node->__do_center ||
230 node->__do_trans ||
231 node->__do_scale ||
232 node->__do_rotation ||
233 node->__do_scaleO);
234
235 REINITIALIZE_SORTED_NODES_FIELD(node->children,node->_sortedChildren);
236 MARK_NODE_COMPILED
237}
238
239void fin_CADPart (struct X3D_CADPart *node) {
240 OCCLUSIONTEST
241
242 if(!renderstate()->render_vp) {
243 pop_transform_local();
244 if (node->__do_anything) {
245 FW_GL_POP_MATRIX();
246 } else {
247 /*Rendering the viewpoint only means finding it, and calculating the reverse WorldView matrix.*/
248 if((node->_renderFlags & VF_Viewpoint) == VF_Viewpoint) {
249 FW_GL_TRANSLATE_F(((node->center).c[0]),((node->center).c[1]),((node->center).c[2])
250 );
251 FW_GL_ROTATE_RADIANS(((node->scaleOrientation).c[3]),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
252 );
253 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]))
254 );
255 FW_GL_ROTATE_RADIANS(-(((node->scaleOrientation).c[3])),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
256 );
257 FW_GL_ROTATE_RADIANS(-(((node->rotation).c[3])),((node->rotation).c[0]),((node->rotation).c[1]),((node->rotation).c[2])
258 );
259 FW_GL_TRANSLATE_F(-(((node->center).c[0])),-(((node->center).c[1])),-(((node->center).c[2]))
260 );
261 FW_GL_TRANSLATE_F(-(((node->translation).c[0])),-(((node->translation).c[1])),-(((node->translation).c[2]))
262 );
263 }
264 }
265 }
266}
267
268
269/************************************************************************/
270/* */
271/* IndexedQuadSet */
272/* */
273/************************************************************************/
274
275
276void render_IndexedQuadSet (struct X3D_IndexedQuadSet *node) {
277 //COMPILE_POLY_IF_REQUIRED( node->coord, node->fogCoord, node->color, node->normal, node->texCoord)
278 if (!compile_poly_if_required(node, node->coord, node->fogCoord, node->color, node->normal, node->texCoord))return;
279 CULL_FACE(node->solid)
280 render_polyrep(node);
281}
282
283/************************************************************************/
284/* */
285/* QuadSet */
286/* */
287/* */
288/************************************************************************/
289
290void render_QuadSet (struct X3D_QuadSet *node) {
291 //COMPILE_POLY_IF_REQUIRED(node->coord, node->fogCoord, node->color, node->normal, node->texCoord)
292 if (!compile_poly_if_required(node, node->coord, node->fogCoord, node->color, node->normal, node->texCoord))return;
293 CULL_FACE(node->solid)
294 render_polyrep(node);
295}
296