我要发帖 回复

管理员

327

主题

4158

积分

15

专家分

兴趣点(最多三项):

视景仿真
地形仿真
高层游戏引擎

私信
发表时间 : 2006-8-31 22:13:18 | 浏览 : 2315    评论 : 1
This example illustrates how to use a call-back function with a vgPicker:

Create an instance of call-back function for vgPicker

How to add call-back function to the vgPicker

How to use the vgCommon function vgGetProp

How to get a pointer to the picked item from the call-back

How to use vgPrint to show information about a vgClass



The vgPicker supports the following call-back events

VGPICK_PICKED

VGPICK_UNPICKED

VGPICK_PICKED_POSCHANGE

VGPICK_NEW_MOVE        

VGPICK_NEW_MULTIMOVE

  1.   







  2.       
  3.      
  4.    
  5.    

  6.   
  7.               

  8. #include <stdlib.h>       //  definition of print               

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

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


  11. //  
  12. //  
  13. //  add a call back on the pick event, Note we do not
  14. //  pass in any user data as the vgPicker passes the
  15. //  picked item through udata pointer
  16. //  
  17. //  
  18. vgAddFunc( vgFindPicker("my_picker"), VGPICK_PICKED, newPickEventCB, NULL );
  19.   


  20. void
  21. newPickEventCB( vgCommon* handle, void *udata ) {
  22. // #################################################################
  23. // #
  24. // # Static member function  
  25. // #
  26. // #    This Call-back function when the vpPicker picks a new item
  27. // #
  28. // #################################################################
  29. vgPicker  *picker     = NULL;
  30. vgCommon  *pickedItem = NULL;
  31.   
  32.     //
  33.     //  The *handle is always a pointer to the      
  34.     //  vgClass instance we placed on the call-back
  35.     //
  36.     picker = (vgPicker*)handle;

  37.     //
  38.     //
  39.     //  Normally on Vega Calls instance call backs the user supplies
  40.     //  udata which should be structure created from the shared arena
  41.     //  
  42.     //
  43.     //  However with the picked event the vgPicker uses the udata to
  44.     //  pass in a pointer to the item tha has been picked item which
  45.     //  has to be cast to its correct type
  46.     //
  47.     //  

  48.     int which = vgGetProp( picker, VGPICK_HL_LEVEL );

  49.     switch( which ){


  50.         case VGPICK_OBJECT   :   
  51.         case VGPICK_PART     :   
  52.         case VGPICK_PART_DCS :
  53.         case VGPICK_PLAYER   :

  54.                 pickedItem = dynamic_cast<vgCommon  *>(udata);

  55.                 //
  56.                 // Sanity check do we have a vega class pointer
  57.                 //
  58.                 if( pickedItem == NULL )
  59.                     return;

  60.                
  61.                 //  
  62.                 // Do something with the picked item
  63.                 //
  64.                 vgPrint( pickedItem );

  65.                 break;


  66.         case VGPICK_GEODE :
  67.                
  68.                 printf("pfGeode Picked  0x%p\n", udata );

  69.                 break;

  70.             
  71.         case VGPICK_GEOSET :
  72.                 printf("pfGeoSet Picked  0x%p\n", udata );

  73.                 break;
  74.             
  75.         default:

  76.                 printf("Unknown Picker Level\n");

  77.                 break;
  78.         }

  79.    
  80. } //  newPickEventCB

复制代码

最近VR访客

xiaoming630 评论于2007-11-4 15:31:05

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

GMT+8, 2021-3-7 01:29 PM

返回顶部