Example #1
0
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);
}
Example #2
0
/***************************************************************
* 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;
}
Example #3
0
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();
}
Example #4
0
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);
}
/***************************************************************
* 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;
}
//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: 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);
}
Example #8
0
File: Wire.cpp Project: nixz/covise
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
}
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);
}
//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);
}
Example #11
0
File: trees.cpp Project: Sylla/osg
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);


	
}
Example #13
0
/***************************************************************
* 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);
}
/***************************************************************
* Function: ANIMLoadGeometryCreator()
*
* xformScaleFwd: Root transform node for inflating geometries
* xformScaleBwd: Root transform node for shrinking geometries
* sphereExteriorSwitch: Switch control for single exterior sphere
*
***************************************************************/
void ANIMLoadGeometryCreator(PositionAttitudeTransform** xformScaleFwd, PositionAttitudeTransform** xformScaleBwd,
			     Switch **sphereExteriorSwitch, Geode **sphereExteriorGeode,
			     int &numTypes, ANIMShapeSwitchEntry ***shapeSwitchEntryArray)
{
    *xformScaleFwd = new PositionAttitudeTransform;
    *xformScaleBwd = new PositionAttitudeTransform;

    MatrixTransform *geomCreatorTrans = new MatrixTransform;

    MatrixTransform *sphereExteriorTrans = new MatrixTransform;
    *sphereExteriorSwitch = new Switch;
    Switch *createBoxSwitch = new Switch;
    Switch *createCylinderSwitch = new Switch;

    (*xformScaleFwd)->addChild(geomCreatorTrans);
    (*xformScaleBwd)->addChild(geomCreatorTrans);

    geomCreatorTrans->addChild(*sphereExteriorSwitch);
    geomCreatorTrans->addChild(createBoxSwitch);
    geomCreatorTrans->addChild(createCylinderSwitch);
    
    osg::Vec3 pos(-1, 0, 0);

    // create drawables, geodes and attach them to animation switches
    *sphereExteriorGeode = new Geode();
    Sphere *sphere = new Sphere(osg::Vec3(), ANIM_VIRTUAL_SPHERE_RADIUS);
    ShapeDrawable *sphereDrawable = new ShapeDrawable(sphere);
    (*sphereExteriorGeode)->addDrawable(sphereDrawable);


    Box *box = new Box(osg::Vec3(0.1, 0, 0), ANIM_VIRTUAL_SPHERE_RADIUS / 1.9);
    (*sphereExteriorGeode)->addDrawable(new ShapeDrawable(box));

    float r = ANIM_VIRTUAL_SPHERE_RADIUS / 3.0;
    Cylinder *cylinder = new Cylinder(osg::Vec3(-0.05, 0, -0.05), r, r * 2);
    (*sphereExteriorGeode)->addDrawable(new ShapeDrawable(cylinder));
    
    Cone *cone = new osg::Cone(osg::Vec3(0, -0.1, 0.05), r, r * 2);
    (*sphereExteriorGeode)->addDrawable(new ShapeDrawable(cone));


    Material *transmaterial = new Material;
    transmaterial->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
    transmaterial->setAlpha(Material::FRONT_AND_BACK, 0.6f);

    Image* envMap = osgDB::readImageFile(ANIMDataDir() + "Textures/ShapeContainer.JPG");
    Texture2D* envTex = new Texture2D(envMap);    
    
    StateSet *sphereStateSet = (sphereDrawable)->getOrCreateStateSet();
    sphereStateSet->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON );
    sphereStateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
    sphereStateSet->setAttributeAndModes(transmaterial, StateAttribute::OVERRIDE | StateAttribute::ON);
    sphereStateSet->setTextureAttributeAndModes(0, envTex, StateAttribute::ON);
    sphereStateSet->setMode(GL_CULL_FACE, StateAttribute::ON);

    sphereExteriorTrans->addChild(*sphereExteriorGeode);
    (*sphereExteriorSwitch)->addChild(sphereExteriorTrans);
    (*sphereExteriorSwitch)->setAllChildrenOn();

    // write into shape switch entry array record
    numTypes = 2;
    *shapeSwitchEntryArray = new ANIMShapeSwitchEntry*[numTypes];
    (*shapeSwitchEntryArray)[0] = new ANIMShapeSwitchEntry;
    (*shapeSwitchEntryArray)[1] = new ANIMShapeSwitchEntry;
    (*shapeSwitchEntryArray)[0]->mSwitch = createBoxSwitch;
    (*shapeSwitchEntryArray)[1]->mSwitch = createCylinderSwitch;

    ANIMCreateSingleShapeSwitchAnimation(&((*shapeSwitchEntryArray)[0]), CAVEGeodeShape::BOX);
    ANIMCreateSingleShapeSwitchAnimation(&((*shapeSwitchEntryArray)[1]), CAVEGeodeShape::CYLINDER);

    /* set up the forward / backward scale animation paths for geometry creator */
    AnimationPath* animationPathScaleFwd = new AnimationPath;
    AnimationPath* animationPathScaleBwd = new AnimationPath;
    animationPathScaleFwd->setLoopMode(AnimationPath::NO_LOOPING);
    animationPathScaleBwd->setLoopMode(AnimationPath::NO_LOOPING);
   
    Vec3 scaleFwd, scaleBwd;
    float step = 1.f / ANIM_VIRTUAL_SPHERE_NUM_SAMPS;
    for (int i = 0; i < ANIM_VIRTUAL_SPHERE_NUM_SAMPS + 1; i++)
    {
        float val = i * step;
        scaleFwd = Vec3(val, val, val);
        scaleBwd = Vec3(1.f-val, 1.f-val, 1.f-val);
        animationPathScaleFwd->insert(val, AnimationPath::ControlPoint(pos, Quat(), scaleFwd));
        animationPathScaleBwd->insert(val, AnimationPath::ControlPoint(pos, Quat(), scaleBwd));
    }

    AnimationPathCallback *animCallbackFwd = new AnimationPathCallback(animationPathScaleFwd, 
						0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME);
    AnimationPathCallback *animCallbackBwd = new AnimationPathCallback(animationPathScaleBwd, 
						0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME); 
    (*xformScaleFwd)->setUpdateCallback(animCallbackFwd);
    (*xformScaleBwd)->setUpdateCallback(animCallbackBwd);
}
Example #15
0
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);
}
/***************************************************************
* 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);
    }
}
Example #17
0
void BoxShape::generate()	
{
	/****************************************************************
	 *								*
	 *			Vertices				*
	 *								*
	 ****************************************************************
	 */
	vertices = new Vec3Array();

  //assuming box points coming this way:        5-----------6
  //                                           /|          /|
  //                                          / |         / |
  //                                         /  |        /  |
  //                                        0---4-------3---7
  //                                        |  /        |  /
  //                                        | /         | / 
  //                                        |/          |/   
  //                                        1-----------2 




	// check if all 4 points are present, otherwise use default method to calculate vertices
	if(!genVer)
	{		
		vertices->push_back(p1);
		vertices->push_back(p2);
		vertices->push_back(p3);		
		vertices->push_back(p4);
		vertices->push_back(p5);
		vertices->push_back(p6);
		vertices->push_back(p7);		
		vertices->push_back(p8);
		
		//setVertexArray(vertices);
			
		
	}
	else if (genVer)
	{		                                                    // -y = coming out of screen?
		vertices->push_back(Vec3( center.x()-(width/2) , center.y()-(depth/2) , center.z()+(height/2) ));
		vertices->push_back(Vec3( center.x()-(width/2) , center.y()-(depth/2) , center.z()-(height/2) ));
		vertices->push_back(Vec3( center.x()+(width/2) , center.y()-(depth/2) , center.z()-(height/2) ));		
		vertices->push_back(Vec3( center.x()+(width/2) , center.y()-(depth/2) , center.z()+(height/2) ));
		vertices->push_back(Vec3( center.x()-(width/2) , center.y()+(depth/2) , center.z()-(height/2) ));
		vertices->push_back(Vec3( center.x()-(width/2) , center.y()+(depth/2) , center.z()+(height/2) ));
		vertices->push_back(Vec3( center.x()+(width/2) , center.y()+(depth/2) , center.z()+(height/2) ));		
		vertices->push_back(Vec3( center.x()+(width/2) , center.y()+(depth/2) , center.z()-(height/2) ));
		
		//setVertexArray(vertices);
	
	}

	  setVertexArray(vertices);
  	
  	//front face
		DrawElementsUInt* frontface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
		frontface->push_back(0);
		frontface->push_back(1);
		frontface->push_back(2);
		frontface->push_back(3);
		addPrimitiveSet(frontface);
		//back face
		DrawElementsUInt* backface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
		backface->push_back(4);
		backface->push_back(5);
		backface->push_back(6);
		backface->push_back(7);
		addPrimitiveSet(backface);
		//top face
		DrawElementsUInt* topface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
		topface->push_back(5);
		topface->push_back(0);
		topface->push_back(3);
		topface->push_back(6);
		addPrimitiveSet(topface);
		//bottom face
		DrawElementsUInt* bottomface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
		bottomface->push_back(1);
		bottomface->push_back(4);
		bottomface->push_back(7);
		bottomface->push_back(2);
		addPrimitiveSet(bottomface);
		//left face
		DrawElementsUInt* leftface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
		leftface->push_back(0);
		leftface->push_back(5);
		leftface->push_back(4);
		leftface->push_back(1);
		addPrimitiveSet(leftface);
		//right face
		DrawElementsUInt* rightface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
		rightface->push_back(3);
		rightface->push_back(2);
		rightface->push_back(7);
		rightface->push_back(6);
		addPrimitiveSet(rightface);



	/****************************************************************
	 *								*
	 *			normals	  				*
	 *								*
	 ****************************************************************
	 */


	Vec3Array* normals = new Vec3Array(1);
	(*normals)[0].set(1.0f, 1.0f, 1.0f);
	setNormalArray(normals);
	setNormalBinding(Geometry::BIND_OVERALL);

	/****************************************************************
	 *								*
	 *			colors					*
	 *								*
	 ****************************************************************
	 */
	/*if (!genVer)
	{
		colors = new Vec4Array(8);
		(*colors)[0].set(color1.x(), color1.y(), color1.z(), color1.w());
		(*colors)[1].set(color1.x(), color1.y(), color1.z(), color1.w());
		(*colors)[2].set(color2.x(), color2.y(), color2.z(), color2.w());		
		(*colors)[3].set(color2.x(), color2.y(), color2.z(), color2.w());	
		(*colors)[4].set(color1.x(), color1.y(), color1.z(), color1.w());
		(*colors)[5].set(color1.x(), color1.y(), color1.z(), color1.w());
		(*colors)[6].set(color2.x(), color2.y(), color2.z(), color2.w());		
		(*colors)[7].set(color2.x(), color2.y(), color2.z(), color2.w());	
		
	}
	else
	{*/
		colors = new Vec4Array(8);
		(*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(color1.x(), color1.y(), color1.z(), color1.w());
		(*colors)[3].set(color2.x(), color2.y(), color2.z(), color2.w());
		(*colors)[4].set(color1.x(), color1.y(), color1.z(), color1.w());
		(*colors)[5].set(color2.x(), color2.y(), color2.z(), color2.w());
		(*colors)[6].set(color1.x(), color1.y(), color1.z(), color1.w());
		(*colors)[7].set(color2.x(), color2.y(), color2.z(), color2.w());
		//(*colors)[8].set(color1.x(), color1.y(), color1.z(), color1.w());	
		//(*colors)[9].set(color2.x(), color2.y(), color2.z(), color2.w());
	
	//}
	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);


	

}