37 #ifdef G4VIS_BUILD_OI_DRIVER
45 #include <Inventor/SbBox.h>
46 #include <Inventor/fields/SoSFFloat.h>
47 #include <Inventor/misc/SoChildList.h>
48 #include <Inventor/nodes/SoSeparator.h>
49 #include <Inventor/nodes/SoCube.h>
50 #include <Inventor/nodes/SoScale.h>
51 #include <Inventor/actions/SoAction.h>
52 #include <Inventor/nodes/SoIndexedFaceSet.h>
53 #include <Inventor/SoPrimitiveVertex.h>
54 #include <Inventor/elements/SoTextureCoordinateElement.h>
62 SO_NODE_CONSTRUCTOR(SoBox);
65 SO_NODE_ADD_FIELD(fDx, (1.0));
66 SO_NODE_ADD_FIELD(fDy, (1.0));
67 SO_NODE_ADD_FIELD(fDz, (1.0));
68 SO_NODE_ADD_FIELD(alternateRep, (NULL));
69 children =
new SoChildList(
this);
81 SO_NODE_INIT_CLASS(SoBox,SoShape,
"Shape");
91 SoState *state = action->getState();
95 SbBool useTexFunction=
96 (SoTextureCoordinateElement::getType(state) ==
97 SoTextureCoordinateElement::FUNCTION);
102 const SoTextureCoordinateElement *tce = NULL;
104 if (useTexFunction) {
105 tce = SoTextureCoordinateElement::getInstance(state);
116 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
117 point.setValue(x,y,z); \
118 normal.setValue(nx,ny,nz); \
119 if (useTexFunction) { \
120 texCoord=tce->get(point,normal); \
126 pv.setPoint(point); \
127 pv.setNormal(normal); \
128 pv.setTextureCoords(texCoord); \
133 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
134 int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,
135 4,5,6,7, SO_END_FACE_INDEX,
136 0,1,5,4, SO_END_FACE_INDEX,
137 1,2,6,5, SO_END_FACE_INDEX,
138 2,3,7,6, SO_END_FACE_INDEX,
139 3,0,4,7, SO_END_FACE_INDEX};
143 float points[NPOINTS][3];
144 points[0][0] =
fDx.getValue();
145 points[0][1] =
fDy.getValue();
146 points[0][2] = -
fDz.getValue();
148 points[1][0] = -
fDx.getValue();
149 points[1][1] =
fDy.getValue();
150 points[1][2] = -
fDz.getValue();
152 points[2][0] = -
fDx.getValue();
153 points[2][1] = -
fDy.getValue();
154 points[2][2] = -
fDz.getValue();
156 points[3][0] =
fDx.getValue();
157 points[3][1] = -
fDy.getValue();
158 points[3][2] = -
fDz.getValue();
160 points[4][0] =
fDx.getValue();
161 points[4][1] =
fDy.getValue();
162 points[4][2] =
fDz.getValue();
164 points[5][0] = -
fDx.getValue();
165 points[5][1] =
fDy.getValue();
166 points[5][2] =
fDz.getValue();
168 points[6][0] = -
fDx.getValue();
169 points[6][1] = -
fDy.getValue();
170 points[6][2] =
fDz.getValue();
172 points[7][0] =
fDx.getValue();
173 points[7][1] = -
fDy.getValue();
174 points[7][2] =
fDz.getValue();
176 float normals[NFACES][3];
178 normals[0][0] = 0 ; normals[0][1] = 0; normals [0][2] = -1;
180 normals[1][0] = 0 ; normals[1][1] = 0; normals [1][2] = 1;
182 normals[2][0] = 0 ; normals[2][1] = 1; normals [2][2] = 0;
184 normals[3][0] = -1 ; normals[3][1] = 0; normals [3][2] = 0;
186 normals[4][0] = 0 ; normals[4][1] = -1; normals [4][2] = 0;
188 normals[5][0] = 1 ; normals[5][1] = 0; normals [5][2] = 0;
192 for (
int nf=0;nf<NFACES;nf++) {
193 beginShape(action,TRIANGLE_FAN);
194 index = indices[nf * 5];
195 x = points[index][0];
196 y = points[index][1];
197 z = points[index][2];
198 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
199 index = indices[nf * 5 + 1];
200 x = points[index][0];
201 y = points[index][1];
202 z = points[index][2];
203 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
204 index = indices[nf * 5 + 2];
205 x = points[index][0];
206 y = points[index][1];
207 z = points[index][2];
208 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
209 index = indices[nf * 5 + 3];
210 x = points[index][0];
211 y = points[index][1];
212 z = points[index][2];
213 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
226 SbVec3f vmin(-
fDx.getValue(),-
fDy.getValue(),-
fDz.getValue()),
227 vmax(
fDx.getValue(),
fDy.getValue(),
fDz.getValue());
228 center.setValue(0,0,0);
229 box.setBounds(vmin,vmax);
242 SoSeparator *sep = (SoSeparator *) ( *
children)[0];
243 SoScale *
scale = (SoScale *)( sep->getChild(0));
245 scale->scaleFactor.setValue(
fDx.getValue(),
fDy.getValue(),
fDz.getValue());
255 SoSeparator *sep =
new SoSeparator();
256 SoScale *scale =
new SoScale();
257 SoCube *cube =
new SoCube();
259 sep->addChild(scale);