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

📄 hoopstestview.cpp

📁 使用HOOPS库开发的一个教学演示工具。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	//we need to adjust the axis window outside the mvo class as the calculation of the window	//extents is mfc specific 	AdjustAxisWindow();	// send this model accross the hnet sever for collabrative clients	m_pHView->EmitSegment(hmodel->GetModelKey(), true);	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////显示欢迎信息	HC_Open_Segment_By_Key(m_pHView->GetModelKey());		HC_Flush_Contents(".","everything"); 		HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\lab.hsf"),m_pHView->GetModel()->GetStreamFileTK());	HC_Close_Segment();	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////显示欢迎信息	MyInit();	SetTimer(0,1,NULL);	//先启动仿真屏幕更新线程,可以看到初始状态。}void ChoopstestView::OnPrint(CDC* pDC, CPrintInfo* pInfo) {	// The default color of lines and edges is white, need to re-set them to	// a different color so that they will be visibile when printed.  Since	// the color is set in the parent segment, the new color setting will only	// affect geometry which has not got a color set explicitly.	HC_Open_Segment_By_Key(GetSceneKey());	  HC_Set_Color_By_Index("edges, lines, text", 4);	HC_Close_Segment();		CHoopsView::OnPrint(pDC, pInfo);	// reset edge/line colors back to their orignial state   	HC_Open_Segment_By_Key(GetSceneKey());	  HC_Set_Color_By_Index("edges, lines, text", 1);	HC_Close_Segment();	m_pHView->Update();	}void ChoopstestView::OnToolsRendermodeGouraudshaded() { 	m_pHView->SetRenderMode(HRenderGouraud, true);	m_pHView->Update();}void ChoopstestView::OnUpdateToolsRendermodeGouraudshaded(CCmdUI* pCmdUI) {	if (m_pHView->GetRenderMode() == HRenderGouraud)		pCmdUI->SetCheck (1);    else        pCmdUI->SetCheck (0);}void ChoopstestView::OnToolsRendermodeHiddenline() { 	m_pHView->SetRenderMode(HRenderHiddenLine, true);	m_pHView->Update();}void ChoopstestView::OnUpdateToolsRendermodeHiddenline(CCmdUI* pCmdUI) {	if (m_pHView->GetRenderMode() == HRenderHiddenLine || m_pHView->GetRenderMode() == HRenderHiddenLineHOOPS)		pCmdUI->SetCheck (1);    else        pCmdUI->SetCheck (0);}void ChoopstestView::OnToolsRendermodeWireframe() { 	m_pHView->SetRenderMode(HRenderWireframe, true);	m_pHView->Update();}void ChoopstestView::OnUpdateToolsRendermodeWireframe(CCmdUI* pCmdUI) {	if (m_pHView->GetRenderMode() == HRenderWireframe)		pCmdUI->SetCheck (1);    else        pCmdUI->SetCheck (0);}void ChoopstestView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) {	if (!bActivate)	{ 		HOpCameraOrbit *op = (HOpCameraOrbit *)m_pHView->GetOperator();		if (strcmp(op->GetName(),"HOpCameraOrbit")==0)			op->m_Angle1 = op->m_Angle2 = op->m_Angle3 = 0;					if( GetFirstUpdate() == true) 			m_pHView->Update();	}	ChoopstestView *act = (ChoopstestView *)pActivateView;	ChoopstestView *deact = (ChoopstestView *)pDeactiveView;	CHoopsView::OnActivateView(bActivate, pActivateView, pDeactiveView);}//======================================================================//	Function :		ChoopstestView::CreateHNetClient//	Description :	Creates a dockable dialogbar containing the client//					dialog controls//	Return :bool	-	//	Parameters ://			HNetClient* pHNetClient	-	//	Note ://======================================================================bool ChoopstestView::CreateHNetClient(HNetClient* pHNetClient) {	assert( pHNetClient );	if( m_pHNetClientDlgBar )	{		m_pHNetClientDlgBar->ShowWindow(SW_SHOWNORMAL);		return false;	}	CFrameWnd* pParentFrm = GetParentFrame();	assert(pParentFrm);	m_pHNetClientDlgBar = new HNetClientDlgBar(pHNetClient, m_pHView);	if (!m_pHNetClientDlgBar->Create(pParentFrm, IDD_CLIENTDLG, CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_GRIPPER , IDD_CLIENTDLG))	{		AfxMessageBox(_T("Failed to create DlgBar"));		return false;      // fail to create	}	m_pHNetClientDlgBar->EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT );	pParentFrm->DockControlBar(m_pHNetClientDlgBar, AFX_IDW_DOCKBAR_RIGHT);	return true;}//======================================================================//	Function :		ChoopstestView::DestroyHNetClient//	Description :	Destroys the client dialogbar//	Return :bool	-	//	Parameters ://	Note ://======================================================================bool ChoopstestView::DestroyHNetClient() {	if( m_pHNetClientDlgBar )	{		delete m_pHNetClientDlgBar;		m_pHNetClientDlgBar = 0;	}	return true;}HNetClient* ChoopstestView::GetHNetClient(){	if( m_pHNetClientDlgBar )		return m_pHNetClientDlgBar->GetHNetClient();	else		return 0;}void ChoopstestView::OnFileLoad() {	int width = 500, height = 500;		CString filter, def_file_ext;	CFileDialog my_dlg(TRUE, def_file_ext, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter , NULL);	if (my_dlg.DoModal() == IDOK)	{		HhoopstestModel * hmodel = (HhoopstestModel*) m_pHView->GetModel();		assert(hmodel);		LoadFile( my_dlg.GetPathName() );	}}void ChoopstestView::OnUpdateFileLoad(CCmdUI* pCmdUI) {	DISABLE_IF_HNETCLIENT_NOT_IN_CONTROL( pCmdUI )}void ChoopstestView::LoadFile( LPCTSTR csFilePathName ) {	// understand the file extension - if unknown better return	char file_ext[1024]; 	HUtility::FindFileNameExtension(H_ASCII_TEXT(csFilePathName), file_ext);	if(strlen(file_ext) == 0) 	{		AfxMessageBox(_T("Error: No file extension. Could not determine input file format.\n"));		return;	}	ChoopstestDoc * pDoc = (ChoopstestDoc *)GetDocument();	ASSERT_VALID(pDoc);	HhoopstestModel * hmodel = (HhoopstestModel*) m_pHView->GetModel();	assert(hmodel);	// we are flushing all the geometry - to avoid any problems, unselect any selected stuff.	m_pHView->GetSelection()->DeSelectAll();	// flush all the the solid modeler entities and HOOPS Geometry	m_pHView->Flush(true);	HC_Open_Segment_By_Key(m_pHView->GetSceneKey());		HC_Flush_Contents (".", "geometry");	HC_Close_Segment();	HFileInputResult result = InputOK;	HStreamFileToolkit* tk = m_pHView->GetModel()->GetStreamFileTK();	tk->Restart();	// read the model here	((HhoopstestModel *)m_pHView->GetModel())->Read(H_ASCII_TEXT(csFilePathName));	// send the model to the collabrative clients	m_pHView->EmitSegment(hmodel->GetModelKey(), true);	m_pHView->FitWorld();		// fit the camera to the new scene extents	m_pHView->CameraPositionChanged(true, false);	m_pHView->Update();}
// 自定义初始化函数。显示欢迎画面后执行
void ChoopstestView::MyInit(void)
{
	int center[] = {0,0,0};
	char type[256];
	bLeftMenu = FALSE;
	Max = 30;
	R = 1;
	K = 5;
	tick = 0;
	state = 0;
	fBallSize = 0.1;
	down_point.SetPoint(0,0);
	user.sName = "";
	sec = 0;

	//左侧菜单
	RECT Rect;
	GetClientRect(&Rect);
	int y_center = Rect.top + (Rect.bottom - Rect.top) / 2;

	Rect.left = 0;
	Rect.right = 94;

	Rect.top += y_center - 112.5;
	Rect.bottom = Rect.top + 45;
	cButton1.Create("",WS_CHILD|BS_OWNERDRAW,Rect,this,ID_BUTTON1);	cButton1.LoadBitmaps(IDB_BITMAP1);	cButton1.SubclassDlgItem(IDB_BITMAP1,this);	cButton1.SizeToContent();
	Rect.top += 45;
	Rect.bottom += 45;
	cButton2.Create("",WS_CHILD|BS_OWNERDRAW,Rect,this,ID_BUTTON2);	cButton2.LoadBitmaps(IDB_BITMAP2);	cButton2.SubclassDlgItem(IDB_BITMAP2,this);	cButton2.SizeToContent();	Rect.top += 45;
	Rect.bottom += 45;
	cButton3.Create("",WS_CHILD|BS_OWNERDRAW,Rect,this,ID_BUTTON3);	cButton3.LoadBitmaps(IDB_BITMAP3);	cButton3.SubclassDlgItem(IDB_BITMAP3,this);	cButton3.SizeToContent();	Rect.top += 45;
	Rect.bottom += 45;
	cButton4.Create("",WS_CHILD|BS_OWNERDRAW,Rect,this,ID_BUTTON4);	cButton4.LoadBitmaps(IDB_BITMAP4);	cButton4.SubclassDlgItem(IDB_BITMAP4,this);	cButton4.SizeToContent();
	Rect.top += 45;
	Rect.bottom += 45;
	cButtonLeave.Create("",WS_CHILD|BS_OWNERDRAW,Rect,this,ID_LOGOFF);	cButtonLeave.LoadBitmaps(IDB_BITMAP5);	cButtonLeave.SubclassDlgItem(IDB_BITMAP5,this);	cButtonLeave.SizeToContent();
	//单摆
	fLineLength = 1;
	fPhase = 45;
	danbai_jindu = 0;

	//弹簧
	sTanhuang = "/tools/bigtanhuang";
	tanhuang_jindu = 0;
	fScale = 1;

	//保证存在userdata子目录
	CreateDirectory("userdata",NULL);

	//准备所有的资源
	HStreamFileToolkit *mytool = new HStreamFileToolkit;
	//文本
	HC_Open_Segment("/texts");
		HC_Open_Segment("ball");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_ball.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("line");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_line.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("baidong");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_baidong.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("bigball");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_bigball.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("smallball");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_smallball.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("longline");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_longline.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("shortline");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_shotline.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("kuai");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_kuai.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("man");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_man.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("tanhuang");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_tanhuang.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("bigtanhuang");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_bigtanhuang.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("smalltanhuang");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_smalltanhuang.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("changdu");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_changdu.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("chang");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_chang.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("duan");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\t_duan.hsf"),mytool);
		HC_Close_Segment();
		HC_Open_Segment("go");			HC_Set_Text_Font("size = 0.05 sru");			keyGO = HC_KInsert_Text_With_Encoding (0, 0, 0, "unicode",(char *)L"运行");
		HC_Close_Segment();		HC_Open_Segment("stop");			HC_Set_Text_Font("size = 0.05 sru");			keySTOP = HC_KInsert_Text_With_Encoding (0, 0, 0, "unicode",(char *)L"停止");
		HC_Close_Segment();	HC_Close_Segment();

	//工具
	HC_Open_Segment("/tools");
		HC_Open_Segment("ball");	//单位球
			HC_Set_Color("faces = black");
			keyBall = HC_KInsert_Sphere(center,1,0,0);
		HC_Close_Segment();
		HC_Open_Segment("bigball");	//大球
			HC_Set_Color("faces = black");
			keyBigBall = HC_KInsert_Sphere(center,0.2,0,0);
		HC_Close_Segment();
		HC_Open_Segment("smallball");//小球
			HC_Set_Color("faces = black");
			keySmallBall = HC_KInsert_Sphere(center,0.1,0,0);
		HC_Close_Segment();
		HC_Open_Segment("line");	//单位线
			HC_Set_Color("lines = gray");
			HC_Set_Line_Weight(5.0);
			keyLine = HC_KInsert_Line(0,0,0,0,-1,0);
		HC_Close_Segment();
		HC_Open_Segment("longline");//长线
			HC_Set_Color("lines = gray");
			HC_Set_Line_Weight(5.0);
			keyLongLine = HC_KInsert_Line(0,0,0,0,-1,0);
		HC_Close_Segment();
		HC_Open_Segment("shortline");//短线
			HC_Set_Color("lines = gray");
			HC_Set_Line_Weight(5.0);
			keyShortLine = HC_KInsert_Line(0,0,0,0,-0.5,0);
		HC_Close_Segment();
		HC_Open_Segment("bigtanhuang");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\bigtanhuang.hsf"),mytool);

			//找到读入模型的HC_KEY
			HC_Begin_Contents_Search(".","subsegment");
			HC_Find_Contents(type,&keyBigTanhuang);
			HC_End_Contents_Search();
			HC_Open_Segment_By_Key(keyBigTanhuang);
				HC_Begin_Contents_Search(".","geometry");
				HC_Find_Contents(type,&keyBigTanhuang);
				HC_End_Contents_Search();
			HC_Close_Segment();
		HC_Close_Segment();
		HC_Open_Segment("smalltanhuang");
			HTK_Read_Stream_File(H_ASCII_TEXT("hsf\\smalltanhuang.hsf"),mytool);

			//找到读入模型的HC_KEY
			HC_Begin_Contents_Search(".","subsegment");
			HC_Find_Contents(type,&keySmallTanhuang);
			HC_End_Contents_Search();
			HC_Open_Segment_By_Key(keySmallTanhuang);
				HC_Begin_Contents_Search(".","geometry");
				HC_Find_Contents(type,&keySmallTanhuang);
				HC_End_Contents_Search();
			HC_Close_Segment();
		HC_Close_Segment();
		HC_Open_Segment("danbai");
			HC_Set_Line_Weight(5.0);
			HC_Set_Color("lines = black");
			HC_Insert_Line(1,-0.5,0,2,-0.5,0);
			HC_Open_Segment("");
				HC_Rotate_Object(0,0,30);				HC_Translate_Object(1.5,-0.5,0);				HC_Open_Segment("");					HC_Include_Segment("/tools/line");				HC_Close_Segment();				HC_Open_Segment("");					HC_Scale_Object(0.2,0.2,0.2);					HC_Translate_Object(0,-1,0);					HC_Include_Segment("/tools/ball");				HC_Close_Segment();			HC_Close_Segment();
		HC_Close_Segment();
		HC_Open_Segment("tanhuang");
			HC_Set_Line_Weight(5.0);
			HC_Set_Color("lines = black");
			HC_Insert_Line(1,-0.5,0,2,-0.5,0);
			HC_Open_Segment("");
				HC_Translate_Object(1.5,-0.5,0);				HC_Open_Segment("");					HC_Include_Segment("/tools/bigtanhuang");				HC_Close_Segment();				HC_Open_Segment("");					HC_Scale_Object(0.2,0.2,0.2);					HC_Translate_Object(0,-1,0);					HC_Include_Segment("/tools/ball");				HC_Close_Segment();			HC_Close_Segment();
		HC_Close_Segment();
	HC_Close_Segment();

	//表格
	HC_Open_Segment("/table");
		HC_Insert_Line(0.6,-0.3,0,5,-0.3,0);		HC_Insert_Line(0.6,-0.6,0,5,-0.6,0);		HC_Insert_Line(0.6,-0.9,0,5,-0.9,0);		HC_Insert_Line(0.6,-1.2,0,5,-1.2,0);		HC_Insert_Line(0.6,-1.5,0,5,-1.5,0);		HC_Insert_Line(0.6,-0.3,0,0.6,-1.5,0);		HC_Insert_Line(1.1,-0.3,0,1.1,-1.5,0);		HC_Insert_Line(1.6,-0.3,0,1.6,-1.5,0);		HC_Insert_Line(2.1,-0.3,0,2.1,-1.5,0);		HC_Insert_Line(2.6,-0.3,0,2.6,-1.5,0);		HC_Insert_Line(3.1,-0.3,0,3.1,-1.5,0);		HC_Insert_Line(3.6,-0.3,0,3.6,-1.5,0);		HC_Insert_Line(4.1,-0.3,0,4.1,-1.5,0);		HC_Insert_Line(4.6,-0.3,0,4.6,-1.5,0);		HC_Insert_Line(5,-0.3,0,5,-1.5 ,0);		HC_Open_Segment("text");			HC_Insert_Text(0.85,-0.5,0,"");			HC_Insert_Text(1.35,-0.5,0,"1");			HC_Insert_Text(1.85,-0.5,0,"2");			HC_Insert_Text(2.35,-0.5,0,"3");			HC_Insert_Text(2.85,-0.5,0,"4");			HC_Insert_Text(3.35,-0.5,0,"5");			HC_Insert_Text(3.85,-0.5,0,"6");			HC_Insert_Text(4.35,-0.5,0,"7");			HC_Insert_Text(4.85,-0.5,0,"8");		HC_Close_Segment();	HC_Close_Segment();

	//表头
	HC_Open_Segment("/thead");		HC_Open_Segment("danbai");			HC_Open_Segment("");				HC_Translate_Object(0.85,-0.8,0);				HC_Include_Segment("/texts/ball");			HC_Close_Segment();			HC_Open_Segment("");				HC_Translate_Object(0.85,-1.1,0);				HC_Include_Segment("/texts/line");

⌨️ 快捷键说明

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