Example #1
0
/** 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());
}
Example #2
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);
}
Example #3
0
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);
}
Example #4
0
PositionAttitudeTransform *VideoGeode::createVideoSphere(float size, bool texRepeat)
{
	Geode *sphere = new Geode();
	sphere->addDrawable(new ShapeDrawable(new Sphere(Vec3(0, 0, 4), size)));
	
	// assign the material to the sphere
	StateSet *sphereStateSet = sphere->getOrCreateStateSet();
	sphereStateSet->ref();
	sphereStateSet->setAttribute(_material);
	
   try {
      sphereStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON);
   } catch (char *e) {
      throw e;
   }
	
	PositionAttitudeTransform *sphereTransform = new PositionAttitudeTransform();
	sphereTransform->addChild(sphere);
	return sphereTransform;
}
Example #5
0
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);
}
Example #6
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;
}
Example #7
0
osg::Node* Shape::createOSGAxes(const base::Dimension3& dim)
{
  const Real s = 1.5;
  Real d = Math::minimum(0.06,Math::minimum(dim.x,dim.y,dim.z)/16.0);

  Group* g = NewObj Group;
  g->setName("debug");

  // color the axes X:red, Y:green and Z:blue, with white end cones
  StateSet* red = NewObj StateSet();
  osg::Material* rmat = NewObj osg::Material();
  Vec4 cred(1,0,0,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  rmat->setDiffuse( osg::Material::FRONT_AND_BACK, cred );
  rmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  rmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  red->setAttribute( rmat );

  StateSet* green = NewObj StateSet();
  osg::Material* gmat = NewObj osg::Material();
  Vec4 cgreen(0,1,0,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  gmat->setDiffuse( osg::Material::FRONT_AND_BACK, cgreen );
  gmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  gmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  green->setAttribute( gmat );
  
  StateSet* blue = NewObj StateSet();
  osg::Material* bmat = NewObj osg::Material();
  Vec4 cblue(0,0,1,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  bmat->setDiffuse( osg::Material::FRONT_AND_BACK, cblue );
  bmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  bmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  blue->setAttribute( bmat );

  StateSet* white = NewObj StateSet();
  osg::Material* wmat = NewObj osg::Material();
  Vec4 cwhite(1,1,1,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  wmat->setDiffuse( osg::Material::FRONT_AND_BACK, cwhite );
  wmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  wmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  white->setAttribute( wmat );


  // a long Clyinder for the axis and a cone-like cylinder 
  //  for the arrow head of each X,Y and Z.

  MatrixTransform* xrot = NewObj MatrixTransform();
  xrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(0,1,0)));
  xrot->postMult(osg::Matrix::translate(s*dim.x/4.0,0,0));
  g->addChild(xrot);
		
  MatrixTransform* yrot = NewObj MatrixTransform();
  yrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(-1,0,0)));
  yrot->postMult(osg::Matrix::translate(0,s*dim.y/4.0,0));
  g->addChild(yrot);
		
  MatrixTransform* zrot = NewObj MatrixTransform();
  zrot->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0));
  g->addChild(zrot);
		
  // the cylinder axes
  ref<Cylinder> xc(NewObj Cylinder(s*dim.x/2.0,d));
  xrot->addChild(xc->createOSGVisual());
  xrot->setStateSet(red);

  ref<Cylinder> yc(NewObj Cylinder(s*dim.y/2.0,d));
  yrot->addChild(yc->createOSGVisual());
  yrot->setStateSet(green);

  ref<Cylinder> zc(NewObj Cylinder(s*dim.z/2.0,d));
  zrot->addChild(zc->createOSGVisual());
  zrot->setStateSet(blue);

  // Translate each axis cone to the end
  MatrixTransform* xtrans = NewObj MatrixTransform();
  xtrans->setMatrix(osg::Matrix::translate(0,0,s*dim.x/4.0+d));
  xrot->addChild(xtrans);
  
  MatrixTransform* ytrans = NewObj MatrixTransform();
  ytrans->setMatrix(osg::Matrix::translate(0,0,s*dim.y/4.0+d));
  yrot->addChild(ytrans);
  
  MatrixTransform* ztrans = NewObj MatrixTransform();
  ztrans->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0+d));
  zrot->addChild(ztrans);
  
  // the end cones
  ref<Cone> cone(NewObj Cone(4*d,2*d));
  osg::Node* coneNode = cone->createOSGVisual();
  coneNode->setStateSet(white);
  
  xtrans->addChild(coneNode);
  ytrans->addChild(coneNode);
  ztrans->addChild(coneNode);

  return g;
}