| 65 | } |
| 66 | |
| 67 | void ArcEngine::evaluate() |
| 68 | { |
| 69 | float angle = abs(this->angle.getValue()); |
| 70 | |
| 71 | if (radius.getValue() < std::numeric_limits<float>::epsilon() |
| 72 | || deviation.getValue() < std::numeric_limits<float>::epsilon()) { |
| 73 | defaultValues(); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | float deviationAngle(acos((radius.getValue() - deviation.getValue()) / radius.getValue())); |
| 78 | std::vector<SbVec3f> tempPoints; |
| 79 | int segmentCount; |
| 80 | if (deviationAngle >= angle) { |
| 81 | segmentCount = 1; |
| 82 | } |
| 83 | else { |
| 84 | segmentCount = static_cast<int>(angle / deviationAngle) + 1; |
| 85 | if (segmentCount < 2) { |
| 86 | defaultValues(); |
| 87 | return; |
| 88 | } |
| 89 | } |
| 90 | float angleIncrement = (this->angle.getValue() > 0 ? angle : -angle) |
| 91 | / static_cast<float>(segmentCount); |
| 92 | for (int index = 0; index < segmentCount + 1; ++index) { |
| 93 | SbVec3f currentNormal(1.0, 0.0, 0.0); |
| 94 | float currentAngle = index * angleIncrement; |
| 95 | SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), currentAngle); |
| 96 | rotation.multVec(currentNormal, currentNormal); |
| 97 | tempPoints.push_back(currentNormal * radius.getValue()); |
| 98 | } |
| 99 | int tempCount = tempPoints.size(); // for macro. |
| 100 | SO_ENGINE_OUTPUT(points, SoMFVec3f, setNum(tempCount)); |
| 101 | SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(tempCount)); |
| 102 | std::vector<SbVec3f>::const_iterator it; |
| 103 | for (it = tempPoints.begin(); it != tempPoints.end(); ++it) { |
| 104 | int currentIndex = it - tempPoints.begin(); // for macro. |
| 105 | SbVec3f temp(*it); // for macro |
| 106 | SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(currentIndex, temp)); |
| 107 | } |
| 108 | |
| 109 | // Get Midpoint |
| 110 | float a = angle / 2; |
| 111 | SbRotation rot(SbVec3f(0.0, 0.0, 1.0), a); |
| 112 | SbVec3f midPnt(1.0, 0.0, 0.0); |
| 113 | rot.multVec(midPnt, midPnt); |
| 114 | midPnt = midPnt * radius.getValue(); |
| 115 | |
| 116 | SO_ENGINE_OUTPUT(midpoint, SoSFVec3f, setValue(midPnt)); |
| 117 | } |
| 118 | |
| 119 | void ArcEngine::defaultValues() |
| 120 | { |