一个Open Inventor程序

/*----------------------------------------------------------------------------------------------------------

FUNCTION:
SoSeparator *makeProfileLineSet();定义剖面的场景示意图
Main(int, char **argv);主函数按照场景示意图绘制场景

PURPOSE: 利用面集节点(SoLineSet)绘制两个四边形的剖面。

HISTORY: Date:26/11/2007 Author:Shao Yanhong Comment:

---------------------------------------------------------------------------------------------------------*/
#include "assert.h"

#include <Inventor/Win/SoWin.h>
#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
#include <Inventor/nodes/SoCoordinate3.h>
#include <Inventor/nodes/SoLineSet.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoVertexProperty.h>

static const float lineVertices[16][3] = { // 定义两个剖面
{ 1.0f, 2.0f, 1.0f}, { 2.0f, 2.0f, 1.0f}, //顶面四条边
{ 2.0f, 2.0f, 1.0f}, { 2.0f, 2.0f, 2.0f},
{ 2.0f, 2.0f, 2.0f}, { 1.0f, 2.0f, 2.0f},
{ 1.0f, 2.0f, 2.0f}, { 1.0f, 2.0f, 1.0f},

{ 1.0f, 1.0f, 1.0f}, { 2.0f, 1.0f, 1.0f}, //底面四条边
{ 2.0f, 1.0f, 1.0f}, { 2.0f, 1.0f, 2.0f},
{ 2.0f, 1.0f, 2.0f}, { 1.0f, 1.0f, 2.0f},
{ 1.0f, 1.0f, 2.0f}, { 1.0f, 1.0f, 1.0f},
};

// 每个边中顶点的个数
static int numvertices[8] = {2, 2, 2, 2, 2, 2, 2, 2};

SoSeparator *makeProfileLineSet()
{
SoSeparator *profile = new SoSeparator();
profile->ref();


// 定义剖面线框的材质
SoMaterial *myMaterial = new SoMaterial;
myMaterial->diffuseColor.setValue(1.0f, 0.0f, 0.0f);
myMaterial->ambientColor.setValue(1.0f, 0.8f, 0.8f);
profile->addChild(myMaterial);

// 定义定点的坐标
SoCoordinate3 *myCoords = new SoCoordinate3;
myCoords->point.setValues(0, 16, lineVertices);
profile->addChild(myCoords);

// 定义SoLineSet线集
SoLineSet *myLineSet = new SoLineSet;
myLineSet->numVertices.setValues(0, 8, numvertices);
profile->addChild(myLineSet);

profile->unrefNoDelete();
return profile;
}

int main(int, char **argv)
{
HWND myWindow = SoWin::init(argv[0]);
if (myWindow == NULL) exit(1);

SoSeparator *root = new SoSeparator;
root->ref();

root->addChild(makeProfileLineSet());

SoWinExaminerViewer *myViewer = new SoWinExaminerViewer(myWindow);
myViewer->setSceneGraph(root);
myViewer->setBackgroundColor(SbColor(0.9f, 0.9f, 0.95f));
myViewer->setTitle("Two Profiles");
myViewer->show();
myViewer->viewAll();

SoWin::show(myWindow);
SoWin::mainLoop();

return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值