7 #include <Inventor/SbBox.h>
8 #include <Inventor/actions/SoPickAction.h>
9 #include <Inventor/nodes/SoSeparator.h>
10 #include <Inventor/nodes/SoIndexedFaceSet.h>
11 #include <Inventor/nodes/SoIndexedLineSet.h>
12 #include <Inventor/SoPrimitiveVertex.h>
13 #include <Inventor/C/glue/gl.h>
14 #include <Inventor/elements/SoGLCacheContextElement.h>
21 [[maybe_unused]]
static const bool didInit = [&]() {
34 setNodeType(EXTENSION);
44 double x2,
double y2,
double z2,
45 double x3,
double y3,
double z3)
58 const double edge1X(
x2-
x1), edge1Y(
y2-
y1), edge1Z(z2-z1);
59 const double edge2X(x3-
x1), edge2Y(y3-
y1), edge2Z(z3-z1);
60 double nx(edge1Y*edge2Z-edge1Z*edge2Y);
61 double ny(edge1Z*edge2X-edge1X*edge2Z);
62 double nz(edge1X*edge2Y-edge1Y*edge2X);
63 double nl(nx*nx+ny*ny+nz*nz);
64 const double s(1.0/sqrt(nl));
72 double x2,
double y2,
double z2,
73 double x3,
double y3,
double z3,
74 double x4,
double y4,
double z4)
114 SoState *state =
action->getState();
116 if(
action->getTypeId().isDerivedFrom(SoPickAction::getClassTypeId())) {
120 beginShape(
action,TRIANGLES);
130 glBegin(GL_TRIANGLES);
132 for (
int i=0;
i<nFaces;
i++) {
134 for (
int j = 0; j < 3; j++)
135 glVertex3fv((
const GLfloat*)&
m_points[
i*9+j*3]);
147 const bool transparencyOn = glIsEnabled(GL_BLEND);
149 if (disableLighting) glDisable(GL_LIGHTING);
150 if (transparencyOn) glDisable(GL_BLEND);
153 glBegin(GL_LINE_STRIP);
154 glVertex3fv((
const GLfloat*)&
m_points[
i]);
155 glVertex3fv((
const GLfloat*)&
m_points[
i+3]);
156 glVertex3fv((
const GLfloat*)&
m_points[
i+6]);
157 glVertex3fv((
const GLfloat*)&
m_points[
i]);
161 if (disableLighting) glEnable(GL_LIGHTING);
162 if (transparencyOn) glEnable(GL_BLEND);
166 if (state&&state->isElementEnabled(SoGLCacheContextElement::getClassStackIndex())) {
168 SoGLCacheContextElement::shouldAutoCache(state, SoGLCacheContextElement::DO_AUTO_CACHE);
169 #if ((COIN_MAJOR_VERSION>=3)||((COIN_MAJOR_VERSION==2)&&(COIN_MINOR_VERSION>=5)))
170 SoGLCacheContextElement::incNumShapes(state);
179 double targetSize = 100.;
180 addTriangularFacet(-targetSize,-targetSize,0.,targetSize,-targetSize,0.,0.,0.,targetSize);
181 addTriangularFacet(targetSize,-targetSize,0.,targetSize,targetSize,0.,0.,0.,targetSize);
182 addTriangularFacet(targetSize,targetSize,0.,-targetSize,targetSize,0.,0.,0.,targetSize);
183 addTriangularFacet(-targetSize,targetSize,0.,-targetSize,-targetSize,0.,0.,0.,targetSize);
184 addQuadrangularFacet(-targetSize,-targetSize,0.,-targetSize,targetSize,0.,targetSize,targetSize,0.,targetSize,-targetSize,0.);
203 SoSeparator *
sep =
new SoSeparator;
206 SoVertexProperty* vertices =
new SoVertexProperty();
209 SoIndexedFaceSet* faceset =
new SoIndexedFaceSet;
212 faceset->coordIndex.set1Value(j++,
i);
213 if((
i>1) && ((
i-2)%3==0)) {
214 faceset->coordIndex.set1Value(j++,SO_END_FACE_INDEX);
218 faceset->vertexProperty = vertices;
219 sep->addChild(faceset);
228 SoVertexProperty* verticesL =
new SoVertexProperty();
229 SoIndexedLineSet* lineset =
new SoIndexedLineSet;
233 lineset->coordIndex.set1Value(jj++,
kk++);
235 lineset->coordIndex.set1Value(jj++,
kk++);
237 lineset->coordIndex.set1Value(jj++,
kk++);
239 lineset->coordIndex.set1Value(jj++,
kk++);
240 lineset->coordIndex.set1Value(jj++,SO_END_LINE_INDEX);
242 lineset->vertexProperty = verticesL;
243 sep->addChild(lineset);