37 #ifdef G4VIS_BUILD_OI_DRIVER
42 #include <Inventor/SbBox.h>
43 #include <Inventor/actions/SoAction.h>
44 #include <Inventor/fields/SoSFFloat.h>
45 #include <Inventor/misc/SoChildList.h>
46 #include <Inventor/nodes/SoSeparator.h>
47 #include <Inventor/nodes/SoIndexedFaceSet.h>
48 #include <Inventor/nodes/SoNormal.h>
49 #include <Inventor/nodes/SoCoordinate3.h>
50 #include <Inventor/nodes/SoNormalBinding.h>
51 #include <Inventor/SoPrimitiveVertex.h>
52 #include <Inventor/elements/SoTextureCoordinateElement.h>
62 SO_NODE_INIT_CLASS(
SoTrd,SoShape,
"Shape");
67 SO_NODE_CONSTRUCTOR(
SoTrd);
69 SO_NODE_ADD_FIELD(
fDx1,(1.0));
70 SO_NODE_ADD_FIELD(
fDx2,(1.0));
71 SO_NODE_ADD_FIELD(
fDy1,(1.0));
72 SO_NODE_ADD_FIELD(
fDy2,(1.0));
73 SO_NODE_ADD_FIELD(
fDz,(1.0));
87 SoState *state = action->getState();
91 SbBool useTexFunction=
92 (SoTextureCoordinateElement::getType(state) ==
93 SoTextureCoordinateElement::FUNCTION);
98 const SoTextureCoordinateElement *tce = NULL;
100 if (useTexFunction) {
101 tce = SoTextureCoordinateElement::getInstance(state);
112 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
113 point.setValue(x,y,z); \
114 normal.setValue(nx,ny,nz); \
115 if (useTexFunction) { \
116 texCoord=tce->get(point,normal); \
122 pv.setPoint(point); \
123 pv.setNormal(normal); \
124 pv.setTextureCoords(texCoord); \
129 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
130 int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,
131 4,5,6,7, SO_END_FACE_INDEX,
132 0,1,5,4, SO_END_FACE_INDEX,
133 1,2,6,5, SO_END_FACE_INDEX,
134 2,3,7,6, SO_END_FACE_INDEX,
135 3,0,4,7, SO_END_FACE_INDEX};
139 float points[NPOINTS][3];
140 points[0][0] =
fDx1.getValue();
141 points[0][1] =
fDy1.getValue();
142 points[0][2] = -
fDz.getValue();
144 points[1][0] = -
fDx1.getValue();
145 points[1][1] =
fDy1.getValue();
146 points[1][2] = -
fDz.getValue();
148 points[2][0] = -
fDx1.getValue();
149 points[2][1] = -
fDy1.getValue();
150 points[2][2] = -
fDz.getValue();
152 points[3][0] =
fDx1.getValue();
153 points[3][1] = -
fDy1.getValue();
154 points[3][2] = -
fDz.getValue();
156 points[4][0] =
fDx2.getValue();
157 points[4][1] =
fDy2.getValue();
158 points[4][2] =
fDz.getValue();
160 points[5][0] = -
fDx2.getValue();
161 points[5][1] =
fDy2.getValue();
162 points[5][2] =
fDz.getValue();
164 points[6][0] = -
fDx2.getValue();
165 points[6][1] = -
fDy2.getValue();
166 points[6][2] =
fDz.getValue();
168 points[7][0] =
fDx2.getValue();
169 points[7][1] = -
fDy2.getValue();
170 points[7][2] =
fDz.getValue();
174 float st1 =
FSIN(t1);
175 float st2 =
FSIN(t2);
176 float ct1 =
FCOS(t1);
177 float ct2 =
FCOS(t2);
179 float normals[NFACES][3];
181 normals[0][0] = 0 ; normals[0][1] = 0; normals [0][2] = -1;
183 normals[1][0] = 0 ; normals[1][1] = 0; normals [1][2] = 1;
185 normals[2][0] = 0 ; normals[2][1] = ct2; normals [2][2] = -st2;
187 normals[3][0] = -ct1; normals[3][1] = 0; normals [3][2] = -st1;
189 normals[4][0] = 0 ; normals[4][1] = -ct2; normals [4][2] = -st2;
191 normals[5][0] = ct1; normals[5][1] = 0; normals [5][2] = -st1;
195 for (
int nf=0;nf<NFACES;nf++) {
196 beginShape(action,TRIANGLE_FAN);
197 index = indices[nf * 5];
198 x = points[index][0];
199 y = points[index][1];
200 z = points[index][2];
201 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
202 index = indices[nf * 5 + 1];
203 x = points[index][0];
204 y = points[index][1];
205 z = points[index][2];
206 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
207 index = indices[nf * 5 + 2];
208 x = points[index][0];
209 y = points[index][1];
210 z = points[index][2];
211 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
212 index = indices[nf * 5 + 3];
213 x = points[index][0];
214 y = points[index][1];
215 z = points[index][2];
216 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
229 float fDx=
fDx1.getValue(),fDy=
fDy1.getValue();
231 if (
fDx2.getValue() > fDx) fDx =
fDx2.getValue();
232 if (
fDy2.getValue() > fDy) fDy =
fDy2.getValue();
234 SbVec3f vmin(-fDx,-fDy,-
fDz.getValue()),
235 vmax( fDx, fDy,
fDz.getValue());
237 center.setValue(0,0,0);
238 box.setBounds(vmin,vmax);
251 SoSeparator *sep = (SoSeparator *) ( *
children)[0];
252 SoCoordinate3 *theCoordinates = (SoCoordinate3 *) ( sep->getChild(0));
253 SoNormal *theNormals = (SoNormal *) ( sep->getChild(1));
254 SoNormalBinding *theNormalBinding = (SoNormalBinding *) ( sep->getChild(2));
255 SoIndexedFaceSet *theFaceSet = (SoIndexedFaceSet *) ( sep->getChild(3));
257 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
258 float points[NPOINTS][3];
259 float normals[NFACES][3]= {{0,0,-1}, {0,0,1}, {0,1,0}, {-1, 0, 0}, {0, -1, 0}, {1,0,0}};
267 indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,
268 4,5,6,7, SO_END_FACE_INDEX,
269 0,1,5,4, SO_END_FACE_INDEX,
270 1,2,6,5, SO_END_FACE_INDEX,
271 2,3,7,6, SO_END_FACE_INDEX,
272 3,0,4,7, SO_END_FACE_INDEX};
276 points[0][0] =
fDx1.getValue(); points[0][1] =
fDy1.getValue(); points[0][2] = -
fDz.getValue();
277 points[1][0] = -
fDx1.getValue(); points[1][1] =
fDy1.getValue(); points[1][2] = -
fDz.getValue();
278 points[2][0] = -
fDx1.getValue(); points[2][1] = -
fDy1.getValue(); points[2][2] = -
fDz.getValue();
279 points[3][0] =
fDx1.getValue(); points[3][1] = -
fDy1.getValue(); points[3][2] = -
fDz.getValue();
280 points[4][0] =
fDx2.getValue(); points[4][1] =
fDy2.getValue(); points[4][2] =
fDz.getValue();
281 points[5][0] = -
fDx2.getValue(); points[5][1] =
fDy2.getValue(); points[5][2] =
fDz.getValue();
282 points[6][0] = -
fDx2.getValue(); points[6][1] = -
fDy2.getValue(); points[6][2] =
fDz.getValue();
283 points[7][0] =
fDx2.getValue(); points[7][1] = -
fDy2.getValue(); points[7][2] =
fDz.getValue();
287 float st1 =
FSIN(t1);
288 float st2 =
FSIN(t2);
289 float ct1 =
FCOS(t1);
290 float ct2 =
FCOS(t2);
292 normals[0][0] = 0 ; normals[0][1] = 0; normals [0][2] = -1;
293 normals[1][0] = 0 ; normals[1][1] = 0; normals [1][2] = 1;
294 normals[2][0] = 0 ; normals[2][1] = ct2; normals [2][2] = -st2;
295 normals[3][0] = -ct1; normals[3][1] = 0; normals [3][2] = -st1;
296 normals[4][0] = 0 ; normals[4][1] = -ct2; normals [4][2] = -st2;
297 normals[5][0] = ct1; normals[5][1] = 0; normals [5][2] = -st1;
299 for (
int np=0;np<NPOINTS;np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
300 theFaceSet->coordIndex.setValues(0,NINDICES,indices);
301 for (
int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
302 theNormalBinding->value=SoNormalBinding::PER_FACE;
314 SoSeparator *sep =
new SoSeparator();
315 SoCoordinate3 *theCoordinates =
new SoCoordinate3();
316 SoNormal *theNormals =
new SoNormal();
317 SoNormalBinding *theNormalBinding =
new SoNormalBinding();
318 SoIndexedFaceSet *theFaceSet =
new SoIndexedFaceSet();
322 sep->addChild(theCoordinates);
323 sep->addChild(theNormals);
324 sep->addChild(theNormalBinding);
325 sep->addChild(theFaceSet);