void TextureWidget::initLabels() { StateSet* stateSet; Vec3 pos(0.0, -_height / 2.0, EPSILON_Z); _label0 = new osgText::Text(); _label0->setDataVariance(Object::DYNAMIC); _label0->setFont(osgText::readFontFile("fonts/arial.ttf")); _label0->setColor(COL_WHITE); _label0->setFontResolution(20, 20); _label0->setPosition(pos); _label0->setCharacterSize(DEFAULT_FONT_SIZE); _label0->setMaximumWidth(_width); _label0->setMaximumHeight(DEFAULT_LABEL_HEIGHT); _label0->setAlignment(osgText::Text::CENTER_CENTER); _label0->setUseDisplayList(false); stateSet = _label0->getOrCreateStateSet(); stateSet->setMode(GL_LIGHTING, StateAttribute::OFF); _label1 = new osgText::Text(); _label1->setDataVariance(Object::DYNAMIC); _label1->setFont(osgText::readFontFile("fonts/arial.ttf")); _label1->setColor(COL_WHITE); _label1->setFontResolution(20, 20); _label1->setPosition(pos); _label1->setCharacterSize(DEFAULT_FONT_SIZE); _label1->setMaximumWidth(_width); _label1->setMaximumHeight(DEFAULT_LABEL_HEIGHT); _label1->setAlignment(osgText::Text::CENTER_CENTER); _label1->setUseDisplayList(false); stateSet = _label1->getOrCreateStateSet(); stateSet->setMode(GL_LIGHTING, StateAttribute::OFF); }
// Constructor: CAVEGeodeSnapWireframe CAVEGeodeSnapWireframe::CAVEGeodeSnapWireframe() { // unit grid size 'mSnappingUnitDist' will inherit the default value 'gSnappingUnitDist' unless modified mSnappingUnitDist = gSnappingUnitDist; mInitPosition = Vec3(0, 0, 0); mScaleVect = Vec3(1, 1, 1); mDiagonalVect = Vec3(1, 1, 1); mBaseGeometry = new Geometry(); mSnapwireGeometry = new Geometry(); addDrawable(mBaseGeometry); addDrawable(mSnapwireGeometry); Material* material = new Material; material->setAmbient(Material::FRONT_AND_BACK, Vec4(0.0, 1.0, 0.0, 1.0)); material->setDiffuse(Material::FRONT_AND_BACK, Vec4(1.0, 1.0, 0.0, 1.0)); material->setSpecular(Material::FRONT_AND_BACK, osg::Vec4( 1.f, 1.f, 1.f, 1.0f)); material->setAlpha(Material::FRONT_AND_BACK, 0.f); StateSet* stateset = new StateSet(); stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON); stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | osg::StateAttribute::ON ); stateset->setMode(GL_LIGHTING, StateAttribute::OVERRIDE | StateAttribute::ON ); stateset->setRenderingHint(StateSet::TRANSPARENT_BIN); setStateSet(stateset); }
TextureWidget::TextureWidget(Interaction* interaction, float width, float height) : Widget(), Events() { StateSet* stateSet; _interaction = interaction; _width = width; _height = height; createBackground(); createTexturesGeometry(); initLabels(); initTextures(); _texture[0] = new Geode(); _texture[0]->addDrawable(_geom); _texture[0]->addDrawable(_label0); _texture[0]->addDrawable(_texGeom0); stateSet = _texGeom0->getOrCreateStateSet(); stateSet->setMode(GL_LIGHTING, StateAttribute::OFF); stateSet->setRenderingHint(StateSet::TRANSPARENT_BIN); stateSet->setTextureAttributeAndModes(StateAttribute::TEXTURE, _tex0, StateAttribute::ON); _texture[1] = new Geode(); _texture[1]->addDrawable(_geom); _texture[1]->addDrawable(_label1); _texture[1]->addDrawable(_texGeom1); stateSet = _texGeom1->getOrCreateStateSet(); stateSet->setMode(GL_LIGHTING, StateAttribute::OFF); stateSet->setRenderingHint(StateSet::TRANSPARENT_BIN); stateSet->setTextureAttributeAndModes(StateAttribute::TEXTURE, _tex1, StateAttribute::ON); _swTexture = new Switch(); _swTexture->addChild(_texture[0]); _swTexture->addChild(_texture[1]); _swTexture->setSingleChildOn(0); _node->addChild(_swTexture.get()); _leftGeode = new Geode(); _rightGeode = new Geode(); MatrixTransform* transLeft = new MatrixTransform(); MatrixTransform* transRight = new MatrixTransform(); Matrix trans; trans.makeTranslate(Vec3(-_width/2.0, -_height/2.0 - DEFAULT_LABEL_HEIGHT/2.0, 3*EPSILON_Z)); transLeft->setMatrix(trans); transLeft->addChild(_leftGeode); trans.makeTranslate(Vec3(+_width/2.0, -_height/2.0 - DEFAULT_LABEL_HEIGHT/2.0, 3*EPSILON_Z)); transRight->setMatrix(trans); transRight->addChild(_rightGeode); _node->addChild(transLeft); _node->addChild(transRight); _interaction->addListener(this, this); }
void Virvo::initStateset() { StateSet *stateset = new StateSet(); stateset->setMode(GL_LIGHTING, StateAttribute::OFF); stateset->setMode(GL_BLEND, StateAttribute::ON); stateset->setRenderBinDetails(100, "RenderBin"); // draw after everything else setStateSet(stateset); }
void DSGeometryCreator::setHighlight(bool isHighlighted, const osg::Vec3 &pointerOrg, const osg::Vec3 &pointerPos) { int idx = -1; mIsHighlighted = isHighlighted; for (int i = 0; i < mNumShapeSwitches; i++) { ((osg::PositionAttitudeTransform*)(mShapeSwitchEntryArray[i]->mSwitch->getChild(0)))->removeChild(mHighlightGeode); mDSIntersector->loadRootTargetNode(gDesignStateRootGroup, ((osg::PositionAttitudeTransform*)(mShapeSwitchEntryArray[i]->mSwitch->getChild(0)))->getChild(0)); if (mDSIntersector->test(pointerOrg, pointerPos)) { idx = i; } } if (idx > -1) { osg::Sphere *sphere = new osg::Sphere(); mSD = new osg::ShapeDrawable(sphere); mHighlightGeode = new osg::Geode(); mHighlightGeode->addDrawable(mSD); sphere->setRadius(0.25); mSD->setColor(osg::Vec4(1, 1, 1, 0.5)); StateSet *stateset = mSD->getOrCreateStateSet(); stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON); stateset->setMode(GL_CULL_FACE, StateAttribute::OVERRIDE | StateAttribute::ON); stateset->setRenderingHint(StateSet::TRANSPARENT_BIN); //fwdVec[i]->addChild(mHighlightGeode); //((osg::Geode*)mShapeSwitchEntryArray[idx]->mSwitch->getChild(0))->addDrawable(mSD); //std::cout << idx << std::endl; ((osg::PositionAttitudeTransform*)(mShapeSwitchEntryArray[idx]->mSwitch->getChild(0)))->addChild(mHighlightGeode); } /* else { for (int i = 0; i < mNumShapeSwitches; i++) { if (mHighlightGeode) ((osg::PositionAttitudeTransform*)(mShapeSwitchEntryArray[i]->mSwitch->getChild(0)))->removeChild(mHighlightGeode); //((osg::Geode*)mShapeSwitchEntryArray[i]->mSwitch->getChild(0))->removeDrawable(mSD); } }*/ mDSIntersector->loadRootTargetNode(gDesignStateRootGroup, mSphereExteriorGeode); }
Normals::Normals( Node *node, float scale, Mode mode ) { setName(mode == VertexNormals ? "VertexNormals" : "SurfaceNormals"); MakeNormalsVisitor mnv(scale,mode); node->accept( mnv ); ref_ptr<Vec3Array> coords = mnv.getCoords(); ref_ptr<Vec4Array> colors = new Vec4Array; if( mode == SurfaceNormals ) colors->push_back( Vec4( 0, 1, 0, 1 )); else if( mode == VertexNormals ) colors->push_back( Vec4( 1, 0, 0, 1 )); ref_ptr<Geometry> geom = new Geometry; geom->setVertexArray( coords.get() ); geom->setColorArray( colors.get() ); geom->setColorBinding( Geometry::BIND_OVERALL ); geom->addPrimitiveSet( new DrawArrays( PrimitiveSet::LINES, 0, coords->size())); StateSet *sset = new StateSet; sset->setMode( GL_LIGHTING, StateAttribute::OFF); geom->setStateSet( sset ); addDrawable( geom.get() ); }
/*************************************************************** * Function: applyColorTexture() ***************************************************************/ void CAVEGeode::applyColorTexture(const Vec3 &diffuse, const Vec3 &specular, const float &alpha, const string &texFilename) { StateSet *stateset = getOrCreateStateSet(); /* update material parameters */ Material *material = dynamic_cast <Material*> (stateset->getAttribute(StateAttribute::MATERIAL)); if (!material) material = new Material; material->setDiffuse(Material::FRONT_AND_BACK, Vec4(diffuse, 1.f)); material->setSpecular(Material::FRONT_AND_BACK, Vec4(specular, 1.f)); material->setAlpha(Material::FRONT_AND_BACK, alpha); stateset->setAttributeAndModes(material, StateAttribute::ON); /* update texture image */ Texture2D *texture = dynamic_cast <Texture2D*> (stateset->getAttribute(StateAttribute::TEXTURE)); if (!texture) texture = new Texture2D; Image* texImage = osgDB::readImageFile(texFilename); texture->setImage(texImage); texture->setWrap(Texture::WRAP_S,Texture::REPEAT); texture->setWrap(Texture::WRAP_T,Texture::REPEAT); texture->setDataVariance(Object::DYNAMIC); stateset->setTextureAttributeAndModes(0, texture, StateAttribute::ON); stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | osg::StateAttribute::ON ); stateset->setRenderingHint(StateSet::TRANSPARENT_BIN); /* update of color & texture properties */ mDiffuse = diffuse; mSpecular = specular; mAlpha = alpha; mTexFilename = texFilename; }
void Panel::setBGTexture(unsigned char* img, int width, int height) { //_texWidth = width; //_texHeight = height; Texture2D* texture; // Initialize panel texture: texture = new Texture2D(); _panelImage = new Image(); _panelImage->setImage(width, height, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, img, Image::USE_NEW_DELETE); texture->setImage(_panelImage); Vec2Array* texCoords = new Vec2Array(4); (*texCoords)[0].set(0.0, 0.0); (*texCoords)[1].set(1.0, 0.0); (*texCoords)[2].set(1.0, 1.0); (*texCoords)[3].set(0.0, 1.0); _geom->setTexCoordArray(0, texCoords); // Texture: StateSet* stateset = _geom->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING, StateAttribute::OFF); stateset->setRenderingHint(StateSet::TRANSPARENT_BIN); stateset->setTextureAttributeAndModes(0, texture, StateAttribute::ON); _panelImage->dirty(); }
void Panel::setObjectBlendState(Geode *geodeCurrent) { // retrieve or create a StateSet StateSet *stateBlend = geodeCurrent->getOrCreateStateSet(); // create a new blend function using GL_SRC_ALPHA and GL_ONE BlendFunc *bf = new BlendFunc(GL_SRC_ALPHA,GL_ONE); // turn depth testing off // stateBlend->setMode(GL_DEPTH_TEST,StateAttribute::OFF); // turn standard OpenGL lighting on // stateBlend->setMode(GL_LIGHTING,StateAttribute::ON); // turn blending on stateBlend->setMode(GL_BLEND,StateAttribute::ON); // add rendering hint stateBlend->setRenderingHint(StateSet::TRANSPARENT_BIN); // add the blend function to the StateSet stateBlend->setAttribute(bf); // set the StateSet of the Geode to the one that was just created geodeCurrent->setStateSet(stateBlend); }
Geometry* Panel::createGeometry() { _geom = new Geometry(); _panelVertices = new Vec3Array(4); setVertices(); _geom->setVertexArray(_panelVertices); // Create normals: _normals = new Vec3Array(1); (*_normals)[0].set(0.0f, 0.0f, 1.0f); _geom->setNormalArray(_normals); _geom->setNormalBinding(Geometry::BIND_OVERALL); // Create colors: _BGcolor = new Vec4Array(1); setBGColor(); _geom->setColorArray(_BGcolor); _geom->setColorBinding(Geometry::BIND_OVERALL); // Create quad: _geom->addPrimitiveSet(new DrawArrays(GL_QUADS,0,4)); _geom->setUseDisplayList(false); StateSet* stateSet = _geom->getOrCreateStateSet(); stateSet->setMode(GL_LIGHTING, StateAttribute::OFF); return _geom; }
/*************************************************************** * Function: createText() ***************************************************************/ Geode *CAVEGroupReferenceAxis::createText3D(osgText::Text3D **text) { Geode *textGeode = new Geode; *text = new osgText::Text3D; textGeode->addDrawable(*text); (*text)->setFont(CAVEGeode::getDataDir() + "Fonts/TN.ttf"); (*text)->setCharacterSize(gCharSize, 0.7); (*text)->setCharacterDepth(gCharDepth); (*text)->setPosition(Vec3(0, 0, 0)); (*text)->setAlignment(osgText::Text3D::CENTER_BOTTOM); (*text)->setDrawMode(osgText::Text3D::TEXT); (*text)->setAxisAlignment(osgText::Text3D::XZ_PLANE); (*text)->setRenderMode(osgText::Text3D::PER_GLYPH); (*text)->setText(""); Material *material = new Material; material->setDiffuse(Material::FRONT_AND_BACK, Vec4(0, 1, 0, 1)); material->setAmbient(Material::FRONT_AND_BACK, Vec4(0, 1, 0, 1)); material->setAlpha(Material::FRONT_AND_BACK, 1.0f); StateSet *stateset = textGeode->getOrCreateStateSet(); stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON); stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON ); stateset->setRenderingHint(StateSet::TRANSPARENT_BIN); return textGeode; }
/** Create PickBox geometry. */ void PickBox::createGeometry(const Vec4 &c1, const Vec4 &c2, const Vec4 &c3) { Geode *frame[NUM_BOX_COLORS]; int i; // Create geometries: _geom[0] = createWireframe(c1); _geom[1] = createWireframe(c2); _geom[2] = createWireframe(c3); // Create geodes: for (i = 0; i < NUM_BOX_COLORS; ++i) { frame[i] = new Geode(); frame[i]->addDrawable(_geom[i]); frame[i]->setNodeMask(~0); _switch->addChild(frame[i]); } updateWireframe(); // initialize wireframe color // Thick lines and lighting off: LineWidth *lineWidth = new LineWidth(); lineWidth->setWidth(4.0f); StateSet *stateset = _switch->getOrCreateStateSet(); stateset->setAttribute(lineWidth); stateset->setMode(GL_LIGHTING, StateAttribute::OFF); _scale->addChild(_switch.get()); }
void Marker::init(GeometryType gt, Interaction *interaction, float size, Vec4 &color) { Geode *geode; _gt = gt; if (_gt == CONE) geode = createCone(color); else if (_gt == BOX) geode = createBox(color); else geode = createSphere(color); setSize(size); setColor(color); // Make sure lighting is correct when marker is scaled: StateSet *stateSet = geode->getOrCreateStateSet(); stateSet->setMode(GL_RESCALE_NORMAL, StateAttribute::ON); //stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); // Philip added this else the color is not visible in opencover _interaction = interaction; _node->addChild(geode); if (_interaction) _interaction->addListener(this, this); _interactionA = new vrui::coTrackerButtonInteraction(vrui::coInteraction::ButtonA, "MarkerMove", vrui::coInteraction::Medium); _interactionB = NULL; assert(_interactionA); }
Geometry* DigitLabel::createFrame() { float width2, height2; Geometry* geom = new Geometry(); width2 = DEFAULT_LABEL_WIDTH / 2.0 * _scale; height2 = DEFAULT_LABEL_HEIGHT / 2.0 * _scale; Vec3Array* vertices = new Vec3Array(5); (*vertices)[0].set(-width2, -height2, EPSILON_Z); (*vertices)[1].set(width2, -height2, EPSILON_Z); (*vertices)[2].set(width2, height2, EPSILON_Z); (*vertices)[3].set(-width2, height2, EPSILON_Z); (*vertices)[4].set(-width2, -height2, EPSILON_Z); geom->setVertexArray(vertices); Vec3Array* normal = new Vec3Array(1); (*normal)[0].set(0.0, 0.0, 1.0); geom->setNormalArray(normal); geom->setNormalBinding(Geometry::BIND_OVERALL); _frameColor = new Vec4Array(1); (*_frameColor)[0].set(0.0, 0.0, 0.0, 1.0); geom->setColorArray(_frameColor); geom->setColorBinding(Geometry::BIND_OVERALL); geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::LINE_STRIP, 0, 5)); geom->setUseDisplayList(false); StateSet* stateSet = geom->getOrCreateStateSet(); stateSet->setMode(GL_LIGHTING, StateAttribute::OFF); return geom; }
//Constructor CAVEGeodeShape::CAVEGeodeShape(const Type &typ, const Vec3 &initVect, const Vec3 &sVect): mCenterVect(Vec3(0, 0, 0)), mNumVertices(0), mNumNormals(0), mNumTexcoords(0), mDOCollectorIndex(-1) { mVertexArray = new Vec3Array; mNormalArray = new Vec3Array; mUDirArray = new Vec3Array; mVDirArray = new Vec3Array; mTexcoordArray = new Vec2Array; mVertexMaskingVector.clear(); switch (typ) { case BOX: initGeometryBox(initVect, sVect); break; case CYLINDER: initGeometryCylinder(initVect, sVect); break; default: break; } /* texture coordinates is associated with size of the geometry */ Image* img = osgDB::readImageFile(CAVEGeode::getDataDir() + "Textures/White.JPG"); Texture2D* texture = new Texture2D(img); texture->setWrap(Texture::WRAP_S, Texture::MIRROR); texture->setWrap(Texture::WRAP_T, Texture::MIRROR); Material *material = new Material; material->setSpecular(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1)); material->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1)); material->setAlpha(Material::FRONT_AND_BACK, 1.0f); StateSet *stateset = getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0, texture, StateAttribute::ON); stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON); stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON ); stateset->setRenderingHint(StateSet::TRANSPARENT_BIN); }
//Constructor: CAVEGeodeSnapSolidshape CAVEGeodeSnapSolidshape::CAVEGeodeSnapSolidshape(): mSnappingUnitDist(0.0f) { mInitPosition = Vec3(0, 0, 0); mScaleVect = Vec3(1, 1, 1); Material* material = new Material; material->setDiffuse(Material::FRONT_AND_BACK, Vec4(1.0f, 0.5f, 0.0f, 1.0f)); material->setSpecular(Material::FRONT_AND_BACK, osg::Vec4( 1.0f, 0.5f, 0.0f, 1.0f)); material->setAlpha(Material::FRONT, 0.8f); StateSet* stateset = new StateSet(); stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON); stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | osg::StateAttribute::ON ); stateset->setMode(GL_LIGHTING, StateAttribute::OVERRIDE | StateAttribute::ON ); stateset->setRenderingHint(StateSet::TRANSPARENT_BIN); setStateSet(stateset); }
void TFColorWidget::setSize(int size) { LineWidth *width = new LineWidth(); width->setWidth(size); StateSet *state = _geom->getOrCreateStateSet(); state->setAttribute(width, osg::StateAttribute::ON); state->setMode(GL_LIGHTING, StateAttribute::OFF); }
ref_ptr<Geode> MyView::creationGeode(ref_ptr<Drawable> objet){ StateSet* stateset; ref_ptr<Geode> unBouton = new Geode; stateset = unBouton->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,StateAttribute::ON); unBouton->addDrawable(objet.get()); return unBouton; }
void Wire::coverStuff(void) { //start of design functions geom = new osg::Geometry(); geode = new Geode(); geode->setNodeMask(geode->getNodeMask() & ~(Isect::Walk | Isect::Intersection | Isect::Collision | Isect::Touch | Isect::Pick)); geom->setUseDisplayList(true); geom->setUseVertexBufferObjects(false); geode->addDrawable(geom.get()); vert = new Vec3Array; primitives = new DrawArrayLengths(PrimitiveSet::POLYGON); indices = new UShortArray(); normals = new Vec3Array; //cindices = new UShortArray() //colors = new Vec4Array(); StateSet *geoState = geom->getOrCreateStateSet(); this->createGeom(); geom->setVertexArray(vert.get()); geom->setVertexIndices(indices.get()); geom->setNormalIndices(indices.get()); geom->setNormalArray(normals.get()); //geom->setColorIndices(cindices.get()); //geom->setColorArray(colors.get()); geom->addPrimitiveSet(primitives.get()); geoState = geode->getOrCreateStateSet(); if (globalmtl.get() == NULL) { globalmtl = new Material; globalmtl->ref(); globalmtl->setColorMode(Material::OFF); globalmtl->setAmbient(Material::FRONT_AND_BACK, Vec4(0.2f, 0.2f, 0.2f, 1.0)); globalmtl->setDiffuse(Material::FRONT_AND_BACK, Vec4(0.9f, 0.9f, 0.9f, 1.0)); globalmtl->setSpecular(Material::FRONT_AND_BACK, Vec4(0.9f, 0.9f, 0.9f, 1.0)); globalmtl->setEmission(Material::FRONT_AND_BACK, Vec4(0.0f, 0.0f, 0.0f, 1.0)); globalmtl->setShininess(Material::FRONT_AND_BACK, 10.0f); } geoState->setRenderingHint(StateSet::OPAQUE_BIN); geoState->setMode(GL_BLEND, StateAttribute::OFF); geoState->setAttributeAndModes(globalmtl.get(), StateAttribute::ON); //char name[1000]; //sprintf(name,"Wire %d", this->getID()); coVRShader *SolidClipping = coVRShaderList::instance()->get("SolidClipping"); if (SolidClipping) SolidClipping->apply(geode, geom); geode->setName(this->getName()); this->coverGroup->addChild(geode.get()); //end of design functions }
// Create and return a StateSet appropriate for performing an occlusion // query test (disable lighting, texture mapping, etc). Probably some // room for improvement here. Could disable shaders, for example. StateSet* initOQState() { StateSet* state = new StateSet; // TBD Possible bug, need to allow user to set render bin number. state->setRenderBinDetails( 9, "RenderBin" ); state->setMode( GL_LIGHTING, StateAttribute::OFF | StateAttribute::PROTECTED); state->setTextureMode( 0, GL_TEXTURE_2D, StateAttribute::OFF | StateAttribute::PROTECTED); state->setMode( GL_CULL_FACE, StateAttribute::ON | StateAttribute::PROTECTED); ColorMask* cm = new ColorMask( false, false, false, false ); state->setAttributeAndModes( cm, StateAttribute::ON | StateAttribute::PROTECTED); Depth* d = new Depth( Depth::LEQUAL, 0.f, 1.f, false ); state->setAttributeAndModes( d, StateAttribute::ON | StateAttribute::PROTECTED); PolygonMode* pm = new PolygonMode( PolygonMode::FRONT_AND_BACK, PolygonMode::FILL ); state->setAttributeAndModes( pm, StateAttribute::ON | StateAttribute::PROTECTED); PolygonOffset* po = new PolygonOffset( -1., -1. ); state->setAttributeAndModes( po, StateAttribute::ON | StateAttribute::PROTECTED); return state; }
ref_ptr<MatrixTransform> MyView::creationPion(char* name,Vec4 color){ // DEFINITION DU PION StateSet* stateset; ref_ptr<ShapeDrawable> pion = new ShapeDrawable; pion->setShape(new Cone(POSINIT_ALL,0.4,0.9)); pion->setColor(color); ref_ptr<Geode> unPion = new Geode; unPion->addDrawable(pion.get()); stateset = unPion->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,StateAttribute::ON); // Définit un noeud de type transformation géométrique qui gérera le déplacement du pion1 ref_ptr<MatrixTransform> gestionPion = new MatrixTransform; // Dans le graphe de scène, lie le noeud précédant à celui accueillant le parallélépipède gestionPion->postMult(Matrix::translate(0,0,(EPAISSEUR_PLATEAU/2)+(HAUTEUR_PION/2))); gestionPion->addChild(unPion); gestionPion->setName(name); return gestionPion; }
TFColorWidget::TFColorWidget(Interaction *interaction, Measure *b, int size) : Widget() , Events() { _interaction = interaction; Geode *geode = new Geode(); _geom = new Geometry(); _geom->setUseDisplayList(false); _vertices = new Vec3Array(); _vertices->push_back(Vec3(0, 0, 0)); _vertices->push_back(Vec3(0, 0, .2)); _vector = (*_vertices)[1] - (*_vertices)[0]; _vector.normalize(); _geom->setVertexArray(_vertices); DrawElementsUInt *line = new DrawElementsUInt(osg::PrimitiveSet::LINES, 0); line->push_back(0); line->push_back(1); _geom->addPrimitiveSet(line); _colors = new Vec4Array(1); (*_colors)[0].set(0.0, 0.0, 0.0, 1.0); _geom->setColorArray(_colors); _geom->setColorBinding(osg::Geometry::BIND_OVERALL); geode->addDrawable(_geom); _node->addChild(geode); LineWidth *width = new LineWidth(); width->setWidth(size); StateSet *state = _geom->getOrCreateStateSet(); state->setAttribute(width, osg::StateAttribute::ON); state->setMode(GL_LIGHTING, StateAttribute::OFF); _interaction->addListener(this, this); }
void DigitLabel::createDigit() { _digit = 0; _value = 0.0; _digitText = new osgText::Text(); _digitText->setDataVariance(Object::DYNAMIC); _digitText->setFont(osgText::readFontFile("fonts/arial.ttf")); _digitText->setColor(COL_BLACK); _digitText->setFontResolution(20, 20); _digitText->setPosition(Vec3(0.0, 0.0, EPSILON_Z)); _digitText->setCharacterSize(DEFAULT_DIGIT_HEIGHT * _scale); _digitText->setMaximumWidth(DEFAULT_LABEL_WIDTH * _scale); _digitText->setMaximumHeight(DEFAULT_LABEL_HEIGHT * _scale); _digitText->setAlignment(osgText::Text::CENTER_CENTER); _digitText->setUseDisplayList(false); setDigit(); StateSet* stateSet = _digitText->getOrCreateStateSet(); stateSet->setMode(GL_LIGHTING, StateAttribute::OFF); }
Node *makeTrees( void ) { Group *group = new Group; int i; getDatabaseCenterRadius( dbcenter, &dbradius ); struct _tree *t; Texture2D *tex = new Texture2D; tex->setImage(osgDB::readImageFile("Images/tree0.rgba")); StateSet *dstate = new StateSet; dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON ); dstate->setTextureAttribute(0, new TexEnv ); dstate->setAttributeAndModes( new BlendFunc, StateAttribute::ON ); AlphaFunc* alphaFunc = new AlphaFunc; alphaFunc->setFunction(AlphaFunc::GEQUAL,0.05f); dstate->setAttributeAndModes( alphaFunc, StateAttribute::ON ); dstate->setMode( GL_LIGHTING, StateAttribute::OFF ); dstate->setRenderingHint( StateSet::TRANSPARENT_BIN ); int tt[] = { 15, 30, 45, 58, 72, 75, 93, 96, 105, -1 }; int *ttp = tt; i = 0; while( i < 105 ) { ttx = trees[i].x; tty = trees[i].y; qsort( &trees[i], 105 - i, sizeof( _tree ), ct ); i += *ttp; ttp++; } t = trees; i = 0; ttp = tt; while( *ttp != -1 ) { Billboard *bb = new Billboard; //int starti = i; for( ; i < (*ttp); i++ ) { t->x -= 0.3f; float h = Hat(t->x, t->y, t->z ); Vec3 pos( t->x, t->y, t->z-h ); Geometry *geom = makeTree( t, dstate ); bb->addDrawable( geom, pos ); t++; } group->addChild( bb ); ttp++; } return group; }
void TriangleShape::generate() { /**************************************************************** * * * Vertices * * * **************************************************************** */ // check if all 3 points are present, otherwise use default method to calculate vertices if(!genVer) { vertices = new Vec3Array(3); (*vertices)[0].set(p1); (*vertices)[1].set(p2); (*vertices)[2].set(p3); } else if (genVer) { vertices = new Vec3Array(); // top point Vec3d v1(center.x(), center.y(), center.z()+length/2); // bottom left point Vec3d v2((center.x()-cos(120)*length/2), center.y(), (center.z()-sin(-60)*length/2)); // bottom right point Vec3d v3((center.x()-cos(60)*length/2), center.y(), (center.z()-sin(-60)*length/2)); vertices->push_back(center); vertices->push_back(v1); vertices->push_back(center); vertices->push_back(v2); vertices->push_back(center); vertices->push_back(v3); vertices->push_back(center); vertices->push_back(v1); } setVertexArray(vertices); /**************************************************************** * * * normals * * * **************************************************************** */ Vec3Array* normals = new Vec3Array(1); (*normals)[0].set(1.0f, 1.0f, 0.0f); setNormalArray(normals); setNormalBinding(Geometry::BIND_OVERALL); /**************************************************************** * * * colors * * * **************************************************************** */ if (!genVer) { colors = new Vec4Array(3); (*colors)[0].set(color1.x(), color1.y(), color1.z(), color1.w()); (*colors)[1].set(color2.x(), color2.y(), color2.z(), color2.w()); (*colors)[2].set(color3.x(), color3.y(), color3.z(), color3.w()); addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLES, 0, 3)); } else { colors = new Vec4Array(); colors->push_back(color1); colors->push_back(color2); colors->push_back(color1); colors->push_back(color2); colors->push_back(color1); colors->push_back(color2); colors->push_back(color1); colors->push_back(color2); addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP, 0, 8)); } setColorArray(colors); setColorBinding(Geometry::BIND_PER_VERTEX); /**************************************************************** * * * stateset and material * * * **************************************************************** */ StateSet* state = getOrCreateStateSet(); state->setMode(GL_BLEND,StateAttribute::ON|StateAttribute::OVERRIDE); Material* mat = new Material(); mat->setAlpha(Material::FRONT_AND_BACK, 0.1); mat->setColorMode(Material::AMBIENT_AND_DIFFUSE); state->setAttributeAndModes(mat,StateAttribute::ON | StateAttribute::OVERRIDE); /**************************************************************** * * * blending * * * **************************************************************** */ BlendFunc* bf = new BlendFunc(BlendFunc::SRC_ALPHA, BlendFunc::ONE_MINUS_SRC_ALPHA ); state->setAttributeAndModes(bf); state->setRenderingHint(StateSet::TRANSPARENT_BIN); state->setMode(GL_LIGHTING, StateAttribute::ON); setStateSet(state); }
/*************************************************************** * Function: ANIMCreateSinglePageGeodeAnimation() ***************************************************************/ void ANIMCreateSinglePageGeodeAnimation(const string& texfilename, Geode **flipUpGeode, Geode **flipDownGeode, AnimationPathCallback **flipUpCallback, AnimationPathCallback **flipDownCallback) { /* coordinates of page object */ Vec3 topleft = Vec3(-0.19, 0, 0); Vec3 bottomleft = Vec3(-0.19, 0, -0.28); Vec3 bottomright = Vec3( 0.19, 0, -0.28); Vec3 topright = Vec3( 0.19, 0, 0); Vec3 start = Vec3(0, -0.004, 0); Vec3 end = Vec3(0, 0.008, 0); float pageH = 0.28, pageW = 0.38; /* create page pain geometry */ *flipUpGeode = new Geode; *flipDownGeode = new Geode; Geometry *pageGeometry = new Geometry(); Vec3Array* vertices = new Vec3Array; Vec2Array* texcoords = new Vec2Array(4); Vec3Array* normals = new Vec3Array; vertices->push_back(topleft); (*texcoords)[0].set(0, 1); vertices->push_back(bottomleft); (*texcoords)[1].set(0, 0); vertices->push_back(bottomright); (*texcoords)[2].set(1, 0); vertices->push_back(topright); (*texcoords)[3].set(1, 1); for (int i = 0; i < 4; i++) { normals->push_back(Vec3(0, -1, 0)); } DrawElementsUInt* rectangle = new DrawElementsUInt(PrimitiveSet::POLYGON, 0); rectangle->push_back(0); rectangle->push_back(1); rectangle->push_back(2); rectangle->push_back(3); pageGeometry->addPrimitiveSet(rectangle); pageGeometry->setVertexArray(vertices); pageGeometry->setTexCoordArray(0, texcoords); pageGeometry->setNormalArray(normals); pageGeometry->setNormalBinding(Geometry::BIND_PER_VERTEX); (*flipUpGeode)->addDrawable(pageGeometry); (*flipDownGeode)->addDrawable(pageGeometry); /* apply image textures to page geodes */ Image* imgFloorplan = osgDB::readImageFile(texfilename); int imgW = imgFloorplan->s(); int imgH = imgFloorplan->t(); Texture2D* texFloorplan = new Texture2D(imgFloorplan); texFloorplan->setWrap(Texture::WRAP_S, Texture::CLAMP); texFloorplan->setWrap(Texture::WRAP_T, Texture::CLAMP); float imgRatio = (float) imgW / imgH; float pageRatio = pageW / pageH; if (imgRatio <= pageRatio) { (*texcoords)[0].set((1.0 - pageRatio / imgRatio) * 0.5, 1); (*texcoords)[1].set((1.0 - pageRatio / imgRatio) * 0.5, 0); (*texcoords)[2].set((1.0 + pageRatio / imgRatio) * 0.5, 0); (*texcoords)[3].set((1.0 + pageRatio / imgRatio) * 0.5, 1); } else { (*texcoords)[0].set(0, (1.0 + imgRatio / pageRatio) * 0.5); (*texcoords)[1].set(0, (1.0 - imgRatio / pageRatio) * 0.5); (*texcoords)[2].set(1, (1.0 - imgRatio / pageRatio) * 0.5); (*texcoords)[3].set(1, (1.0 + imgRatio / pageRatio) * 0.5); } Material *transmaterial = new Material; transmaterial->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1)); transmaterial->setAlpha(Material::FRONT_AND_BACK, 0.8f); Material *solidmaterial = new Material; solidmaterial->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1)); solidmaterial->setAlpha(Material::FRONT_AND_BACK, 1.0f); StateSet *flipUpStateSet = (*flipUpGeode)->getOrCreateStateSet(); flipUpStateSet->setTextureAttributeAndModes(0, texFloorplan, StateAttribute::ON); flipUpStateSet->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON ); flipUpStateSet->setRenderingHint(StateSet::TRANSPARENT_BIN); flipUpStateSet->setAttributeAndModes(transmaterial, StateAttribute::OVERRIDE | StateAttribute::ON); StateSet *flipDownStateSet = (*flipDownGeode)->getOrCreateStateSet(); flipDownStateSet->setTextureAttributeAndModes(0, texFloorplan, StateAttribute::ON); flipDownStateSet->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON ); flipDownStateSet->setRenderingHint(StateSet::TRANSPARENT_BIN); flipDownStateSet->setAttributeAndModes(solidmaterial, StateAttribute::OVERRIDE | StateAttribute::ON); /* create page flipping animation call backs */ AnimationPath* animationPathFlipUp = new AnimationPath; AnimationPath* animationPathFlipDown = new AnimationPath; animationPathFlipUp->setLoopMode(AnimationPath::NO_LOOPING); animationPathFlipDown->setLoopMode(AnimationPath::NO_LOOPING); Vec3 flipUpOffset, flipDownOffset; Quat flipUpQuat, flipDownQuat; Vec3 offsetstep = (end - start) / ANIM_SKETCH_BOOK_PAGE_FLIP_SAMPS; float anglestep = M_PI * 2 / ANIM_SKETCH_BOOK_PAGE_FLIP_SAMPS; float timestep = 1.0f / ANIM_SKETCH_BOOK_PAGE_FLIP_SAMPS; for (int i = 0; i < ANIM_SKETCH_BOOK_PAGE_FLIP_SAMPS + 1; i++) { float val = i * timestep; flipUpOffset = start + offsetstep * i; flipDownOffset = end - offsetstep * i; flipUpQuat = Quat(i * anglestep, Vec3(-1, 0, 0)); flipDownQuat = Quat(i * anglestep, Vec3(1, 0, 0)); animationPathFlipUp->insert(val, AnimationPath::ControlPoint(flipUpOffset, flipUpQuat, Vec3(1, 1, 1))); animationPathFlipDown->insert(val, AnimationPath::ControlPoint(flipDownOffset, flipDownQuat, Vec3(1, 1, 1))); } *flipUpCallback = new AnimationPathCallback(animationPathFlipUp, 0.0, 1.0f / ANIM_SKETCH_BOOK_PAGE_FLIP_TIME); *flipDownCallback = new AnimationPathCallback(animationPathFlipDown, 0.0, 1.0f / ANIM_SKETCH_BOOK_PAGE_FLIP_TIME); }
Rectangle::Rectangle(Interaction* interaction) : Widget(), Events() { StateSet *state; _interaction = interaction; // create rectangle geometry _rectGeode = new Geode(); _node->addChild(_rectGeode); _rectGeom = new Geometry(); _rectGeode->addDrawable(_rectGeom); _vertices = new Vec3Array(4); (*_vertices)[0].set(-0.5, -0.5, 0.0); (*_vertices)[1].set(0.5, -0.5, 0.0); (*_vertices)[2].set(0.5, 0.5, 0.0); (*_vertices)[3].set(-0.5, 0.5, 0.0); _rectGeom->setVertexArray(_vertices); _rectColor = new Vec4Array(1); (*_rectColor)[0].set(1.0, 1.0, 1.0, 1.0); _rectGeom->setColorArray(_rectColor); _rectGeom->setColorBinding(Geometry::BIND_OVERALL); _rectGeom->setUseDisplayList(false); _rectGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4)); state = _rectGeode->getOrCreateStateSet(); state->setMode(GL_LIGHTING, StateAttribute::OFF); // create spheres _sphere1Color.set(0.0, 0.0, 1.0, 1.0); _sphere2Color.set(0.0, 0.0, 1.0, 1.0); _sphere1Geode = new Geode(); _node->addChild(_sphere1Geode); _sphere2Geode = new Geode(); _node->addChild(_sphere2Geode); _sphere1 = new Sphere((*_vertices)[0], 0.05); _sphere1Drawable = new ShapeDrawable(_sphere1); _sphere1Drawable->setColor(_sphere1Color); _sphere1Drawable->setUseDisplayList(false); _sphere2 = new Sphere((*_vertices)[2], 0.05); _sphere2Drawable = new ShapeDrawable(_sphere2); _sphere2Drawable->setColor(_sphere2Color); _sphere2Drawable->setUseDisplayList(false); _sphere1Geode->addDrawable(_sphere1Drawable); _sphere2Geode->addDrawable(_sphere2Drawable); state = _sphere1Geode->getOrCreateStateSet(); state->setMode(GL_LIGHTING, StateAttribute::OFF); state = _sphere2Geode->getOrCreateStateSet(); state->setMode(GL_LIGHTING, StateAttribute::OFF); _corners = new Vec3Array(4); _edges = new Vec3Array(4); updateRectangle(); _interaction->addListener(this, this); }
/*************************************************************** * Function: createFloorplanGeometry() ***************************************************************/ void VirtualScenicHandler::createFloorplanGeometry(const int numPages, CAVEAnimationModeler::ANIMPageEntry **pageEntryArray) { if (numPages <= 0) { return; } for (int i = 0; i < numPages; i++) { // create floorplan geometry float length = pageEntryArray[i]->mLength; float width = pageEntryArray[i]->mWidth; float altitude = pageEntryArray[i]->mAlti; Geode *floorplanGeode = new Geode; Geometry *floorplanGeometry = new Geometry; Vec3Array* vertices = new Vec3Array; Vec3Array* normals = new Vec3Array; Vec2Array* texcoords = new Vec2Array(4); vertices->push_back(Vec3(-length / 2, width / 2, altitude)); (*texcoords)[0].set(0, 1); vertices->push_back(Vec3(-length / 2, -width / 2, altitude)); (*texcoords)[1].set(0, 0); vertices->push_back(Vec3( length / 2, -width / 2, altitude)); (*texcoords)[2].set(1, 0); vertices->push_back(Vec3( length / 2, width / 2, altitude)); (*texcoords)[3].set(1, 1); for (int k = 0; k < 4; k++) { normals->push_back(Vec3(0, 0, 1)); } DrawElementsUInt* rectangle = new DrawElementsUInt(PrimitiveSet::POLYGON, 0); rectangle->push_back(0); rectangle->push_back(1); rectangle->push_back(2); rectangle->push_back(3); floorplanGeometry->addPrimitiveSet(rectangle); floorplanGeometry->setVertexArray(vertices); floorplanGeometry->setNormalArray(normals); floorplanGeometry->setTexCoordArray(0, texcoords); floorplanGeometry->setNormalBinding(Geometry::BIND_PER_VERTEX); floorplanGeode->addDrawable(floorplanGeometry); mFloorplanSwitch->addChild(floorplanGeode); /* load floorplan images */ Material *transmaterial = new Material; transmaterial->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1)); transmaterial->setAlpha(Material::FRONT_AND_BACK, 1.0f); Image* imgFloorplan = osgDB::readImageFile(pageEntryArray[i]->mTexFilename); Texture2D* texFloorplan = new Texture2D(imgFloorplan); StateSet *floorplanStateSet = floorplanGeode->getOrCreateStateSet(); floorplanStateSet->setTextureAttributeAndModes(0, texFloorplan, StateAttribute::ON); floorplanStateSet->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON ); floorplanStateSet->setRenderingHint(StateSet::TRANSPARENT_BIN); floorplanStateSet->setAttributeAndModes(transmaterial, StateAttribute::OVERRIDE | StateAttribute::ON); } }
void CircleShape::generate() { /******************************************************************** * * * Vertices * * * ******************************************************************** */ int numVertices = 0; vertices = new Vec3Array; for (int i=0; i <= 360; i = i + degree ) { double angle = (i*2*PI)/360; double x,z; x = cos(angle)*radius; z = sin(angle)*radius; vertices->push_back(center); vertices->push_back(Vec3d(x,0,z)+center); numVertices+=2; } vertices->push_back(center); setVertexArray(vertices); /******************************************************************** * * * colors * * * ******************************************************************** */ colors = new Vec4Array(numVertices); for (int g = 0; g < numVertices; g+=2) { (*colors)[g].set(color.x(), color.y(), color.z(), color.w()); (*colors)[g+1].set(gradient.x(), gradient.y(), gradient.z(), gradient.w()); } setColorArray(colors); setColorBinding(Geometry::BIND_PER_VERTEX); addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP, 0,2+(360*2/degree))); /******************************************************************** * * * stateset and material * * * ******************************************************************** */ // stateset and material StateSet* state = getOrCreateStateSet(); state->setMode(GL_BLEND,StateAttribute::ON|StateAttribute::OVERRIDE); Material* mat = new Material(); mat->setAlpha(Material::FRONT_AND_BACK, 0.1); mat->setColorMode(Material::AMBIENT_AND_DIFFUSE); state->setAttributeAndModes(mat,StateAttribute::ON | StateAttribute::OVERRIDE); /******************************************************************** * * * blending * * * ******************************************************************** */ // blending BlendFunc* bf = new BlendFunc(BlendFunc::SRC_ALPHA, BlendFunc::ONE_MINUS_SRC_ALPHA ); state->setAttributeAndModes(bf); state->setRenderingHint(StateSet::TRANSPARENT_BIN); state->setMode(GL_LIGHTING, StateAttribute::ON); setStateSet(state); }
Geode *ClipPlanePlugin::loadPlane() { // *5---*6---*7 // | | | // *3--------*4 // | | | // *0---*1---*2 float w = cover->getSceneSize() * 0.1; // width of plane Vec3Array *lineCoords = new Vec3Array(12); (*lineCoords)[0].set(-w, -0.01, -w); (*lineCoords)[1].set(w, -0.01, -w); (*lineCoords)[2].set(-w, -0.01, 0.0f); (*lineCoords)[3].set(w, -0.01, 0.0f); (*lineCoords)[4].set(-w, -0.01, w); (*lineCoords)[5].set(w, -0.01, w); (*lineCoords)[6].set(-w, -0.01, -w); (*lineCoords)[7].set(-w, -0.01, w); (*lineCoords)[8].set(0.0f, -0.01, -w); (*lineCoords)[9].set(0.0f, -0.01, w); (*lineCoords)[10].set(w, -0.01, -w); (*lineCoords)[11].set(w, -0.01, w); DrawArrayLengths *primitives = new DrawArrayLengths(PrimitiveSet::LINE_STRIP); for (int i = 0; i < 6; i++) { primitives->push_back(2); } Vec3Array *lineColors = new Vec3Array(12); for (int i = 0; i < 12; i++) { (*lineColors)[i].set(Vec3(1.0f, 1.0f, 1.0f)); } Geometry *geoset = new Geometry(); geoset->setVertexArray(lineCoords); geoset->addPrimitiveSet(primitives); geoset->setColorArray(lineColors); Material *mtl = new Material; mtl->setColorMode(Material::AMBIENT_AND_DIFFUSE); mtl->setAmbient(Material::FRONT_AND_BACK, Vec4(0.2f, 0.2f, 0.2f, 1.0f)); mtl->setDiffuse(Material::FRONT_AND_BACK, Vec4(0.9f, 0.9f, 0.9f, 1.0f)); mtl->setSpecular(Material::FRONT_AND_BACK, Vec4(0.9f, 0.9f, 0.9f, 1.0f)); mtl->setEmission(Material::FRONT_AND_BACK, Vec4(0.0f, 0.0f, 0.0f, 1.0f)); mtl->setShininess(Material::FRONT_AND_BACK, 16.0f); Geode *geode = new Geode; geode->setName("ClipPlane"); geode->addDrawable(geoset); StateSet *geostate = geode->getOrCreateStateSet(); geostate->setAttributeAndModes(mtl, StateAttribute::ON); geostate->setMode(GL_LIGHTING, StateAttribute::OFF); LineWidth *lineWidth = new LineWidth(3.0); geostate->setAttributeAndModes(lineWidth, StateAttribute::ON); geode->setStateSet(geostate); return geode; }