我要发帖 回复

管理员

735

主题

2万

积分

30

专家分

忠于职守杰出贡献鼓励

兴趣点(最多三项):

建模技术

私信
发表时间 : 2006-8-31 22:26:58 | 浏览 : 2529    评论 : 4
在使用vega驱动openflight场景的操作中,我们需要的不只是进行所谓的“漫游”工作,还需要根据具体的应用对openflight的场景进行“深入”的操作,这里面也许可能差不多(^_^)需要改变vgpart或者是vgobject的颜色(操作的目标物体变色,使得其可识别),但是vega是基于opengl performer的高层应用,所以这一操作需要用到底层的东西,即使用opengl performer的api在vega中实现此功能,但是,一般的程序员可能对Opengl Performer不是很了解,因此,实现此功能有一定的难度,所以,笔者就此给出此功能实现的代码(非独创),和各位朋友一起共同进步。


#include "vg.h" // Required for the standard Vega classes
#include "vgperf.h" // Required for the vgGetXXXPfNode functions
#include "pf.h" // Required for the standard Performer classes
#include "vgutil.h"
#include "pfutil.h" // Required for pfFindNode

//

// Declare the Pre and Post Node Draw as STATIC these have to be static

//

//





static int highlightPreDrawTravFunc ( pfTraverser *trav, void *data );

static int highlightPostDrawTravFunc ( pfTraverser *trav, void *data );

static int remhighlightPostDrawTravFuncFIX( pfTraverser *trav, void *data);



pfHighlight* createHighlight( const float r ,const float g ,const float b ,const unsigned int fill );



void remHighlightFromVegaPart( vgPart *Part );

void setHighlightOnVegaPart ( vgPart *Part );









pfHighlight*

createHighlight( const float r

,const float g

,const float b

,const unsigned int fill ) {

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

// # Public function

// #

// # Create a and return a new pfHighlight instance

// #

// # Note it is upto the caller to manage the deletion

// # of this instance

// #

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





//

// create the new blank highlight instance

//

pfHighlight *hlight = pfNewHlight( vgGetSharedArena());





// Set the fill/ out line mode for the highlight

//

// The following are possible high style note thatsome may not supported

// on all platforms, also note that the style can be or'd together

// to form combinations of high lights

//

// See the Performer PGuide and man pages for further details

//

//

// PFHL_LINES PFHL_LINES_R

// PFHL_LINESPAT PFHL_LINESPAT2

// PFHL_LINESMASK PFHL_FILL

// PFHL_FILLPAT PFHL_FILLPAT2

// PFHL_FILLTEX PFHL_FILL_R

// PFHL_FILLMASK PFHL_SKIP_BASE

// PFHL_POINTS PFHL_NORMALS

// PFHL_BBOX_LINES PFHL_BBOX_FILL

//

//

pfHlightMode( hlight, fill ) ;



//

// Set the forground and background color for the highlight

//

pfHlightColor( hlight, PFHL_FGCOLOR, r, g, b );

pfHlightColor( hlight, PFHL_BGCOLOR, r, g, b );



//

// Set the alpha to opaque as transparent is not supported

// on many systems

//

pfHlightAlpha( hlight, 1.0f );





//

// Set the line width for line styles

//

pfHlightLineWidth( hlight, 1 .0f);



//

//

// When showing normals make them short

//

pfHlightNormalLength( hlight, 0.5f, 0.0f );





return hlight;



} // createHighlight







int

highlightPreDrawTravFunc( pfTraverser *trav, void *data){

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

// #

// # STATIC Function: (PFTRAV_DRAW)

// #

// # Pre Draw traversal function placed on a node which

// # enables and applies the highlight to the node and

// # all the nodes children

// #

// # note this function MUST be declared as STATIC

// #

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



//

// We need to first save the current Performer State

//

pfPushState();





//

// Now we can enable the highlighting

//

pfEnable( PFEN_HIGHLIGHTING );



//

// Now retrieve the highlight from the passed user data

//

pfHighlight *hlight = (pfHighlight *)data;



//

// If we have a highlight then make it current

//

if( hlight)

pfApplyHlight( hlight );



//

// We need to tell Performer to continue the traverse of this node

//

return (PFTRAV_CONT);



} // highlightPreDrawTravFunc







int

