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

📄 simulatedoc.cpp

📁 这是关于飞机生存力计算软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			&((TriMesh->m_pVertexList[i]).m_fZ));
		
		fXTemp = (TriMesh->m_pVertexList[i]).m_fX;
		fYTemp = (TriMesh->m_pVertexList[i]).m_fY;
		fZTemp = (TriMesh->m_pVertexList[i]).m_fZ;

		//find min x,y,z
		if(fXTemp < XMin)
			XMin = fXTemp;

		if(fYTemp < YMin)
			YMin = fYTemp;
		
		if(fZTemp < ZMin)
			ZMin = fZTemp;

		//find max x,y,z
		if(fXTemp > XMax)
			XMax = fXTemp;

		if(fYTemp > YMax)
			YMax = fYTemp;
		
		if(fZTemp > ZMax)
			ZMax = fZTemp;
	}

	TriMesh->m_fXMin = XMin;
	TriMesh->m_fYMin = YMin;
	TriMesh->m_fZMin = ZMin;
	TriMesh->m_fXMax = XMax;
	TriMesh->m_fYMax = YMax;
	TriMesh->m_fZMax = ZMax;

	//  Pass the Face list line
	fgets(AscChars, 100, AscFile);
	
	//  Now it's time to read the faces!
	for(i=0; i < Faces; i++)
	{
	    fscanf( AscFile, "Face %d: A:%d B:%d C:%d AB:%d BC:%d CA:%d\n",
			&FaceNumber,
			&((TriMesh->m_pTriangleList[i]).m_nA),
			&((TriMesh->m_pTriangleList[i]).m_nB),
			&((TriMesh->m_pTriangleList[i]).m_nC),
			&apTemp,
			&bpTemp,
			&cpTemp);

		//  Pass the Face list line
	    fscanf( AscFile, "%s %d\n", AscChars, &nSmoothingNumber);
	}
    fclose(AscFile);

	if(AddTriMesh(TriMesh))
		UpdateAllViews(0);
	else
	{
		AfxMessageBox(TriMesh->m_sName + CString(" is already in the scene!"),
						MB_OK | MB_ICONSTOP);
		delete TriMesh;
	}
}

CView * CSimulateDoc::GetToolsPanel()
{
	CSimulateApp *pApp = (CSimulateApp *)AfxGetApp();
	CMainFrame *pMainFrame = (CMainFrame *)pApp->m_pMainWnd;
	CView *pView = (CView *)pMainFrame->m_wndSplitter.GetPane(0,0);
	return pView;

}

void CSimulateDoc::OnFileReset() 
{
	// TODO: Add your command handler code here
	CToolsPanel * pToolsPanel;
	CSimulateView * pSimulateView;

	if(AfxMessageBox("Reset will delete all objects in the scene, do you really want to continue?",MB_OKCANCEL)
		== IDOK)
	{
		int Index = m_TriMeshArray.GetSize();
		while(Index--)
			delete m_TriMeshArray.GetAt(Index);
		m_TriMeshArray.RemoveAll();	
		UpdateAllViews(0);
		
		pToolsPanel = (CToolsPanel *)GetToolsPanel();
		pSimulateView = (CSimulateView *)GetSimulateView();

		(((pToolsPanel->m_pTabTools)->m_pTabtoolOpenGL)->m_MeshesList).ResetContent();
		((pToolsPanel->m_pTabTools)->m_pTabtoolSimulate)->ResetAll();
		pSimulateView->ResetSetting();

	}
	
}

CView * CSimulateDoc::GetSimulateView()
{
	CSimulateApp *pApp = (CSimulateApp *)AfxGetApp();
	CMainFrame *pMainFrame = (CMainFrame *)pApp->m_pMainWnd;
	CView *pView = (CView *)pMainFrame->m_wndSplitter.GetPane(0,1);
	return pView;

}

float CVector::fDotProduct(CVector & Vector)
{
	float fDotMetrixValue;
	
	fDotMetrixValue = m_fX * Vector.m_fX
					+ m_fY * Vector.m_fY
					+ m_fZ * Vector.m_fZ;
	
	return fDotMetrixValue;
}

void CVector::CrossProduct(CVector & Vector)
{
	float fX, fY, fZ;
	
	fX = m_fX;
	fY = m_fY;
	fZ = m_fZ;
	m_fX = fY * Vector.m_fZ - Vector.m_fY * fZ;
	m_fY = fZ * Vector.m_fX - Vector.m_fZ * fX;
	m_fZ = fX * Vector.m_fY - Vector.m_fX * fY;
}

