⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vrvpview.h

📁 在MFC单文档格式下实现vp窗口显示,可以最大化
💻 H
字号:
// mfcView.h : interface of the CMFCView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_MFCVIEW_H__63AF631F_682C_442B_A9D1_DFCF09D8DB0D__INCLUDED_)
#define AFX_MFCVIEW_H__63AF631F_682C_442B_A9D1_DFCF09D8DB0D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "vp.h"
#include "vuMemBase.h"
#include "vpKernel.h"
#include "vpObserver.h"
#include "vpChannel.h"
#include "vpModule.h"

class CMFCView : public CView
{
protected: // create from serialization only
	CMFCView();
	DECLARE_DYNCREATE(CMFCView)

// Attributes
public:
	CMFCDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMFCView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CMFCView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
    /**
     * Configures the Vega Prime system and classes. This function calls 
     * vpKernel::configure() and installs input handlers to process various 
     * messages.
     *
     * @see vpKernel
     */
    virtual int configure(void) 
    {
        int ret = vpKernel::instance()->configure();

	    if (!vpWindow::empty()) {
            
            // If distributed rendering is active, set input window to the first 
            // window on the master that is input enabled.
            vpWindow *win = NULL;
            vpWindow::const_iterator it = vpWindow::begin();
            vpWindow::const_iterator ite = vpWindow::end();
            for(; it != ite; ++it) {
                if ((*it)->isWindowOnMaster() && (*it)->getInputEnable() ) {
                    win = *it;
                    break;
                }
            }

            // If the window remains NULL then distributed rendering is not 
            // active and we'll set input to the first window that is input 
            // enabled.
            if( win == NULL )
            {
                it = vpWindow::begin();
                for(; it != ite; ++it) {
                    if ( (*it)->getInputEnable() ) {
                        win = *it;
                        break;
                    }
                }

                // If window is still NULL, force selection of the first window.
                if( win == NULL )
                    win = *vpWindow::begin();
            }

            if (win) {
                win->setKeyboardFunc(keyboardHandler,this); 
                win->setMouseFunc( mouseHandler, this);

                // catch reshape and close events
                win->setReshapeFunc(reshapeHandler,this);
                win->setCloseFunc(closeHandler,this);
			}
		}

        // Capture the state vector for all observers.
        // The captured state vector will be used for resetting.
        vpObserver::const_iterator it  = vpObserver::begin();
        vpObserver::const_iterator ite = vpObserver::end();
        for(; it != ite; ++it) 
            (*it)->captureStateVector();
        
        return ret;
    }

