1#include
2#include "vg.h"
3#include "pf.h"
4#include "assert.h"
5
6
7vgPicker *picker = NULL;
8vgObserver *mainObs = NULL;
9vgChannel *mainChan = NULL;
10vgEnv *mainEnv = NULL;
11vgWindow *mainWin = NULL;
12vgGfx *mainGfx = NULL;
13vgScene *mainScn = NULL;
14
15
16void setSystemPointers();
17void createPicker();
18void userUpdates();
19void checkPickEvent();
20
21void setSystemPointers(){
22// ####################################################
23// # 获取系统的主要指针,注意必须在vgConfigSys()之后调用
24// #
25// ####################################################
26
27 mainWin = vgGetWin( 0 );
28 assert(mainWin);
29
30 mainObs = vgGetObserv( 0 );
31 assert(mainObs );
32
33 mainChan = vgGetObservChan( mainObs, 0 );
34 assert(mainChan);
35
36 mainGfx = vgGetObservGfx( mainObs );
37 assert(mainEnv);
38
39 mainEnv = vgGetEnv( 0 );
40 assert(mainEnv);
41
42 mainScn = vgGetScene(0);
43 assert(mainScn);
44
45}
46
47
48void createPicker(){
49// ########################################
50// # 创建一个vgPicker
51// #
52// ########################################
53
54 picker = vgNewPicker();
55 assert( picker );
56 vgName( picker, "example_picker" );
57
58 //
59 // 指定vgPicker起作用的场景和通道
60 //
61 vgPickerScene( picker, mainScn );
62 vgPickerChannel( picker, mainChan );
63
64 //
65 // 设置vgPicker属性,选择物体红色显示
66 //
67 vgPickerHighLightColor( picker, 1.0f, 0.0f, 0.0f );
68 vgProp( picker, VGPICK_TRANSFORM, VGPICK_TRANSLATE );
69 vgProp( picker, VGPICK_TRANSCOORDS, VGPICK_OBJECT_AXES );
70 vgProp( picker, VGPICK_HL_LEVEL, VGPICK_OBJECT );
71 vgProp( picker, VGPICK_HL_STYLE, VGPICK_HL_LINE );
72 vgProp( picker, VGPICK_TERRAIN_CLAMP, VG_OFF );
73 vgProp( picker, VGPICK_TRANSOVERRIDE, VG_OFF );
74 vgProp( picker, VGPICK_DISPLAY_STDOUT, VG_OFF );
75 vgProp( picker, VGPICK_MULTIPLE_PICKS, VG_OFF );
76 vgProp( picker, VGPICK_AUTOTRANSFORM, VG_OFF );
77 vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XY );
78 vgProp( picker, VGPICK_AUTOTRACKPLANE, VG_OFF );
79 vgProp( picker, VGPICK_DRAG_FACTOR, 1.0f );
80 vgProp( picker, VGPICK_RENDER_ISECT, VG_OFF );
81
82 //
83 // 设置vgPicker的相交矢量
84 //
85 vgPickerClampIsector( picker, 0x10000000 );
86 vgPickerIsector( picker, 0x10000000 );
87
88 // 启用vgPicker
89 vgProp( picker, VGCOMMON_ENABLED, VG_ON );
90
91}
92
93void checkPickEvent(){
94// ###################################################
95// # 判断vgPicker当前的动作
96// #
97// #
98// ###################################################
99static vgMouse mouse;
100static vgPosition *pos = NULL;
101 if( pos == NULL ){
102 pos = vgNewPos();
103 assert( pos );
104 }
105 vgGetMouse( &mouse );
106
107 // 鼠标左键:拾取或取消拾取物体
108 if( mouse.lb && !mouse.mb && !mouse.rb ) {
109 vgGetPos( obs, pos );
110 vgPerformPickProcessing( picker, pos) ;
111 }
112
113 // 拖拽鼠标右键:在指定的平面上移动选定的物体
114 if( !mouse.lb && !mouse.mb && mouse.rb ) {
115 vgGetPos( obs, pos );
116 vgPickerDoMouseTransform( picker, pos);
117 }
118
119}
120
121void userUpdates( ) {
122// ############################################
123// # 响应用户的键盘输入:
124// # 1——在XY平面上移动物体(默认情况)
125// # 2——在XZ平面上移动物体
126// # 3——在YZ平面上移动物体
127// ############################################
128int key = 0;
129
130 while( (key = vgGetWinKey( mainWin )) != 0 ) {
131
132 switch( key ) {
133
134 case '1':
135 vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XY );
136 break;
137
138 case '2':
139 vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XZ );
140 break;
141
142 case '3':
143 vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_YZ );
144 break;
145
146
147 default: break;
148
149 }
150 }
151
152}
153
154int main(int argc, char* argv[]) {
155
156
157
158 if( argc \n", argv[0] );
159 exit ( -1 );
160 }
161
162 vgInitSys();
163 vgDefineSys( argv[1] );
164 vgConfigSys();
165
166 setSystemPointers();
167 createPicker();
168
169 //
170 //设置物体mask掩码与vgPicker相一致,使得所有的物体都可以被选中
171 //
172 for( int i= 0; i < vgGetNumObj(), i++ ){
173
174 vgObject *obj = vgGetObj(i);
175 unsigned int mask = vgGetObjClass( obj );
176 mask |= vgGetPickerIsector( picker );
177 vgObjClass( obj, mask );
178 }
179
180 while( true ) {
181
182 vgSyncFrame();
183 vgFrame();
184 userUpdates();
185 checkPickEvent();
186 }
187
188
189return 0;
190}
2#include "vg.h"
3#include "pf.h"
4#include "assert.h"
5
6
7vgPicker *picker = NULL;
8vgObserver *mainObs = NULL;
9vgChannel *mainChan = NULL;
10vgEnv *mainEnv = NULL;
11vgWindow *mainWin = NULL;
12vgGfx *mainGfx = NULL;
13vgScene *mainScn = NULL;
14
15
16void setSystemPointers();
17void createPicker();
18void userUpdates();
19void checkPickEvent();
20
21void setSystemPointers(){
22// ####################################################
23// # 获取系统的主要指针,注意必须在vgConfigSys()之后调用
24// #
25// ####################################################
26
27 mainWin = vgGetWin( 0 );
28 assert(mainWin);
29
30 mainObs = vgGetObserv( 0 );
31 assert(mainObs );
32
33 mainChan = vgGetObservChan( mainObs, 0 );
34 assert(mainChan);
35
36 mainGfx = vgGetObservGfx( mainObs );
37 assert(mainEnv);
38
39 mainEnv = vgGetEnv( 0 );
40 assert(mainEnv);
41
42 mainScn = vgGetScene(0);
43 assert(mainScn);
44
45}
46
47
48void createPicker(){
49// ########################################
50// # 创建一个vgPicker
51// #
52// ########################################
53
54 picker = vgNewPicker();
55 assert( picker );
56 vgName( picker, "example_picker" );
57
58 //
59 // 指定vgPicker起作用的场景和通道
60 //
61 vgPickerScene( picker, mainScn );
62 vgPickerChannel( picker, mainChan );
63
64 //
65 // 设置vgPicker属性,选择物体红色显示
66 //
67 vgPickerHighLightColor( picker, 1.0f, 0.0f, 0.0f );
68 vgProp( picker, VGPICK_TRANSFORM, VGPICK_TRANSLATE );
69 vgProp( picker, VGPICK_TRANSCOORDS, VGPICK_OBJECT_AXES );
70 vgProp( picker, VGPICK_HL_LEVEL, VGPICK_OBJECT );
71 vgProp( picker, VGPICK_HL_STYLE, VGPICK_HL_LINE );
72 vgProp( picker, VGPICK_TERRAIN_CLAMP, VG_OFF );
73 vgProp( picker, VGPICK_TRANSOVERRIDE, VG_OFF );
74 vgProp( picker, VGPICK_DISPLAY_STDOUT, VG_OFF );
75 vgProp( picker, VGPICK_MULTIPLE_PICKS, VG_OFF );
76 vgProp( picker, VGPICK_AUTOTRANSFORM, VG_OFF );
77 vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XY );
78 vgProp( picker, VGPICK_AUTOTRACKPLANE, VG_OFF );
79 vgProp( picker, VGPICK_DRAG_FACTOR, 1.0f );
80 vgProp( picker, VGPICK_RENDER_ISECT, VG_OFF );
81
82 //
83 // 设置vgPicker的相交矢量
84 //
85 vgPickerClampIsector( picker, 0x10000000 );
86 vgPickerIsector( picker, 0x10000000 );
87
88 // 启用vgPicker
89 vgProp( picker, VGCOMMON_ENABLED, VG_ON );
90
91}
92
93void checkPickEvent(){
94// ###################################################
95// # 判断vgPicker当前的动作
96// #
97// #
98// ###################################################
99static vgMouse mouse;
100static vgPosition *pos = NULL;
101 if( pos == NULL ){
102 pos = vgNewPos();
103 assert( pos );
104 }
105 vgGetMouse( &mouse );
106
107 // 鼠标左键:拾取或取消拾取物体
108 if( mouse.lb && !mouse.mb && !mouse.rb ) {
109 vgGetPos( obs, pos );
110 vgPerformPickProcessing( picker, pos) ;
111 }
112
113 // 拖拽鼠标右键:在指定的平面上移动选定的物体
114 if( !mouse.lb && !mouse.mb && mouse.rb ) {
115 vgGetPos( obs, pos );
116 vgPickerDoMouseTransform( picker, pos);
117 }
118
119}
120
121void userUpdates( ) {
122// ############################################
123// # 响应用户的键盘输入:
124// # 1——在XY平面上移动物体(默认情况)
125// # 2——在XZ平面上移动物体
126// # 3——在YZ平面上移动物体
127// ############################################
128int key = 0;
129
130 while( (key = vgGetWinKey( mainWin )) != 0 ) {
131
132 switch( key ) {
133
134 case '1':
135 vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XY );
136 break;
137
138 case '2':
139 vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XZ );
140 break;
141
142 case '3':
143 vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_YZ );
144 break;
145
146
147 default: break;
148
149 }
150 }
151
152}
153
154int main(int argc, char* argv[]) {
155
156
157
158 if( argc \n", argv[0] );
159 exit ( -1 );
160 }
161
162 vgInitSys();
163 vgDefineSys( argv[1] );
164 vgConfigSys();
165
166 setSystemPointers();
167 createPicker();
168
169 //
170 //设置物体mask掩码与vgPicker相一致,使得所有的物体都可以被选中
171 //
172 for( int i= 0; i < vgGetNumObj(), i++ ){
173
174 vgObject *obj = vgGetObj(i);
175 unsigned int mask = vgGetObjClass( obj );
176 mask |= vgGetPickerIsector( picker );
177 vgObjClass( obj, mask );
178 }
179
180 while( true ) {
181
182 vgSyncFrame();
183 vgFrame();
184 userUpdates();
185 checkPickEvent();
186 }
187
188
189return 0;
190}