本文整理汇总了C++中GeometryUnrecPtr类的典型用法代码示例。如果您正苦于以下问题:C++ GeometryUnrecPtr类的具体用法?C++ GeometryUnrecPtr怎么用?C++ GeometryUnrecPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeometryUnrecPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: calcGeometryCenter
Pnt3f calcGeometryCenter(GeometryUnrecPtr geo)
{
if(geo == NULL ||
geo->getPositions() == NULL ||
geo->getPositions()->size() == 0)
{
return Pnt3f();
}
GeoVectorProperty* Positions(geo->getPositions());
Pnt3f Sum;
for(UInt32 i(1) ; i<Positions->size(); ++i)
{
Sum = Sum + Vec3f(Positions->getValue<Pnt3f>(i));
}
return Sum * (1.0f/static_cast<Real32>(Positions->size()));
}
示例5: processTransformations
void MergeGraphOp::processTransformations(Node * const node)
{
MFUnrecChildNodePtr::const_iterator mfit = node->getMFChildren()->begin();
MFUnrecChildNodePtr::const_iterator mfen = node->getMFChildren()->end ();
std::vector<Node *> toAdd;
std::vector<Node *> toSub;
for ( ; mfit != mfen; ++mfit )
{
bool special=isInExcludeList(*mfit);
bool leaf=isLeaf(*mfit);
bool empty=true;
//if a transformation:
if ((*mfit)->getCore()->getType().isDerivedFrom(
Transform::getClassType()))
{
if (!leaf && !special)
{
//try to apply it to children geometries
//move all "moveable" children one level up
//if empty after that, delete it
MFUnrecChildNodePtr::const_iterator it2 =
(*mfit)->getMFChildren()->begin();
MFUnrecChildNodePtr::const_iterator en2 =
(*mfit)->getMFChildren()->end ();
for ( ; it2 != en2; ++it2 )
{
if (!isInExcludeList(*it2))
{
//check if geometry
if ((*it2)->getCore()->getType().isDerivedFrom(
Geometry::getClassType()))
{
if(!isLeaf(*it2))
{
//hmm...bad tree...
empty=false;
}
else
{
//it is a leaf geometry, so apply the transformation
Geometry *geo_old =
dynamic_cast<Geometry *>(
(*it2)->getCore());
//GeometryPtr geo = geo_old->clone();
GeometryUnrecPtr geo =
dynamic_pointer_cast<Geometry>(
OSG::deepClone(geo_old, "Material"));
Transform *t =
dynamic_cast<Transform *>(
(*mfit)->getCore());
GeoPnt3fProperty *pos = dynamic_cast<GeoPnt3fProperty *>(geo->getPositions());
GeoVec3fProperty *norm = dynamic_cast<GeoVec3fProperty *>(geo->getNormals());
GeoColor3fProperty *color = dynamic_cast<GeoColor3fProperty *>(geo->getColors());
GeoColor3fProperty *scolor = dynamic_cast<GeoColor3fProperty *>(geo->getSecondaryColors());
GeoVec3fProperty *texcoord0 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords());
GeoVec3fProperty *texcoord1 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords1());
GeoVec3fProperty *texcoord2 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords2());
GeoVec3fProperty * texcoord3 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords3());
Matrix m=t->getMatrix();
if(pos!=NULL)
{
for(UInt32 i = 0; i < pos->size(); ++i)
{
Pnt3f p=pos->getValue(i);
m.multFull(p, p);
pos->setValue(p,i);
}
}
if(norm!=NULL)
{
for(UInt32 i = 0; i < norm->size(); ++i)
{
Vec3f n=norm->getValue(i);
m.mult(n, n);
n.normalize();
norm->setValue(n,i);
}
}
if(color != NULL && _color_is_vector)
{
for(UInt32 i = 0; i < color->size(); ++i)
{
Color3f c = color->getValue(i);
Vec3f v;
v.setValue(c.getValuesRGB());
m.mult(v, v);
v.normalize();
c.setValuesRGB(v[0], v[1], v[2]);
color->setValue(c,i);
}
}
//.........这里部分代码省略.........
示例6: 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;
}
示例7: 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;
}
示例8: read
//----------------------------
// Function name: read
//----------------------------
//
//Parameters:
//p: Scene &image, const char *fileName
//GlobalVars:
//g:
//Returns:
//r:bool
// Caution
//c:
//Assumations:
//a:
//Describtions:
//d: read the image from the given file
//SeeAlso:
//s:
//
//------------------------------
NodeTransitPtr OBJSceneFileType::read( std::istream &is,
const Char8 *,
Resolver ) const
{
NodeUnrecPtr rootPtr, nodePtr;
std::string elem;
std::map<std::string, DataElem>::const_iterator elemI;
Vec3f vec3r;
Pnt3f pnt3r;
Vec2f vec2r;
Real32 x,y,z;
GeoPnt3fPropertyUnrecPtr coordPtr = GeoPnt3fProperty::create();
GeoVec2fPropertyUnrecPtr texCoordPtr = GeoVec2fProperty::create();
GeoVec3fPropertyUnrecPtr normalPtr = GeoVec3fProperty::create();
GeometryUnrecPtr geoPtr;
GeoIntegralPropertyUnrecPtr posIndexPtr, texIndexPtr, normalIndexPtr;
GeoIntegralPropertyUnrecPtr lensPtr;
GeoIntegralPropertyUnrecPtr typePtr;
DataElem dataElem;
DataElem lastDataElem;
Char8 strBuf[8192], *token, *nextToken;
Int32 strBufSize = sizeof(strBuf)/sizeof(Char8);
Int32 index, posIndex = 0, indexType;
Int32 i,j,n,primCount[3];
std::list<Mesh> meshList;
std::map<std::string, SimpleTexturedMaterialUnrecPtr> mtlMap;
std::map<std::string, SimpleTexturedMaterialUnrecPtr>::iterator mtlI;
Mesh emptyMesh;
Face emptyFace;
TiePoint emptyTie;
Int32 indexMask, meshIndexMask;
std::list<Face>::iterator faceI;
std::list<Mesh>::iterator meshI;
bool isSingleIndex;
// create the first mesh entry
meshList.push_back(emptyMesh);
meshI = meshList.begin();
if(is)
{
primCount[0] = 0;
primCount[1] = 0;
primCount[2] = 0;
for(is >> elem; is.eof() == false; is >> elem)
{
if(elem[0] == '#' || elem[0] == '$')
{
is.ignore(INT_MAX, '\n');
}
else
{
SceneFileHandler::the()->updateReadProgress();
elemI = _dataElemMap.find(elem);
dataElem = ((elemI == _dataElemMap.end()) ?
UNKNOWN_DE : elemI->second );
switch (dataElem)
{
case OBJECT_DE:
case GROUP_DE:
case SMOOTHING_GROUP_DE:
is.ignore(INT_MAX, '\n');
break;
case VERTEX_DE:
primCount[0]++;
is >> x >> y >> z;
pnt3r.setValues(x,y,z);
coordPtr->addValue(pnt3r);
break;
case VERTEX_TEXTURECOORD_DE:
primCount[1]++;
is >> x >> y;
vec2r.setValues(x,y);
texCoordPtr->addValue(vec2r);
break;
case VERTEX_NORMAL_DE:
primCount[2]++;
is >> x >> y >> z;
//.........这里部分代码省略.........
示例9: 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;
}
示例10: 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;
}
示例11: OSG_COLLADA_LOG
Node *
ColladaGeometry::createInstance(ColladaInstInfo *colInstInfo)
{
typedef ColladaInstanceGeometry::MaterialMap MaterialMap;
typedef ColladaInstanceGeometry::MaterialMapConstIt MaterialMapConstIt;
domGeometryRef geometry = getDOMElementAs<domGeometry>();
NodeUnrecPtr groupN = makeCoredNode<Group>();
OSG_COLLADA_LOG(("ColladaGeometry::createInstance id [%s]\n",
geometry->getId()));
if(getGlobal()->getOptions()->getCreateNameAttachments() == true &&
geometry->getName() != NULL )
{
setName(groupN, geometry->getName());
}
ColladaInstanceGeometryRefPtr colInstGeo =
dynamic_cast<ColladaInstanceGeometry *>(colInstInfo->getColInst());
const MaterialMap &matMap =
colInstGeo->getMaterialMap();
// iterate over all parts of geometry
GeoStoreIt gsIt = _geoStore.begin();
GeoStoreIt gsEnd = _geoStore.end ();
for(; gsIt != gsEnd; ++gsIt)
{
OSG_ASSERT(gsIt->_propStore.size() == gsIt->_indexStore.size());
// find the material associated with the geometry's material symbol
MaterialMapConstIt mmIt = matMap.find(gsIt->_matSymbol);
std::string matTarget;
if(mmIt != matMap.end())
{
matTarget = mmIt->second->getTarget();
}
// check if the geometry was already used with that material
GeometryUnrecPtr geo = NULL;
InstanceMapConstIt instIt = gsIt->_instMap.find(matTarget);
if(instIt != gsIt->_instMap.end())
{
// reuse geometry
geo = dynamic_pointer_cast<Geometry>(
getInstStore()[instIt->second]);
getGlobal()->getStatCollector()->getElem(
ColladaGlobal::statNGeometryUsed)->inc();
}
else
{
// create new geometry
geo = Geometry::create();
getGlobal()->getStatCollector()->getElem(
ColladaGlobal::statNGeometryCreated)->inc();
geo->setLengths(gsIt->_lengths);
geo->setTypes (gsIt->_types );
handleBindMaterial(*gsIt, geo, colInstGeo);
// record the instantiation of the geometry with the
// material for reuse
gsIt->_instMap.insert(
InstanceMap::value_type(matTarget, getInstStore().size()));
editInstStore().push_back(geo);
}
NodeUnrecPtr geoN = makeNodeFor(geo);
groupN->addChild(geoN);
}
// store the generated group node
editInstStore().push_back(groupN);
return groupN;
}
示例12: read
NodeTransitPtr RAWSceneFileType::read( std::istream &is,
const Char8 *,
Resolver ) const
{
NodeTransitPtr root;
GeometryUnrecPtr geo;
GeoPnt3fPropertyUnrecPtr points;
GeoVec3fPropertyUnrecPtr normals;
GeoIntegralPropertyUnrecPtr index;
GeoIntegralPropertyUnrecPtr lens;
GeoIntegralPropertyUnrecPtr type;
Vec3f vec[3];
UInt32 i = 0, n, triCount = 0;
Real32 x,y,z;
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);
}
//.........这里部分代码省略.........
示例13: setRoot
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 );
}
}
示例14: 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;
}
示例15: setMaterialX
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();
}