Beispiel #1
0
void Patch::init()
{
    for (int res = 0; res < 2; ++res)
    {
        for (int trile = 0; trile < 4; ++trile)
        {
            Geometry* geom = new Geometry;
            geom->setUseVertexBufferObjects(true);
            _data->setGeometryAttributes(geom);
            geom->addPrimitiveSet(_patchSet->trilePset[res][trile]);
            _trile[res][trile] = new Geode;
            _trile[res][trile]->addDrawable(geom);
        }
    }
    for (int j = 0; j < 4; ++j)
    {
        for (int i = 0; i < 4; ++i)
        {
            Geometry* geom = new Geometry;
            geom->setUseVertexBufferObjects(true);
            _data->setGeometryAttributes(geom);
            geom->addPrimitiveSet(_patchSet->stripPset[j][i]);
            _strip[j][i] = new Geode;
            _strip[j][i]->addDrawable(geom);
        }
    }
}
Beispiel #2
0
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;
}
Beispiel #3
0
Geode* createTextureQuad(Texture2D *texture)
{
    Vec3Array *vertices = new Vec3Array;
    vertices->push_back(Vec3(-1.0, -1.0, 0.0));
    vertices->push_back(Vec3(1.0, -1.0, 0.0));
    vertices->push_back(Vec3(1.0, 1.0, 0.0));
    vertices->push_back(Vec3(-1.0, 1.0, 0.0));

    Vec2Array *texcoord = new Vec2Array;
    texcoord->push_back(Vec2(0.0, 0.0));
    texcoord->push_back(Vec2(1.0, 0.0));
    texcoord->push_back(Vec2(1.0, 1.0));
    texcoord->push_back(Vec2(0.0, 1.0));

    Geometry *geom = new Geometry;
    geom->setVertexArray(vertices);
    geom->setTexCoordArray(0, texcoord);
    geom->addPrimitiveSet(new DrawArrays(GL_QUADS, 0, 4));

    Geode *geode = new Geode;
    geode->addDrawable(geom);
    geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, StateAttribute::ON);

    return geode;
}
Beispiel #4
0
/** This creates the wireframe PickBox around the widget.
  Volume vertex names:
  <PRE>
      4____ 7        y
     /___ /|         |
   0|   3| |         |___x
    | 5  | /6       /
    |/___|/        z
    1    2
  </PRE>
*/
Geometry *PickBox::createWireframe(const Vec4 &color)
{
    Geometry *geom = new Geometry();

    updateVertices(geom);

    // Set colors:
    Vec4Array *colors = new Vec4Array();
    colors->push_back(color);
    geom->setColorArray(colors);
    geom->setColorBinding(Geometry::BIND_OVERALL);

    // Set normals:
    Vec3Array *normals = new Vec3Array();
    normals->push_back(Vec3(0.0f, 0.0f, 1.0f));
    geom->setNormalArray(normals);
    geom->setNormalBinding(Geometry::BIND_OVERALL);

    // This time we simply use primitive, and hardwire the number of coords
    // to use since we know up front:
    geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::LINES, 0, 24));

    geom->setUseDisplayList(false); // allow dynamic changes

    return geom;
}
Beispiel #5
0
MoonNode::MoonNode() : osg::Group()
{
	haveTexture = false;
	m_DirtyImage = true;
	m_Latitude = -100.0;
	m_EarthShine = 0.0;

	m_RenderDistance = SKY_DOME_RADIUS;
	float x, y;
	x = y = 1.0;

	// set up the drawstate.
	m_MoonStateSet = new osg::StateSet;


	osg::BlendFunc *bf = new osg::BlendFunc;
	bf->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
	m_MoonStateSet->setAttributeAndModes(bf, osg::StateAttribute::ON);

	// set up the geoset.
	Geometry* geom = new Geometry;
	geom->setStateSet( m_MoonStateSet.get() );

	Vec3Array* coords = new Vec3Array(4);
	(*coords)[0].set(-x,0.0f,y);
	(*coords)[1].set(-x,0.0f,-y);
	(*coords)[2].set(x,0.0f,-y);
	(*coords)[3].set(x,0.0f,y);
	geom->setVertexArray(coords);

	Vec2Array* tcoords = new Vec2Array(4);
	(*tcoords)[0].set(0.0f,1.0f);
	(*tcoords)[1].set(0.0f,0.0f);
	(*tcoords)[2].set(1.0f,0.0f);
	(*tcoords)[3].set(1.0f,1.0f);
	geom->setTexCoordArray(0,tcoords);

	osg::Vec4Array* colours = new osg::Vec4Array(1);
	(*colours)[0].set(1.0f,1.0f,1.0,1.0f);
	geom->setColorArray(colours);
	geom->setColorBinding(Geometry::BIND_OVERALL);

	geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS,0,4));

	m_Moon = geom;
	
	m_Transform = new osg::MatrixTransform;
	addChild( m_Transform.get() );

	m_Billboard = new AstroBillboard;
	m_Billboard->setCullingActive(false);
	m_Billboard->setStateSet( m_MoonStateSet.get() );
	m_Billboard->addDrawable(m_Moon.get());
	m_Billboard->setAxes(osg::Vec3(0.0,1.0,0.0), osg::Vec3(0.0,0.0,1.0), osg::Vec3(0.0,1.0,0.0));
	m_Transform->addChild(m_Billboard.get());
	m_Transform->setStateSet( m_MoonStateSet.get() );
	m_Transform->setCullingActive(false);

}
Beispiel #6
0
Geode* ChessUtils::createRectangleWithTexture(Vec3 centerPosition, Image* image, int width, int height, Vec4 color) {
	int halfWidth = width / 2;
	int halfHeight = height / 2;

	Vec3Array* vertices = new Vec3Array();	
	vertices->push_back(Vec3(centerPosition.x() - halfWidth, centerPosition.y() - halfHeight, centerPosition.z()));
	vertices->push_back(Vec3(centerPosition.x() + halfWidth, centerPosition.y() - halfHeight, centerPosition.z()));
	vertices->push_back(Vec3(centerPosition.x() + halfWidth, centerPosition.y() + halfHeight, centerPosition.z()));
	vertices->push_back(Vec3(centerPosition.x() - halfWidth, centerPosition.y() + halfHeight, centerPosition.z()));

	Vec3Array* normals = new Vec3Array();
	normals->push_back(Vec3(0.0f, 0.0f, 1.0f));

	Vec2Array* texcoords = new Vec2Array();
	texcoords->push_back(Vec2(0.0f, 0.0f));
	texcoords->push_back(Vec2(1.0f, 0.0f));
	texcoords->push_back(Vec2(1.0f, 1.0f));
	texcoords->push_back(Vec2(0.0f, 1.0f));

	Vec4Array* colors = new Vec4Array();
	colors->push_back(color);

	Geometry* quad = new Geometry();
	quad->setVertexArray(vertices);
	quad->setNormalArray(normals);
	quad->setNormalBinding(osg::Geometry::BIND_OVERALL);	
	quad->setColorArray(colors);
	quad->setColorBinding(osg::Geometry::BIND_OVERALL);
	quad->setTexCoordArray(0, texcoords);
	quad->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));

	Texture2D* texture = new Texture2D();
	if (image != NULL) {
		texture->setImage(image);
	}			

	Geode* geode = new Geode();
	geode->addDrawable(quad);

	osg::BlendFunc* blendFunc = new osg::BlendFunc();
	blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	osg::TexEnv* blendTexEnv = new osg::TexEnv();
	blendTexEnv->setMode(osg::TexEnv::BLEND);

	osg::StateSet* geodeStateset = geode->getOrCreateStateSet();
	geodeStateset->setAttributeAndModes(blendFunc);
	geodeStateset->setTextureAttribute(0, blendTexEnv);
	geodeStateset->setTextureAttributeAndModes(0, texture);
	geodeStateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
	
	return geode;
}
Beispiel #7
0
static Geometry *makeTree( _tree *tree, StateSet *dstate )
{
    float vv[][3] =
    {
        { -tree->w/2.0f, 0.0f, 0.0f },
        {  tree->w/2.0f, 0.0f, 0.0f },
        {  tree->w/2.0f, 0.0f, 2.0f * tree->h },
        { -tree->w/2.0f, 0.0f, 2.0f * tree->h },
    };

    Vec3Array& v = *(new Vec3Array(4));
    Vec2Array& t = *(new Vec2Array(4));
    Vec4Array& l = *(new Vec4Array(1));

    int   i;

    l[0][0] = l[0][1] = l[0][2] = l[0][3] = 1;

    for( i = 0; i < 4; i++ )
    {
        v[i][0] = vv[i][0];
        v[i][1] = vv[i][1];
        v[i][2] = vv[i][2];
    }

    t[0][0] = 0.0; t[0][1] = 0.0;
    t[1][0] = 1.0; t[1][1] = 0.0;
    t[2][0] = 1.0; t[2][1] = 1.0;
    t[3][0] = 0.0; t[3][1] = 1.0;

    Geometry *geom = new Geometry;

    geom->setVertexArray( &v );

    geom->setTexCoordArray( 0, &t );

    geom->setColorArray( &l );
    geom->setColorBinding( Geometry::BIND_OVERALL );

    geom->addPrimitiveSet( new DrawArrays(PrimitiveSet::QUADS,0,4) );

    geom->setStateSet( dstate );

    return geom;
}
Beispiel #8
0
Hyperspace::Hyperspace()
{
	setGlows(false);
	//start by creating a bunch of "stars"
	int stars = 2500;
	osg::Geode* geode = new Geode();
	Geometry* geom = new Geometry;
	geode->addDrawable(geom);
	Vec4Array* colors = new Vec4Array();
	colors->push_back(Vec4(1, 1, 1, 1));
	geom->setColorArray(colors);
	geom->setColorBinding(Geometry::BIND_OVERALL);
	Vec3Array* verts = new Vec3Array();
	geom->setVertexArray(verts);
	geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLES, 0, stars*3));
	geom->getOrCreateStateSet()->setMode(GL_LIGHTING, false);
	for(int i  = 0; i < stars; i++)
	{
		float radius = Util::random(10, 150);
		float theta = 6.28 * Util::loggedRandom("Hyperspace theta") / RAND_MAX;
		float s = cosf(theta);
		float c = sinf(theta);
		Vec3 localUp(-s, c, 0);
		float width = Util::random(0.1, 0.25) * radius / 25;;
		float length = Util::random(10, 30) * radius / 20;
		float z = 0;
		Vec3 basePos(c*radius, s*radius, z+length*0.5);
		Vec3 zDir(0, 0, 1);
		verts->push_back(basePos + zDir * length * 0.5 + localUp * width * 0);
//		verts->push_back(basePos + zDir * length * 0.5 - localUp * width * 0.5);
		verts->push_back(basePos - zDir * length * 0.5 - localUp * width * 0.5);
		verts->push_back(basePos - zDir * length * 0.5 + localUp * width * 0.5);
	}
	mPat->setPosition(Vec3(0, 0, -250));
	mPat->addChild(geode);
	mHSTime = -1;
	update(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);
}
Beispiel #10
0
PositionAttitudeTransform *VideoGeode::createVideoPlane(float sizeX, float sizeY, bool texRepeat)
{
	// vertex array
	Vec3Array *vertexArray = new Vec3Array();
   
   sizeX /= 2.0;
   sizeY /= 2.0;
	
   vertexArray->push_back(Vec3(-sizeX, 0, -sizeY));
	vertexArray->push_back(Vec3(sizeX, 0, -sizeY));
	vertexArray->push_back(Vec3(sizeX, 0, sizeY));
	vertexArray->push_back(Vec3(-sizeX, 0, sizeY));

	
   /*vertexArray->push_back(Vec3(-sizeX, -sizeY, 0));
	vertexArray->push_back(Vec3(sizeX, -sizeY, 0));
	vertexArray->push_back(Vec3(sizeX, sizeY, 0));
	vertexArray->push_back(Vec3(-sizeX, sizeY, 0));*/
   
	// face array
	DrawElementsUInt *faceArray = new DrawElementsUInt(PrimitiveSet::TRIANGLES, 0);
	
	faceArray->push_back(0); // face 1
	faceArray->push_back(1);
	faceArray->push_back(2);
	faceArray->push_back(2); // face 2
	faceArray->push_back(3);
	faceArray->push_back(0);
	
	// normal array
	Vec3Array *normalArray = new Vec3Array();
	normalArray->push_back(Vec3(0, 0, 1));
	
	// normal index
	TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4> *normalIndexArray;
	normalIndexArray = new TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4>();
	
	normalIndexArray->push_back(0);
	normalIndexArray->push_back(0);
	normalIndexArray->push_back(0);
	normalIndexArray->push_back(0);
	
	// texture coordinates
	Vec2Array *texCoords = new Vec2Array();
	texCoords->push_back(Vec2(0.0f, 0.0f));
	texCoords->push_back(Vec2(1.0f, 0.0f));
	texCoords->push_back(Vec2(1.0f, 1.0f));
	texCoords->push_back(Vec2(0.0f, 1.0f));
	
	Geometry *geometry = new Geometry();
	geometry->setVertexArray(vertexArray);
	geometry->setNormalArray(normalArray);
	geometry->setNormalIndices(normalIndexArray);
	geometry->setNormalBinding(Geometry::BIND_PER_VERTEX);
	geometry->setTexCoordArray(0, texCoords);
	geometry->addPrimitiveSet(faceArray);
	
	Geode *plane = new Geode();
	plane->addDrawable(geometry);
	
	// assign the material to the sphere
	StateSet *planeStateSet = plane->getOrCreateStateSet();
	planeStateSet->ref();
	planeStateSet->setAttribute(_material);
	
   try {
		planeStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON);
   } catch (char *e) {
      throw e;
   }
	
	PositionAttitudeTransform *planeTransform = new PositionAttitudeTransform();
	planeTransform->addChild(plane);
	return planeTransform;
}
Beispiel #11
0
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;
}
/***************************************************************
* 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);
    }
}
Beispiel #13
0
ref_ptr<osg::Geode>
arengine::Image::createGeodeForImage(osg::Image* image,int posx, int posy, int width, int height)
{
	if (image)
	{
		if (width>0 && height>0)
		{

			float y = 1.0;
			float x = y*((float)width/float(height));

			// set up the texture.

			Config *config = Singleton<Config>::getInstance();

			osg::Texture *texture;
			float texcoord_x;
			float texcoord_y;
			if (config->useTexture2D())
			{
				osg::Texture2D *texture2D = new osg::Texture2D;
				texture2D->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
				texture2D->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
				texture2D->setResizeNonPowerOfTwoHint(false);
				texture2D->setImage(image);

				texcoord_x = 1.0f;
				texcoord_y = 1.0f;
				texture = texture2D;
			}
			else
			{
				osg::TextureRectangle *textureRect = new osg::TextureRectangle;
				textureRect->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
				textureRect->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
				//texture->setResizeNonPowerOfTwoHint(false);
				textureRect->setImage(image);

				texcoord_x = image->s();
				texcoord_y = image->t();
				texture = textureRect;
			}

			// set up the drawstate.
			osg::StateSet* dstate = new osg::StateSet;
			dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
			dstate->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
			dstate->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);

			// set up the geoset.
			Geometry* geom = new Geometry;
			geom->setStateSet(dstate);

			Vec2Array* coords = new Vec2Array(4);
			(*coords)[0].set(posx, posy + height);
			(*coords)[1].set(posx, posy);
			(*coords)[2].set(posx + width, posy);
			(*coords)[3].set(posx + width, posy + height);
			geom->setVertexArray(coords);

			Vec2Array* tcoords = new Vec2Array(4);
			(*tcoords)[0].set(0.0f*texcoord_x,1.0f*texcoord_y);
			(*tcoords)[1].set(0.0f*texcoord_x,0.0f*texcoord_y);
			(*tcoords)[2].set(1.0f*texcoord_x,0.0f*texcoord_y);
			(*tcoords)[3].set(1.0f*texcoord_x,1.0f*texcoord_y);
			geom->setTexCoordArray(0,tcoords);

			osg::Vec4Array* colours = new osg::Vec4Array(1);
			(*colours)[0].set(1.0f,1.0f,1.0,1.0f);
			geom->setColorArray(colours);
			geom->setColorBinding(Geometry::BIND_OVERALL);

			geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS,0,4));

			// set up the geode.
			osg::Geode* geode = new osg::Geode;
			geode->addDrawable(geom);

			return geode;

		}
		else
		{
			return NULL;
		}
	}
	else
	{
		return NULL;
	}
}
Beispiel #14
0
Node *makeSky( void )
{
    int i, j;
    float lev[] = { -5, -1.0, 1.0, 15.0, 30.0, 60.0, 90.0  };
    float cc[][4] =
    {
        { 0.0, 0.0, 0.15 },
        { 0.0, 0.0, 0.15 },
        { 0.4, 0.4, 0.7 },
        { 0.2, 0.2, 0.6 },
        { 0.1, 0.1, 0.6 },
        { 0.1, 0.1, 0.6 },
        { 0.1, 0.1, 0.6 },
    };
    float x, y, z;
    float alpha, theta;
    float radius = 20.0f;
    int nlev = sizeof( lev )/sizeof(float);

    Geometry *geom = new Geometry;

    Vec3Array& coords = *(new Vec3Array(19*nlev));
    Vec4Array& colors = *(new Vec4Array(19*nlev));
    Vec2Array& tcoords = *(new Vec2Array(19*nlev));
    
    
    int ci = 0;

    for( i = 0; i < nlev; i++ )
    {
        for( j = 0; j <= 18; j++ )
        {
            alpha = osg::DegreesToRadians(lev[i]);
            theta = osg::DegreesToRadians((float)(j*20));

            x = radius * cosf( alpha ) * cosf( theta );
            y = radius * cosf( alpha ) * -sinf( theta );
            z = radius * sinf( alpha );

            coords[ci][0] = x;
            coords[ci][1] = y;
            coords[ci][2] = z;

            colors[ci][0] = cc[i][0];
            colors[ci][1] = cc[i][1];
            colors[ci][2] = cc[i][2];
            colors[ci][3] = 1.0;

            tcoords[ci][0] = (float)j/18.0;
            tcoords[ci][1] = (float)i/(float)(nlev-1);

            ci++;
        }


    }

    for( i = 0; i < nlev-1; i++ )
    {
        DrawElementsUShort* drawElements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP);
        drawElements->reserve(38);

        for( j = 0; j <= 18; j++ )
        {
            drawElements->push_back((i+1)*19+j);
            drawElements->push_back((i+0)*19+j);
        }

        geom->addPrimitiveSet(drawElements);
    }
    
    geom->setVertexArray( &coords );
    geom->setTexCoordArray( 0, &tcoords );

    geom->setColorArray( &colors );
    geom->setColorBinding( Geometry::BIND_PER_VERTEX );


    Texture2D *tex = new Texture2D;
    tex->setImage(osgDB::readImageFile("Images/white.rgb"));

    StateSet *dstate = new StateSet;

    dstate->setTextureAttributeAndModes(0, tex, StateAttribute::OFF );
    dstate->setTextureAttribute(0, new TexEnv );
    dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
    dstate->setMode( GL_CULL_FACE, StateAttribute::ON );
    

    // clear the depth to the far plane.
    osg::Depth* depth = new osg::Depth;
    depth->setFunction(osg::Depth::ALWAYS);
    depth->setRange(1.0,1.0);   
    dstate->setAttributeAndModes(depth,StateAttribute::ON );

    dstate->setRenderBinDetails(-2,"RenderBin");

    geom->setStateSet( dstate );

    Geode *geode = new Geode;
    geode->addDrawable( geom );

    geode->setName( "Sky" );

    return geode;
}
Beispiel #15
0
Datei: tank.cpp Projekt: 3dcl/osg
Node *makeTank( void )
{

    Geode *geode = new Geode;

    getDatabaseCenterRadius( dbcenter, &dbradius );

    Matrix mat(
        0.05, 0, 0, 0,
        0, 0.05, 0, 0,
        0, 0, 0.05, 0,
        1.5999 - 0.3,
        3.1474,
        dbcenter[2] + 0.6542 - 0.09,
        1
        );

    // 42 required for sides, 22 for the top.
    Vec3Array& vc = *(new Vec3Array(42+22));
    Vec2Array& tc = *(new Vec2Array(42+22));

    Geometry *gset = new Geometry;
    gset->setVertexArray( &vc );
    gset->setTexCoordArray( 0, &tc );

    // create the sides of the tank.
    unsigned int i, c = 0;
    for( i = 0; i <= 360; i += 18 )
    {
        float x, y, z;
        float s, t;
        float theta = osg::DegreesToRadians((float)i);

        s = (float)i/90.0;
        t = 1.0;

        x = radius * cosf( theta );
        y = radius * sinf( theta );
        z = 1.0;

        vc[c][0] = x;
        vc[c][1] = y;
        vc[c][2] = z;

        tc[c][0] = s;
        tc[c][1] = t;

        c++;

        t = 0.0;
        z = 0.0;

        vc[c][0] = x;
        vc[c][1] = y;
        vc[c][2] = z;

        tc[c][0] = s;
        tc[c][1] = t;
        c++;
    }

    gset->addPrimitiveSet( new DrawArrays(PrimitiveSet::TRIANGLE_STRIP,0,c) );

    // create the top of the tank.

    int prev_c = c;

    vc[c][0] = 0.0f;
    vc[c][1] = 0.0f;
    vc[c][2] = 1.0f;

    tc[c][0] = 0.0f;
    tc[c][1] = 0.0f;
    c++;

    for( i = 0; i <= 360; i += 18 )
    {
        float x, y, z;
        float s, t;
        float theta = osg::DegreesToRadians((float)i);

        //    s = (float)i/360.0;
        //   t = 1.0;
        s = cosf( theta );
        t = sinf( theta );

        x = radius * cosf( theta );
        y = radius * sinf( theta );
        z = 1.0;

        vc[c][0] = x;
        vc[c][1] = y;
        vc[c][2] = z;

        tc[c][0] = s;
        tc[c][1] = t;

        c++;
    }

    for( i = 0; i < c; i++ )
        conv( vc[i], mat, vc[i] );
     
     gset->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,prev_c,c-prev_c));




    Texture2D *tex = new Texture2D;

    tex->setWrap( Texture2D::WRAP_S, Texture2D::REPEAT );
    tex->setWrap( Texture2D::WRAP_T, Texture2D::REPEAT );
    tex->setImage(osgDB::readImageFile("Images/tank.rgb"));

    StateSet *dstate = new StateSet;
    dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
    dstate->setTextureAttribute(0, new TexEnv );

    gset->setStateSet( dstate );
    geode->addDrawable( gset );

    return geode;
}
Beispiel #16
0
Node *makeTerrain( void )
{
    int m, n;
    int  i, j;
    float dbcenter[3];
    float dbradius;

    getDatabaseCenterRadius( dbcenter, &dbradius );

    m = (sizeof( vertex ) /(sizeof( float[3])))/39;
    n = 39;

    Vec3Array& v    = *(new Vec3Array(m*n));
    Vec2Array& t    = *(new Vec2Array(m*n));
    Vec4Array& col  = *(new Vec4Array(1));

    col[0][0] = col[0][1] = col[0][2] = col[0][3] = 1.0f;

    for( i = 0; i < m * n; i++ )
    {
        float* vc = vertex[i];
        v[i][0] = vc[0] - dbcenter[0];
        v[i][1] = vc[1] - dbcenter[1];
        v[i][2] = vc[2];

        float* tc = texcoord[i];
        t[i][0] = tc[0];
        t[i][1] = tc[1];
    }

    Geometry *geom = new Geometry;

    geom->setVertexArray( &v );
    geom->setTexCoordArray( 0, &t );

    geom->setColorArray( &col, Array::BIND_OVERALL );

    for( i = 0; i < m-2; i++ )
    {
        DrawElementsUShort* elements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP);
        elements->reserve(39*2);
        for( j = 0; j < n; j++ )
        {
            elements->push_back((i+0)*n+j);
            elements->push_back((i+1)*n+j);
        }
        geom->addPrimitiveSet(elements);
    }


    Texture2D *tex = new Texture2D;

    tex->setImage(osgDB::readRefImageFile("Images/lz.rgb"));

    StateSet *dstate = new StateSet;
    dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
    dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
    dstate->setTextureAttribute(0, new TexEnv );

    geom->setStateSet( dstate );

    Geode *geode = new Geode;
    geode->addDrawable( geom );

    return geode;
}