float CVector::fLength()
{
	return(sqrt(m_fX * m_fX + m_fY * m_fY + m_fZ * m_fZ));
}

void CVector::Normalize()
{
	float fVectorLength;
	
	fVectorLength = fLength();

	if(fVectorLength > 0.00000001)
	{
		m_fX = m_fX/fVectorLength;
		m_fY = m_fY/fVectorLength;
		m_fZ = m_fZ/fVectorLength;
	}
}

CVector & CVector::operator = (const CVector & Vector)
{
	m_fX = Vector.m_fX;
	m_fY = Vector.m_fY;
	m_fZ = Vector.m_fZ;
	return(*this);
}

int CTriMesh::nIsPointInMesh(CVertex & Vertex)
{
	int i;
	float fV1_X, fV1_Y, fV1_Z;
	float fV2_X, fV2_Y, fV2_Z;

	for(i=0; i < m_nFaces; i++)
	{
		fV1_X = m_pVertexList[m_pTriangleList[i].m_nB].m_fX -
				m_pVertexList[m_pTriangleList[i].m_nA].m_fX;

		fV1_Y = m_pVertexList[m_pTriangleList[i].m_nB].m_fY -
				m_pVertexList[m_pTriangleList[i].m_nA].m_fY;

		fV1_Z = m_pVertexList[m_pTriangleList[i].m_nB].m_fZ -
				m_pVertexList[m_pTriangleList[i].m_nA].m_fZ;

		fV2_X = m_pVertexList[m_pTriangleList[i].m_nC].m_fX -
				m_pVertexList[m_pTriangleList[i].m_nB].m_fX;

		fV2_Y = m_pVertexList[m_pTriangleList[i].m_nC].m_fY -
				m_pVertexList[m_pTriangleList[i].m_nB].m_fY;

		fV2_Z = m_pVertexList[m_pTriangleList[i].m_nC].m_fZ -
				m_pVertexList[m_pTriangleList[i].m_nB].m_fZ;

/*					(fV1_Y * fV2_Z - fV2_Y * fV1_Z,
					fV1_Z * fV2_X - fV2_Z * fV1_X,
					fV1_X * fV2_Y - fV2_X * fV1_Y);*/
	}
	return 0;

}

void CMatrix::Multiply(CMatrix & Matrix)
{
	if(m_nColumn != Matrix.m_nRow)
		return;

	int i, j, k;
	float* TempData = new float[m_nRow * Matrix.m_nColumn];
	float TempSum;
	
	for(i = 0; i < m_nRow; i++)
	{
		for(j = 0; j < Matrix.m_nColumn; j++)
		{
			TempSum = 0.;
			for(k = 0; k < m_nColumn; k++)
			{
				TempSum = TempSum + this->operator()(i, k) * 
							Matrix(k, j);
			}
			TempData[i * (Matrix.m_nColumn) + j] = TempSum;
		}
	}

	delete [] m_pMatrixData;
	m_pMatrixData = TempData; 
	m_nColumn = Matrix.m_nColumn;
}

float & CMatrix::operator ( )(int nRow, int nColumn)
{
	try
	{
		if(nRow < 0 | nRow >= m_nRow | nColumn < 0 | nColumn > m_nColumn)
			throw "Invalid Row or Cloumn number!";
	}
	catch(char * szExcept)
	{
		CString sMsg;
		sMsg.Format("Exception raised: %s\n", szExcept);
		AfxMessageBox(sMsg, MB_ICONSTOP | MB_OK);
		exit(1);
	}

	return m_pMatrixData[nRow * m_nColumn + nColumn];
}

