📄 zsvegaview.cpp
字号:
// zsVegaView.cpp : implementation of the zsVegaView class
//
#include "stdafx.h"
//#include "logo\logo.h"
#include "zsVegaView.h"
#include "vg.h"
#include "vgwin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CzsVegaView
IMPLEMENT_DYNCREATE(zsVegaView, CView)
BEGIN_MESSAGE_MAP(zsVegaView, CView)
//{{AFX_MSG_MAP(zsVegaView)
ON_WM_SIZE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// zsVegaView construction/destruction
zsVegaView::zsVegaView()
{
EnableAutomation();
vegaInitted = vegaDefined = vegaConfiged = FALSE;
vegaThread = NULL;
}
zsVegaView::~zsVegaView()
{
stopVega();
}
BOOL zsVegaView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_OVERLAPPED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// zsVegaView drawing
void zsVegaView::OnDraw(CDC* pDC)
{
// TODO: add draw code for native data here
}
const unsigned int kVegaWndID = 1301;
// Call this to create if using this View as just a Wnd
BOOL zsVegaView::create( const RECT& rect, CWnd* parent )
{
DWORD style = WS_OVERLAPPED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE ;
BOOL ret = CWnd::Create( NULL,
"Vega Window",
style,
rect, parent,
kVegaWndID );
return ret;
}
///////////////////////////////////////////////////////////////////////////////////
// The vega thread routines
///////////////////////////////////////////////////////////////////////////////////
// This routine is the thread that gets started to run Vega
UINT runVegaApp( LPVOID pParam )
{
// pParam is actually a pointer to a zsVegaView
zsVegaView* pOwner = (zsVegaView*)pParam;
vgInitWinSys( AfxGetInstanceHandle(), pOwner->GetSafeHwnd() );
pOwner->setVegaInitted( TRUE );
pOwner->postInit();
vgDefineSys( pOwner->getAdfName() );
pOwner->setVegaDefined( TRUE );
pOwner->postDefine();
vgConfigSys();
pOwner->setVegaConfiged( TRUE );
pOwner->postConfig();
vgAddFunc( vgGetChan(0), VGCHAN_POSTDRAW, 0, NULL );
while ( pOwner->getContinueRunning() ) {
vgSyncFrame ();
pOwner->postSync();
vgFrame ();
pOwner->postFrame();
}
// For software symmetry, it would be nice to call vgExit here, since vgInitSys
// is called above. However, it calls pfExit which calls exit(), so the MFC
// app never gets a chance to clean up. So, it is now up to the MFC app using
// this class to call vgExit. CWinApp::ExitInstance() is a good place for this.
// vgExit(0);
pOwner->setVegaInitted( FALSE );
return 0;
}
void zsVegaView::runVega( void )
{
continueRunning = TRUE;
// Kick off the thread that runs Vega. This thread will become the
// app thread.
vegaThread = AfxBeginThread( runVegaApp, this );
// THREAD_PRIORITY_HIGHEST );
// THREAD_PRIORITY_TIME_CRITICAL );
// SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_LOWEST );
// Wait for Vega thread to complete define
while ( ! getVegaDefined() ) {
Sleep(10);
}
// get some common objects defined in the adf
win = vgGetWin( 0 );
if( win == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find window -- check %s", getAdfName());
exit( -1 );
}
gfx = vgGetGfx( 0 );
if( gfx == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find gfx -- check %s", getAdfName());
exit( -1 );
}
chan = vgGetChan( 0 );
if( chan == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find chan -- check %s", getAdfName());
exit( -1 );
}
obs = vgGetObserv( 0 );
if( obs == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find obs -- check %s", getAdfName());
exit( -1 );
}
scene = vgGetScene( 0 );
if( scene == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find scene -- check %s", getAdfName());
exit( -1 );
}
// Override the border setting - we always want no border
vgProp( win, VGWIN_WINBORDER, 0 );
}
void zsVegaView::stopVega( void )
{
if ( ! vegaInitted ) return;
unPauseVega();
continueRunning = FALSE;
// Wait for Vega thread to finish
while ( vegaInitted )
Sleep( 10 );
}
void zsVegaView::pauseVega( void )
{
vgDrawEnabled(0);
}
void zsVegaView::unPauseVega( void )
{
vgDrawEnabled(1);
}
void zsVegaView::toggleGfx( int what )
{
long i = (long)vgGetProp( gfx, what );
if( i )
vgProp( gfx, what, VG_OFF );
else
vgProp( gfx, what, VG_ON );
}
/////////////////////////////////////////////////////////////////////////////
// Overrides
// virtual
const char* zsVegaView::getAdfName( void )
{
return "simple.adf";
}
// virtual
void zsVegaView::postInit( void )
{
}
//virtual
void zsVegaView::postDefine( void )
{
}
//virtual
void zsVegaView::postConfig( void )
{
}
//virtual
void zsVegaView::postSync( void )
{
}
// virtual
void zsVegaView::postFrame( void ) {
// ##########################################################
// # Function : #
// # To process any none latency critical processing #
// # such as keypressess and picking events #
// ##########################################################
static vgScene *scn = NULL;
static vgEnv *en1 = NULL ;
static float timeDay =0.95f;
static int stats = 0;
static int key, e,i=0,num=0;
while( (key = vgGetWinKey( vgGetWin(0) )) != 0 ) {
//if( cmdLineOpt.actionMode )
// processKeyBindings( key );
// ******************************************************
// * Check for and process any standard keyboard events *
// ******************************************************
switch( key ) {
case '<':
// *************************************************
// * Descrease the Time of day for all enviroments *
// *************************************************
timeDay -= 0.01f;
if( timeDay < 0.0f )
timeDay = 0.0f;
for ( e = 0; e < vgGetNumEnv(); e++ ){
en1 = vgGetEnv( e) ;
vgProp( en1, VGENV_TOD, timeDay );
}
break;
case '>':
// ************************************************
// * Increase the Time of day for all enviroments *
// ************************************************
timeDay += 0.01f;
if( timeDay > 0.98f )
timeDay = 0.98f;
for ( e = 0; e < vgGetNumEnv(); e++ ){
en1 = vgGetEnv( e) ;
vgProp( en1, VGENV_TOD, timeDay );
}
break;
case 's':
// *********************************************
// * Display and toggle throught the statitics *
// *********************************************
stats += 1;
if( stats > VGCHAN_FILL+1 )
stats = VGCHAN_STATSOFF;
vgProp( vgGetChan(0), VGCHAN_STATSSEL, stats );
break;
// ****************************************************
// * Toggle the default properties between on and off *
// ****************************************************
case 'f': toggleGfx( VGGFX_FOG ); break;
case 'l': toggleGfx( VGGFX_LIGHTING ); break;
case 't': toggleGfx( VGGFX_TEXTURE ); break;
case 'w': toggleGfx( VGGFX_WIREFRAME ); break;
default: break;
} // swithc( key )
} // while(key)
}
/////////////////////////////////////////////////////////////////////////////
// zsVegaView printing
BOOL zsVegaView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void zsVegaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void zsVegaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// zsVegaView diagnostics
#ifdef _DEBUG
void zsVegaView::AssertValid() const
{
CView::AssertValid();
}
void zsVegaView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// zsVegaView message handlers
void zsVegaView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if ( ! getVegaInitted() ) return;
vgWinSize( win, 0, cx, 0, cy );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -