| |||||||||
|
|
| |||||||
|
| ||||||||
| |||||||||
#include <stdlib.h> // 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 checkPickEvent();
void checkPickEvent(){
static vgPosition *pos = NULL;
if( pos == NULL ){ pos = vgNewPos(); assert( pos ); }
// // Left mouse pressed then do a pick action // if( mouse.lb && !mouse.mb && !mouse.rb ) { vgGetPos( obs, pos ); vgPerformPickProcessing( picker, pos) ; }
// // will transform the picked object in the selected //
vgPickerDoMouseTransform( picker, pos); } } // checkPickEvent()
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 ); vgProp( picker, VGPICK_TRANSCOORDS, VGPICK_OBJECT_AXES ); vgProp( picker, VGPICK_HL_LEVEL, VGPICK_OBJECT ); vgProp( picker, VGPICK_HL_STYLE, VGPICK_HL_LINE ); 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 );
// // Set the Internal isector mask to ALL
//
vgPickerClampIsector( picker, 0x10000000 ); vgPickerIsector( picker, 0x10000000 );
// // We need to turn the vgPicker ON
//
vgProp( picker, VGCOMMON_ENABLED, VG_ON );
} // createPicker()
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 '1': vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XY ); break;
case '2': vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_XZ ); break;
case '3': vgProp( picker, VGPICK_TRACKPLANE, VGPICK_TRACK_YZ ); break;
default: break;
} // switch } // while
} // userUpdates()
int
main(int argc, char* argv[]) {
// // This simple example requires that ADF configuration // is passed on the command line // // // 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();
// // Quick and dirty, make ever object have its // isector mask set such that is can be picked //
for( int i= 0; i < vgGetNumObj(), i++ ){
vgObject *obj = vgGetObj(i); unsigned int mask = vgGetObjClass( obj ); mask |= vgGetPickerIsector( picker ); vgObjClass( obj, mask ); }
// // Keep drawing until the default exit // key is pressed (ESC) or the windo closed // while( true ) {
vgSyncFrame(); vgFrame();
checkPickEvent(); }
return 0; }
|
||
© Copyright 2004 Gordon Tomlinson All Rights Reserved. All logos, trademarks and copyrights in this site are property of their respective owner. |