Vega中拾取物体
发表于:2007-05-26来源:作者:点击数:
标签:
其实就是vgPicker的用法了。。。 #include stdio.h #include vg.h #include pf.h #include assert.h vgPicker *picker = NULL ;vgObserver *obs = NULL ;vgChannel *chan = NULL ;vgEnv *env = NULL ;vgWindow *win = NULL ;vgGfx *gfx = NULL ;vgScene *scn
其实就是vgPicker的用法了。。。
#include <stdio.h>
#include "vg.h"
#include "pf.h"
#include "assert.h"
vgPicker *picker = NULL;
vgObserver *obs = NULL;
vgChannel *chan = NULL;
vgEnv *env = NULL;
vgWindow *win = NULL;
vgGfx *gfx = NULL;
vgScene *scn = NULL;
void setPointers();
void createPicker();
void checkPickEvent();
void
setPointers()
{
win = vgGetWin(0);
assert(win);
obs = vgGetObserv(0);
assert(obs);
chan = vgGetObservChan(obs, 0);
assert(chan);
gfx = vgGetObservGfx(obs);
assert(gfx);
env = vgGetEnv(0);
assert(env);
scn = vgGetScene(0);
assert(scn);
}
/*
* 创建vgPicker
*/
void
createPicker()
{
picker = vgNewPicker();
assert(picker);
vgName(picker, "picker");
/*
* 指定vgPicker作用的场景和通道
*/
vgPickerScene(picker, scn);
vgPickerChannel(picker, chan);
/*
* 设置vgPicker属性,选择物体红色显示
*/
vgPickerHighLightColor(picker, 1.0f, 0.0f, 0.0f);
vgProp(picker, VGPICK_TRANSFORM, VGPICK_TRANSLATE);
vgProp(picker, VGPICK_TRANSCOORDS, VGPICK_OBJECT_AXES);
vgProp(picker, VGPICK_HL_LEVEL, VGPICK_OBJECT);
vgProp(picker, VGPICK_HL_STYLE, VGPICK_HL_BBOX_LINES);
vgProp(picker, VGPICK_TERRAIN_CLAMP, VG_OFF);
vgProp(picker, VGPICK_TRANSOVERRIDE, VG_OFF);
vgProp(picker, VGPICK_DISPLAY_STDOUT, VG_OFF);
vgProp(picker, VGPICK_MULTIPLE_PICKS, VG_OFF);
vgProp(picker, VGPICK_AUTOTRANSFORM, VG_OFF);
vgProp(picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XY);
vgProp(picker, VGPICK_AUTOTRACKPLANE, VG_OFF);
vgProp(picker, VGPICK_DRAG_FACTOR, 1.0f);
vgProp(picker, VGPICK_RENDER_ISECT, VG_OFF);
/*
* 设置vgPicker的相交矢量
*/
vgPickerClampIsector(picker, 0x10000000);
vgPickerIsector(picker, 0x10000000);
/* 启用vgPicker */
vgProp(picker, VGCOMMON_ENABLED, VG_ON);
}
void
checkPickEvent()
{
static vgMouse mouse;
static vgPosition *pos = NULL;
if (pos == NULL)
{
pos = vgNewPos();
assert(pos);
}
vgGetMouse(&mouse);
/* 鼠标左键:拾取或取消拾取物体 */
if(mouse.lb && !mouse.mb && !mouse.rb)
{
vgGetPos(obs, pos);
vgPerformPickProcessing(picker, pos);
}
}
int
main(int argc, char** argv)
{
int i;
if (argc < 1)
{
printf("%s <config-file>\n", argv[0]);
exit(-1);
}
vgInitSys();
vgDefineSys(argv[1]);
vgConfigSys();
setPointers();
createPicker();
/*
* 设置物体mask掩码与vgPicker相一致,使得所有的物体都可以被选中
*/
for (i = 0; i < vgGetNumObj(); i++)
{
vgObject *obj = vgGetObj(i);
unsigned int mask = vgGetObjClass(obj);
mask |= vgGetPickerIsector(picker);
vgObjClass(obj, mask);
}
while (1)
{
vgSyncFrame();
vgFrame();
checkPickEvent();
}
return 0;
}
原文转自:http://www.ltesting.net
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-