本文整理汇总了C++中StateSet::setAttributeAndModes方法的典型用法代码示例。如果您正苦于以下问题:C++ StateSet::setAttributeAndModes方法的具体用法?C++ StateSet::setAttributeAndModes怎么用?C++ StateSet::setAttributeAndModes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateSet
的用法示例。
在下文中一共展示了StateSet::setAttributeAndModes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/***************************************************************
* 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;
}
示例2: applyColorTexture
/***************************************************************
* 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;
}
示例3: Geometry
// 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);
}
示例4: mNumVertices
//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);
}
示例5: main
int main()
{
using namespace osg;
// // read Neuron Obj file from desk
// ref_ptr<Node> model = osgDB::readNodeFile( "Neuron.obj" );
// model->setName("Neuron");
ref_ptr<MatrixTransform> mt = new MatrixTransform;
// mt->addChild( model.get() );
myModel model1 ("Neuron.obj","Neuron");
mt = model1.getMatrix();
osgUtil::SmoothingVisitor sv;
model->accept( sv );
// BlendFunc
ref_ptr<BlendFunc> blendFunc = new BlendFunc;
blendFunc->setFunction( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
StateSet* stateset = model->getOrCreateStateSet();
stateset->setAttributeAndModes( blendFunc );
// Material
ref_ptr<StateSet> nodess = model->getOrCreateStateSet();
ref_ptr<Material> nodeMaterial = new Material;
nodeMaterial->setDiffuse( Material::FRONT , Vec4(0.5f,0.5f,0.5f,1.0f));
nodeMaterial->setAmbient( Material::FRONT , Vec4(2.0f,0.0f,0.0f,1.0f) );
nodeMaterial->setTransparency(Material::FRONT , 0.25f);
//nodeMaterial->setAlpha( Material::FRONT , 0.5f );
nodess->setAttribute( nodeMaterial.get() );
// create camera
ref_ptr<Camera> camera = new Camera();
camera->setClearMask( GL_DEPTH_BUFFER_BIT );
camera->setRenderOrder( Camera::POST_RENDER );
camera->setReferenceFrame( Camera::ABSOLUTE_RF );
camera->setViewMatrixAsLookAt( Vec3d(-1.0f,0.0f,0.0f) , Vec3d(0.0,0.0,0.0) , Vec3d(0.0f,1.0f,0.0f) );
// create root node
ref_ptr<Group> root = new Group;
// add child to it
root->addChild( mt.get() );
root->addChild( camera.get() );
ref_ptr<PickHandler> picker = new PickHandler;
root->addChild( picker->getOrCreateSelectionBox() );
ref_ptr<ModelController> ctrler = new ModelController( mt.get() );
// create viewer to display data
osgViewer::Viewer viewer;
viewer.addEventHandler( picker.get() );
viewer.addEventHandler( ctrler.get() );
viewer.setSceneData( root.get() );
return viewer.run();
}
示例6: applyAlpha
/***************************************************************
* Function: applyAlpha()
***************************************************************/
void CAVEGeode::applyAlpha(const float &alpha)
{
StateSet *stateset = getOrCreateStateSet();
/* update material parameters */
Material *material = dynamic_cast <Material*> (stateset->getAttribute(StateAttribute::MATERIAL));
if (!material) material = new Material;
material->setAlpha(Material::FRONT_AND_BACK, alpha);
stateset->setAttributeAndModes(material, StateAttribute::ON);
/* update alpha value */
mAlpha = alpha;
}
示例7: coverStuff
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
}
示例8: initOQState
// 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;
}
示例9: mSnappingUnitDist
//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);
}
示例10: setVSParamountPreviewHighlight
/***************************************************************
* Function: setVSParamountPreviewHighlight()
***************************************************************/
void VirtualScenicHandler::setVSParamountPreviewHighlight(bool flag, Geode *paintGeode)
{
StateSet *stateset = paintGeode->getOrCreateStateSet();
Material *material = dynamic_cast<Material*> (stateset->getAttribute(StateAttribute::MATERIAL));
if (!material)
material = new Material;
if (flag)
{
material->setAlpha(Material::FRONT_AND_BACK, 0.5f);
material->setDiffuse(Material::FRONT_AND_BACK, Vec4(0.3, 1.0, 0.3, 1.0));
material->setSpecular(Material::FRONT_AND_BACK, Vec4(0.3, 1.0, 0.3, 1.0));
}
else
{
material->setAlpha(Material::FRONT_AND_BACK, 1.0f);
material->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
material->setSpecular(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
}
stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON);
}
示例11: ANIMCreateSinglePageGeodeAnimation
/***************************************************************
* 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;
//.........这里部分代码省略.........
示例12: setMaterial
void JTOpenPlugin::setMaterial(osg::Node *osgNode, JtkHierarchy *CurrNode)
{
JtkMaterial *partMaterial = NULL;
((JtkPart *)CurrNode)->getMaterial(partMaterial);
if (partMaterial)
{
float *ambient = NULL,
*diffuse = NULL,
*specular = NULL,
*emission = NULL,
shininess = -999.0;
StateSet *stateset = NULL;
osg::Geode *osgGeode = dynamic_cast<osg::Geode *>(osgNode);
if (osgGeode)
{
osg::Drawable *drawable = osgGeode->getDrawable(0);
if (drawable)
{
stateset = drawable->getOrCreateStateSet();
}
else
stateset = osgGeode->getOrCreateStateSet();
}
else
stateset = osgNode->getOrCreateStateSet();
osg::Material *mtl = new osg::Material();
partMaterial->getAmbientColor(ambient);
if (ambient)
{
mtl->setAmbient(Material::FRONT_AND_BACK, Vec4(ambient[0], ambient[1], ambient[2], ambient[3]));
JtkEntityFactory::deleteMemory(ambient);
}
partMaterial->getDiffuseColor(diffuse);
if (diffuse)
{
mtl->setDiffuse(Material::FRONT_AND_BACK, Vec4(diffuse[0], diffuse[1], diffuse[2], diffuse[3]));
JtkEntityFactory::deleteMemory(diffuse);
}
partMaterial->getSpecularColor(specular);
if (specular)
{
mtl->setSpecular(Material::FRONT_AND_BACK, Vec4(specular[0], specular[1], specular[2], specular[3]));
JtkEntityFactory::deleteMemory(specular);
}
partMaterial->getEmissionColor(emission);
if (emission)
{
mtl->setEmission(Material::FRONT_AND_BACK, Vec4(emission[0], emission[1], emission[2], emission[3]));
JtkEntityFactory::deleteMemory(emission);
}
partMaterial->getShininess(shininess);
if (shininess != -999.0)
{
mtl->setShininess(Material::FRONT_AND_BACK, shininess);
}
stateset->setAttributeAndModes(mtl, StateAttribute::ON);
}
}
示例13: DrawArrayLengths
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;
}
示例14: generate
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);
}
示例15: createFloorplanGeometry
/***************************************************************
* 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);
}
}