Open Inventor练习-传感器(SoFieldSensor)功能
2011-10-10 17:11
183 查看
传感器是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(); }
演示结果如下.
相关文章推荐
- Open Inventor练习-SoSelection节点下三维物体选择功能
- Android利用Sensor(传感器)实现水平仪功能
- Android利用Sensor(传感器)实现指南针小功能
- 我的Android进阶之旅------>Android利用Sensor(传感器)实现指南针功能
- Open Inventor练习-SoSelection三维场景中查找功能
- 【安卓小细节汇总】sensor传感器实现摇一摇功能
- 我的Android进阶之旅------>Android利用Sensor(传感器)实现水平仪功能的小例
- Java基础知识强化之IO流笔记55:IO流练习之 自定义类模拟LineNumberReader的获取行号功能案例
- Android 传感器(Sensor)API教程 (七) 倾斜加速度
- [Android Pro] Android--Sensor传感器
- [Android实例] Sensor传感器源码的阅读与应用开发简单实例
- Android--Sensor传感器
- 练习4实现strchr的功能,即在一个字符串中查找一个字符
- Android传感器Sensor工作流程
- smartphone sensor(智能手机传感器)
- Android - 小功能 - 传感器之重力传感器
- 案例52-crm练习新增客户中加入文件上传功能(struts2文件上传)
- python练习模仿购物车功能
- Sensor(传感器)讲解与实例
- Android之传感器系统(Gsensor) .