当你打开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;
//打开相机,导入相机参数,更改相机长宽大小,初始化相机参数,捕获图像
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);
}
//导入一个或多个标识的图像矩阵
static int setupMarkersObjects(char *objectDataFilename)
{
// Load in the object