osgVector4 WindowsManager::getColor (const std::string& colorName) { if (colorName == "blue") return osgVector4 (0.f, 0.f, 1.f, 1.f); else if (colorName == "green") return osgVector4 (0.f, 1.f, 0.f, 1.f); else if (colorName == "red") return osgVector4 (1.f, 0.f, 0.f, 1.f); else if (colorName == "white") return osgVector4 (1.f, 1.f, 1.f, 1.f); else return osgVector4 (0.f, 0.f, 0.f, 1.f); }
void LeafNodeFace::init () { /* Set face Geometry */ face_ptr_ = new ::osg::Geometry(); std::cout << "Creating face\n"; /* Create Geode for adding geometry */ geode_ptr_ = new osg::Geode(); geode_ptr_->addDrawable(face_ptr_); vertices_ = new ::osg::Vec3Array(); face_ptr_->setVertexArray( vertices_ ); /* Define the face color */ color_ptr_ = new ::osg::Vec4Array(); color_ptr_->push_back(osgVector4(1.,1.,1.,1.)); face_ptr_->setColorArray(color_ptr_.get()); face_ptr_->setColorBinding(::osg::Geometry::BIND_OVERALL); /* Allow transparency */ geode_ptr_->getOrCreateStateSet()->setMode(GL_BLEND, ::osg::StateAttribute::ON); /* Add geode to the queue */ this->asQueue()->addChild(geode_ptr_); }
LeafNodeCapsule::LeafNodeCapsule (const std::string& name, const float& radius, const float &height) : Node(name) { init(); setRadius(radius); setHeight(height); setColor(osgVector4(1.,1.,1.,1.)); }
// reimplmented from Node : use the mathematical representation instead of OSG representation : //( origin in the extremity and not in the center, length on the X+ and not Z+) // if size <0, display it on the opposite extremity void LeafNodeCapsule::addLandmark(const float& size) { ::osg::GeometryRefPtr geom_ptr = new ::osg::Geometry(); /* Define points of the beam */ ::osg::Vec3ArrayRefPtr points_ptr = new ::osg::Vec3Array(6); float offset; float absSize = (float) fabs(size); if(size<0){ offset = getHeight()/2; }else offset = - getHeight()/2; points_ptr->at(0) = osgVector3(0.,0.,offset); points_ptr->at(1) = osgVector3(0.,0.,absSize+offset); points_ptr->at(2) = osgVector3(0.,0.,offset); points_ptr->at(3) = osgVector3(0.,absSize,offset); points_ptr->at(4) = osgVector3(0.,0.,offset); points_ptr->at(5) = osgVector3(-absSize,0.,offset); /* Define the color */ ::osg::Vec4ArrayRefPtr color_ptr = new ::osg::Vec4Array(3); color_ptr->at(0) = osgVector4(1.,0.,0.,1.); color_ptr->at(1) = osgVector4(0.,1.,0.,1.); color_ptr->at(2) = osgVector4(0.,0.,1.,1.); geom_ptr->setVertexArray(points_ptr.get()); geom_ptr->setColorArray(color_ptr.get()); geom_ptr->setColorBinding(::osg::Geometry::BIND_PER_PRIMITIVE_SET); geom_ptr->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0,2)); geom_ptr->addPrimitiveSet(new osg::DrawArrays(GL_LINES,2,2)); geom_ptr->addPrimitiveSet(new osg::DrawArrays(GL_LINES,4,2)); landmark_geode_ptr_ = new osg::Geode(); landmark_geode_ptr_->addDrawable(geom_ptr); //set Landmark as ALWAYS ON TOP landmark_geode_ptr_->setNodeMask(0xffffffff); landmark_geode_ptr_->getOrCreateStateSet()->setRenderBinDetails(INT_MAX, "DepthSortedBin"); landmark_geode_ptr_->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, ::osg::StateAttribute::OFF | ::osg::StateAttribute::PROTECTED); landmark_geode_ptr_->getOrCreateStateSet()->setMode(GL_CULL_FACE, ::osg::StateAttribute::ON | ::osg::StateAttribute::PROTECTED ); landmark_geode_ptr_->getOrCreateStateSet()->setMode(GL_LIGHTING, ::osg::StateAttribute::OFF | ::osg::StateAttribute::PROTECTED); this->asQueue()->addChild(landmark_geode_ptr_); }
NodeRod::NodeRod (const std::string& name, osgVector4 color, float radius, float totalLength,size_t maxCapsule):Node(name), list_of_capsule_() { radius_ = radius; totalLength_ = totalLength; color_ = osgVector4(color); maxCapsule_=maxCapsule; for (size_t i = 0; i< maxCapsule ; i++){ std::stringstream nameCap; nameCap << name << "_cap"<<i; LeafNodeCapsulePtr_t cap = LeafNodeCapsule::create(nameCap.str(),radius,(totalLength/((float)maxCapsule)),color); list_of_capsule_.push_back(cap); this->asQueue()->addChild(cap->asGroup()); } }
osgVector4 WindowsManager::getColor (const value_type* colorCorba) { return osgVector4 (colorCorba[0], colorCorba[1], colorCorba[2], colorCorba[3]); }