本文整理汇总了C++中NodeRecPtr::getToWorld方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeRecPtr::getToWorld方法的具体用法?C++ NodeRecPtr::getToWorld怎么用?C++ NodeRecPtr::getToWorld使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeRecPtr
的用法示例。
在下文中一共展示了NodeRecPtr::getToWorld方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VRIntersect_computeTexel
Vec2f VRIntersect_computeTexel(VRIntersection& ins, NodeRecPtr node) {
if (!ins.hit) return Vec2f(0,0);
if (node == 0) return Vec2f(0,0);
GeometryRefPtr geo = dynamic_cast<Geometry*>( node->getCore() );
if (geo == 0) return Vec2f(0,0);
auto texcoords = geo->getTexCoords();
if (texcoords == 0) return Vec2f(0,0);
TriangleIterator iter = geo->beginTriangles(); iter.seek( ins.triangle );
Matrix m = node->getToWorld();
m.invert();
Pnt3f local_pnt; m.mult(ins.point, local_pnt);
Pnt3f p0 = iter.getPosition(0);
Pnt3f p1 = iter.getPosition(1);
Pnt3f p2 = iter.getPosition(2);
Vec3f cr = (p1 - p0).cross(p2 - p0);
Vec3f n = cr; n.normalize();
float areaABC = n.dot(cr);
float areaPBC = n.dot((p1 - local_pnt).cross(p2 - local_pnt));
float areaPCA = n.dot((p2 - local_pnt).cross(p0 - local_pnt));
float a = areaPBC / areaABC;
float b = areaPCA / areaABC;
float c = 1.0f - a - b;
return iter.getTexCoords(0) * a + iter.getTexCoords(1) * b + iter.getTexCoords(2) * c;
}
示例2: 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);
//SkeletonDrawer System Material
LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
ExampleLineChunk->setWidth(4.0f);
ExampleLineChunk->setSmooth(true);
BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));
ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
ExampleMaterial->addChunk(ExampleLineChunk);
ExampleMaterial->addChunk(ExampleMaterialChunk);
ExampleMaterial->addChunk(ExampleBlendChunk);
GeometryRefPtr SphereGeometry = makeSphereGeo(2, 0.25f);
GeometryRefPtr BoxGeometry = makeBoxGeo(0.5f,0.5f,0.5f,1,1,1);
//Skeleton
SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create();
//Joint
TransformRecPtr ExampleRootJoint = Transform::create();
NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint);
//Add this joint to the skeleton
ExampleSkeleton->pushToJoints(ExampleRootJointNode, Matrix());
NodeRecPtr TempRootJointNode = ExampleRootJointNode;
NodeRefPtr GeoNode = makeNodeFor(BoxGeometry);
TempRootJointNode->addChild(GeoNode);
Matrix TempMat;
//Create a set of randomly placed child joints
for (Real32 i = 0.0f; i < 5.0f; ++i)
{
TransformRecPtr ExampleChildJoint = Transform::create();
NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint);
GeoNode = makeNodeFor(SphereGeometry);
ExampleChildJointNode->addChild(GeoNode);
//TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
switch((static_cast<UInt32>(i) % 3))
{
case 0:
TempMat.setTranslate(2.0f,0.0f,0.0f);
break;
case 1:
TempMat.setTranslate(0.0f,2.0f,0.0f);
break;
case 2:
TempMat.setTranslate(0.0f,0.0f,2.0f);
break;
}
//Set bind and current transformations to TempMat (calculated above)
ExampleChildJoint->setMatrix(TempMat);
//Add ExampleChildJoint as a child to the previous joint
TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint
//ExampleChildJoint will be the next parent joint
TempRootJointNode = ExampleChildJointNode;
//Add this joint to the skeleton
Matrix InvBind(TempRootJointNode->getToWorld());
InvBind.invert();
ExampleSkeleton->pushToJoints(ExampleChildJointNode, InvBind);
//.........这里部分代码省略.........
示例3: main
//.........这里部分代码省略.........
SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create();
//Joint
JointRecPtr ExampleRootJoint = Joint::create();
//Add this joint to the skeleton
ExampleSkeleton->pushToJoints(ExampleRootJoint, Matrix());
NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint);
NodeRecPtr TempRootJointNode = ExampleRootJointNode;
NodeRefPtr GeoNode = makeNodeFor(BoxGeometry);
TempRootJointNode->addChild(GeoNode);
Matrix TempMat;
//Create a set of randomly placed child joints
for (Real32 i = 0.0f; i < 5.0f; ++i)
{
JointRecPtr ExampleChildJoint = Joint::create();
NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint);
GeoNode = makeNodeFor(SphereGeometry);
ExampleChildJointNode->addChild(GeoNode);
//TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
switch((static_cast<UInt32>(i) % 3))
{
case 0:
TempMat.setTranslate(2.0f,0.0f,0.0f);
break;
case 1:
TempMat.setTranslate(0.0f,2.0f,0.0f);
break;
case 2:
TempMat.setTranslate(0.0f,0.0f,2.0f);
break;
}
//Set bind and current transformations to TempMat (calculated above)
ExampleChildJoint->setJointTransformation(TempMat);
//Add ExampleChildJoint as a child to the previous joint
TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint
//ExampleChildJoint will be the next parent joint
TempRootJointNode = ExampleChildJointNode;
//Add this joint to the skeleton
Matrix InvBind(TempRootJointNode->getToWorld());
InvBind.invert();
ExampleSkeleton->pushToJoints(ExampleChildJoint, InvBind);
}
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we won't draw the skeleton's bind pose
ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When the skeleton's bind pose is rendered, it will be 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 is rendered in blue
//Skeleton Node
SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
//Create scene
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SkeletonNode);
scene->addChild(ExampleRootJointNode);
mgr->setRoot(scene);
//Setup the Animation
setupAnimation(ExampleRootJoint,
dynamic_cast<Joint*>(ExampleRootJointNode->getChild(1)->getCore()));
//Set the currently playing animation to TheJointAnimation (can be switched at runtime via a key command)
TheCurrentAnimation = TheJointAnimation;
// 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,
"11BoneAnimation");
//Main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例4: 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);
//Print key command info
std::cout << "\n\nKEY COMMANDS:" << std::endl;
std::cout << "space Play/Pause the animation" << std::endl;
std::cout << "B Show/Hide the bind pose skeleton" << std::endl;
std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl;
std::cout << "P Show/Hide the current pose skeleton" << std::endl;
std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl;
std::cout << "CTRL-Q Exit\n\n" << std::endl;
//SkeletonDrawer System Material
LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
ExampleLineChunk->setWidth(2.0f);
ExampleLineChunk->setSmooth(true);
BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));
ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
ExampleMaterial->addChunk(ExampleLineChunk);
ExampleMaterial->addChunk(ExampleMaterialChunk);
ExampleMaterial->addChunk(ExampleBlendChunk);
//Skeleton
ExampleSkeleton = SkeletonBlendedGeometry::create();
//===========================================Joints==================================================================
Matrix TempMat;
Matrix InvBind;
/*================================================================================================*/
/* Pelvis */
Pelvis = Joint::create(); //create a joint called Pelvis
TempMat.setTranslate(0.0,7.0,0.0);
Pelvis->setJointTransformation(TempMat);
NodeRecPtr PelvisNode = makeNodeFor(Pelvis);
InvBind = PelvisNode->getToWorld();
InvBind.invert();
ExampleSkeleton->pushToJoints(Pelvis, InvBind);
setName(Pelvis, "Pelvis Joint");
setName(PelvisNode, "Pelvis Node");
/*================================================================================================*/
/* Clavicle */
Clavicle = Joint::create(); //create a joint called Clavicle
TempMat.setTranslate(0.0,5.0,0.0);
Clavicle->setJointTransformation(TempMat);
NodeRecPtr ClavicleNode = makeNodeFor(Clavicle);
PelvisNode->addChild(ClavicleNode);
InvBind = ClavicleNode->getToWorld();
InvBind.invert();
ExampleSkeleton->pushToJoints(Clavicle, InvBind);
setName(Clavicle, "Clavicle Joint");
setName(ClavicleNode, "Clavicle Node");
/*================================================================================================*/
/* Left Shoulder */
LeftShoulder = Joint::create(); //create a joint called LeftShoulder
TempMat.setTranslate(1.0,-0.5,0.0);
LeftShoulder->setJointTransformation(TempMat);
NodeRecPtr LeftShoulderNode = makeNodeFor(LeftShoulder);
ClavicleNode->addChild(LeftShoulderNode);
//.........这里部分代码省略.........