OIV之照相机 COIN3D

照相机:

照相机节点可以对场景中所有位于它之后的节点拍摄一张照片。因为照相机必须位

于我们想要观察的物体之前,所以,通常要将照相机放在靠近场景最顶端的位置上。一个场

景在同一时刻只能有一个激活的照相机。当前几何坐标变换将会影响照相机的空间位置。

   所有照相机节点类都是从抽象基类 SoCamera 派生出来的。

viewAll()方法可以很容易地让照相机使用当前的方向来观察整个场景。

getViewVolume()方法返回照相机的取景裁剪体.

SoCamera类包括两个子类 

    SoPerspectiveCamera 可以模拟人眼的功能:远处的物体变小,近处的物体变

                        大。如果想模拟物体是怎样显示在人类的眼中,使用透视投影

                         照相机是最自然不过的事情了。

   SoOrthographicCamera 平行投影 (parallel projections)照相机。平行投影方式不会因

                     为距离的原因而使图像发生变形。

key code:

int main(int, char **argv) { // Initialize Inventor and Win HWND myWindow = SoWin::init(argv[0]); if (myWindow == NULL) exit(1); SoSeparator *root = new SoSeparator; root->ref(); // Create a blinker node and put it in the scene. A blinker // switches between its children at timed intervals.默认一秒 SoBlinker *myBlinker = new SoBlinker;//频闪节点 root->addChild(myBlinker); // Create three cameras. Their positions will be set later. // This is because the viewAll method depends on the size // of the render area, which has not been created yet. SoOrthographicCamera *orthoViewAll =new SoOrthographicCamera;//平行投影照相机 SoPerspectiveCamera *perspViewAll = new SoPerspectiveCamera; //透视投影照相机 SoPerspectiveCamera *perspOffCenter =new SoPerspectiveCamera;//透视投影照相机 myBlinker->addChild(orthoViewAll); myBlinker->addChild(perspViewAll); myBlinker->addChild(perspOffCenter); // Create a light root->addChild(new SoDirectionalLight); // Read the object from a file and add to the scene SoInput myInput; if (!myInput.openFile("../data/parkbench.iv")) exit(1); SoSeparator *fileContents = SoDB::readAll(&myInput); if (fileContents == NULL) exit (1); SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(0.8f, 0.23f, 0.03f); //设置颜色 root->addChild(myMaterial); root->addChild(fileContents); SoWinRenderArea *myRenderArea = new SoWinRenderArea(myWindow); // Establish camera positions. // First do a viewAll on all three cameras. // Then modify the position of the off-center camera. SbViewportRegion myRegion(myRenderArea->getSize()); orthoViewAll->viewAll(root, myRegion); perspViewAll->viewAll(root, myRegion); perspOffCenter->viewAll(root, myRegion); SbVec3f initialPos; initialPos = perspOffCenter->position.getValue(); float x, y, z; initialPos.getValue(x,y,z); perspOffCenter->position.setValue(x + x/2.0f, y + y/2.0f, z + z/4.0f); myRenderArea->setSceneGraph(root); myRenderArea->setTitle("Cameras"); myRenderArea->show(); SoWin::show(myWindow); SoWin::mainLoop(); return 0; }

 

 

 

 

 

 

 

你可能感兴趣的:(object,File,null,float,parallel,照片)