我要发帖 回复

正式会员

9

主题

34

积分

0

专家分

:

私信
发表时间 : 2009-1-29 18:20:32 | 浏览 : 1313    评论 : 2
用vgpicker实现拾取,
把VGPICK_HL_LEVEL 设为 VGPICK_OBJECT,拾取 OBJECT没问题;
把VGPICK_HL_LEVEL 设为 VGPICK_PART,能拾取PART,也能拾取OBJECT。
但我想只拾取object中的part (拾取物体中的DOF节点,比如说是面板上的一个按钮),鼠标点面板没反映,点按钮才有反映。(不分成两个Object)

我用Lynx中的Object Property Editor把面板上的按钮设置碰撞检测掩码(设置成和vgpicker一样),面板不设置碰撞检测掩码,但这样的话,根本拾取不了。

有哪位大虾知道,指点下。

最近VR访客

superhit 评论于2009-2-2 20:12:15

关于对象拾取与距离量测的基本方法与实现

关于对象拾取与距离量测的基本方法与实现
这个是一个使用鼠标拾取与量测常遇到的问题,我这里给出一个简易的代码实现,具体的参考说明文档扩充。水平有限,请批评指正!
Keyboard Controls :

'p' Pick and unpick vgObject under cursor
'<' Decrease the Time of day
'<' Increase the Time of day
's' Display and cycle statistics
'f' Toggle Fog on and off
't' Toggle texturing on and off
'w' Toggle wire frame mode on and off
When you have compiled and run, place the cursor over an object in the scene and press the 'p' key.
This will trigger the pick event the the objects geometry under the cursor will high lighted.
If you Press 'p' again on the same geometry and the geometry will become un-picked.



Note you must ensure that the vgObjects Isector mask is set and not set to 0x0

This example does require a simple ADF, such as simple.adf , esprit.adf etc.)


#include  // definition of exit

#include "vg.h" // main include file for Vega

#include "pf.h" // main include file for Performer

#include "assert.h" // definition of assert



#define UNTIL_THE_COWS_COME_HOME 1



vgPicker *picker = NULL;
vgObserver *mainObs = NULL;
vgChannel *mainChan = NULL;
vgEnv *mainEnv = NULL;
vgWindow *mainWin = NULL;
vgGfx *mainGfx = NULL;
vgScene *mainScn = NULL;


void setSystemPointers();
void createPicker();
void userUpdates();
void updateGFX( vgGfx *gfx, int what );
void doPick();

void setSystemPointers(){

// ####################################################
// # Local Function
// #
// # Set soem convinience pointers to the Vage sytems
// # components defined in the ADF this function must
// # be called after vgConfigSys() has been called
// #
// ####################################################

mainWin = vgGetWin( 0 );
assert(mainWin);

mainObs = vgGetObserv( 0 );
assert(mainObs );

mainChan = vgGetObservChan( mainObs, 0 );
assert(mainChan);

mainGfx = vgGetObservGfx( mainObs );
assert(mainEnv);

mainEnv = vgGetEnv( 0 );
assert(mainEnv);

mainScn = vgGetScene(0);
assert(mainScn);

} // setSystemPointers()





void

updateGFX( vgGfx *gfx, int what ){

// ############################################

// # Local Function

// #

// # Simply toggle the GFX passed property

// #

// ############################################

int state = 0;



//

// Sanity check

//

if( gfx == NULL )

return;




state = (int)vgGetProp( gfx, what );



if( state )

vgProp( gfx, what, VG_OFF );

else

vgProp( gfx, what, VG_ON );



} // updateGFX()







void

userUpdates( ) {

// ############################################

// # Local Function

// #

// # To process user keyboard input

// #

// ############################################

int key = 0;

static int stats = 0;

static float tod = 1.0;

static float first = 1;





//

// First time through we need to

// retrieve the current time of day

//

if (first) {

first = 0;

tod = vgGetProp( mainEnv, VGENV_TOD );

}





//

// Note that in windows the Queue is

// contains only one character

//

while( (key = vgGetWinKey( mainWin )) != 0 ) {



switch( key ) {



case '<':

tod -= 0.01f;

if( tod < 0.0 )

tod = 0.0;

vgProp( mainEnv, VGENV_TOD, tod );

break;



case '>':

tod  = 0.01f;

if( tod > 1.0 )

tod = 1.0;

vgProp( mainEnv, VGENV_TOD, tod );

break;





case 's':

stats  = 1;

if( stats > VGCHAN_FILL   1 )

stats = VGCHAN_STATSOFF;



vgProp( mainChan, VGCHAN_STATSSEL, stats );

break;



case 'f': updateGFX( mainGfx, VGGFX_FOG );

break;



case 't': updateGFX( mainGfx, VGGFX_TEXTURE );

break;



case 'w': updateGFX( mainGfx, VGGFX_WIREFRAME );

break;





case 'p' : doPick();

break;



default: break;



} // switch

} // while



} // userUpdates()