highlightPostDrawTravFunc( pfTraverser *trav, void *data){

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

// #

// # STATIC Function: (PFTRAV_DRAW)

// #

// # Post Draw traversal function on a node which disables

// # the highlight applied in the corresponding pre draw

// # fucntion

// #

// # note this function MUST be declared as STATIC

// #

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





//

// Now we disable the highlighting we enabled

//

pfDisable( PFEN_HIGHLIGHTING );



//

// And restore the Performer state

//

pfPopState();



//

// We need to tell Performer to continue the traverse of this node

//

return (PFTRAV_CONT);





} // highlightPostDrawTravFunc









int

remhighlightPostDrawTravFuncFIX( pfTraverser *trav, void *data){

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

// #

// # STATIC Function: (PFTRAV_DRAW)

// #

// # Post Draw traversal function on a node which disables

// # the highlight applied in the corresponding pre draw

// # fucntion

// #

// #

// # This should be added in the remove highligh function

// # because when pfNodeTravFuncs( node, PFTRAV_DRAW, NULL, NULL )

// # called the call backs are removed but an apparent bug in Vega

// # means that the Predraw gets applied but the post draw function

// # does not and the highlight stays on this fixes the problem by

// # explicitly disbaling the highlighitng

// #

// #

// # note this function MUST be declared as STATIC

// #

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





//

// Now we disable the highlighting we enabled

//

pfDisable( PFEN_HIGHLIGHTING );



//

// Retrieve which node we are

//

pfNode *node = pfGetTravNode( trav );



//

// We only need to call this one so we can self remove

//

pfNodeTravFuncs( node, PFTRAV_DRAW, NULL, NULL);



//

// We need to tell Performer to continue the traverse of this node

//

return (PFTRAV_CONT);



} // remhighlightPostDrawTravFuncFIX





void

setHighlightOnVegaPart( vgPart *Part ){

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

// #

// # Public Function

// #

// # Example of how to add Highlightinh to a Vega Part

// #

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





//

// Sanity check we need a Part

//

if( Part == NULL )

return;



//

// Get the root Performer node of the Part

//

pfNode *node = vgGetPartPfNode( Part );

if( node == NULL )

return;



//

// Create the Highlight instance, Red and Filled

//

pfHighlight *hlight = createHighlight( 1.0f, 0.0f, 0.0f, PFHL_FILL);

if( hlight == NULL )

return;





//

// Set the Pre and Post draw callback which enable and disable the highlight

//

pfNodeTravFuncs( node, PFTRAV_DRAW, highlightPreDrawTravFunc, highlightPostDrawTravFunc );



//

// Set the highlight instance as the user data for the callbacks

//

pfNodeTravData( node, PFTRAV_DRAW, hlight );





} //setHighlightOnVegaPart







void

remHighlightFromVegaPart( vgPart *Part ){

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

// #

// # Public Function

// #

// # Remove the highlight Callbacks from the passed Part

// #

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





//

// Sanity check we need a Part

//

if( Part == NULL )

return;





//

// Get the root Performer node of the Part

//

pfNode *node = vgGetPartPfNode( Part );

if( node == NULL )

return;



//

// Retrieve the highlight instance from the user data

//

pfHighlight *hlight = (pfHighlight *)pfGetNodeTravData( node, PFTRAV_DRAW );



//

// Remove the highlight call back functions by simply setting

// them to NULL on the Node, Performer only supports one call

// pre and post traversal callbacks per node

//

pfNodeTravFuncs( node, PFTRAV_DRAW, NULL, NULL);





//

//

// Theres an apperent bug in Vega where the Highlight will stay on

// becuase the removal of the draw function gets called with the

// highlight enabled but the post never gets called to remove the

// highlight, so the state is wrong this is a work around that will

// ensure that the highlight is removed

//

//

pfNodeTravFuncs( node, PFTRAV_DRAW, NULL, remhighlightPostDrawTravFuncFIX);



//

// And remove the data simply by

//

pfNodeTravData( node, PFTRAV_DRAW, NULL );





//

// If we got a highlight back from the user data

// then we delete it

//

if( hlight != NULL )

pfDelete( hlight);





} // remHighlightFromVegaPart

最近VR访客

ziye 评论于2008-3-13 09:03:15
谢谢了
独山子 评论于2008-3-13 11:00:33
受教了~
逆水行舟,不进则退。
jiafeihu 评论于2011-1-16 18:37:29
多谢啦~
jiafeihu 评论于2011-1-16 18:54:17
不过怎么编译有很多错呢?

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

GMT+8, 2021-3-3 12:10 AM

返回顶部