38 #ifdef G4VIS_BUILD_OI_DRIVER
43 #include <Inventor/SbBox.h>
44 #include <Inventor/actions/SoAction.h>
45 #include <Inventor/fields/SoSFFloat.h>
46 #include <Inventor/misc/SoChildList.h>
47 #include <Inventor/nodes/SoSeparator.h>
48 #include <Inventor/nodes/SoIndexedFaceSet.h>
49 #include <Inventor/nodes/SoNormal.h>
50 #include <Inventor/nodes/SoCoordinate3.h>
51 #include <Inventor/nodes/SoNormalBinding.h>
52 #include <Inventor/SoPrimitiveVertex.h>
53 #include <Inventor/elements/SoTextureCoordinateElement.h>
63 SO_NODE_INIT_CLASS(
SoTrd,SoShape,
"Shape");
68 SO_NODE_CONSTRUCTOR(
SoTrd);
70 SO_NODE_ADD_FIELD(
fDx1,(1.0));
71 SO_NODE_ADD_FIELD(
fDx2,(1.0));
72 SO_NODE_ADD_FIELD(
fDy1,(1.0));
73 SO_NODE_ADD_FIELD(
fDy2,(1.0));
74 SO_NODE_ADD_FIELD(
fDz,(1.0));
88 SoState *state = action->getState();
92 SbBool useTexFunction=
93 (SoTextureCoordinateElement::getType(state) ==
94 SoTextureCoordinateElement::FUNCTION);
99 const SoTextureCoordinateElement *tce = NULL;
101 if (useTexFunction) {
102 tce = SoTextureCoordinateElement::getInstance(state);
113 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
114 point.setValue(x,y,z); \
115 normal.setValue(nx,ny,nz); \
116 if (useTexFunction) { \
117 texCoord=tce->get(point,normal); \
123 pv.setPoint(point); \
124 pv.setNormal(normal); \
125 pv.setTextureCoords(texCoord); \
130 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
131 int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,
132 4,5,6,7, SO_END_FACE_INDEX,
133 0,1,5,4, SO_END_FACE_INDEX,
134 1,2,6,5, SO_END_FACE_INDEX,
135 2,3,7,6, SO_END_FACE_INDEX,
136 3,0,4,7, SO_END_FACE_INDEX};
140 float points[NPOINTS][3];
141 points[0][0] =
fDx1.getValue();
142 points[0][1] =
fDy1.getValue();
143 points[0][2] = -
fDz.getValue();
145 points[1][0] = -
fDx1.getValue();
146 points[1][1] =
fDy1.getValue();
147 points[1][2] = -
fDz.getValue();
149 points[2][0] = -
fDx1.getValue();
150 points[2][1] = -
fDy1.getValue();
151 points[2][2] = -
fDz.getValue();
153 points[3][0] =
fDx1.getValue();
154 points[3][1] = -
fDy1.getValue();
155 points[3][2] = -
fDz.getValue();
157 points[4][0] =
fDx2.getValue();
158 points[4][1] =
fDy2.getValue();
159 points[4][2] =
fDz.getValue();
161 points[5][0] = -
fDx2.getValue();
162 points[5][1] =
fDy2.getValue();
163 points[5][2] =
fDz.getValue();
165 points[6][0] = -
fDx2.getValue();
166 points[6][1] = -
fDy2.getValue();
167 points[6][2] =
fDz.getValue();
169 points[7][0] =
fDx2.getValue();
170 points[7][1] = -
fDy2.getValue();
171 points[7][2] =
fDz.getValue();
175 float st1 =
FSIN(t1);
176 float st2 =
FSIN(t2);
177 float ct1 =
FCOS(t1);
178 float ct2 =
FCOS(t2);
180 float normals[NFACES][3];
182 normals[0][0] = 0 ; normals[0][1] = 0; normals [0][2] = -1;
184 normals[1][0] = 0 ; normals[1][1] = 0; normals [1][2] = 1;
186 normals[2][0] = 0 ; normals[2][1] = ct2; normals [2][2] = -st2;
188 normals[3][0] = -ct1; normals[3][1] = 0; normals [3][2] = -st1;
190 normals[4][0] = 0 ; normals[4][1] = -ct2; normals [4][2] = -st2;
192 normals[5][0] = ct1; normals[5][1] = 0; normals [5][2] = -st1;
196 for (
int nf=0;nf<NFACES;nf++) {
197 beginShape(action,TRIANGLE_FAN);
198 index = indices[nf * 5];
199 x = points[index][0];
200 y = points[index][1];
201 z = points[index][2];
202 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
203 index = indices[nf * 5 + 1];
204 x = points[index][0];
205 y = points[index][1];
206 z = points[index][2];
207 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
208 index = indices[nf * 5 + 2];
209 x = points[index][0];
210 y = points[index][1];
211 z = points[index][2];
212 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
213 index = indices[nf * 5 + 3];
214 x = points[index][0];
215 y = points[index][1];
216 z = points[index][2];
217 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
230 float fDx=
fDx1.getValue(),fDy=
fDy1.getValue();
232 if (
fDx2.getValue() > fDx) fDx =
fDx2.getValue();
233 if (
fDy2.getValue() > fDy) fDy =
fDy2.getValue();
235 SbVec3f vmin(-fDx,-fDy,-
fDz.getValue()),
236 vmax( fDx, fDy,
fDz.getValue());
238 center.setValue(0,0,0);
239 box.setBounds(vmin,vmax);
252 SoSeparator *sep = (SoSeparator *) ( *
children)[0];
253 SoCoordinate3 *theCoordinates = (SoCoordinate3 *) ( sep->getChild(0));
254 SoNormal *theNormals = (SoNormal *) ( sep->getChild(1));
255 SoNormalBinding *theNormalBinding = (SoNormalBinding *) ( sep->getChild(2));
256 SoIndexedFaceSet *theFaceSet = (SoIndexedFaceSet *) ( sep->getChild(3));
258 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
259 float points[NPOINTS][3];
260 float normals[NFACES][3]= {{0,0,-1}, {0,0,1}, {0,1,0}, {-1, 0, 0}, {0, -1, 0}, {1,0,0}};
268 indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,
269 4,5,6,7, SO_END_FACE_INDEX,
270 0,1,5,4, SO_END_FACE_INDEX,
271 1,2,6,5, SO_END_FACE_INDEX,
272 2,3,7,6, SO_END_FACE_INDEX,
273 3,0,4,7, SO_END_FACE_INDEX};
277 points[0][0] =
fDx1.getValue(); points[0][1] =
fDy1.getValue(); points[0][2] = -
fDz.getValue();
278 points[1][0] = -
fDx1.getValue(); points[1][1] =
fDy1.getValue(); points[1][2] = -
fDz.getValue();
279 points[2][0] = -
fDx1.getValue(); points[2][1] = -
fDy1.getValue(); points[2][2] = -
fDz.getValue();
280 points[3][0] =
fDx1.getValue(); points[3][1] = -
fDy1.getValue(); points[3][2] = -
fDz.getValue();
281 points[4][0] =
fDx2.getValue(); points[4][1] =
fDy2.getValue(); points[4][2] =
fDz.getValue();
282 points[5][0] = -
fDx2.getValue(); points[5][1] =
fDy2.getValue(); points[5][2] =
fDz.getValue();
283 points[6][0] = -
fDx2.getValue(); points[6][1] = -
fDy2.getValue(); points[6][2] =
fDz.getValue();
284 points[7][0] =
fDx2.getValue(); points[7][1] = -
fDy2.getValue(); points[7][2] =
fDz.getValue();
288 float st1 =
FSIN(t1);
289 float st2 =
FSIN(t2);
290 float ct1 =
FCOS(t1);
291 float ct2 =
FCOS(t2);
293 normals[0][0] = 0 ; normals[0][1] = 0; normals [0][2] = -1;
294 normals[1][0] = 0 ; normals[1][1] = 0; normals [1][2] = 1;
295 normals[2][0] = 0 ; normals[2][1] = ct2; normals [2][2] = -st2;
296 normals[3][0] = -ct1; normals[3][1] = 0; normals [3][2] = -st1;
297 normals[4][0] = 0 ; normals[4][1] = -ct2; normals [4][2] = -st2;
298 normals[5][0] = ct1; normals[5][1] = 0; normals [5][2] = -st1;
300 for (
int np=0;np<NPOINTS;np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
301 theFaceSet->coordIndex.setValues(0,NINDICES,indices);
302 for (
int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
303 theNormalBinding->value=SoNormalBinding::PER_FACE;
315 SoSeparator *sep =
new SoSeparator();
316 SoCoordinate3 *theCoordinates =
new SoCoordinate3();
317 SoNormal *theNormals =
new SoNormal();
318 SoNormalBinding *theNormalBinding =
new SoNormalBinding();
319 SoIndexedFaceSet *theFaceSet =
new SoIndexedFaceSet();
323 sep->addChild(theCoordinates);
324 sep->addChild(theNormals);
325 sep->addChild(theNormalBinding);
326 sep->addChild(theFaceSet);
SoSFFloat fDy1
half-length of y, at -fDz
virtual SoChildList * getChildren() const
GetChildList, required whenever the class has hidden children.
static double normal(HepRandomEngine *eptr)
SoChildList * children
ChildList. Required whenever the class has hidden children.
SoSFFloat fDz
half-length along Z
SoSFNode alternateRep
Alternate rep - required.
SoSFFloat fDx1
half-length of x, at -fDz
virtual ~SoTrd()
Destructor, required.
virtual void generatePrimitives(SoAction *action)
Generate Primitives, required.
virtual void clearAlternateRep()
We better be able to clear it, too!
virtual void generateAlternateRep()
virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er)
compute bounding Box, required
SoSFFloat fDx2
half-length of x, at +fDz
SoTrd()
Constructor, required.
SoSFFloat fDy2
half-length of y, at +fDz
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData