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

📄 headerin3d.cpp

📁 VC++ DEMO, used for the beginners and the amour
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	return TRUE;
}

LRESULT HeaderIn3D::DefineUserMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	return Behavior::DefineUserMsgProc(hWnd,msg,wParam,lParam);
}

BOOL HeaderIn3D::DrawEntironment()
{
	DEVICE->BeginScene();

	DEVICE->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.0f, 1.0f), 1.0f, 0 );
	D3DXMATRIX mat,matTrans;
	D3DXMatrixIdentity(&mat);
	DEVICE->SetTransform(D3DTS_WORLD,&mat);
	DEVICE->SetTransform(D3DTS_VIEW,&m_dyCamera->MatrixLookAtLH());
	DEVICE->SetLight(0,&m_dyPointLight);
	DEVICE->LightEnable(0,TRUE);
	DEVICE->SetMaterial(&m_dyMazeMat);
	DEVICE->SetRenderState(D3DRS_AMBIENT,0x55555555);
	DEVICE->SetRenderState(D3DRS_LIGHTING,TRUE);
	DEVICE->SetStreamSource(0,m_dyMazeVB,sizeof(MAZEVERTEX));
	DEVICE->SetVertexShader(MAZEVERTEX::FVF_MAZEVERTEX);
	DEVICE->SetTexture(0,m_dyRoof);
	DEVICE->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);
	DEVICE->SetTexture(0,m_dyFloor);
	DEVICE->DrawPrimitive(D3DPT_TRIANGLELIST,6,2);
	D3DXMatrixTranslation(&matTrans,-(ROW-1),0,-(COL-1));
	D3DXMatrixMultiply(&mat,&matTrans,&mat);
	
	DEVICE->SetTexture(0,m_dyMazeWall);
	
	int Number = 0;
	for(int row = 0; row < ROW; row++)
	{
		for(int col = 0; col < COL; col++)
		{			
			if(DefMaze[Number] == 1)
			{
				DEVICE->SetTransform(D3DTS_WORLD,&mat);
				DEVICE->DrawPrimitive(D3DPT_TRIANGLELIST,12,8);
			}
			else if ( DefMaze[Number] == 2 )
			{
				DEVICE->SetTexture(0,m_dyWin);
				DEVICE->SetTransform(D3DTS_WORLD,&mat);
				DEVICE->DrawPrimitive(D3DPT_TRIANGLELIST,12,8);
				DEVICE->SetTexture(0,m_dyMazeWall);
			}
			Number ++;
			D3DXMatrixTranslation(&matTrans,2,0,0);
			D3DXMatrixMultiply(&mat,&matTrans,&mat);
		}
		D3DXMatrixTranslation(&matTrans,-ROW*2,0,2);
		D3DXMatrixMultiply(&mat,&matTrans,&mat);
	}
	DEVICE->SetTexture(0,0);
	TCHAR strRate[64];
	m_dyFPS->Limit(50);
	m_dyFPS->Refresh();
	sprintf(strRate,"Limit FPS:50.0    Current FPS:%4.1f",m_dyFPS->GetFPS());
	m_dyEnFont->BeginTextOut();
	m_dyEnFont->Text2DOut(m_strAdapterInfo,5,2,D3DCOLOR_RGBA(255,123,255,255));
	m_dyEnFont->Text2DOut(strRate,5,140,D3DCOLOR_RGBA(255,123,255,255));
	m_dyEnFont->Text2DOut("Numeric Key +: INC SPEED\nNumeric Key  -: DEC SPEED\n",5,35,D3DCOLOR_RGBA(255,23,0,255));
	m_dyEnFont->EndTextOut();
	m_dyChar2Font->BeginTextOut();
	m_dyChar2Font->Text2DOut(m_strHelpInfo,5,70,D3DCOLOR_RGBA(255,23,0,255),-1,1,1);
	m_dyChar2Font->EndTextOut();
	DEVICE->EndScene();
	DEVICE->Present(0,0,0,0);
	return TRUE;
}

