93 SoState *state = action->getState();
97 SbBool useTexFunction=
98 (SoTextureCoordinateElement::getType(state) ==
99 SoTextureCoordinateElement::FUNCTION);
104 const SoTextureCoordinateElement *tce = NULL;
106 if (useTexFunction) {
107 tce = SoTextureCoordinateElement::getInstance(state);
113 SbVec3f point, normal;
118#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
119 point.setValue(x,y,z); \
120 normal.setValue(nx,ny,nz); \
121 if (useTexFunction) { \
122 texCoord=tce->get(point,normal); \
128 pv.setPoint(point); \
129 pv.setNormal(normal); \
130 pv.setTextureCoords(texCoord); \
135 const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
136 int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,
137 4,5,6,7, SO_END_FACE_INDEX,
138 0,1,5,4, SO_END_FACE_INDEX,
139 1,2,6,5, SO_END_FACE_INDEX,
140 2,3,7,6, SO_END_FACE_INDEX,
141 3,0,4,7, SO_END_FACE_INDEX};
145 float points[NPOINTS][3];
146 points[0][0] =
fDx.getValue();
147 points[0][1] =
fDy.getValue();
148 points[0][2] = -
fDz.getValue();
150 points[1][0] = -
fDx.getValue();
151 points[1][1] =
fDy.getValue();
152 points[1][2] = -
fDz.getValue();
154 points[2][0] = -
fDx.getValue();
155 points[2][1] = -
fDy.getValue();
156 points[2][2] = -
fDz.getValue();
158 points[3][0] =
fDx.getValue();
159 points[3][1] = -
fDy.getValue();
160 points[3][2] = -
fDz.getValue();
162 points[4][0] =
fDx.getValue();
163 points[4][1] =
fDy.getValue();
164 points[4][2] =
fDz.getValue();
166 points[5][0] = -
fDx.getValue();
167 points[5][1] =
fDy.getValue();
168 points[5][2] =
fDz.getValue();
170 points[6][0] = -
fDx.getValue();
171 points[6][1] = -
fDy.getValue();
172 points[6][2] =
fDz.getValue();
174 points[7][0] =
fDx.getValue();
175 points[7][1] = -
fDy.getValue();
176 points[7][2] =
fDz.getValue();
178 float normals[NFACES][3];
180 normals[0][0] = 0 ; normals[0][1] = 0; normals [0][2] = -1;
182 normals[1][0] = 0 ; normals[1][1] = 0; normals [1][2] = 1;
184 normals[2][0] = 0 ; normals[2][1] = 1; normals [2][2] = 0;
186 normals[3][0] = -1 ; normals[3][1] = 0; normals [3][2] = 0;
188 normals[4][0] = 0 ; normals[4][1] = -1; normals [4][2] = 0;
190 normals[5][0] = 1 ; normals[5][1] = 0; normals [5][2] = 0;
194 for (
int nf=0;nf<NFACES;nf++) {
195 beginShape(action,TRIANGLE_FAN);
196 index = indices[nf * 5];
197 x = points[index][0];
198 y = points[index][1];
199 z = points[index][2];
200 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
201 index = indices[nf * 5 + 1];
202 x = points[index][0];
203 y = points[index][1];
204 z = points[index][2];
205 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
206 index = indices[nf * 5 + 2];
207 x = points[index][0];
208 y = points[index][1];
209 z = points[index][2];
210 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);
211 index = indices[nf * 5 + 3];
212 x = points[index][0];
213 y = points[index][1];
214 z = points[index][2];
215 GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);