📄 新建 文本文档 (2).txt
字号:
This example illustrates how to :
Shows a basic Vega application
How to use vgGetProp
How to use vgProp
How to get keyboard input with vgGetWinKey
How load an ADf file with vgDefineSys
How to get a pointers to vgClasses
How to change the time of day
How to display statistics
How to toggle texture on and off
How to toggle Fog on and off
How to toggle Wireframe mode on and off
Keyboard Controls :
'<' 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
This example does require a simple ADF, such as simple.adf , esprit.adf etc.)
#include <stdlib.h> // definition of exit
#include "vg.h" // main include file for Vega
#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 userUpdates();
void updateGFX( vgGfx *gfx, int what );
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;
default: break;
} // switch
} // while
} // userUpdates()
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 <ADF config file>\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();
//
// Keep drawing until the default exit
// key is pressed (ESC) or the windo closed
//
while( true ) {
vgSyncFrame();
vgFrame();
userUpdates();
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -