26 #include <boost/format.hpp>
29 #include <Inventor/nodes/SoTransform.h>
36 SO_KIT_INIT_CLASS(
SceneObject, SoBaseKit,
"BaseKit");
39 bool scene3D::SceneObject::isInitialized =
false;
43 std::string collection,
44 SoSeparator* geometry,
45 SoSeparator* collision) :
46 classId(classId), collection(collection), manipNode(nullptr), isManipulated(false)
49 if (!SceneObject::isInitialized)
52 SceneObject::isInitialized =
true;
57 SO_KIT_ADD_CATALOG_ENTRY(root, SoSeparator,
false,
this,
"", TRUE);
58 SO_KIT_ADD_CATALOG_ENTRY(transformManip, SoTransformManip, TRUE, root,
"", TRUE);
59 SO_KIT_ADD_CATALOG_ENTRY(
transform, SoTransform, TRUE, root,
"", TRUE);
60 SO_KIT_ADD_CATALOG_ENTRY(modelswitch, SoSwitch, TRUE, root,
"", TRUE);
61 SO_KIT_ADD_CATALOG_ENTRY(visual, SoSeparator, TRUE, modelswitch,
"", TRUE);
62 SO_KIT_ADD_CATALOG_ENTRY(collision, SoSeparator, TRUE, modelswitch,
"", TRUE);
63 SO_KIT_INIT_INSTANCE();
69 this->setPart(
"root",
new SoSeparator);
72 this->transformNode =
new SoTransform;
73 this->setPart(
"transform", this->transformNode);
76 this->switchNode =
new SoSwitch;
77 this->setPart(
"modelswitch", this->switchNode);
79 this->switchNode->whichChild = 0;
82 this->setPart(
"visual", geometry);
85 this->setPart(
"collision", collision);
88 scene3D::SceneObject::SceneObject() : isManipulated(false)
92 SO_KIT_ADD_CATALOG_ENTRY(root, SoSeparator,
false,
this,
"", TRUE);
93 SO_KIT_ADD_CATALOG_ENTRY(
transform, SoTransform, TRUE,
this,
nullptr, TRUE);
94 SO_KIT_ADD_CATALOG_ENTRY(transformManip, SoTransformManip, TRUE, root,
"", TRUE);
95 SO_KIT_ADD_CATALOG_ENTRY(modelswitch, SoSwitch, TRUE,
this,
nullptr, TRUE);
96 SO_KIT_ADD_CATALOG_ENTRY(visual, SoSeparator, TRUE,
this, modelswitch, TRUE);
97 SO_KIT_ADD_CATALOG_ENTRY(collision, SoSeparator, TRUE,
this, modelswitch, TRUE);
98 SO_KIT_INIT_INSTANCE();
104 if (this->hasManipulator())
106 SoTransform* tempTransform =
new SoTransform;
107 tempTransform->ref();
109 tempTransform->combineRight(transformNode);
110 tempTransform->combineRight(manipNode);
112 SbVec3f result = tempTransform->translation.getValue();
113 tempTransform->unref();
117 return this->transformNode->translation.getValue();
123 this->transformNode->translation.setValue(translation);
126 if (this->hasManipulator())
128 this->manipNode->setToDefaults();
135 if (this->hasManipulator())
137 SoTransform* tempTransform =
new SoTransform;
138 tempTransform->ref();
140 tempTransform->combineRight(transformNode);
141 tempTransform->combineRight(manipNode);
144 SbRotation result = tempTransform->rotation.getValue();
145 tempTransform->unref();
149 return this->transformNode->rotation.getValue();
155 this->transformNode->rotation.setValue(rotation);
158 if (this->hasManipulator())
160 this->manipNode->setToDefaults();
167 this->switchNode->whichChild = show ? 1 : 0;
171 scene3D::SceneObject::addManipulator(SoTransformManip* manip)
173 this->manipNode = manip;
174 this->setPart(
"transformManip", manipNode);
178 scene3D::SceneObject::applyManipulator()
180 if (this->hasManipulator())
182 transformNode->combineRight(manipNode);
183 this->setPart(
"transformManip", NULL);
184 this->manipNode =
nullptr;
189 scene3D::SceneObject::hasManipulator()
191 return this->manipNode !=
nullptr;
197 return this->objectId;
203 this->objectId = objectId;
215 this->classId = classId;
227 this->collection = collection;
230 std::map<std::string, std::string>
233 std::map<std::string, std::string> allAttributes;
237 this->getTranslation().getValue(
x, y, z);
238 allAttributes.insert(std::pair<std::string, std::string>(
"Translation X",
std::to_string(
x)));
239 allAttributes.insert(std::pair<std::string, std::string>(
"Translation Y",
std::to_string(y)));
240 allAttributes.insert(std::pair<std::string, std::string>(
"Translation Z",
std::to_string(z)));
243 float pw, px, py, pz;
244 this->getRotation().getValue(px, py, pz, pw);
245 allAttributes.insert(std::pair<std::string, std::string>(
"Rotation X",
std::to_string(px)));
246 allAttributes.insert(std::pair<std::string, std::string>(
"Rotation Y",
std::to_string(py)));
247 allAttributes.insert(std::pair<std::string, std::string>(
"Rotation Z",
std::to_string(pz)));
248 allAttributes.insert(std::pair<std::string, std::string>(
"Angle",
std::to_string(pw)));
252 matrix.setRotate(this->getRotation());
253 matrix.setTranslate(this->getTranslation());
256 for (
int i = 0; i < 4; i++)
258 out.append(
boost::str(boost::format(
"%3.2g %3.2g %3.2g %3.2g") % matrix[i][0] %
259 matrix[i][1] % matrix[i][2] % matrix[i][3]));
267 allAttributes.insert(std::pair<std::string, std::string>(
"Matrix", out));
269 return allAttributes;
273 scene3D::SceneObject::pushHistory()
275 this->lastRotation = this->getRotation();
276 this->lastTranslation = this->getTranslation();
280 scene3D::SceneObject::getHistoryRotation()
282 return this->lastRotation;
286 scene3D::SceneObject::getHistoryTranslation()
288 return lastTranslation;
292 scene3D::SceneObject::trackThisTransformation(SoTransform* transformation)
294 this->manipNode->rotation.connectFrom(&transformation->rotation);
295 this->manipNode->translation.connectFrom(&transformation->translation);
299 scene3D::SceneObject::untrackTransformations()
301 this->manipNode->rotation.disconnect();
302 this->manipNode->translation.disconnect();
308 return !isManipulated;