void

doPick(){

// ###################################################

// # Local Function

// #

// # Perform the a pick action if we are already

// # have a valid pick picking it will unpick it

// #

// ###################################################

static vgPosition *pos = NULL;

pfGeode *geode = NULL;

float range,x,y,z;





if( pos == NULL ){

pos = vgNewPos();

assert( pos );

}



//

// We need to get the observers position

//

vgGetPos( mainObs, pos );





//

// Do the interection test if we have a valid hit with

// the an item then process it otherwise do nothing

// This takes the Eye ( mainObs ) position and fires a

// LOS isector throught the Eye and mouse position

//

if( vgPerformPickProcessing( picker, pos) ){



//
// Retrieve a pointer to the pick item
// The following are used to get specific types
//
// (vgPlayer *) vgGetPickerPickedPlayer( picker );
// (vgPobject *) vgGetPickerPickedObject( picker );

// (vgPart *) vgGetPickerPickedPart ( picker );

// (pfGeode *) vgGetPickerPickedGeode ( picker );

// (pfGeoSet *) vgGetPickerPickedGeoSet( picker );

//

// set with vgProp( picker, VGPICK_HL_LEVEL, VGPICK_GEODE );

//

geode = (pfGeode*) vgGetPickerPickedGeode ( picker );


//

// Get the intersection positionand range to the pick point

//

vgGetPickerIntersection( picker, &range, &x,&y, &z);



}



} // doPick()



void

createPicker(){

// ########################################

// # Local Function

// #

// # Create an instance of vgPicker

// #

// ########################################



//

// Create the new Terrain picker

//

picker = vgNewPicker();

assert( picker );



vgName( picker, "example_picker" );





//

// we use the default scene 0 and channel 0

//

vgPickerScene( picker, mainScn );

vgPickerChannel( picker, mainChan );



//

// Set the Pick highlight to Red

//

vgPickerHighLightColor( picker, 1.0f, 0.0f, 0.0f );



//

// Set the default for the vgPicker instance

//

vgProp( picker, VGPICK_TRANSFORM, VGPICK_TRANSLATE );

vgProp( picker, VGPICK_TRANSCOORDS, VGPICK_OBJECT_AXES );

vgProp( picker, VGPICK_HL_LEVEL, VGPICK_GEODE );

vgProp( picker, VGPICK_HL_STYLE, VGPICK_HL_FILL );

vgProp( picker, VGPICK_CLAMP, VGPICK_CLAMP_Z );

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, 0.0f );

vgProp( picker, VGPICK_RENDER_ISECT, VG_OFF );



//

// Set the Internal isector mask to ALL

//

vgPickerClampIsector( picker, 0xffffffff );

vgPickerIsector( picker, 0xffffffff );



//

// We need to turn the vgPicker ON

//

vgProp( picker, VGCOMMON_ENABLED, VG_ON );



} // createPicker()







int

main(int argc, char* argv[]) {







//

// This simple example requires that ADF configuration

// is passed on the command line

//
if( argc < 2 ) {
printf ( "usage: %s \n", argv[0] );
exit ( -1 );
}



//

// Vega must be first initialise

//

vgInitSys();



//

// Next we defined the major Vega class instances by

// passing the name of an ADF file from the command line

//

vgDefineSys( argv[1] );



//

// Now create the class instance defined in the ADF

//

vgConfigSys();





//

// Grab some pointers to the classes created

//

setSystemPointers();



//

// Create and initialise our picker

//

createPicker();



//

// Keep drawing until the default exit

// key is pressed (ESC) or the windo closed

//

while( true ) {



vgSyncFrame();

vgFrame();

userUpdates();

}





return 0;

}
zsagile 评论于2009-2-3 20:38:27
没什么用,不过还是谢谢你

手机版|VR开发网 统计 津ICP备18009691号
网安备12019202000257

GMT+8, 2022-1-29 12:34 PM

返回顶部