本文整理汇总了C++中GeometryUnrecPtr::setMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryUnrecPtr::setMaterial方法的具体用法?C++ GeometryUnrecPtr::setMaterial怎么用?C++ GeometryUnrecPtr::setMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeometryUnrecPtr
的用法示例。
在下文中一共展示了GeometryUnrecPtr::setMaterial方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupAnimation
void setupAnimation(void)
{
//Read animation data from XML file
FCFileType::FCPtrStore NewContainers;
NewContainers = FCFileHandler::the()->read(BoostPath("./Data/15TestAnimations.xml"));
FCFileType::FCPtrStore::iterator Itor;
for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
{
if( (*Itor)->getType().isDerivedFrom(Animation::getClassType()))
{
//Set the animation to the one we just read in
TheAnimation = (dynamic_pointer_cast<Animation>(*Itor));
}
else if( (*Itor)->getType() == (SimpleMaterial::getClassType()))
{
//Set torus material
TheTorusMaterial = (dynamic_pointer_cast<SimpleMaterial>(*Itor));
//Attach torus material to torus geometry
TorusGeometry->setMaterial(TheTorusMaterial);
}
}
TheAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
TheAnimation->start();
}
示例2: buildBox
PhysicsBodyUnrecPtr buildBox(const Pnt3f& Position,
const Vec3f& Dimensions,
const Color3f& Color,
Node* const spaceGroupNode,
PhysicsWorld* const physicsWorld,
PhysicsHashSpace* const physicsSpace)
{
Matrix m;
//create OpenSG mesh
GeometryUnrecPtr box;
NodeUnrecPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialUnrecPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color);
box->setMaterial(box_mat);
TransformUnrecPtr boxTrans;
NodeUnrecPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
m.setTranslate(Position);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyUnrecPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(Position));
boxBody->setBoxMass(1.0,Dimensions.x(), Dimensions.y(), Dimensions.z());
boxBody->setLinearDamping(0.0001);
boxBody->setAngularDamping(0.0001);
PhysicsBoxGeomUnrecPtr boxGeom = PhysicsBoxGeom::create();
boxGeom->setBody(boxBody);
boxGeom->setSpace(physicsSpace);
boxGeom->setLengths(Dimensions);
//add attachments
boxNode->addAttachment(boxGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
return boxBody;
}
示例3: buildSphere
//////////////////////////////////////////////////////////////////////////
//! build a sphere
//////////////////////////////////////////////////////////////////////////
PhysicsBodyUnrecPtr buildSphere(void)
{
Real32 Radius((Real32)(rand()%2)*0.5+0.5);
Matrix m;
//create OpenSG mesh
GeometryUnrecPtr sphere;
NodeUnrecPtr sphereNode = makeSphere(2, Radius);
sphere = dynamic_cast<Geometry*>(sphereNode->getCore());
SimpleMaterialUnrecPtr sphere_mat = SimpleMaterial::create();
sphere_mat->setAmbient(Color3f(0.0,0.0,0.0));
sphere_mat->setDiffuse(Color3f(0.0,0.0,1.0));
sphere->setMaterial(sphere_mat);
TransformUnrecPtr sphereTrans;
NodeUnrecPtr sphereTransNode = makeCoredNode<Transform>(&sphereTrans);
m.setIdentity();
Real32 randX = (Real32)(rand()%10)-5.0;
Real32 randY = (Real32)(rand()%10)-5.0;
m.setTranslate(randX, randY, 10.0);
sphereTrans->setMatrix(m);
//create ODE data
PhysicsBodyUnrecPtr sphereBody = PhysicsBody::create(physicsWorld);
sphereBody->setPosition(Vec3f(randX, randY, 10.0));
sphereBody->setLinearDamping(0.0001);
sphereBody->setAngularDamping(0.0001);
sphereBody->setSphereMass(1.0,Radius);
PhysicsSphereGeomUnrecPtr sphereGeom = PhysicsSphereGeom::create();
sphereGeom->setBody(sphereBody);
sphereGeom->setSpace(physicsSpace);
sphereGeom->setRadius(Radius);
//add attachments
sphereNode->addAttachment(sphereGeom);
sphereTransNode->addAttachment(sphereBody);
sphereTransNode->addChild(sphereNode);
//add to SceneGraph
spaceGroupNode->addChild(sphereTransNode);
commitChanges();
return sphereBody;
}
示例4: buildBox
//////////////////////////////////////////////////////////////////////////
//! build a box
//////////////////////////////////////////////////////////////////////////
PhysicsBodyUnrecPtr buildBox(void)
{
Vec3f Lengths((Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0);
Matrix m;
//create OpenSG mesh
GeometryUnrecPtr box;
NodeUnrecPtr boxNode = makeBox(Lengths.x(), Lengths.y(), Lengths.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialUnrecPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color3f(0.0,1.0 ,0.0));
box->setMaterial(box_mat);
TransformUnrecPtr boxTrans;
NodeUnrecPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
Real32 randX = (Real32)(rand()%10)-5.0;
Real32 randY = (Real32)(rand()%10)-5.0;
m.setTranslate(randX, randY, 10.0);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyUnrecPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(randX, randY, 10.0));
boxBody->setBoxMass(1.0, Lengths.x(), Lengths.y(), Lengths.z());
PhysicsBoxGeomUnrecPtr boxGeom = PhysicsBoxGeom::create();
boxGeom->setBody(boxBody);
boxGeom->setSpace(physicsSpace);
boxGeom->setLengths(Lengths);
//add attachments
boxNode->addAttachment(boxGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
return boxBody;
}
示例5: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Shader Material
BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
//Material Chunk
MaterialChunkUnrecPtr ShaderMaterialChunk = MaterialChunk::create();
ShaderMaterialChunk->setAmbient(Color4f(0.4f,0.4f,0.4f,1.0f));
ShaderMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
ShaderMaterialChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f));
//Shader Chunk
SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create();
TheSHLChunk->setVertexProgram(createSHLVertexProg());
TheSHLChunk->setFragmentProgram(createSHLFragProg());
//Color Parameter
ShaderVariableVec4fUnrecPtr Color1Parameter = ShaderVariableVec4f::create();
Color1Parameter->setName("Color1");
Color1Parameter->setValue(Vec4f(0.0f,1.0f,0.0f,1.0f));
ShaderVariableVec4fUnrecPtr Color2Parameter = ShaderVariableVec4f::create();
Color2Parameter->setName("Color2");
Color2Parameter->setValue(Vec4f(1.0f,1.0f,1.0f,1.0f));
//Shader Parameter Chunk
SHLParameterChunkUnrecPtr SHLParameters = SHLParameterChunk::create();
SHLParameters->getParameters().push_back(Color1Parameter);
SHLParameters->getParameters().push_back(Color2Parameter);
SHLParameters->setSHLChunk(TheSHLChunk);
ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create();
ShaderMaterial->addChunk(ShaderMaterialChunk);
ShaderMaterial->addChunk(TheSHLChunk);
ShaderMaterial->addChunk(SHLParameters);
//Torus Node
GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32);
TorusGeometry->setMaterial(ShaderMaterial);
NodeUnrecPtr TorusNode = Node::create();
TorusNode->setCore(TorusGeometry);
// Make Main Scene Node
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusNode);
mgr->setRoot(scene);
// Show the whole Scene
mgr->showAll();
//Create the Animations
initAnimations(Color1Parameter, "value");
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"04ShaderAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例6: read
//.........这里部分代码省略.........
geoPtr->setTypes ( typePtr );
if ( (meshIndexMask & 2) && texCoordPtr->size() > 0 )
{
geoPtr->setTexCoords ( texCoordPtr );
texIndexPtr = GeoUInt32Property::create();
if(!isSingleIndex)
geoPtr->setIndex(texIndexPtr, Geometry::TexCoordsIndex);
}
else
{
geoPtr->setTexCoords ( NULL );
}
if ( (meshIndexMask & 4) && normalPtr->size() > 0 )
{
geoPtr->setNormals ( normalPtr );
normalIndexPtr = GeoUInt32Property::create();
if(!isSingleIndex)
geoPtr->setIndex(normalIndexPtr, Geometry::NormalsIndex);
}
else
{
geoPtr->setNormals ( NULL );
}
if (meshI->mtlPtr == NULL)
{
meshI->mtlPtr = SimpleTexturedMaterial::create();
meshI->mtlPtr->setDiffuse( Color3f( .8f, .8f, .8f ) );
meshI->mtlPtr->setSpecular( Color3f( 1.f, 1.f, 1.f ) );
meshI->mtlPtr->setShininess( 20.f );
}
geoPtr->setMaterial ( meshI->mtlPtr );
for ( faceI = meshI->faceList.begin();
faceI != meshI->faceList.end(); faceI++)
{
n = UInt32(faceI->tieVec.size());
// add the lens entry
lensPtr->push_back(n);
// add the type entry
typePtr->push_back(GL_POLYGON);
// create the index values
for (i = 0; i < n; i++)
{
if (isSingleIndex)
{
posIndexPtr->push_back(faceI->tieVec[i].index[0]);
}
else
{
posIndexPtr->push_back(faceI->tieVec[i].index[0]);
if(texIndexPtr != NULL)
texIndexPtr->push_back(faceI->tieVec[i].index[1]);
if(normalIndexPtr != NULL)
normalIndexPtr->push_back(faceI->tieVec[i].index[2]);
}
}
}
if(isSingleIndex)
{
示例7: onCreate
void PlaneMoveManipulator::onCreate(const PlaneMoveManipulator* source)
{
// Skip direct parent, don't want the default geometry creation
Transform::onCreate(source);
SimpleMaterialUnrecPtr pMat = SimpleMaterial::create();
pMat->setDiffuse(Color3f(.5, .5, .5));
pMat->setLit (false );
setMaterialX(pMat);
pMat = SimpleMaterial::create();
pMat->setDiffuse(Color3f(0, 1, 0));
pMat->setLit (false );
LineChunkUnrecPtr lc = LineChunk::create();
lc->setWidth(3);
pMat->addChunk(lc);
setMaterialY(pMat);
pMat = SimpleMaterial::create();
pMat->setDiffuse(Color3f(0., 0., 1.));
pMat->setLit (true );
setMaterialZ(pMat);
// SimpleMaterial *simpleMat;
// Geometry *geo;
setExternalUpdateHandler(NULL);
// add a name attachment
NameUnrecPtr nameN = Name::create();
nameN->editFieldPtr()->setValue("XYManipulator");
addAttachment(nameN);
// make the axis line. Not really a handle, but easier to manage this way.
GeoBuilder b;
b.vertex(Pnt3f(0,0,0));
b.vertex(Pnt3f(0,getLength()[1],0));
b.line(0, 1);
GeometryUnrecPtr g = b.getGeometry();
g->setMaterial(getMaterialY());
NodeUnrecPtr pNode = makeNodeFor(g);
setTransYNode(pNode);
// make the plane handle
pNode = Node::create();
setTransXNode(pNode);
g = makePlaneGeo(getLength()[0] / 2.f, getLength()[2] / 2.f, 1, 1);
g->setMaterial(getMaterialX());
pNode = makeNodeFor(g);
OSG::ComponentTransformUnrecPtr transHandleXC = ComponentTransform::create();
setHandleXNode(pNode);
getTransXNode()->setCore (transHandleXC );
getTransXNode()->addChild(getHandleXNode());
transHandleXC->setTranslation(Vec3f(0, getLength()[1], 0));
transHandleXC->setRotation (Quaternion(Vec3f(1, 0, 0), osgDegree2Rad(90)));
//
// make the rotate handle
pNode = Node::create();
setTransZNode(pNode);
g = makeCylinderGeo(0.05f, 0.1f, 16, true, true, true);
g->setMaterial(getMaterialZ());
pNode = makeNodeFor(g);
OSG::ComponentTransformUnrecPtr transHandleZC = ComponentTransform::create();
setHandleZNode(pNode);
getTransZNode()->setCore (transHandleZC );
getTransZNode()->addChild(getHandleZNode());
transHandleZC->setTranslation(Vec3f(0, getLength()[1], 0));
commitChanges();
}
示例8: initGeometries
void VTKPolyDataMapper::initGeometries(void)
{
NodeUnrecPtr pRoot = Node::create();
pRoot->setCore(Group::create());
setRoot(pRoot);
for(UInt32 i = 0; i < 4; ++i)
{
GeometryUnrecPtr pGeo = Geometry::create();
ChunkMaterialUnrecPtr pMat = ChunkMaterial::create();
MaterialChunkUnrecPtr pMatChunk = MaterialChunk::create();
GeoPnt3fPropertyUnrecPtr pPoints = GeoPnt3fProperty ::create();
GeoUInt32PropertyUnrecPtr pLengths = GeoUInt32Property ::create();
GeoUInt8PropertyUnrecPtr pTypes = GeoUInt8Property ::create();
GeoColor4fPropertyUnrecPtr pColors = GeoColor4fProperty::create();
GeoVec3fPropertyUnrecPtr pNormals = GeoVec3fProperty ::create();
if(i < 2)
{
pMatChunk->setLit(false);
}
pMatChunk->setDiffuse (OSG::Color4f(1.0, 1.0, 1.0, 1.0));
pMatChunk->setSpecular (OSG::Color4f(0.0, 0.0, 0.0, 1.0));
pMatChunk->setShininess(10.0f);
pMat->addChunk(pMatChunk);
TwoSidedLightingChunkUnrecPtr pTSLChunk =
TwoSidedLightingChunk::create();
pMat->addChunk(pTSLChunk);
pGeo->setDlistCache(false );
pGeo->setMaterial (pMat );
pGeo->setPositions (pPoints );
pGeo->setLengths (pLengths);
pGeo->setTypes (pTypes );
pGeo->setColors (pColors );
if(i > 1)
{
pGeo->setNormals(pNormals);
}
OSG::NodeUnrecPtr pGeoRoot = OSG::Node::create();
pGeoRoot->setCore (pGeo);
pGeoRoot->setTravMask(0 );
pRoot->addChild(pGeoRoot);
this->pushToGeometries (pGeo );
this->pushToMaterials (pMat );
this->pushToMaterialChunks(pMatChunk);
this->pushToPositions (pPoints );
this->pushToLength (pLengths );
this->pushToTypes (pTypes );
this->pushToColors (pColors );
this->pushToNormals (pNormals );
this->pushToGeoRoots (pGeoRoot );
}
}
示例9: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
OSG::preloadSharedObject("OSGFileIO");
OSG::preloadSharedObject("OSGImageFileIO");
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));
//Box Geometry
GeometryUnrecPtr BoxGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1);
ChunkMaterialUnrecPtr TheBoxMaterial = ChunkMaterial::create();
BoxGeometry->setMaterial(TheBoxMaterial);
NodeUnrecPtr BoxGeometryNode = Node::create();
BoxGeometryNode->setCore(BoxGeometry);
//Make Box Node
NodeUnrecPtr BoxNode = Node::create();
TransformUnrecPtr BoxNodeTrans;
BoxNodeTrans = Transform::create();
BoxNode->setCore(BoxNodeTrans);
BoxNode->addChild(BoxGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans;
Trans = ComponentTransform::create();
scene->setCore(Trans);
// add the torus as a child
scene->addChild(BoxNode);
//Setup the Animation
AnimationUnrecPtr TheAnimation = setupAnimation(TheBoxMaterial);
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
// tell the manager what to manage
sceneManager.setRoot (scene);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"09TextureSelectAnimation");
//Main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例10: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Setup the Animation
setupAnimation();
//Box Geometry
GeometryUnrecPtr BoxGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1);
BoxGeometry->setMaterial(TheBoxMaterial);
NodeUnrecPtr BoxGeometryNode = Node::create();
BoxGeometryNode->setCore(BoxGeometry);
//Make Box Node
NodeUnrecPtr BoxNode = Node::create();
TransformUnrecPtr BoxNodeTrans;
BoxNodeTrans = Transform::create();
BoxNode->setCore(BoxNodeTrans);
BoxNode->addChild(BoxGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans;
Trans = ComponentTransform::create();
scene->setCore(Trans);
// add the torus as a child
scene->addChild(BoxNode);
// tell the manager what to manage
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"05TextureAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例11: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Torus Material
SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create();
TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3));
TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7));
TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0));
TheTorusMaterial->setShininess(20.0);
//Torus Geometry
GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
TorusGeometry->setMaterial(TheTorusMaterial);
NodeUnrecPtr TorusGeometryNode = Node::create();
TorusGeometryNode->setCore(TorusGeometry);
//Make Torus Node
NodeUnrecPtr TorusNode = Node::create();
TransformUnrecPtr TorusNodeTrans = Transform::create();
setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans = ComponentTransform::create();
setName(Trans, std::string("MainTransformationCore"));
scene->setCore(Trans);
// add the torus as a child
scene->addChild(TorusNode);
AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
TheAnimation.get(),
TutorialWindow.get()));
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
// tell the manager what to manage
sceneManager.setRoot (scene);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"07AnimationGroup");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例12: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Window Listener
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Torus Material
TheTorusMaterial = SimpleMaterial::create();
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setAmbient(Color3f(0.3,0.3,0.3));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setDiffuse(Color3f(0.7,0.7,0.7));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setSpecular(Color3f(1.0,1.0,1.0));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setShininess(20.0);
//Torus Geometry
GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
TorusGeometry->setMaterial(TheTorusMaterial);
NodeUnrecPtr TorusGeometryNode = Node::create();
TorusGeometryNode->setCore(TorusGeometry);
//Make Torus Node
NodeUnrecPtr TorusNode = Node::create();
TorusNodeTrans = Transform::create();
setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans;
Trans = ComponentTransform::create();
setName(Trans, std::string("MainTransformationCore"));
scene->setCore(Trans);
// add the torus as a child
scene->addChild(TorusNode);
setupAnimation();
// tell the manager what to manage
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"OpenSG 07AnimationGroup Window");
//Enter main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例13: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));
//Shader Chunk
SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create();
TheSHLChunk->setVertexProgram(createSHLVertexProg());
TheSHLChunk->setFragmentProgram(createSHLFragProg());
//TheSHLChunk->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f));
//TheSHLChunk->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f));
//Shader Parameter Chunk
SimpleSHLVariableChunkUnrecPtr SHLParameters = SimpleSHLVariableChunk::create();
//Color Parameter
SHLParameters->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f));
SHLParameters->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f));
ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create();
ShaderMaterial->addChunk(TheSHLChunk);
ShaderMaterial->addChunk(SHLParameters);
//Torus Node
GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32);
TorusGeometry->setMaterial(ShaderMaterial);
NodeUnrecPtr TorusNode = Node::create();
TorusNode->setCore(TorusGeometry);
// Make Main Scene Node
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusNode);
sceneManager.setRoot(scene);
// Show the whole Scene
sceneManager.showAll();
//Create the Animations
ShaderVariableVec4fUnrecPtr Color1Parameter;
ShaderVariableVec4fUnrecPtr Color2Parameter;
Color1Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color1")));
Color2Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color2")));
commitChanges();
AnimationUnrecPtr TheAnimation = setupAnimation(Color1Parameter, "value");
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"04ShaderAnimation");
//Main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例14: main
//.........这里部分代码省略.........
//Right Hip
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
//Right Femur
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
//Right Tibia
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
norms->push_back(Vec3f( 0.0,0.0,1.0));
//Right Foot
norms->push_back(Vec3f( 0.0,1.0,0.0));
norms->push_back(Vec3f( 0.0,1.0,0.0));
norms->push_back(Vec3f( 0.0,1.0,0.0));
norms->push_back(Vec3f( 0.0,1.0,0.0));
//Tell the geometry (geo) to use the points and normals we just defined
geo->setTypes (type);
geo->setLengths (lens);
geo->setPositions(pnts);
geo->setNormals(norms);
// assign a material to the geometry to make it visible. The details
// of materials are defined later.
geo->setMaterial(getDefaultMaterial());
//Create unbound geometry node (for displaying mesh in its bind pose)
UnboundGeometry = Node::create();
UnboundGeometry->setCore(geo);
UnboundGeometry->setTravMask(0); //By default, we won't show the mesh's bind pose
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we don't draw the skeleton's bind pose
ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When drawn, the skeleton's bind pose renders green
ExampleSkeletonDrawable->setDrawPose(true); //By default, we do draw the skeleton's current pose
ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose renders blue
//Skeleton Node
SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
// Skeleton Blended Geometry
// Here we are attaching the "skin" to the skeleton so that when the skeleton is animated, the skin moves with it
ExampleSkeleton->setBaseGeometry(geo);
//Back
ExampleSkeleton->addJointBlending(0,Pelvis,1.0f);
ExampleSkeleton->addJointBlending(1,Pelvis,1.0f);
ExampleSkeleton->addJointBlending(2,Clavicle,1.0f);
示例15: read
//.........这里部分代码省略.........
if(is)
{
root = Node ::create();
geo = Geometry::create();
root->setCore( geo );
points = GeoPnt3fProperty::create();
geo->setPositions(points);
normals = GeoVec3fProperty::create();
geo->setNormals(normals);
triCount = i = 0;
while(1)
{
is >> x >> y >> z;
if(is.eof())
{
break;
}
else
{
points->editFieldPtr()->push_back(Pnt3f(x, y, z));
vec[i].setValues(x,y,z);
std::cerr << x << " " << y << " " << z << std::endl;
if(i == 2)
{
vec[0] -= vec[1];
vec[1] -= vec[2];
vec[0].crossThis(vec[1]);
vec[0].normalize();
normals->editFieldPtr()->push_back(vec[0]);
normals->editFieldPtr()->push_back(vec[0]);
normals->editFieldPtr()->push_back(vec[0]);
i = 0;
triCount++;
}
else
{
i++;
}
}
}
if(triCount != 0)
{
index = GeoUInt32Property::create();
geo->setIndex(index, Geometry::PositionsIndex);
geo->setIndex(index, Geometry::NormalsIndex );
n = triCount * 3;
for(i = 0; i < n; i++)
index->push_back(i);
lens = GeoUInt32Property::create();
geo->setLengths(lens);
lens->push_back(n);
type = GeoUInt8Property::create();
geo->setTypes(type);
type->push_back(GL_TRIANGLES);
}
SimpleMaterialUnrecPtr mat = SimpleMaterial::create();
mat->setDiffuse (Color3f( .8f, .8f, .8f));
mat->setSpecular (Color3f( 1.f, 1.f, 1.f ));
mat->setShininess(20.f );
geo->setMaterial(mat);
}
if(triCount)
{
SNOTICE << triCount << " triangle read " << std::endl;
}
commitChanges();
return root;
}