	virtual void onKeyInput(vrWindow::Key key, int mod)
    {
        vpChannel *channel = *vpChannel::begin();
        vpObserver *observer = *vpObserver::begin();

        switch (key) {

        case vrWindow::KEY_ESCAPE: // quit the application
			AfxGetMainWnd()->PostMessage(WM_COMMAND,ID_APP_EXIT);
            break;

        case vrWindow::KEY_TILDE:
            {
            
                vpChannel::const_iterator it  = vpChannel::begin();
                vpChannel::const_iterator ite = vpChannel::end();
                for(; it != ite; ++it){
                    if(m_bStatisticsEnabled){
                        (*it)->setStatisticsPage(vpChannel::PAGE_OFF);
                    }else{
                        (*it)->setStatisticsPage(vpChannel::PAGE_FRAME_RATE);
                    }
                }
                if(m_bStatisticsEnabled){
                    m_bStatisticsEnabled = false;
                }else{
                    m_bStatisticsEnabled = true;
                }
            }
            break;

        case vrWindow::KEY_s:
            {
                vpChannel::const_iterator it  = vpChannel::begin();
                vpChannel::const_iterator ite = vpChannel::end();
                for(; it != ite; ++it) 
                    (*it)->cycleStatisticsPage(true);
            }
            break;

        case vrWindow::KEY_S:
            {
                vpChannel::const_iterator it  = vpChannel::begin();
                vpChannel::const_iterator ite = vpChannel::end();
                for(; it != ite; ++it) 
                    (*it)->cycleStatisticsPage(false);
            }
            break;

        case vrWindow::KEY_BACKSPACE: // reset observer state vector
            {
                vpObserver::const_iterator it  = vpObserver::begin();
                vpObserver::const_iterator ite = vpObserver::end();
                for(; it != ite; ++it) 
                    (*it)->resetStateVector();
                
            }
            break;

        case vrWindow::KEY_ENTER: // recapture observer state vector
            {
                vpObserver::const_iterator it  = vpObserver::begin();
                vpObserver::const_iterator ite = vpObserver::end();
                for(; it != ite; ++it) 
                    (*it)->captureStateVector();
            }
            break;

        case vrWindow::KEY_c: // put observer at the center of the scene
            {
                vpObserver::const_iterator it  = vpObserver::begin();
                vpObserver::const_iterator ite = vpObserver::end();
                for(; it != ite; ++it) 
                    centerObserver(*it);
                
            }
            break;

        case vrWindow::KEY_f: // enable / disable fog
            {
                vpChannel::const_iterator it  = vpChannel::begin();
                vpChannel::const_iterator ite = vpChannel::end();
                for(; it != ite; ++it) 
                    (*it)->toggleGraphicsModeEnable(
                        vpChannel::GRAPHICS_MODE_FOG);
            }
            break;

        case vrWindow::KEY_l: // enable / disable lighting
            {
                vpChannel::const_iterator it  = vpChannel::begin();
                vpChannel::const_iterator ite = vpChannel::end();
                for(; it != ite; ++it) 
                    (*it)->toggleGraphicsModeEnable(
                        vpChannel::GRAPHICS_MODE_LIGHT);
            }
            break;

        case vrWindow::KEY_p: // print observer absolute position
            {
                vpObserver::const_iterator it  = vpObserver::begin();
                vpObserver::const_iterator ite = vpObserver::end();
                vuVec3<double>xyz;
                vuVec3<double>hpr;
                int i;
                for(i=0; it != ite; ++it, ++i) {
                    (*it)->getAbsolutePosition(&xyz, &hpr);
                    printf("observer[%d]:\n", i);
                    printf("\t(x y z) = (%g %g %g)\n", xyz[0], xyz[1], xyz[2]);
                    printf("\t(h p r) = (%g %g %g)\n", hpr[0], hpr[1], hpr[2]);
                }
                
            }
            break;

        case vrWindow::KEY_t: // enable / disable texture
            {
                vpChannel::const_iterator it  = vpChannel::begin();
                vpChannel::const_iterator ite = vpChannel::end();
                for(; it != ite; ++it) 
                    (*it)->toggleGraphicsModeEnable(
                        vpChannel::GRAPHICS_MODE_TEXTURE);
            }
            break;

        case vrWindow::KEY_T: // enable / disable transparency
            {
                vpChannel::const_iterator it  = vpChannel::begin();
                vpChannel::const_iterator ite = vpChannel::end();
                for(; it != ite; ++it) 
                    (*it)->toggleGraphicsModeEnable(
                        vpChannel::GRAPHICS_MODE_TRANSPARENCY);
            }
            break;

        case vrWindow::KEY_w: // enable / disable wireframe
            {
                vpChannel::const_iterator it  = vpChannel::begin();
                vpChannel::const_iterator ite = vpChannel::end();
                for(; it != ite; ++it) 
                    (*it)->toggleGraphicsModeEnable(
                        vpChannel::GRAPHICS_MODE_WIREFRAME);
            }
            break;

        case vrWindow::KEY_x: // enable / disable the motion model
            {
                vpObserver::const_iterator it  = vpObserver::begin();
                vpObserver::const_iterator ite = vpObserver::end();
                bool enable = !(*it)->getStrategyEnable();
                for(; it != ite; ++it) 
                    (*it)->setStrategyEnable(enable);
                
            }
            break;

        }

    }

	virtual void onMouseInput(const vrWindow::Mouse& mouse, int mod) {}

    virtual void onReshape(int width, int height) {}

    virtual void onClose() {}
    
    static void keyboardHandler(vrWindow*,
                                vrWindow::Key k,
                                int mod, 
                                void* data)
    {
        static_cast<CMFCView*>(data)->onKeyInput(k,mod);
    }

    static void mouseHandler(vrWindow*,
                             const vrWindow::Mouse& mouse,
                             int mod, 
                             void* data)
    {
        static_cast<CMFCView*>(data)->onMouseInput(mouse,mod);
    }

    static void reshapeHandler(vrWindow*, 
                               int width,
                               int height,
                               void* data)
    {
        static_cast<CMFCView*>(data)->onReshape(width,height);
    }

    static void closeHandler(vrWindow*, 
                             void* data)
    {
        static_cast<CMFCView*>(data)->onClose();
    }


    /**
     * position all observers at the center of the scene.
     *
     * @see vpObserver
     */
    virtual void centerObserver(vpObserver *observer) {
        if (observer == NULL  ||
            observer->getScene() == NULL)
            return;

        const vuSphere<double>& bsphere = observer->getScene()->getBounds();
        double x = bsphere.m_ctr[0];
        double y = bsphere.m_ctr[1];
        double z = bsphere.m_ctr[2];
        observer->setPosition(x, y, z);
    }

// Generated message map functions
protected:
	//{{AFX_MSG(CMFCView)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	bool m_bStatisticsEnabled;
};

#ifndef _DEBUG  // debug version in MFCView.cpp
inline CMFCDoc* CMFCView::GetDocument()
   { return (CMFCDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MFCVIEW_H__63AF631F_682C_442B_A9D1_DFCF09D8DB0D__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -