本文整理汇总了C++中NodeUnrecPtr::addAttachment方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeUnrecPtr::addAttachment方法的具体用法?C++ NodeUnrecPtr::addAttachment怎么用?C++ NodeUnrecPtr::addAttachment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeUnrecPtr
的用法示例。
在下文中一共展示了NodeUnrecPtr::addAttachment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main
// Initialize GLUT & OpenSG and set up the rootNode
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
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);
//Make Torus Node
NodeUnrecPtr TorusNode = makeTorus(.5, 2, 32, 32);
//Make Main Scene Node
NodeUnrecPtr scene = makeCoredNode<Group>();
setName(scene, "scene");
rootNode = Node::create();
setName(rootNode, "rootNode");
ComponentTransformUnrecPtr Trans;
Trans = ComponentTransform::create();
rootNode->setCore(Trans);
// add the torus as a child
rootNode->addChild(scene);
//Setup Physics Scene
physicsWorld = PhysicsWorld::create();
physicsWorld->setWorldContactSurfaceLayer(0.005);
physicsWorld->setAutoDisableFlag(1);
physicsWorld->setAutoDisableTime(0.75);
physicsWorld->setWorldContactMaxCorrectingVel(100.0);
physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81));
//physicsSpace = PhysicsSimpleSpace::create();
//physicsSpace = PhysicsQuadTreeSpace::create();
//physicsSpace = PhysicsHashSpace::create();
physicsSpace = PhysicsSweepAndPruneSpace::create();
CollisionContactParametersUnrecPtr DefaultCollisionParams = CollisionContactParameters::createEmpty();
DefaultCollisionParams->setMode(dContactApprox1 | dContactBounce);
DefaultCollisionParams->setMu(0.3);
DefaultCollisionParams->setMu2(0.0);
DefaultCollisionParams->setBounce(0.2);
DefaultCollisionParams->setBounceSpeedThreshold(0.1);
DefaultCollisionParams->setSoftCFM(0.1);
DefaultCollisionParams->setSoftERP(0.2);
DefaultCollisionParams->setMotion1(0.0);
DefaultCollisionParams->setMotion2(0.0);
DefaultCollisionParams->setMotionN(0.0);
DefaultCollisionParams->setSlip1(0.0);
DefaultCollisionParams->setSlip2(0.0);
physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams);
physHandler = PhysicsHandler::create();
physHandler->setWorld(physicsWorld);
physHandler->pushToSpaces(physicsSpace);
physHandler->setUpdateNode(rootNode);
physHandler->attachUpdateProducer(TutorialWindow->editEventProducer());
rootNode->addAttachment(physHandler);
rootNode->addAttachment(physicsWorld);
rootNode->addAttachment(physicsSpace);
/************************************************************************/
/* create spaces, geoms and bodys */
/************************************************************************/
//create a group for our space
GroupUnrecPtr spaceGroup;
spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
//create the ground plane
GeometryUnrecPtr plane;
NodeUnrecPtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1);
plane = dynamic_cast<Geometry*>(planeNode->getCore());
//and its Material
SimpleMaterialUnrecPtr plane_mat = SimpleMaterial::create();
plane_mat->setAmbient(Color3f(0.7,0.7,0.7));
plane_mat->setDiffuse(Color3f(0.9,0.6,1.0));
plane->setMaterial(plane_mat);
//.........这里部分代码省略.........
示例5: read
NodeTransitPtr SceneFileHandlerBase::read(const Char8 *fileName,
GraphOpSeq *graphOpSeq,
Resolver resolver,
bool bWarnNotFound )
{
NodeTransitPtr returnValue(NULL);
if(fileName == NULL)
{
SWARNING << "cannot read NULL file" << std::endl;
return NodeTransitPtr(NULL);
}
std::string fullFilePath = initPathHandler(fileName);
if(fullFilePath.empty() == true)
{
if(_readFP != NULL)
{
// that's a fallback could be a url so the callback
// can handle this correctly.
SceneFileType *type = getFileType(fileName);
if(type != NULL)
{
// create a dummy stream with the bad flag set.
std::ifstream in;
in.setstate(std::ios::badbit);
returnValue = _readFP(type, in, fileName);
}
else
{
if(bWarnNotFound == true)
SWARNING << "Couldn't open file " << fileName << std::endl;
}
}
else
{
if(bWarnNotFound == true)
SWARNING << "Couldn't open file " << fileName << std::endl;
}
commitChanges();
return returnValue;
}
SceneFileType *type = getFileType(fullFilePath.c_str());
NodeUnrecPtr scene = NULL;
if(type != NULL)
{
triggerReadBegin(fullFilePath.c_str());
updateReadProgress(0);
SINFO << "try to read " << fullFilePath
<< " as " << type->getName() << std::endl;
std::ifstream in(fullFilePath.c_str(), std::ios::binary);
if(in)
{
scene = read(in, fullFilePath.c_str(), graphOpSeq);
in.close();
if(scene != NULL)
{
triggerReadEnd(fullFilePath.c_str());
FileContextAttachmentUnrecPtr pFContext =
dynamic_cast<FileContextAttachment *>(
scene->findAttachment(
FileContextAttachment::getClassGroupId()));
if(pFContext == NULL)
{
pFContext = FileContextAttachment::create();
pFContext->setResolvedName(fullFilePath);
scene->addAttachment(pFContext);
}
}
}
else
{
if(bWarnNotFound == true)
{
SWARNING << "Couldn't open input stream for file "
<< fullFilePath
<< std::endl;
}
}
#ifndef OSG_DISABLE_DEPRECATED
// Ok stream interface didn't work try via filename
if(scene == NULL)
scene = type->readFile(fullFilePath.c_str());
//.........这里部分代码省略.........