void CTriMesh::PreCalculateForIntersection(CTriMeshForIntersection& TriMeshForIntersection,
										   CMatrix& Matrix)
{
	int i;
	float fAXBeforProjection, fAYBeforProjection, fAZBeforProjection;
	float fBXBeforProjection, fBYBeforProjection, fBZBeforProjection;
	float fCXBeforProjection, fCYBeforProjection, fCZBeforProjection;
	float fAXAfterProjection, fAYAfterProjection, fAZAfterProjection;
	float fBXAfterProjection, fBYAfterProjection, fBZAfterProjection;
	float fCXAfterProjection, fCYAfterProjection, fCZAfterProjection;
	float fSP;
	CString sMsg;
	CLine Line;
	Node<CLine>* LineNode;
	List<CLine>* pBoundaryLineList;
	List<CTriangleVisible>* pTriangleVisibleList;
	CTriangleVisible TriangleVisible; 

	pBoundaryLineList = TriMeshForIntersection.m_pBoundaryLineList;
	pTriangleVisibleList = TriMeshForIntersection.m_pTriangleVisibleList;
	//Get the mesh name
	TriMeshForIntersection.m_sName = m_sName;

	for(i=0; i < m_nFaces; i++)
		{
			fAXBeforProjection = m_pVertexList[m_pTriangleList[i].m_nA].m_fX;
			fAYBeforProjection = m_pVertexList[m_pTriangleList[i].m_nA].m_fY;
			fAZBeforProjection = m_pVertexList[m_pTriangleList[i].m_nA].m_fZ;

			fBXBeforProjection = m_pVertexList[m_pTriangleList[i].m_nB].m_fX;
			fBYBeforProjection = m_pVertexList[m_pTriangleList[i].m_nB].m_fY;
			fBZBeforProjection = m_pVertexList[m_pTriangleList[i].m_nB].m_fZ;

			fCXBeforProjection = m_pVertexList[m_pTriangleList[i].m_nC].m_fX;
			fCYBeforProjection = m_pVertexList[m_pTriangleList[i].m_nC].m_fY;
			fCZBeforProjection = m_pVertexList[m_pTriangleList[i].m_nC].m_fZ;

			//Projection of point A
			fAXAfterProjection = Matrix(0, 0) * fAXBeforProjection +
								Matrix(0, 1) * fAYBeforProjection +	
								Matrix(0, 2) * fAZBeforProjection +	
								Matrix(0, 3) * 1.0;

			fAYAfterProjection = Matrix(1, 0) * fAXBeforProjection +
								Matrix(1, 1) * fAYBeforProjection +	
								Matrix(1, 2) * fAZBeforProjection +	
								Matrix(1, 3) * 1.0;
			
			fAZAfterProjection = Matrix(2, 0) * fAXBeforProjection +
								Matrix(2, 1) * fAYBeforProjection +	
								Matrix(2, 2) * fAZBeforProjection +	
								Matrix(2, 3) * 1.0;

			//Projection of point B
			fBXAfterProjection = Matrix(0, 0) * fBXBeforProjection +
								Matrix(0, 1) * fBYBeforProjection +	
								Matrix(0, 2) * fBZBeforProjection +	
								Matrix(0, 3) * 1.0;

			fBYAfterProjection = Matrix(1, 0) * fBXBeforProjection +
								Matrix(1, 1) * fBYBeforProjection +	
								Matrix(1, 2) * fBZBeforProjection +	
								Matrix(1, 3) * 1.0;
			
			fBZAfterProjection = Matrix(2, 0) * fBXBeforProjection +
								Matrix(2, 1) * fBYBeforProjection +	
								Matrix(2, 2) * fBZBeforProjection +	
								Matrix(2, 3) * 1.0;

			//Projection of point C 
			fCXAfterProjection = Matrix(0, 0) * fCXBeforProjection +
								Matrix(0, 1) * fCYBeforProjection +	
								Matrix(0, 2) * fCZBeforProjection +	
								Matrix(0, 3) * 1.0;

			fCYAfterProjection = Matrix(1, 0) * fCXBeforProjection +
								Matrix(1, 1) * fCYBeforProjection +	
								Matrix(1, 2) * fCZBeforProjection +	
								Matrix(1, 3) * 1.0;
			
			fCZAfterProjection = Matrix(2, 0) * fCXBeforProjection +
								Matrix(2, 1) * fCYBeforProjection +	
								Matrix(2, 2) * fCZBeforProjection +	
								Matrix(2, 3) * 1.0;
							
			fSP = (fBXAfterProjection - fAXAfterProjection) * 
					(fCYAfterProjection - fAYAfterProjection) - 
					(fCXAfterProjection - fAXAfterProjection) * 
					(fBYAfterProjection - fAYAfterProjection);
			
			//If fSP > 0.000001 This Triangle is visible,
			//else is invisible
			if(fSP > 0.000001)
			{
				//First insert this visible triangle to the list
				(TriangleVisible.m_VertexA).m_fX = fAXAfterProjection;
				(TriangleVisible.m_VertexA).m_fY = fAYAfterProjection;
				(TriangleVisible.m_VertexA).m_fZ = fAZAfterProjection;

				(TriangleVisible.m_VertexB).m_fX = fBXAfterProjection;
				(TriangleVisible.m_VertexB).m_fY = fBYAfterProjection;
				(TriangleVisible.m_VertexB).m_fZ = fBZAfterProjection;

				(TriangleVisible.m_VertexC).m_fX = fCXAfterProjection;
				(TriangleVisible.m_VertexC).m_fY = fCYAfterProjection;
				(TriangleVisible.m_VertexC).m_fZ = fCZAfterProjection;
				
				pTriangleVisibleList->InsertNewNodeAtTail(TriangleVisible);

				//Secondly insert the outline
				Line.m_nFirstPoint = m_pTriangleList[i].m_nA;
				(Line.m_FirstVertex).m_fX = fAXAfterProjection;
				(Line.m_FirstVertex).m_fY = fAYAfterProjection;
				(Line.m_FirstVertex).m_fZ = fAZAfterProjection;

				Line.m_nSecondPoint = m_pTriangleList[i].m_nB;
				(Line.m_SecondVertex).m_fX = fBXAfterProjection;
				(Line.m_SecondVertex).m_fY = fBYAfterProjection;
				(Line.m_SecondVertex).m_fZ = fBZAfterProjection;

				if(pBoundaryLineList->pFindItem(Line) != NULL)
					pBoundaryLineList->DeleteAfter(pBoundaryLineList->pFindItem(Line));
				else
					pBoundaryLineList->InsertNewNodeAtTail(Line);

				Line.m_nFirstPoint = m_pTriangleList[i].m_nB;
				(Line.m_FirstVertex).m_fX = fBXAfterProjection;
				(Line.m_FirstVertex).m_fY = fBYAfterProjection;
				(Line.m_FirstVertex).m_fZ = fBZAfterProjection;

				Line.m_nSecondPoint = m_pTriangleList[i].m_nC;
				(Line.m_SecondVertex).m_fX = fCXAfterProjection;
				(Line.m_SecondVertex).m_fY = fCYAfterProjection;
				(Line.m_SecondVertex).m_fZ = fCZAfterProjection;

				if(pBoundaryLineList->pFindItem(Line) != NULL)
					pBoundaryLineList->DeleteAfter(pBoundaryLineList->pFindItem(Line));
				else
					pBoundaryLineList->InsertNewNodeAtTail(Line);

				Line.m_nFirstPoint = m_pTriangleList[i].m_nC;
				(Line.m_FirstVertex).m_fX = fCXAfterProjection;
				(Line.m_FirstVertex).m_fY = fCYAfterProjection;
				(Line.m_FirstVertex).m_fZ = fCZAfterProjection;

				Line.m_nSecondPoint = m_pTriangleList[i].m_nA;
				(Line.m_SecondVertex).m_fX = fAXAfterProjection;
				(Line.m_SecondVertex).m_fY = fAYAfterProjection;
				(Line.m_SecondVertex).m_fZ = fAZAfterProjection;

				if(pBoundaryLineList->pFindItem(Line) != NULL)
					pBoundaryLineList->DeleteAfter(pBoundaryLineList->pFindItem(Line));
				else
					pBoundaryLineList->InsertNewNodeAtTail(Line);
			}
		}
	
	float fXMinOfBoundaryLine = TriMeshForIntersection.m_fXMin;
	float fYMinOfBoundaryLine = TriMeshForIntersection.m_fYMin;
	float fXMaxOfBoundaryLine = TriMeshForIntersection.m_fXMax;
	float fYMaxOfBoundaryLine = TriMeshForIntersection.m_fYMax;
	LineNode = pBoundaryLineList->pGetHead();
	LineNode = LineNode->m_pNext;
	while(LineNode != NULL)
	{
//		glVertex3f(((LineNode->m_Data).m_FirstVertex).m_fX,
//					((LineNode->m_Data).m_FirstVertex).m_fY,
//					0);					
		
		if(((LineNode->m_Data).m_FirstVertex).m_fX < fXMinOfBoundaryLine)
			fXMinOfBoundaryLine = ((LineNode->m_Data).m_FirstVertex).m_fX;

		if(((LineNode->m_Data).m_FirstVertex).m_fY < fYMinOfBoundaryLine)
			fYMinOfBoundaryLine = ((LineNode->m_Data).m_FirstVertex).m_fY;

		if(((LineNode->m_Data).m_FirstVertex).m_fX > fXMaxOfBoundaryLine)
			fXMaxOfBoundaryLine = ((LineNode->m_Data).m_FirstVertex).m_fX;

		if(((LineNode->m_Data).m_FirstVertex).m_fY > fYMaxOfBoundaryLine)
			fYMaxOfBoundaryLine = ((LineNode->m_Data).m_FirstVertex).m_fY;

⌨️ 快捷键说明

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