23
#include "PreCompiled.h"
29
# include <Inventor/engines/SoCalculator.h>
30
# include <Inventor/engines/SoComposeVec3f.h>
31
# include <Inventor/engines/SoConcatenate.h>
32
# include <Inventor/engines/SoComposeRotation.h>
33
# include <Inventor/engines/SoComposeRotationFromTo.h>
35
# include <Inventor/nodekits/SoShapeKit.h>
36
# include <Inventor/nodes/SoCone.h>
37
# include <Inventor/nodes/SoFont.h>
38
# include <Inventor/nodes/SoLineSet.h>
39
# include <Inventor/nodes/SoMaterial.h>
40
# include <Inventor/nodes/SoMatrixTransform.h>
41
# include <Inventor/nodes/SoResetTransform.h>
42
# include <Inventor/nodes/SoSeparator.h>
43
# include <Inventor/nodes/SoTransform.h>
44
# include <Inventor/nodes/SoVertexProperty.h>
50
SO_ENGINE_SOURCE(ArcEngine)
54
SO_ENGINE_CONSTRUCTOR(ArcEngine);
56
SO_ENGINE_ADD_INPUT(radius, (10.0));
57
SO_ENGINE_ADD_INPUT(angle, (1.0));
58
SO_ENGINE_ADD_INPUT(deviation, (0.25));
60
SO_ENGINE_ADD_OUTPUT(points, SoMFVec3f);
61
SO_ENGINE_ADD_OUTPUT(pointCount, SoSFInt32);
62
SO_ENGINE_ADD_OUTPUT(midpoint, SoSFVec3f);
65
void ArcEngine::initClass()
67
SO_ENGINE_INIT_CLASS(ArcEngine, SoEngine, "Engine");
70
void ArcEngine::evaluate()
72
float angle = abs(this->angle.getValue());
74
if (radius.getValue() < std::numeric_limits<float>::epsilon() ||
75
deviation.getValue() < std::numeric_limits<float>::epsilon())
81
float deviationAngle(acos((radius.getValue() - deviation.getValue()) / radius.getValue()));
82
std::vector<SbVec3f> tempPoints;
84
if (deviationAngle >= angle) {
88
segmentCount = static_cast<int>(angle / deviationAngle) + 1;
89
if (segmentCount < 2) {
94
float angleIncrement = (this->angle.getValue() > 0 ? angle : -angle) / static_cast<float>(segmentCount);
95
for (int index = 0; index < segmentCount + 1; ++index)
97
SbVec3f currentNormal(1.0, 0.0, 0.0);
98
float currentAngle = index * angleIncrement;
99
SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), currentAngle);
100
rotation.multVec(currentNormal, currentNormal);
101
tempPoints.push_back(currentNormal * radius.getValue());
103
int tempCount = tempPoints.size();
104
SO_ENGINE_OUTPUT(points, SoMFVec3f, setNum(tempCount));
105
SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(tempCount));
106
std::vector<SbVec3f>::const_iterator it;
107
for (it = tempPoints.begin(); it != tempPoints.end(); ++it)
109
int currentIndex = it-tempPoints.begin();
111
SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(currentIndex, temp));
116
SbRotation rot(SbVec3f(0.0, 0.0, 1.0), a);
117
SbVec3f midPnt(1.0, 0.0, 0.0);
118
rot.multVec(midPnt, midPnt);
119
midPnt = midPnt * radius.getValue();
121
SO_ENGINE_OUTPUT(midpoint, SoSFVec3f, setValue(midPnt));
125
void ArcEngine::defaultValues()
128
SO_ENGINE_OUTPUT(points, SoMFVec3f, setNum(2));
129
SbVec3f point1(10.0, 0.0, 0.0);
130
SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(0, point1));
131
SbVec3f point2(7.07f, 7.07f, 0.0);
132
SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(1, point2));
133
SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(2));
134
SbVec3f point3(7.07f, 7.07f, 0.0);
135
SO_ENGINE_OUTPUT(midpoint, SoSFVec3f, setValue(point3));