本文整理汇总了C++中NodeRefPtr::getCore方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeRefPtr::getCore方法的具体用法?C++ NodeRefPtr::getCore怎么用?C++ NodeRefPtr::getCore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeRefPtr
的用法示例。
在下文中一共展示了NodeRefPtr::getCore方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create3DObjects
void create3DObjects(void)
{
// Make Object Nodes
NodeRefPtr ExampleTorusGeo = makeTorus(90, 270, 16, 16);
NodeRefPtr ExampleConeGeo = makeCone(150, 50, 16, true, true);
NodeRefPtr ExampleSphereGeo = makeSphere(4, 100);
NodeRefPtr ExampleBoxGeo = makeBox(100, 100, 100, 1, 1, 1);
// AssignTextures
dynamic_cast<Geometry*>(ExampleConeGeo->getCore())->setMaterial(createBlueMaterial());
dynamic_cast<Geometry*>(ExampleSphereGeo->getCore())->setMaterial(createRedMaterial());
dynamic_cast<Geometry*>(ExampleBoxGeo->getCore())->setMaterial(createGreenMaterial());
// Preform transformations on them
Matrix mat;
// On Torus
mat.setTranslate(0.0,100.0,-200.0);
TransformRefPtr TorusTranCore = Transform::create();
TorusTranCore->setMatrix(mat);
ExampleTorus = Node::create();
ExampleTorus->setCore(TorusTranCore);
ExampleTorus->addChild(ExampleTorusGeo);
// On Sphere
mat.setTranslate(250.0,0.0,0.0);
TransformRefPtr SphereTranCore = Transform::create();
SphereTranCore->setMatrix(mat);
ExampleSphere = Node::create();
ExampleSphere->setCore(SphereTranCore);
ExampleSphere->addChild(ExampleSphereGeo);
// On Cone
mat.setTranslate(0.0,0.0,-250.0);
TransformRefPtr ConeTranCore = Transform::create();
ConeTranCore->setMatrix(mat);
ExampleCone = Node::create();
ExampleCone->setCore(ConeTranCore);
ExampleCone->addChild(ExampleConeGeo);
// On Box
mat.setTranslate(250.0,250.0,0.0);
TransformRefPtr ExampleBoxTranCore = Transform::create();
ExampleBoxTranCore->setMatrix(mat);
ExampleBox = Node::create();
ExampleBox->setCore(ExampleBoxTranCore);
ExampleBox->addChild(ExampleBoxGeo);
}
示例2: buildBox
//////////////////////////////////////////////////////////////////////////
//! build a box
//////////////////////////////////////////////////////////////////////////
void buildBox(void)
{
Vec3f Lengths((Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0);
Matrix m;
//create OpenSG mesh
GeometryRefPtr box;
NodeRefPtr boxNode = makeBox(Lengths.x(), Lengths.y(), Lengths.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialRefPtr 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);
TransformRefPtr boxTrans;
NodeRefPtr 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
PhysicsBodyRefPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(randX, randY, 10.0));
boxBody->setBoxMass(1.0, Lengths.x(), Lengths.y(), Lengths.z());
//std::cout << "mass: " << boxBody->getMass() << std::endl
//<< "massCenterOfGravity: " << boxBody->getMassCenterOfGravity().x() << ", " << boxBody->getMassCenterOfGravity().y() << ", " << boxBody->getMassCenterOfGravity().z() << std::endl
//<< "massInertiaTensor: " << std::endl
//<< boxBody->getMassInertiaTensor()[0][0] << " "<< boxBody->getMassInertiaTensor()[0][1] << " "<< boxBody->getMassInertiaTensor()[0][2] << " " << boxBody->getMassInertiaTensor()[0][3] << std::endl
//<< boxBody->getMassInertiaTensor()[1][0] << " "<< boxBody->getMassInertiaTensor()[1][1] << " "<< boxBody->getMassInertiaTensor()[1][2] << " " << boxBody->getMassInertiaTensor()[1][3] << std::endl
//<< boxBody->getMassInertiaTensor()[2][0] << " "<< boxBody->getMassInertiaTensor()[2][1] << " "<< boxBody->getMassInertiaTensor()[2][2] << " " << boxBody->getMassInertiaTensor()[2][3] << std::endl
//<< boxBody->getMassInertiaTensor()[3][0] << " "<< boxBody->getMassInertiaTensor()[3][1] << " "<< boxBody->getMassInertiaTensor()[3][2] << " " << boxBody->getMassInertiaTensor()[3][3] << std::endl
//<< std::endl;
PhysicsBoxGeomRefPtr 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();
}
示例3: buildTriMesh
//////////////////////////////////////////////////////////////////////////
//! trimesh defined by filenode will be loaded
//////////////////////////////////////////////////////////////////////////
void buildTriMesh(void)
{
NodeRefPtr tri = cloneTree(TriGeometryBase);
if(tri!=NULL)
{
GeometryRefPtr triGeo = dynamic_cast<Geometry*>(tri->getCore());
Matrix m;
SimpleMaterialRefPtr tri_mat = SimpleMaterial::create();
tri_mat->setAmbient(Color3f(0.1,0.1,0.2));
tri_mat->setDiffuse(Color3f(1.0,0.1,0.7));
triGeo->setMaterial(tri_mat);
TransformRefPtr triTrans;
NodeRefPtr triTransNode = makeCoredNode<Transform>(&triTrans);
m.setIdentity();
Real32 randX = (Real32)(rand()%10)-5.0;
Real32 randY = (Real32)(rand()%10)-5.0;
m.setTranslate(randX, randY, 18.0);
triTrans->setMatrix(m);
//create ODE data
Vec3f GeometryBounds(calcMinGeometryBounds(triGeo));
PhysicsBodyRefPtr triBody = PhysicsBody::create(physicsWorld);
triBody->setPosition(Vec3f(randX, randY, 18.0));
triBody->setLinearDamping(0.0001);
triBody->setAngularDamping(0.0001);
triBody->setBoxMass(1.0,GeometryBounds.x(), GeometryBounds.y(), GeometryBounds.z());
PhysicsGeomRefPtr triGeom;
if(true)
{
triGeom = PhysicsTriMeshGeom::create();
triGeom->setBody(triBody);
//add geom to space for collision
triGeom->setSpace(physicsSpace);
//set the geometryNode to fill the ode-triMesh
NodeRefPtr TorusGeometryNode(makeTorus(0.55, 1.05, 6, 6));
dynamic_pointer_cast<PhysicsTriMeshGeom>(triGeom)->setGeometryNode(TorusGeometryNode);
}
//add attachments
tri->addAttachment(triGeom);
triTransNode->addAttachment(triBody);
//add to SceneGraph
triTransNode->addChild(tri);
spaceGroupNode->addChild(triTransNode);
}
else
{
SLOG << "Could not read MeshData!" << endLog;
}
commitChanges();
}
示例4: buildShip
//////////////////////////////////////////////////////////////////////////
//! build a ship
//////////////////////////////////////////////////////////////////////////
PhysicsBodyRefPtr buildShip(Vec3f Dimensions, Pnt3f Position)
{
Real32 Radius(osgMax(Dimensions.x(), Dimensions.y())/2.0f);
Real32 Length(Dimensions.z() - 2.0f*Radius);
Matrix m;
//create OpenSG mesh
GeometryRefPtr box;
NodeRefPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialRefPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color3f(1.0,1.0 ,0.0));
box->setMaterial(box_mat);
TransformRefPtr boxTrans;
NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
m.setTranslate(Position - Vec3f(0.0f,0.0f,0.5f*Dimensions.z()));
boxTrans->setMatrix(m);
for(UInt32 i(0) ; i<box->getPositions()->size() ; ++i)
{
box->getPositions()->setValue<Pnt3f>(box->getPositions()->getValue<Pnt3f>(i) + Vec3f(0.0,0.0,Dimensions.z()/2.0f),i);
}
//create ODE data
PhysicsBodyRefPtr CapsuleBody = PhysicsBody::create(physicsWorld);
CapsuleBody->setPosition(Vec3f(Position - Vec3f(0.0f,0.0f,0.5f*Dimensions.z())));
CapsuleBody->setLinearDamping(0.01);
CapsuleBody->setMaxAngularSpeed(0.0);
CapsuleBody->setCapsuleMass(1.0,3,Radius, Length);
PhysicsCapsuleGeomRefPtr CapsuleGeom = PhysicsCapsuleGeom::create();
CapsuleGeom->setBody(CapsuleBody);
CapsuleGeom->setOffsetPosition(Vec3f(0.0f,0.0f,0.5f*Dimensions.z()));
CapsuleGeom->setSpace(hashSpace);
CapsuleGeom->setRadius(Radius);
CapsuleGeom->setLength(Length);
//add attachments
boxNode->addAttachment(CapsuleGeom);
boxTransNode->addAttachment(CapsuleBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
return CapsuleBody;
}
示例5: buildCharacter
//////////////////////////////////////////////////////////////////////////
//! build a character
//////////////////////////////////////////////////////////////////////////
PhysicsBodyRefPtr buildCharacter(Vec3f Dimensions,
Pnt3f Position,
Node* const spaceGroupNode,
PhysicsWorld* const physicsWorld,
PhysicsHashSpace* const physicsSpace
)
{
Real32 Radius(osgMax(Dimensions.x(), Dimensions.y())/2.0f);
Real32 Length(Dimensions.z() - 2.0f*Radius);
Matrix m;
//create OpenSG mesh
GeometryRefPtr box;
//NodeRefPtr characterNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
NodeRefPtr characterNode = SceneFileHandler::the()->read("Data/Jack.osb");
if(characterNode == NULL)
{
characterNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
}
box = dynamic_cast<Geometry*>(characterNode->getCore());
TransformRefPtr boxTrans;
NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
m.setTranslate(Position);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyRefPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(Position));
//boxBody->setLinearDamping(0.001);
//boxBody->setAngularDamping(0.001);
boxBody->setMaxAngularSpeed(0.0);
boxBody->setCapsuleMass(1.0,3,Radius, Length);
PhysicsCapsuleGeomRefPtr CapsuleGeom = PhysicsCapsuleGeom::create();
CapsuleGeom->setBody(boxBody);
CapsuleGeom->setSpace(physicsSpace);
CapsuleGeom->setRadius(Radius);
CapsuleGeom->setLength(Length);
//add attachments
characterNode->addAttachment(CapsuleGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(characterNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
return boxBody;
}
示例6: buildSphere
//////////////////////////////////////////////////////////////////////////
//! build a sphere
//////////////////////////////////////////////////////////////////////////
void buildSphere(void)
{
Real32 Radius((Real32)(rand()%2)*0.5+0.5);
Matrix m;
//create OpenSG mesh
GeometryRefPtr sphere;
NodeRefPtr sphereNode = makeSphere(2, Radius);
sphere = dynamic_cast<Geometry*>(sphereNode->getCore());
SimpleMaterialRefPtr 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);
TransformRefPtr sphereTrans;
NodeRefPtr 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
PhysicsBodyRefPtr sphereBody = PhysicsBody::create(physicsWorld);
sphereBody->setPosition(Vec3f(randX, randY, 10.0));
sphereBody->setAngularDamping(0.0001);
sphereBody->setSphereMass(1.0,Radius);
PhysicsSphereGeomRefPtr 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();
}
示例7: buildBox
//////////////////////////////////////////////////////////////////////////
//! build a box
//////////////////////////////////////////////////////////////////////////
PhysicsBodyRefPtr buildBox(Vec3f Dimensions, Pnt3f Position)
{
Matrix m;
//create OpenSG mesh
GeometryRefPtr box;
NodeRefPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialRefPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color3f(0.0,1.0 ,1.0));
box->setMaterial(box_mat);
TransformRefPtr boxTrans;
NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
m.setTranslate(Position);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyRefPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(Position));
boxBody->setLinearDamping(0.001);
boxBody->setAngularDamping(0.001);
boxBody->setBoxMass(1.0,Dimensions.x(), Dimensions.y(), Dimensions.z());
PhysicsBoxGeomRefPtr boxGeom = PhysicsBoxGeom::create();
boxGeom->setBody(boxBody);
boxGeom->setSpace(hashSpace);
boxGeom->setLengths(Dimensions);
//add attachments
boxNode->addAttachment(boxGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
return boxBody;
}
示例8: selectedNodeChanged
void selectedNodeChanged(void)
{
mgr->setHighlight(SelectedNode);
//Update Details Panel
if(SelectedNode == NULL)
{
NodeNameValueLabel->setText("");
NodeCoreTypeValueLabel->setText("");
NodeMinValueLabel->setText("");
NodeMaxValueLabel->setText("");
NodeCenterValueLabel->setText("");
NodeTriCountValueLabel->setText("");
NodeTravMaskValueLabel->setText("");
NodeOcclusionMaskValueLabel->setText("");
NodeActiveValueLabel->setText("");
}
else
{
const Char8 *NodeName = getName(SelectedNode);
if(NodeName == NULL)
{
NodeNameValueLabel->setText("Unnamed Node");
}
else
{
NodeNameValueLabel->setText(NodeName);
}
NodeCoreTypeValueLabel->setText(SelectedNode->getCore()->getType().getCName());
BoxVolume DyVol;
SelectedNode->getWorldVolume(DyVol);
Pnt3f Min,Max,Center;
DyVol.getBounds(Min,Max);
DyVol.getCenter(Center);
std::string TempText("");
TempText = boost::lexical_cast<std::string>(Min.x()) + ", " +boost::lexical_cast<std::string>(Min.x()) + ", " + boost::lexical_cast<std::string>(Min.x());
NodeMinValueLabel->setText(TempText);
TempText = boost::lexical_cast<std::string>(Max.x()) + ", " +boost::lexical_cast<std::string>(Max.x()) + ", " + boost::lexical_cast<std::string>(Max.x());
NodeMaxValueLabel->setText(TempText);
TempText = boost::lexical_cast<std::string>(Center.x()) + ", " +boost::lexical_cast<std::string>(Center.x()) + ", " + boost::lexical_cast<std::string>(Center.x());
NodeCenterValueLabel->setText(TempText);
//GeometryPrimitivesCounter PrimCounter;
//PrimCounter(SelectedNode);
//NodeTriCountValueLabel->setText(boost::lexical_cast<std::string>(PrimCounter.getTriCount()));
//NodeTravMaskValueLabel->setText(boost::lexical_cast<std::string>(SelectedNode->getTravMask()));
//NodeOcclusionMaskValueLabel->setText(boost::lexical_cast<std::string>(SelectedNode->getOcclusionMask()));
//NodeActiveValueLabel->setText(boost::lexical_cast<std::string>(SelectedNode->getActive()));
}
}
示例9: 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 Base Geometry Node
TriGeometryBase = makeTorus(0.5, 1.0, 24, 24);
//Make Main Scene Node
NodeRefPtr scene = makeCoredNode<Group>();
setName(scene, "scene");
rootNode = Node::create();
setName(rootNode, "rootNode");
ComponentTransformRefPtr Trans;
Trans = ComponentTransform::create();
rootNode->setCore(Trans);
// add the torus as a child
rootNode->addChild(scene);
//Make The Physics Characteristics Node
PhysicsCharacteristicsDrawableRefPtr PhysDrawable = PhysicsCharacteristicsDrawable::create();
PhysDrawable->setRoot(rootNode);
PhysDrawableNode = Node::create();
PhysDrawableNode->setCore(PhysDrawable);
PhysDrawableNode->setTravMask(TypeTraits<UInt32>::getMin());
rootNode->addChild(PhysDrawableNode);
//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 = PhysicsHashSpace::create();
physHandler = PhysicsHandler::create();
physHandler->setWorld(physicsWorld);
physHandler->pushToSpaces(physicsSpace);
physHandler->setUpdateNode(rootNode);
physHandler->attachUpdateProducer(TutorialWindow->editEventProducer());
/************************************************************************/
/* create spaces, geoms and bodys */
/************************************************************************/
//create a group for our space
GroupRefPtr spaceGroup;
spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
//create the ground plane
GeometryRefPtr plane;
NodeRefPtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1);
plane = dynamic_cast<Geometry*>(planeNode->getCore());
//and its Material
SimpleMaterialRefPtr 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);
//create Physical Attachments
PhysicsBoxGeomRefPtr planeGeom = PhysicsBoxGeom::create();
planeGeom->setLengths(Vec3f(30.0, 30.0, 1.0));
//add geoms to space for collision
planeGeom->setSpace(physicsSpace);
//add Attachments to nodes...
spaceGroupNode->addAttachment(physicsSpace);
//.........这里部分代码省略.........