static void setShape(Link* link, SgGroup* shape, bool isVisual) { SgNodePtr node; if(shape->empty()){ node = new SgNode; } else { SgInvariantGroup* invariant = new SgInvariantGroup; if(link->Rs().isApprox(Matrix3::Identity())){ shape->copyChildrenTo(invariant); } else { SgPosTransform* transformRs = new SgPosTransform; transformRs->setRotation(link->Rs()); shape->copyChildrenTo(transformRs); invariant->addChild(transformRs); } node = invariant; } if(node){ if(isVisual){ link->setVisualShape(node); } else { link->setCollisionShape(node); } } }
void TranslationDragger::addCustomAxis(int axis, SgNode* node) { SgInvariantGroup* invariant = new SgInvariantGroup; invariant->setName(axisNames[axis]); invariant->addChild(node); customAxes->addChild(invariant); addChildOnce(customAxes); }
TranslationDragger::TranslationDragger(bool setDefaultAxes) { draggableAxes_ = TX | TY | TZ; axisCylinderNormalizedRadius = 0.04; defaultAxesScale = new SgScaleTransform; customAxes = new SgGroup; for(int i=0; i < 3; ++i){ SgMaterial* material = new SgMaterial; Vector3f color(0.2f, 0.2f, 0.2f); color[i] = 1.0f; material->setDiffuseColor(Vector3f::Zero()); material->setEmissiveColor(color); material->setAmbientIntensity(0.0f); material->setTransparency(0.6f); axisMaterials[i] = material; } if(setDefaultAxes){ MeshGenerator meshGenerator; SgMeshPtr mesh = meshGenerator.generateArrow(1.8, 0.08, 0.1, 2.5); for(int i=0; i < 3; ++i){ SgShape* shape = new SgShape; shape->setMesh(mesh); shape->setMaterial(axisMaterials[i]); SgPosTransform* arrow = new SgPosTransform; arrow->addChild(shape); if(i == 0){ arrow->setRotation(AngleAxis(-PI / 2.0, Vector3::UnitZ())); } else if(i == 2){ arrow->setRotation(AngleAxis( PI / 2.0, Vector3::UnitX())); } SgInvariantGroup* invariant = new SgInvariantGroup; invariant->setName(axisNames[i]); invariant->addChild(arrow); SgSwitch* axis = new SgSwitch; axis->addChild(invariant); defaultAxesScale->addChild(axis); } addChild(defaultAxesScale); } isContainerMode_ = false; }