Open Inventor练习-传感器(SoFieldSensor)功能

传感器是Open Inventor的重要功能,也是其重要特性,有了它三维功能可以做的活灵活现,此例子是演示的一个圆锥体动作传感器(SoFieldSensor)监视,实际是关联到视镜的摄像头上,只要其位置发生变化,传感器就会感知到,并输出新的位置信息到控制台窗口。代码如下。

#define COIN_DLL #define SOWIN_DLL // 加载COIN库文件 #ifdef _DEBUG #pragma comment(lib, "SoWin1d.lib") #pragma comment(lib, "Coin3d.lib") #else #pragma comment(lib, "SoWin1.lib") #pragma comment(lib, "Coin3.lib") #endif // 添加COIN头文件-Window操作显示库和节点库 #include <Inventor/Win/SoWin.h> #include <Inventor/Win/viewers/SoWinExaminerViewer.h> #include <Inventor/events/SoKeyboardEvent.h> #include <Inventor/nodes/SoCone.h> #include <Inventor/nodes/SoDirectionalLight.h> #include <Inventor/nodes/SoEventCallback.h> #include <Inventor/nodes/SoMaterial.h> #include <Inventor/nodes/SoPerspectiveCamera.h> #include <Inventor/nodes/SoTransform.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/nodes/SoSwitch.h> #include <Inventor/sensors/SoFieldSensor.h> void moveCB(void *data, SoSensor *sensor) { SoSFVec3f *pos = (SoSFVec3f *)((SoFieldSensor *)sensor)->getAttachedField(); printf("detected camera movement: %f %f %f\n", pos->getValue()[0], pos->getValue()[1], pos->getValue()[2]); } int main(int argc, char **argv) { HWND w = SoWin::init(argv[0]); SoWinExaminerViewer *viewer = new SoWinExaminerViewer(w); viewer->setSceneGraph(new SoCone); SoCamera *camera = viewer->getCamera(); SoFieldSensor *sensor = new SoFieldSensor(moveCB, NULL); sensor->attach(&camera->position); SoWin::show(w); viewer->show(); SoWin::mainLoop(); }
演示结果如下.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值