BOOL HeaderIn3D::LocalKeyboard(UINT nScanCode, WPARAM wParam, LPARAM lParam)
{
	D3DXVECTOR3 vLookAt,vEyeAt,vView;
	LONG temp1_int,temp2_int;
	FLOAT fSpeed = m_dyfSpeed / m_dyFPS->GetFPS();
	FLOAT fAngle = ANGLE / m_dyFPS->GetFPS();
	CHECK_RANGE(fSpeed,0,0.4f);
	switch ( nScanCode )
	{
	case DIK_W:
		vEyeAt = m_dyCamera->EyeAt();
		D3DXVec3Subtract(&vView,&m_dyCamera->LookAt(),&vEyeAt);
		D3DXVec3Normalize(&vView,&vView);
		vLookAt = m_dyCamera->EyeAt() + vView * fSpeed;
		if (vLookAt.x - vEyeAt.x > 0)
			vLookAt.x += LEAST;
		else
			vLookAt.x -= LEAST;	
		if (vLookAt.z-vEyeAt.z > 0)
			vLookAt.z+= LEAST;
		else
			vLookAt.z-= LEAST;
		
		temp1_int = LONG(((vLookAt.x+COL)/2)+((COL*INT((vEyeAt.z+ROW)/2))));
		temp2_int = LONG(((vEyeAt.x+COL)/2)+((COL*INT((vLookAt.z+ROW)/2))));
		
		if(vView.x > 0 && vView.z > 0)
		{
			if ( (temp2_int + 1) == (temp1_int + COL) && 
				DefMaze[temp2_int] == 0 &&
				DefMaze[temp1_int] == 0 )
			{
				temp1_int = temp2_int + 1;
				temp2_int = temp1_int;
			}
		}
		else if ( vView.x > 0 && vView.z < 0 )
		{
			if ( (temp2_int + 1) == (temp1_int - COL) &&
				DefMaze[temp2_int] == 0 &&
				DefMaze[temp1_int] == 0)
			{
				temp2_int = temp1_int - COL;
				temp1_int = temp2_int;
			}
		}
		else if ( vView.x < 0 && vView.z > 0 )
		{
			if ( (temp1_int + COL) == (temp2_int - 1) && 
				DefMaze[temp2_int] == 0 && 
				DefMaze[temp1_int] == 0)
			{
				temp1_int = temp2_int - 1;
				temp2_int = temp1_int;
			}
		}
		else if ( vView.x < 0 && vView.z < 0 )
		{
			if ( (temp1_int - COL) == (temp2_int - 1) && 
				DefMaze[temp2_int] == 0 && 
				DefMaze[temp1_int] == 0)
			{
				temp1_int = temp2_int - 1;
				temp2_int = temp1_int;
			}
		}

		if(DefMaze[temp1_int] == 0 )
			m_dyCamera->MatrixTranslateXAxis(fSpeed);
		if(DefMaze[temp2_int] == 0 )
			m_dyCamera->MatrixTranslateZAxis(fSpeed);
		if (DefMaze[temp2_int] == 2 || DefMaze[temp1_int] == 2)
		{
			m_dyCamera->MatrixTranslateXYZAxis(fSpeed*0.1f);
			m_dyCamera->MatrixLookAt(D3DXVECTOR3(-17,0,-17),D3DXVECTOR3(-17,0,1),D3DXVECTOR3(0,1,0));
		}
		break;
	case DIK_S:
		vEyeAt = m_dyCamera->EyeAt();
		D3DXVec3Subtract(&vView,&m_dyCamera->LookAt(),&vEyeAt);
		D3DXVec3Normalize(&vView,&vView);
		vLookAt = m_dyCamera->EyeAt() - vView * fSpeed;
		if (vLookAt.x - vEyeAt.x > 0)
			vLookAt.x += LEAST;
		else
			vLookAt.x -= LEAST;
				
		if (vLookAt.z-vEyeAt.z > 0)
			vLookAt.z += LEAST;
		else
			vLookAt.z -= LEAST;
		
		temp1_int = LONG(((vLookAt.x+COL)/2)+((COL*INT((vEyeAt.z+ROW)/2))));
		temp2_int = LONG(((vEyeAt.x+COL)/2)+((COL*INT((vLookAt.z+ROW)/2))));

		if(vView.x > 0 && vView.z > 0)
		{
			if ( (temp2_int - 1) == (temp1_int - COL) && 
				DefMaze[temp2_int] == 0 &&
				DefMaze[temp1_int] == 0 )
			{
				temp1_int = temp2_int - 1;
				temp2_int = temp1_int;
			}
		}
		else if ( vView.x > 0 && vView.z < 0 )
		{
			if ( (temp2_int - 1) == (temp1_int + COL)&& 
				DefMaze[temp2_int] == 0 &&
				DefMaze[temp1_int] == 0  )
			{
				temp1_int = temp2_int - 1;
				temp2_int = temp1_int;
			}
		}
		else if ( vView.x < 0 && vView.z > 0 )
		{
			if ( (temp1_int - COL) == (temp2_int + 1) && 
				DefMaze[temp2_int] == 0 &&
				DefMaze[temp1_int] == 0 )
			{
				temp1_int = temp2_int + 1;
				temp2_int = temp1_int;
			}
		}
		else if ( vView.x < 0 && vView.z < 0 && 
				DefMaze[temp2_int] == 0 &&
				DefMaze[temp1_int] == 0 )
		{
			if ( (temp1_int + COL) == (temp2_int + 1) )
			{
				temp1_int = temp2_int + 1;
				temp2_int = temp1_int;
			}
		}

		if(DefMaze[temp1_int] == 0 )
			m_dyCamera->MatrixTranslateXAxis(-fSpeed);
		if(DefMaze[temp2_int] == 0 )
			m_dyCamera->MatrixTranslateZAxis(-fSpeed);

		if(DefMaze[temp2_int] == 2 || DefMaze[temp1_int] == 2)
		{
			m_dyCamera->MatrixTranslateXYZAxis(-fSpeed*0.1f);
		}
		break;
	case DIK_LEFT:
		m_dyCamera->MatrixRotationAxis(0.0f,-fAngle);
		break;
	case DIK_RIGHT:
		m_dyCamera->MatrixRotationAxis(0.0f,fAngle);
		break;
	case DIK_A:
		m_dyCamera->MatrixRotationAxis(0.0f,-fAngle);
		break;
	case DIK_D:
		m_dyCamera->MatrixRotationAxis(0.0f,fAngle);
		break;
	case DIK_ADD:
		m_dyfSpeed++;
		CHECK_RANGE(m_dyfSpeed,1,5);
		break;
	case DIK_SUBTRACT:
		m_dyfSpeed--;
		CHECK_RANGE(m_dyfSpeed,1,5);
		break;
	default: break;
	}
	return TRUE; 
}


BOOL HeaderIn3D::CleanupOnLastTime()
{
	m_bActive = FALSE;
	m_bReady = FALSE;
	SAFE_RELEASE(m_dyRoof);
	SAFE_RELEASE(m_dyFloor);
	SAFE_RELEASE(m_dyMazeWall);
	SAFE_RELEASE(m_dyWin);
	SAFE_RELEASE(m_dyMazeVB);
	m_dyEnFont->SetfreeContext();
	m_dyChar2Font->SetfreeContext();
	m_dyCardFont->SetfreeContext();
	return TRUE;
}

⌨️ 快捷键说明

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