本文整理汇总了C++中TransformPtr::setMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ TransformPtr::setMatrix方法的具体用法?C++ TransformPtr::setMatrix怎么用?C++ TransformPtr::setMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TransformPtr
的用法示例。
在下文中一共展示了TransformPtr::setMatrix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: display
void display(void)
{
Real32 time = glutGet(GLUT_ELAPSED_TIME );
//create the Quaternion the describes the rotation of
//the planet around the sun
Quaternion planetRot = Quaternion(Vec3f(0,1,0), time/float(1000));
//now the rotation of the moon around the planet
//the division by 12 speeds up the rotation by 12 compared to the
//planet rotation
Quaternion moonRot = Quaternion(Vec3f(0,1,0), time/float(1000/12));
//generate the Matrices
Matrix p,m;
p.setIdentity();
m.setIdentity();
p.setRotate(planetRot);
m.setRotate(moonRot);
p.setTranslate(20,0,0);
m.setTranslate(8,0,0);
beginEditCP(planetTransform, Transform::MatrixFieldMask);
planetTransform->setMatrix(p);
endEditCP(planetTransform, Transform::MatrixFieldMask);
beginEditCP(moonTransform, Transform::MatrixFieldMask);
moonTransform->setMatrix(m);
endEditCP(moonTransform, Transform::MatrixFieldMask);
mgr->redraw();
}
示例2: keyPressed
virtual void keyPressed(const KeyEventPtr e)
{
if(e->getKey() == KeyEvent::KEY_Q && e->getModifiers() & KeyEvent::KEY_MODIFIER_CONTROL)
{
TutorialWindowEventProducer->closeWindow();
}
switch(e->getKey())
{
case KeyEvent::KEY_S:
statFlag = !statFlag;
mgr->setStatistics(statFlag);
break;
case KeyEvent::KEY_EQUALS:
{
Vec3f Translation;
Quaternion Rotation;
Vec3f Scale;
Quaternion ScaleOrient;
Matrix ThePointLightMat = ThePointLightBeaconTransform->getMatrix();
ThePointLightMat.getTransform(Translation,Rotation,Scale,ScaleOrient);
Translation = Translation + Vec3f(0.0,10.0,0.0);
ThePointLightMat.setTranslate(Translation);
beginEditCP(ThePointLightBeaconTransform);
ThePointLightBeaconTransform->setMatrix(ThePointLightMat);
endEditCP(ThePointLightBeaconTransform);
}
break;
case KeyEvent::KEY_MINUS:
{
Vec3f Translation;
Quaternion Rotation;
Vec3f Scale;
Quaternion ScaleOrient;
Matrix ThePointLightMat = ThePointLightBeaconTransform->getMatrix();
ThePointLightMat.getTransform(Translation,Rotation,Scale,ScaleOrient);
Translation = Translation + Vec3f(0.0,-10.0,0.0);
ThePointLightMat.setTranslate(Translation);
beginEditCP(ThePointLightBeaconTransform);
ThePointLightBeaconTransform->setMatrix(ThePointLightMat);
endEditCP(ThePointLightBeaconTransform);
}
break;
case KeyEvent::KEY_T:
beginEditCP(TheBlinnMat, BlinnMaterial::DiffuseTextureFieldMask);
endEditCP(TheBlinnMat, BlinnMaterial::DiffuseTextureFieldMask);
break;
}
}
示例3: OnTrackingButtonReleased
void CFlystickTranslationResetTool::OnTrackingButtonReleased(Quaternion q, Vec3f position){
std::cout << "CFlystickTranslationResetTool::OnTrackingButtonReleased()" << std::endl;
if (! m_bToolActive){
std::cout << "tool is not active" << std::endl;
return;
}
if (m_posgPickedObjectNode == NullFC){
std::cout << "CFlystickTranslationResetTool: No object picked to reset translation" << std::endl;
return;
}
NodePtr parentingTransformNode = GetParentTransformNode(m_posgPickedObjectNode);
if (parentingTransformNode != NullFC){
std::cout << "CFlystickTranslationResetTool: Resetting translation!" << std::endl;
TransformPtr transform = TransformPtr::dcast(parentingTransformNode->getCore());
Matrix m = transform->getMatrix();
m.setTranslate(0.0, 0.0, 0.0);
beginEditCP(transform, Transform::MatrixFieldMask);{
transform->setMatrix(m);
};endEditCP(transform, Transform::MatrixFieldMask);
}else{
std::cout << "CFlystickTranslationResetTool: Found no parenting transform to reset!" << std::endl;
}
m_bToolActive = false;
}
示例4: glutGet
void
display(void)
{
Matrix m1, m2;
m1.setRotate( tball.getRotation() );
m2.setTranslate( tball.getPosition() );
m1.mult( m2 );
cam_trans->editSFMatrix()->setValue( m1 );
// move the object
float t = glutGet(GLUT_ELAPSED_TIME);
Quaternion q;
q.setValueAsAxisDeg(0, 1, 0, t / 5000);
m1.setTransform(Vec3f(osgsin(t / 500.), 0, osgcos(t / 500)), q);
tr->setMatrix(m1);
if ( doRender )
win->render( ract );
else
win->draw( dact );
}
示例5: display
// redraw the window
void display(void)
{
Matrix m;
Real32 t = glutGet(GLUT_ELAPSED_TIME );
if(animate)
{
m.setTransform(Vec3f( osgsin(t / 1000.f),
osgcos(t / 1000.f),
osgsin(t / 1000.f)),
Quaternion( Vec3f(0,1,0),
t / 1000.f),
Vec3f( osgsin(t / 900.f)*.5+.7,
osgcos(t / 900.f)*.5+.7,
osgsin(t / 900.f)*.5+.7));
beginEditCP(trans1, Transform::MatrixFieldMask);
{
trans1->setMatrix(m);
}
endEditCP (trans1, Transform::MatrixFieldMask);
m.setTransform(Vec3f( osgsin(t / 500.f),
osgcos(t / 500.f),
osgsin(t / 500.f)),
Quaternion( Vec3f(0,1,0),
t / 1000.f),
Vec3f( osgsin(t / 400.f)*.5+.7,
osgcos(t / 400.f)*.5+.7,
osgsin(t / 400.f)*.5+.7));
beginEditCP(trans2, Transform::MatrixFieldMask);
{
trans2->setMatrix(m);
}
endEditCP (trans2, Transform::MatrixFieldMask);
}
// render
mgr->redraw();
// all done, swap
glutSwapBuffers();
}
示例6: buildBox
//////////////////////////////////////////////////////////////////////////
//! build a box
//////////////////////////////////////////////////////////////////////////
void buildBox(void)
{
Vec3f Lengths(frand()*2.0+0.5, frand()*2.0+0.5, frand()*2.0+0.5);
Matrix m;
//create OpenSG mesh
GeometryPtr box;
NodePtr boxNode = makeBox(Lengths.x(), Lengths.y(), Lengths.z(), 1, 1, 1);
box = GeometryPtr::dcast(boxNode->getCore());
SimpleMaterialPtr box_mat = SimpleMaterial::create();
beginEditCP(box_mat);
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color3f(0.0,1.0 ,0.0));
endEditCP(box_mat);
beginEditCP(box, Geometry::MaterialFieldMask);
box->setMaterial(box_mat);
endEditCP(box, Geometry::MaterialFieldMask);
TransformPtr boxTrans;
NodePtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
Real32 randX = frand()*10.0-5.0;
Real32 randY = frand()*10.0-5.0;
m.setTranslate(randX, randY, 10.0);
beginEditCP(boxTrans, Transform::MatrixFieldMask);
boxTrans->setMatrix(m);
endEditCP(boxTrans, Transform::MatrixFieldMask);
//create ODE data
PhysicsBodyPtr boxBody = PhysicsBody::create(physicsWorld);
beginEditCP(boxBody, PhysicsBody::PositionFieldMask);
boxBody->setPosition(Vec3f(randX, randY, 10.0));
endEditCP(boxBody, PhysicsBody::PositionFieldMask);
boxBody->setBoxMass(1.0, Lengths.x(), Lengths.y(), Lengths.z());
PhysicsBoxGeomPtr boxGeom = PhysicsBoxGeom::create();
beginEditCP(boxGeom, PhysicsBoxGeom::BodyFieldMask | PhysicsBoxGeom::SpaceFieldMask | PhysicsBoxGeom::LengthsFieldMask | PhysicsBoxGeom::CategoryBitsFieldMask);
boxGeom->setBody(boxBody);
boxGeom->setSpace(physicsSpace);
boxGeom->setLengths(Lengths);
boxGeom->setCategoryBits(BoxCategory);
endEditCP(boxGeom, PhysicsBoxGeom::BodyFieldMask | PhysicsBoxGeom::SpaceFieldMask | PhysicsBoxGeom::LengthsFieldMask | PhysicsBoxGeom::CategoryBitsFieldMask);
//add attachments
beginEditCP(boxNode, Node::AttachmentsFieldMask);
boxNode->addAttachment(boxGeom);
endEditCP(boxNode, Node::AttachmentsFieldMask);
beginEditCP(boxTransNode, Node::AttachmentsFieldMask | Node::ChildrenFieldMask);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(boxNode);
endEditCP(boxTransNode, Node::AttachmentsFieldMask | Node::ChildrenFieldMask);
//add to SceneGraph
beginEditCP(spaceGroupNode, Node::ChildrenFieldMask);
spaceGroupNode->addChild(boxTransNode);
endEditCP(spaceGroupNode, Node::ChildrenFieldMask);
}
示例7: buildSphere
//////////////////////////////////////////////////////////////////////////
//! build a sphere
//////////////////////////////////////////////////////////////////////////
void buildSphere(void)
{
Real32 Radius(frand()*1.5+0.2);
Matrix m;
//create OpenSG mesh
GeometryPtr sphere;
NodePtr sphereNode = makeSphere(2, Radius);
sphere = GeometryPtr::dcast(sphereNode->getCore());
SimpleMaterialPtr sphere_mat = SimpleMaterial::create();
beginEditCP(sphere_mat);
sphere_mat->setAmbient(Color3f(0.0,0.0,0.0));
sphere_mat->setDiffuse(Color3f(0.0,0.0,1.0));
endEditCP(sphere_mat);
beginEditCP(sphere, Geometry::MaterialFieldMask);
sphere->setMaterial(sphere_mat);
endEditCP(sphere);
TransformPtr sphereTrans;
NodePtr sphereTransNode = makeCoredNode<Transform>(&sphereTrans);
m.setIdentity();
Real32 randX = frand()*10.0-5.0;
Real32 randY = frand()*10.0-5.0;
m.setTranslate(randX, randY, 10.0);
beginEditCP(sphereTrans, Transform::MatrixFieldMask);
sphereTrans->setMatrix(m);
endEditCP(sphereTrans);
//create ODE data
PhysicsBodyPtr sphereBody = PhysicsBody::create(physicsWorld);
beginEditCP(sphereBody, PhysicsBody::PositionFieldMask | PhysicsBody::AngularDampingFieldMask);
sphereBody->setPosition(Vec3f(randX, randY, 10.0));
sphereBody->setAngularDamping(0.0001);
endEditCP(sphereBody, PhysicsBody::PositionFieldMask | PhysicsBody::AngularDampingFieldMask);
sphereBody->setSphereMass(0.4,Radius);
PhysicsSphereGeomPtr sphereGeom = PhysicsSphereGeom::create();
beginEditCP(sphereGeom, PhysicsSphereGeom::BodyFieldMask | PhysicsSphereGeom::SpaceFieldMask | PhysicsSphereGeom::RadiusFieldMask | PhysicsSphereGeom::CategoryBitsFieldMask);
sphereGeom->setBody(sphereBody);
sphereGeom->setSpace(physicsSpace);
sphereGeom->setRadius(Radius);
sphereGeom->setCategoryBits(SphereCategory);
endEditCP(sphereGeom, PhysicsSphereGeom::BodyFieldMask | PhysicsSphereGeom::SpaceFieldMask | PhysicsSphereGeom::RadiusFieldMask | PhysicsSphereGeom::CategoryBitsFieldMask);
//add attachments
beginEditCP(sphereNode, Node::AttachmentsFieldMask);
sphereNode->addAttachment(sphereGeom);
endEditCP(sphereNode);
beginEditCP(sphereTransNode, Node::AttachmentsFieldMask | Node::ChildrenFieldMask);
sphereTransNode->addAttachment(sphereBody);
sphereTransNode->addChild(sphereNode);
endEditCP(sphereTransNode);
//add to SceneGraph
beginEditCP(spaceGroupNode, Node::ChildrenFieldMask);
spaceGroupNode->addChild(sphereTransNode);
endEditCP(spaceGroupNode);
}
示例8: createSymmetricEmitterLine
void Particles::createSymmetricEmitterLine(Vec3f dir, Real32 dist, UInt16 num)
{
NodePtr localTransNode;
TransformPtr localTrans;
Matrix m;
dir.normalize();
for (int i = 1; i < num; i++)
{
localTransNode = Node::create();
localTrans = Transform::create();
m.setIdentity();
m.setTranslate(dir*(i*dist));
beginEditCP(localTrans, Transform::MatrixFieldMask);
localTrans->setMatrix(m);
endEditCP(localTrans, Transform::MatrixFieldMask);
beginEditCP(localTransNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
localTransNode->setCore(localTrans);
localTransNode->addChild(cloneTree(particleNode));
endEditCP(localTransNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
beginEditCP(particleTransNode, Node::ChildrenFieldMask);
particleTransNode->addChild(localTransNode);
endEditCP(particleTransNode, Node::ChildrenFieldMask);
localTransNode = Node::create();
localTrans = Transform::create();
m.setIdentity();
m.setTranslate(dir*(-i*dist));
beginEditCP(localTrans, Transform::MatrixFieldMask);
localTrans->setMatrix(m);
endEditCP(localTrans, Transform::MatrixFieldMask);
beginEditCP(localTransNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
localTransNode->setCore(localTrans);
localTransNode->addChild(cloneTree(particleNode));
endEditCP(localTransNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
beginEditCP(particleTransNode, Node::ChildrenFieldMask);
particleTransNode->addChild(localTransNode);
endEditCP(particleTransNode, Node::ChildrenFieldMask);
} // for
} // createSymmetricEmitterLine
示例9: update
virtual void update(const UpdateEventPtr e)
{
Real32 RotateRate(1.0f);
Matrix RotMat;
RotMat.setRotate(Quaternion(Vec3f(0.0,1.0,0.0),RotateRate*e->getElapsedTime()));
Matrix NewMat(RootTransformCore->getMatrix());
NewMat.multLeft(RotMat);
beginEditCP(RootTransformCore, Transform::MatrixFieldMask);
RootTransformCore->setMatrix(NewMat);
endEditCP(RootTransformCore, Transform::MatrixFieldMask);
}
示例10: display
// redraw the window
void display( void )
{
Matrix m;
Real32 t = glutGet(GLUT_ELAPSED_TIME );
m.setTransform(Vec3f(0, .9, 0),
Quaternion( Vec3f(1,1,0), osgsin(t / 1000.f) / 2.f));
// set the transform's matrix
beginEditCP(trans, Transform::MatrixFieldMask);
{
trans->setMatrix(m);
}
endEditCP (trans, Transform::MatrixFieldMask);
mgr->redraw();
}
示例11: duplicate
void Particles::duplicate(Vec3f deltaPos, Quaternion deltaRot)
{
NodePtr copyTransNode = cloneTree(particleTransNode);
TransformPtr copyTrans = Transform::create();
Matrix m;
m.setIdentity();
m.setRotate(deltaRot);
m.setTranslate(deltaPos);
beginEditCP(copyTrans);
copyTrans->setMatrix(m);
endEditCP(copyTrans);
beginEditCP(copyTransNode);
copyTransNode->setCore(copyTrans);
endEditCP(copyTransNode);
beginEditCP(particleTransNode);
particleTransNode->addChild(copyTransNode);
endEditCP(particleTransNode);
} // duplicate
示例12: setLightSettings
void SkyBackgroundPluginForm::setLightSettings( LightPtr light, LightSettingsHandler &handler )
{
beginEditCP(light);
light->setAmbient(handler.ambient);
light->setDiffuse(handler.diffuse);
light->setSpecular(handler.specular);
endEditCP(light);
NodePtr beacon = light->getBeacon();
if (beacon == NullFC)
{
TransformPtr beaconTransform = Transform::create();
beacon = Node::create();
beginEditCP(beacon);
beacon->setCore(beaconTransform);
endEditCP(beacon);
}
TransformPtr transform = TransformPtr::dcast(beacon->getCore());
if (transform == NullFC)
{
TransformPtr beaconTransform = Transform::create();
beginEditCP(beacon);
beacon->setCore(beaconTransform);
endEditCP(beacon);
transform = beaconTransform;
}
Matrix m;
float transFactor = LightDistanceExSlider->value();
Vec3f translate = Vec3f(handler.direction.x() * transFactor, handler.direction.y() * transFactor,
handler.direction.z() * transFactor);
if (zUpCheckBox->isChecked())
m.setTranslate(translate.x(), translate.y(), translate.z());
else
m.setTranslate(translate.x(), translate.z(), -translate.y());
beginEditCP(transform);
transform->setMatrix(m);
endEditCP(transform);
}
示例13: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindowEventProducer = createDefaultWindowEventProducer();
WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();
TutorialWindowEventProducer->setDisplayCallback(display);
TutorialWindowEventProducer->setReshapeCallback(reshape);
//Add Window Listener
TutorialKeyListener TheKeyListener;
TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindowEventProducer->getWindow());
//Make a SphereNode for the point light
LambertMaterialPtr TheLightMat = LambertMaterial::create();
beginEditCP(TheLightMat, LambertMaterial::IncandescenceFieldMask);
TheLightMat->setIncandescence(Color3f(1.0,1.0,1.0));
endEditCP(TheLightMat, LambertMaterial::IncandescenceFieldMask);
GeometryPtr LightSphereGeo = makeSphereGeo(2,2.0);
beginEditCP(LightSphereGeo, Geometry::MaterialFieldMask);
LightSphereGeo->setMaterial(TheLightMat);
endEditCP (LightSphereGeo, Geometry::MaterialFieldMask);
NodePtr LightSphereNode = Node::create();
beginEditCP(LightSphereNode, Node::CoreFieldMask);
LightSphereNode->setCore(LightSphereGeo);
endEditCP (LightSphereNode, Node::CoreFieldMask);
//Create the beacon for the Point Light
Matrix ThePointLightMat;
ThePointLightMat.setTranslate(Vec3f(0.0,100.0,0.0));
ThePointLightBeaconTransform = Transform::create();
beginEditCP(ThePointLightBeaconTransform);
ThePointLightBeaconTransform->setMatrix(ThePointLightMat);
endEditCP(ThePointLightBeaconTransform);
NodePtr ThePointLightBeaconNode = Node::create();
beginEditCP(ThePointLightBeaconNode);
ThePointLightBeaconNode->setCore(ThePointLightBeaconTransform);
ThePointLightBeaconNode->addChild(LightSphereNode);
endEditCP(ThePointLightBeaconNode);
//Set the light properties desired
PointLightPtr ThePointLight = PointLight::create();
beginEditCP(ThePointLight);
ThePointLight->setAmbient(0.3,0.3,0.3,0.3);
ThePointLight->setDiffuse(1.0,1.0,1.0,1.0);
ThePointLight->setSpecular(1.0,1.0,1.0,1.0);
ThePointLight->setBeacon(ThePointLightBeaconNode);
endEditCP(ThePointLight);
NodePtr ThePointLightNode = Node::create();
beginEditCP(ThePointLightNode);
ThePointLightNode->setCore(ThePointLight);
endEditCP(ThePointLightNode);
//Set the light properties desired
SpotLightPtr TheSpotLight = SpotLight::create();
beginEditCP(TheSpotLight);
TheSpotLight->setAmbient(0.3,0.3,0.3,0.3);
TheSpotLight->setDiffuse(1.0,1.0,1.0,1.0);
TheSpotLight->setSpecular(1.0,1.0,1.0,1.0);
TheSpotLight->setBeacon(ThePointLightBeaconNode);
TheSpotLight->setDirection(Vec3f(0.0,-1.0,0.0));
TheSpotLight->setSpotExponent(5.0);
TheSpotLight->setSpotCutOff(1.1);
endEditCP(TheSpotLight);
NodePtr TheSpotLightNode = Node::create();
beginEditCP(TheSpotLightNode);
TheSpotLightNode->setCore(TheSpotLight);
endEditCP(TheSpotLightNode);
//Load in the Heightmap Image
ImagePtr PerlinNoiseImage = createPerlinImage(Vec2s(256,256), Vec2f(10.0f,10.0f),0.5f,1.0f,Vec2f(0.0f,0.0f),0.25f,6,PERLIN_INTERPOLATE_COSINE,false,Image::OSG_L_PF, Image::OSG_UINT8_IMAGEDATA);
TextureChunkPtr TheTextureChunk = TextureChunk::create();
beginEditCP(TheTextureChunk);
TheTextureChunk->setImage(PerlinNoiseImage);
endEditCP(TheTextureChunk);
//Lambert Material
LambertMaterialPtr TheLambertMat = LambertMaterial::create();
//.........这里部分代码省略.........
示例14: updateScene
void updateScene()
{
statfg->editCollector().getElem(majorAlignDesc)->set(alignmentToString(layoutParam.majorAlignment));
statfg->editCollector().getElem(minorAlignDesc)->set(alignmentToString(layoutParam.minorAlignment));
statfg->editCollector().getElem(dirDesc)->set(layoutParam.horizontal ? "Horizontal" : "Vertical");
statfg->editCollector().getElem(horiDirDesc)->set(layoutParam.leftToRight ? "Left to right" : "Right to left");
statfg->editCollector().getElem(vertDirDesc)->set(layoutParam.topToBottom ? "Top to bottom" : "Bottom to top");
if(face == NULL)
return;
// Put it all together into a Geometry NodeCore.
TextLayoutResult layoutResult;
Real32 scale = 2.f;
face->layout(lines, layoutParam, layoutResult);
#if 0
GeometryPtr geo = Geometry::create();
face->fillGeo(geo, layoutResult, scale);
NodePtr textNode = Node::create();
beginEditCP(textNode, Node::CoreFieldMask);
{
textNode->setCore(geo);
}
endEditCP(textNode, Node::CoreFieldMask);
#else
NodePtr textNode = face->makeNode(layoutResult, scale);
GeometryPtr geo = GeometryPtr::dcast(textNode->getCore());
#endif
NodePtr transNodePtr = Node::create();
TransformPtr transPtr = Transform::create();
Matrix transMatrix;
transMatrix.setTranslate(0.f, 0.f, -0.03f);
beginEditCP(transPtr);
{
transPtr->setMatrix(transMatrix);
}
endEditCP(transPtr);
beginEditCP(transNodePtr, Node::CoreFieldMask | Node::ChildrenFieldMask);
{
transNodePtr->setCore(transPtr);
transNodePtr->addChild(textNode);
}
endEditCP(transNodePtr, Node::CoreFieldMask | Node::ChildrenFieldMask);
ImagePtr imagePtr = face->getTexture();
TextureChunkPtr texChunk = TextureChunk::create();
beginEditCP(texChunk);
{
texChunk->setImage(imagePtr);
texChunk->setWrapS(GL_CLAMP);
texChunk->setWrapT(GL_CLAMP);
texChunk->setMagFilter(GL_NEAREST);
texChunk->setMinFilter(GL_NEAREST);
texChunk->setEnvMode(GL_MODULATE);
}
endEditCP(texChunk);
MaterialChunkPtr matChunk = MaterialChunk::create();
beginEditCP(matChunk);
{
matChunk->setAmbient(Color4f(1.f, 1.f, 1.f, 1.f));
matChunk->setDiffuse(Color4f(1.f, 1.f, 1.f, 1.f));
matChunk->setEmission(Color4f(0.f, 0.f, 0.f, 1.f));
matChunk->setSpecular(Color4f(0.f, 0.f, 0.f, 1.f));
matChunk->setShininess(0);
}
endEditCP(matChunk);
BlendChunkPtr blendChunk = BlendChunk::create();
beginEditCP(blendChunk);
{
blendChunk->setSrcFactor(GL_SRC_ALPHA);
blendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
}
endEditCP(blendChunk);
ChunkMaterialPtr m = ChunkMaterial::create();
beginEditCP(m);
{
m->addChunk(texChunk);
m->addChunk(matChunk);
m->addChunk(blendChunk);
}
endEditCP(m);
beginEditCP(geo, Geometry::MaterialFieldMask);
{
geo->setMaterial(m);
}
endEditCP(geo, Geometry::MaterialFieldMask);
beginEditCP(scene, Node::ChildrenFieldMask);
{
scene->editMFChildren()->clear();
scene->addChild(createCoordinateCross());
scene->addChild(createMetrics(face, scale, layoutParam, layoutResult));
scene->addChild(transNodePtr);
}
endEditCP(scene, Node::ChildrenFieldMask);
//.........这里部分代码省略.........
示例15: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindowEventProducer = createDefaultWindowEventProducer();
WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();
TutorialWindowEventProducer->setDisplayCallback(display);
TutorialWindowEventProducer->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
TutorialUpdateListener TheUpdateListener;
TutorialWindowEventProducer->addUpdateListener(&TheUpdateListener);
// Create the SceneManager
mgr = new SceneManager;
// Tell the Manager what to manage
mgr->setWindow(MainWindow);
// Make Torus Node (creates Torus in background of scene)
NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Torus Node (creates Torus in background of scene)
NodePtr BoxGeometryNode = makeBox(0.5,0.5,0.5,50,2,2);
//Set the Camera Beacon Node
Matrix Offset;
//Offset.setTranslate(0.0f,2.5f,6.0f);
Offset.setTranslate(0.0f,0.0,6.0f);
CameraBeaconTransform = Transform::create();
beginEditCP(CameraBeaconTransform, Transform::MatrixFieldMask);
CameraBeaconTransform->setMatrix(Offset);
endEditCP(CameraBeaconTransform, Transform::MatrixFieldMask);
NodePtr CameraBeaconNode = Node::create();
beginEditCP(CameraBeaconNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
CameraBeaconNode->setCore(CameraBeaconTransform);
endEditCP(CameraBeaconNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
//Set the Box Transform Node
BoxTransform = Transform::create();
NodePtr BoxNode = Node::create();
beginEditCP(BoxNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
BoxNode->setCore(BoxTransform);
BoxNode->addChild(BoxGeometryNode);
BoxNode->addChild(CameraBeaconNode);
endEditCP(BoxNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
// Make Main Scene Node and add the Torus
NodePtr scene = osg::Node::create();
beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
scene->setCore(osg::Group::create());
scene->addChild(TorusGeometryNode);
scene->addChild(BoxNode);
endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
//Set the Root node to the Scene Manager
mgr->setRoot(scene);
//The perspective decoratee camera
CameraPtr PCamera = PerspectiveCamera::create();
beginEditCP(PerspectiveCameraPtr::dcast(PCamera));
PerspectiveCameraPtr::dcast(PCamera)->setBeacon(CameraBeaconNode);
PerspectiveCameraPtr::dcast(PCamera)->setFov (deg2rad(60.f));
PerspectiveCameraPtr::dcast(PCamera)->setNear (0.1f);
PerspectiveCameraPtr::dcast(PCamera)->setFar (10000.f);
endEditCP(PerspectiveCameraPtr::dcast(PCamera));
//Create the Rubber band Camera
Vec3f PositionCoefficients(0.1,1.5,1.5);
Vec3f OrientationCoefficients(0.1,2.5,2.5);
RubberCamera = RubberBandCamera::create();
beginEditCP(RubberCamera, RubberBandCamera::DecorateeFieldMask | RubberBandCamera::BeaconFieldMask | RubberBandCamera::PositionCoefficientsFieldMask | RubberBandCamera::OrientationCoefficientsFieldMask);
RubberCamera->setDecoratee(PCamera);
RubberCamera->setBeacon(CameraBeaconNode);
RubberCamera->setPositionCoefficients(PositionCoefficients);
RubberCamera->setOrientationCoefficients(OrientationCoefficients);
endEditCP(RubberCamera, RubberBandCamera::DecorateeFieldMask | RubberBandCamera::BeaconFieldMask | RubberBandCamera::PositionCoefficientsFieldMask | RubberBandCamera::OrientationCoefficientsFieldMask);
RubberCamera->setToBeacon();
mgr->setCamera(RubberCamera);
// Show the whole Scene
//mgr->showAll();
//Open Window
Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
TutorialWindowEventProducer->openWindow(WinPos,
WinSize,
"01RubberBandCamera");
//Enter main Loop
//.........这里部分代码省略.........