Artoolkit的例子simpleVRML详解

本文详细解析了ARtoolkit examples文件夹中的simpleVRML示例,指出其与其它示例的主要区别在于使用了ar作为主框架而非通常的opengl。simpleVRML显示的3D模型是通过绘图软件如3Ds MAX创建并以wrl格式存储,而非OPENGL绘制。wrl是VRML(虚拟现实建模语言)的场景模型文件,一种用于创建真实或虚构世界场景的建模语言,广泛应用于互联网上的三维互动网站制作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        当你打开Artoolkit工具包的examples文件夹,你会发现simpleVRML这个例子与其他的例子是不一样的。最主要的区别在于使用的MainLoop()框架不同,这个例子是以ar为主框架,而其他的大部分例子则是以opengl为主框架。因为框架不同,所以该例子显示的模型不是用OPENGL绘制的,而是用绘图软件绘制的,比如3Ds  MAX、Sketchup、Solidworks……,以wrl格式文件存储。wrl文件是一种虚拟现实文本格式文件,也是VRML的场景模型文件的扩展名,可以用VRML浏览器打开,用VrmlPad软件修改、编辑。VRML(Virtual Reality Modeling Language)即虚拟现实建模语言。是一种用于建立真实世界的场景模型或人们虚构的三维世界的场景建模语言,也具有平台无关性。是目前Internet上基于 WWW的三维互动网站制作的主流语言。

        下面来看一下simpleVRML.c程序的整体架构,头文件和变量的声明我就不多说了。

#ifdef _WIN32
#include 
#endif
#include 
#include 
#include 

#ifdef __APPLE__
#include 
#else
//#define GLUT_DISABLE_ATEXIT_HACK
#include 
#endif

#include 
#include 
#include 	// arParamDisp()//显示参数
#include 
#include 
#include 

#include "object.h"

/*Constants常量*/
#define VIEW_SCALEFACTOR	0.025	//1.0 ARToolKit unit becomes 0.025 of my OpenGL units.范围因子,一个ARToolKit单位变成0.025个OpenGL单位。
#define VIEW_SCALEFACTOR_1	1.0		// 1.0 ARToolKit unit becomes 1.0 of my OpenGL units.
#define VIEW_SCALEFACTOR_4	4.0		// 1.0 ARToolKit unit becomes 4.0 of my OpenGL units.
#define VIEW_DISTANCE_MIN	4.0		// Objects closer to the camera than this will not be displayed.目标与摄像机距离小于这个不显示
#define VIEW_DISTANCE_MAX	4000.0	// Objects further away from the camera than this will not be displayed.目标与摄像机距离大于这个不显示

/*Global variables全局变量*/

//Preferences.
//OpenGL初始化参数设置Preferences.
static int prefWindowed = TRUE;
static int prefWidth = 640;	// Fullscreen mode width.//全屏模式的宽度
static int prefHeight = 480;// Fullscreen mode height.//全屏模式的高度
static int prefDepth = 32;// Fullscreen mode bit depth.//全屏模式的位深度
static int prefRefresh = 0;	// Fullscreen mode refresh rate. Set to 0 to use default rate.//全屏模式刷新率

//Image acquisition.//图像采集
static ARUint8	*gARTImage = NULL;//获取图像

//Marker detection.//标识检测
static int	 gARTThreshhold = 100; //标识检测时的二值化阈值
static long	 gCallCountMarkerDetect = 0;//初始化ARToolKit 帧频计数器为0

//Transformation matrix retrieval.//转换矩阵检索
static int	gPatt_found = FALSE;//At least one marker.//用gPatt_found判断是否找到标识

// Drawing.
static ARParam	gARTCparam;
static ARGL_CONTEXT_SETTINGS_REF gArglSettings = NULL;

//Object Data.
static ObjectData_T	*gObjectData;
static int	gObjectDataCount;
①setupCamera()函数。作用:打开相机,导入相机参数,更改相机长宽大小,初始化相机参数,捕获图像。
//打开相机,导入相机参数,更改相机长宽大小,初始化相机参数,捕获图像
static int setupCamera(const char *cparam_name, char *vconf, ARParam *cparam)
{	
    ARParam	  wparam;//储存相机参数
	int	  xsize, ysize;//储存图像大小的值

    // Open the video path.ddd//打开视频路径
    if (arVideoOpen(vconf) < 0) 
    {
    	fprintf(stderr, "setupCamera(): Unable to open connection to camera.\n");
    	return (FALSE);
	}
	
    // Find the size of the window.//得到当前视频图像的大小
    if (arVideoInqSize(&xsize, &ysize)<0) return (FALSE);
    fprintf(stdout,"Camera image size (x,y)= (%d,%d)\n", xsize, ysize);
	
	// Load the camera parameters, resize for the window and init.
	//导入相机参数,重新定义窗口大小
    if (arParamLoad(cparam_name, 1, &wparam) < 0) 
    {
		fprintf(stderr, "setupCamera(): Error loading parameter file %s for camera.\n", cparam_name);
        return (FALSE);
    }
    arParamChangeSize(&wparam, xsize, ysize, cparam);
    fprintf(stdout, "*** Camera Parameter ***\n");
    arParamDisp(cparam);//显示参数值
	
    arInitCparam(cparam);//初始化相机参数

	if (arVideoCapStart() != 0) 
	{
    	fprintf(stderr, "setupCamera(): Unable to begin camera data capture.\n");
		return (FALSE);		
	}
	
	return (TRUE);
}
②setupMarkersObjects()函数。作用:导入一个或多个标识的图像矩阵。
//导入一个或多个标识的图像矩阵
static int setupMarkersObjects(char *objectDataFilename)
{	
	// Load in the object 
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值