📄 mfc122view.cpp
字号:
// MFC122View.cpp : implementation of the CMFC122View class
//
#include "stdafx.h"
#include "MFC122.h"
#include "MFC122Doc.h"
#include "MFC122View.h"
#include "MainFrm.h"
#include "vpPositionable.h"
#include "vpSearchPath.h"
#include "vpKernel.h"
#include "vuMath.h"
#include <vuImage.h>
#include <vuImageFactory.h>
#include <GL/gl.h>
#include <time.h>
#include <vsgu.h>
#include <vp.h>
#include <vpApp.h>
#include <vuAllocTracer.h>
#include <vpIsectorLOS.h>
#include <vsDof.h>
#include <vsLod.h>
#include <vrLight.h>
#include <vrMode.h>
#include <vpInput.h>
#include <vpMotionUfo.h>
#include <vpInputMouse.h>
#include <vsTraversalUser.h>
#include <vsGeometry.h>
#include <vpObject.h>
#include <vrRenderStrategy.h>
#include <vpInputKeyboard.h>
//#include <vpOverlay2DText.h>
vpMulderPicker *myPicker;
#ifdef _MPI_STATIC_LIBS
// include loader headers for loader initialization
#include <vuImageFactory.h>
#include <vrTextureFactory.h>
#include <vsNodeFactory.h>
#include <vsNodeLoader.h>
#include <vsgi_sgi.h>
#include <vsgi_bmp.h>
#include <vsgi_jpg.h>
#include <vsgi_gif.h>
#include <vsgt_default.h>
#include <vsgn_flt.h>
#include <vsgn_vsb.h>
#include <vsgn_builder.h>
#include <vpCoordSysCpp.h>
#include <vpDBM.h>
#include <vpEnv.h>
#include <vpInput.h>
#include <vpMotion.h>
//#include <vpMuldersnap.h>
#include <vpModule.h>
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMFC122View
IMPLEMENT_DYNCREATE(CMFC122View, CView)
BEGIN_MESSAGE_MAP(CMFC122View, CView)
//{{AFX_MSG_MAP(CMFC122View)
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMFC122View construction/destruction
CMFC122View::CMFC122View()
{
// TODO: add construction code here
}
CMFC122View::~CMFC122View()
{
delete myPicker;//删除picker对象
}
BOOL CMFC122View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMFC122View drawing
void CMFC122View::OnDraw(CDC* pDC)
{
CMFC122Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMFC122View printing
BOOL CMFC122View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMFC122View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMFC122View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMFC122View diagnostics
#ifdef _DEBUG
void CMFC122View::AssertValid() const
{
CView::AssertValid();
}
void CMFC122View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMFC122Doc* CMFC122View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFC122Doc)));
return (CMFC122Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMFC122View message handlers
int CMFC122View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
//初始化
int result;
result = vp::initialize(__argc, __argv);
assert(result == vsgu::SUCCESS);
#ifdef _MPI_STATIC_LIBS
// 初始化模块
vpModule *module;
module = vpcoordsysInitialize();
if (module) module->initialize(__argc, __argv);
module = vpdbmInitialize();
if (module) module->initialize(__argc, __argv);
module = vpenvInitialize();
if (module) module->initialize(__argc, __argv);
module = vpinputInitialize();
if (module) module->initialize(__argc, __argv);
module = vpmotionInitialize();
if (module) module->initialize(__argc, __argv);
// 初始化所有的家载
vuImageFactory::registerLoader("bmp", vuFunctorR<vuImageLoader *>(
vuImageLoader_bmp::create, 0));
vuImageFactory::registerLoader("jpg", vuFunctorR<vuImageLoader *>(
vuImageLoader_jpg::create, 0));
vuImageFactory::registerLoader("gif", vuFunctorR<vuImageLoader *>(
vuImageLoader_gif::create, 0));
vuImageFactory::registerLoader("sgi", vuFunctorR<vuImageLoader *>(
vuImageLoader_sgi::create, 0));
vrTextureFactory::registerLoader("default", vuFunctorR<vrTextureLoader *>(
vrTextureLoader_default::create, 0));
vsNodeFactory::registerLoader("flt", vuFunctorR<vsNodeLoader *>(
vsNodeLoader_flt::create, 0));
vsNodeFactory::registerLoader("vsb", vuFunctorR<vsNodeLoader *>(
vsNodeLoader_vsb::create, 0));
#endif
CString acfFile;
//定义acf文件
result = vpKernel::instance()->define("mfc.acf");
assert(result == vsgu::SUCCESS);
result = vpKernel::instance()->configure();
assert(result == vsgu::SUCCESS);
assert(vpWindow::size() != 0);
//创建window窗口
vpWindow *vpWin = *vpWindow::begin();
vpWin->setParent(m_hWnd);
vpWin->setBorderEnable(false);
vpWin->setFullScreenEnable(true);
//循环?在那里循环?
int frameNum = vpKernel::instance()->beginFrame();
assert(frameNum != 0);
result = vpKernel::instance()->endFrame();
assert(result == vsgu::SUCCESS);
// setup timer that updates frame
// NOTE: Timer messages (WM_TIMER) are low priority messages. They
// are processed after all other messages have been processed.
// Updating frames this way makes the application more responsive
// at the expense of frame updates.
// Timeout of -1 means send a WM_TIMER message as soon as the last
// message was handled. This will allow the Vega Prime window to update
// as fast as it can.
const int TIMER_ID = 1;
int returnValue = SetTimer(TIMER_ID, 100, NULL);
assert(returnValue == TIMER_ID);
// vpWin->setKeyboardFunc(keyboardHandler, this);
// vpWin->setMouseFunc( mouseHandler, this);
//加入输入设备的句柄
vpWin->setUserVrWinMsgHandler(myVrWinMsgHandler);
// END: Vega Prime - Initialization
//配置acf文件
postConfigure();
return 0;
}
void CMFC122View::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
if(bActivate) {
vpWindow *vpWin = *vpWindow::begin();
// 设置焦点
HWND hVPWnd = vpWin->getWindow();
assert(::IsWindow( hVPWnd ) == TRUE);
::SetFocus(hVPWnd);
}
}
void CMFC122View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//设置时间
int frameNum = vpKernel::instance()->beginFrame();
assert(frameNum != 0);
int result = vpKernel::instance()->endFrame();
assert(result == vsgu::SUCCESS);
//加入字
HDC hdc=wglGetCurrentDC();
::SetBkMode( hdc, TRANSPARENT );
::SetTextColor( hdc, RGB(255,0,0) );
CString str;
str.Format("Email:vr2004@sina.com");
::TextOut(hdc,5,300,str,str.GetLength());
str.Format("主页:http://159.226.117.32/home/");
::TextOut(hdc,5,340,str,str.GetLength());
CView::OnTimer(nIDEvent);
}
void CMFC122View::OnSize(UINT nType, int cx, int cy)
{
//控制window的大小
CView::OnSize(nType, cx, cy);
vpWindow *vpWin = *vpWindow::begin();
vpWin->setSize(cx, cy);
}
//输入设备的消息句柄,只是鼠标的消息句柄和键盘消息的的状态?
bool CMFC122View::myVrWinMsgHandler(vrWindow *vrWin, vrWindow::Message id, int param1, int param2, int param3)
{
switch(id){
case vrWindow::MESSAGE_MOUSE_LEFT_DOWN:
//AfxMessageBox("MESSAGE_MOUSE_LEFT_DOWN");
break;
case vrWindow::MESSAGE_MOUSE_MIDDLE_DOWN:
printf( "MESSAGE_MOUSE_MIDDLE_DOWN" );
break;
case vrWindow::MESSAGE_MOUSE_RIGHT_DOWN:
printf( "MESSAGE_MOUSE_RIGHT_DOWN" );
break;
case vrWindow::MESSAGE_MOUSE_LEFT_UP:
//AfxMessageBox( "MESSAGE_MOUSE_LEFT_UP" );
//如果检测到交叉:打开通道
if(myPicker->performPickProcessing(*vpChannel::begin())){
//获得此时的交叉点
vuVec3<double> * point=myPicker->get3DPos();
double x,y,z;
//获得这个点的三个坐标值
point->get(&x,&y,&z);
printf("查询三维坐标为:%.3f,%.3f,%3f\n",(float)x,(float)y,(float)z);
//获得检测到的节点
vsNode *node=myPicker->getSelectNode();
const char *name="";
//如果节点不为空并且节点的名字不为空
if(node&&node->getName()!=NULL)
name=node->getName();
//对窗口上的面板进行更新
CMainFrame* pMainWnd;
//获得主窗口的句柄
pMainWnd=(CMainFrame*)AfxGetMainWnd();
//更新窗口中数据值
pMainWnd->updateLeftView ((float)x,(float)y,(float)z,name);
}else{
//如果节点名字为空,clear数据
CMainFrame* pMainWnd;
pMainWnd = (CMainFrame*)AfxGetMainWnd();
pMainWnd->updateLeftView (0,0,0,"");
}
break;
case vrWindow::MESSAGE_MOUSE_MIDDLE_UP:
printf( "MESSAGE_MOUSE_MIDDLE_UP" );
break;
case vrWindow::MESSAGE_MOUSE_RIGHT_UP:
printf( "MESSAGE_MOUSE_RIGHT_UP" );
break;
case vrWindow::MESSAGE_MOUSE_LEFT_DOUBLE_CLICK:
printf( "MESSAGE_MOUSE_LEFT_DOUBLE_CLICK" );
break;
case vrWindow::MESSAGE_MOUSE_MIDDLE_DOUBLE_CLICK:
printf( "MESSAGE_MOUSE_MIDDLE_DOUBLE_CLICK" );
break;
case vrWindow::MESSAGE_MOUSE_RIGHT_DOUBLE_CLICK:
printf( "MESSAGE_MOUSE_RIGHT_DOUBLE_CLICK" );
break;
case vrWindow::MESSAGE_MOUSE_MOVE:
//printf( "MESSAGE_MOUSE_MOVE" );
break;
case vrWindow::MESSAGE_MOUSE_WHEEL:
printf( "MESSAGE_MOUSE_WHEEL" );
break;
case vrWindow::MESSAGE_KEY_DOWN:
AfxMessageBox( "MESSAGE_KEY_DOWN" );
break;
case vrWindow::MESSAGE_KEY_UP:
AfxMessageBox("MESSAGE_KEY_UP");
break;
case vrWindow::MESSAGE_CREATE:
printf( "MESSAGE_CREATE" ); break;
case vrWindow::MESSAGE_PAINT: printf( "MESSAGE_PAINT" ); break;
case vrWindow::MESSAGE_SIZE:
//AfxMessageBox( "MESSAGE_SIZE" );
break;
case vrWindow::MESSAGE_MOVE: printf( "MESSAGE_MOVE" ); break;
case vrWindow::MESSAGE_CLOSE:
printf( "MESSAGE_CLOSE" );
break;
case vrWindow::MESSAGE_DESTROY:
printf( "MESSAGE_DESTROY" );
break;
case vrWindow::MESSAGE_SHOW:
printf( "MESSAGE_SHOW" );
break;
case vrWindow::MESSAGE_HIDE:
printf( "MESSAGE_HIDE" );
break;
case vrWindow::MESSAGE_FOCUS_IN:
//AfxMessageBox( "MESSAGE_FOCUS_IN" );
break;
case vrWindow::MESSAGE_FOCUS_OUT:
//AfxMessageBox( "MESSAGE_FOCUS_OUT" );
break;
case vrWindow::KEY_f:
AfxMessageBox( "MESSAGE_FOCUShhhhhhhhh_OUT" );
break;
default:
printf( "UNKNOWN MESSAGE" );
break;
}
//printf(" %d %d %d\n", param1, param2, param3 );
vrWin->defaultVrWinMsgHandler(vrWin,id,param1,param2,param3);
return true;
}
void CMFC122View::postConfigure()
{
createPicker();
}
//创建picker
void CMFC122View::createPicker()
{
//创建picker
myPicker=new vpMulderPicker();
//设置picker的名字
myPicker->setName ("myPicker");
//打开picker
myPicker->setEnable (true);
//设置picker的掩码
myPicker->setIsectMask(0xFFFFFFFF);
//设置picker对象的目标
myPicker->setTarget(*vpScene::begin());
//设置线宽
myPicker->setLineWidth(3);
//设置目标模式
//myPicker->setTargetMode(vpMulderPicker::MODE_GEOMETRY);
myPicker->setTargetMode(vpMulderPicker::MODE_NAMEDPART);
}
BOOL CMFC122View::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return true;
// return CView::OnEraseBkgnd(pDC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -