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

📄 boidswinmenu.cpp

📁 3D的Boids效果演示源程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

// Menu driven command to change boids to animated birds.
afx_msg void BoidsWin::OnAnimBird( )
{
	// Abort change if mesh is already in use.
	if ( flyerMesh == IDR_MESH_BIRDBODY )
	{
		return;
	}


	// Set the window's data member.
	flyerMesh = IDR_MESH_BIRDBODY;

	// Set the mesh counter back to zero.
	flyerMeshesChanged = 0;
}


// Menu driven command to change the colour of the flyers.
afx_msg void BoidsWin::OnFlyerWhite( )
{
	flyerColour = RGB_WHITE;  // Set the main window's data member.

	for ( int index = 0; index < numFlyers; index++ )
	{
		flyers[ index ] -> setColour( flyerColour );
	}
}


// Menu driven command to change the colour of the flyers.
afx_msg void BoidsWin::OnFlyerYellow( )
{
	flyerColour = RGB_YELLOW;  // Set the main window's data member.

	for ( int index = 0; index < numFlyers; index++ )
	{
		flyers[ index ] -> setColour( flyerColour );
	}
}


// Menu driven command to change the colour of the flyers.
afx_msg void BoidsWin::OnFlyerPink( )
{
	flyerColour = RGB_PINK;  // Set the main window's data member.

	for ( int index = 0; index < numFlyers; index++ )
	{
		flyers[ index ] -> setColour( flyerColour );
	}
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateWireframe( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( renderStyle == D3DRMRENDER_WIREFRAME );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateUnlitFlat( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( renderStyle == D3DRMRENDER_UNLITFLAT );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateFlat( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( renderStyle == D3DRMRENDER_FLAT );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateGouraud( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( renderStyle == D3DRMRENDER_GOURAUD );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateTetra( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( flyerMesh == IDR_MESH_TETRA );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateBird( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( flyerMesh == IDR_MESH_BIRD );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateAnimBird( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( flyerMesh == IDR_MESH_BIRDBODY );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateFlyerWhite( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( flyerColour == RGB_WHITE );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateFlyerYellow( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( flyerColour == RGB_YELLOW );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateFlyerPink( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( flyerColour == RGB_PINK );
}


// Menu driven command to deactivate the landscape.
afx_msg void BoidsWin::OnLandNone( )
{
	landscape.renderNone( );
}


// Menu driven command to render the landscape in a wireframe style.
afx_msg void BoidsWin::OnLandWireframe( )
{
	landscape.toggleWireframe( );
}


// Menu driven command to render the landscape in a flat unlit style.
afx_msg void BoidsWin::OnLandUnlitFlat( )
{
	landscape.toggleUnlitFlat( );
}


// Menu driven command to render the landscape in a flat shaded style.
afx_msg void BoidsWin::OnLandFlat( )
{
	landscape.toggleFlat( );
}


// Menu driven command to render the landscape in a Gouraud style.
afx_msg void BoidsWin::OnLandGouraud( )
{
	landscape.toggleGouraud( );
}


// Menu driven command to set the solid fill colour of the land to green.
afx_msg void BoidsWin::OnLandSolidGreen( )
{
	landscape.setSolidColour( LSC_GREEN );
}


// Menu driven command to set the solid fill colour of the land to checkered.
afx_msg void BoidsWin::OnLandSolidCheckered( )
{
	landscape.setSolidColour( LSC_CHECKERED );
}


// Menu driven command to recalculate the altitudes of the landscape's matrix.
afx_msg void BoidsWin::OnLandRecalculate( )
{
	landscape.recalculate( );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateLandNone( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( landscape.getExists( ) == false );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateLandWireFrame( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( landscape.getWireframeOn( ) );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateLandUnlitFlat( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( landscape.getSolidStyle( ) ==
					D3DRMRENDER_UNLITFLAT && landscape.getSolidOn( ) );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateLandFlat( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( landscape.getSolidStyle( ) ==
						D3DRMRENDER_FLAT && landscape.getSolidOn( ) );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateLandGouraud( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( landscape.getSolidStyle( ) ==
					D3DRMRENDER_GOURAUD && landscape.getSolidOn( ) );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateLandSolidGreen( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( landscape.getSolidColour( ) ==
							LSC_GREEN && landscape.getSolidOn( ) );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateLandSolidCheckered( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( landscape.getSolidColour( ) ==
							LSC_CHECKERED && landscape.getSolidOn( ) );
}


// Toggle the menu driven flock forming behaviour flag.
afx_msg void BoidsWin::OnFlockForming( )
{
	if ( flockFormingActive == false )
	{
		flockFormingActive = true;
	}
	else
	{
		flockFormingActive = false;
	}
}


// Toggle the menu driven velocity matching behaviour flag.
afx_msg void BoidsWin::OnVelocityMatching( )
{
	if ( velocityMatchingActive == false )
	{
		velocityMatchingActive = true;
	}
	else
	{
		velocityMatchingActive = false;
	}
}


// Toggle the menu driven collision avoidance behaviour flag.
afx_msg void BoidsWin::OnCollisionAvoidance( )
{
	if ( collisionAvoidanceActive == false )
	{
		collisionAvoidanceActive = true;
	}
	else
	{
		collisionAvoidanceActive = false;
	}
}


// Bring up the Flyer Attributes dialog.
afx_msg void BoidsWin::OnFlyerAttributes( )
{
	// Abort the command if currently in full screen mode.
	if ( fullScreenMode )
	{
		return;
	}


	// Set the multitasking flag.
	appIdle = false;

	// Restart the rendering thread if stopped.
	threadEnabled = true;

	if ( threadFinished == true )
	{
		threadFinished = false;
		ptrD3DThread = AfxBeginThread( d3dThread, this,
											THREAD_PRIORITY_NORMAL );
	}


	// Create the dialog box.
	BoidsDialogAttr dialogBox( "IDD_ATTRIBUTES_DIALOG", this );

	dialogBox.DoModal( );  // Make the dialog box appear.


	// Stop the rendering thread when done.
	threadEnabled = false;
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateFlockForming( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( flockFormingActive );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateVelocityMatching( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( velocityMatchingActive );
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateCollisionAvoidance( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( collisionAvoidanceActive );
}


// Switch between FS mode and Windowed mode.
void BoidsWin::OnSwitchFSMode( )
{
	// If in full screen mode, return to windowed mode.
	if ( fullScreenMode )
	{
		windowedMode( );
	}
	else  // If in windowed mode, switch to full screen mode.
	{
		OnFullScreen( );
	}
}


// Bring up the dialog box for selecting the full screen mode resolution.
afx_msg void BoidsWin::OnSelectMode( )
{
	// Abort the command if currently in full screen mode.
	if ( fullScreenMode )
	{
		return;
	}


	// Set the multitasking flag.
	appIdle = false;

	// Restart the rendering thread if stopped.
	threadEnabled = true;

	if ( threadFinished == true )
	{
		threadFinished = false;
		ptrD3DThread = AfxBeginThread( d3dThread, this,
										THREAD_PRIORITY_NORMAL );
	}


	// Create the dialog box.
	BoidsDialogDisp dialogBox( "IDD_DISPLAYMODE_DIALOG", this );

	dialogBox.DoModal( );  // Make the dialog box appear.


	// Stop the rendering thread when done.
	threadEnabled = false;
}


// Set the windowed mode screen size to 640 x 480.
afx_msg void BoidsWin::OnWin640_480( )
{
	// Abort the command if currently in full screen mode.
	if ( fullScreenMode )
	{
		return;
	}

	restore( );  // Restore the window if maximised.

	// Create the size.
	CRect windowSize( WINDOW_LEFT_POSITION, WINDOW_TOP_POSITION,
					WINDOW_LEFT_POSITION + 640, WINDOW_TOP_POSITION + 480 );

	// Move the window to the new size.
	MoveWindow( &windowSize, true );
}


// Set the windowed mode screen size to 800 x 600.
afx_msg void BoidsWin::OnWin800_600( )
{
	// Abort the command if currently in full screen mode.
	if ( fullScreenMode )
	{
		return;
	}

	restore( );  // Restore the window if maximised.

	// Create the size.
	CRect windowSize( WINDOW_LEFT_POSITION, WINDOW_TOP_POSITION,
					WINDOW_LEFT_POSITION + 800, WINDOW_TOP_POSITION + 600 );

	// Move the window to the new size.
	MoveWindow( &windowSize, true );
}


// Set the windowed mode screen size to 1024 x 768.
afx_msg void BoidsWin::OnWin1024_768( )
{
	// Abort the command if currently in full screen mode.
	if ( fullScreenMode )
	{
		return;
	}

	restore( );  // Restore the window if maximised.

	// Create the size.
	CRect windowSize( WINDOW_LEFT_POSITION, WINDOW_TOP_POSITION,
					WINDOW_LEFT_POSITION + 1024, WINDOW_TOP_POSITION + 768 );

	// Move the window to the new size.
	MoveWindow( &windowSize, true );
}


// Toggle the control panel to show or hide itself.
afx_msg void BoidsWin::OnToggleControls( )
{
	// Only perform the change if in windowed mode.
	if ( fullScreenMode )
	{
		return;  // Abort the function.
	}


	// Abort if the rendering thread is still active.
	if ( threadFinished == false )
	{
		// Set the multitasking flags.
		threadEnabled = false;
		needToggleControls = true;

		return;
	}


	// Toggle the flags.
	if ( showControlPanel )
	{
		// Hide the control panel.
		showControlPanel = false;
	}
	else
	{
		// Show the control panel.
		showControlPanel = true;
	}

	// Call the worker function.
	showControls( showControlPanel );


	// Clear the flag when the operation has completed.
	needToggleControls = false;
}


// Update the checkmark on the window's menu item.
afx_msg void BoidsWin::OnUpdateToggleControls( CCmdUI *ptrCmdUI )
{
	ptrCmdUI -> SetCheck( showControlPanel );
}


// Display an about box for the window's help menu.
afx_msg void BoidsWin::OnAbout( )
{
	// Abort the command if currently in full screen mode.
	if ( fullScreenMode )
	{
		return;
	}


	// Set the multitasking flag.
	appIdle = false;

	// Restart the rendering thread if stopped.
	threadEnabled = true;

	if ( threadFinished == true )
	{
		threadFinished = false;
		ptrD3DThread = AfxBeginThread( d3dThread, this,
									THREAD_PRIORITY_NORMAL );
	}


	// Message box giving details about the application.
	// Generate the text string.
	CString text = "3D Boids v";
	text += VERSION;
	text += "\n";
	text += RELEASE_DATE;
	text += "\n\nBy Robert Platt\n";
	text += "http://www.navgen.com/\n\n";
	text += "BSc(Hons) Software Engineering Project\n";
	text += "University of Westminster, London, England";

	// Display the message box.
	MessageBox( text, "3D Boids", MB_OK );


	// Stop the rendering thread when done.
	threadEnabled = false;
}

⌨️ 快捷键说明

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