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

📄 wanguanview.cpp

📁 弯管机的弯管控制程序。可以在弯管机加工前分析管型与机型是否能够加工出来。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
}

void CWanGuanView::DrawAxis()
{
	glBegin( GL_LINES);
			// x轴
			glColor3f(1.0F, 0.0F, 0.0F);
			glVertex3f(-3.0f, 0.0f, 0.0f);
			glVertex3f( 3.0f, 0.0f, 0.0f);
			glVertex3f( 2.5f, 0.5f, 0.0f);
			glVertex3f( 3.0f, 0.0f, 0.0f);
			glVertex3f( 2.5f,-0.5f,-0.0f);
			glVertex3f( 3.0f, 0.0f, 0.0f);
			
			// y轴
			glColor3f(0.0F, 1.0F, 0.0F);
			glVertex3f( 0.0f, -3.0f, 0.0f);
			glVertex3f( 0.0f,  3.0f, 0.0f);
			glVertex3f(-0.5f,  2.5f, 0.0f);
			glVertex3f( 0.0f,  3.0f, 0.0f);
			glVertex3f( 0.5f,  2.5f, 0.0f);
			glVertex3f( 0.0f,  3.0f, 0.0f);

			// z轴
			glColor3f(0.0F, 0.0F, 1.0F);
			glVertex3f( 0.0f, 0.0f, -3.0f);
			glVertex3f( 0.0f, 0.0f,  3.0f);
			glVertex3f(-0.5f, 0.0f,  2.5f);
			glVertex3f( 0.0f, 0.0f,  3.0f);
			glVertex3f( 0.5f, 0.0f,  2.5f);
			glVertex3f( 0.0f, 0.0f,  3.0f);

	glEnd();

}

void CWanGuanView::drawTorus(float fGuanInR,YBCArray &YBCs,int iCurrentLine)
{
	int iybcsnum,i;
	 float fGuanC,fGuanOutR;
	GLfloat clipPlaneVerts[4][3] = {
    { 10.0F, 10.0F, 0.5F },
    {-10.0F, 10.0F, 0.5F },
    {-10.0F,-10.0F, 0.5F },
    { 10.0F,-10.0F, 0.5F },};
	GLdouble clipPlane[4] = { 1.0, 0.0, -0.0, 0.0 };
	GLdouble clipPlane1[4] = { 0.0, 1.0, -0.0, 0.0 };
	float fb,fy,fc,ftr;
	iybcsnum=YBCs.GetSize();
	glPushMatrix();

	for ( i=iybcsnum;i>iCurrentLine;i--)
	{

		fb=YBCs[i-1].fB;
		fy=YBCs[i-1].fY;
		fc=YBCs[i-1].fC;
		ftr=YBCs[i-1].fR;
		if(i!=iCurrentLine+1){
			//fc
			glRotatef(-fc,0.0f,0.0f,1.0f);// 绕Z 轴旋转fc
			//fb
			glTranslatef(0.0f,ftr,0.0f);  //沿Y走fTR
			glRotatef(-fb,1.0f,0.0f,0.0f);// 绕Z 轴旋转fc
			glTranslatef(0.0,-ftr,0.0f);  //沿Y走-fTR
			//fy
			glTranslatef(fy,0,0.0f);  //沿Y走fY
		}
	}
	 fGuanC=90-YBCs[iCurrentLine].fC;
	 fGuanOutR=YBCs[iCurrentLine].fR;
	glPushMatrix();	  

    glClipPlane(GL_CLIP_PLANE0, clipPlane);
    glPushMatrix();
    glRotatef(fGuanC, 0.0F, 0.0F, 1.0F);
    glClipPlane(GL_CLIP_PLANE1, clipPlane1);
    glPopMatrix();
 //  glEnable(GL_STENCIL_TEST);
	glEnable(GL_CLIP_PLANE0);
	glEnable(GL_CLIP_PLANE1);

	glutSolidTorus(fGuanInR,fGuanOutR,30,50);
	glDisable(GL_CLIP_PLANE0);
	glDisable(GL_CLIP_PLANE1);
    glPopMatrix();

	glPopMatrix();  
	
//    glBegin(GL_QUADS);
//    glVertex3fv(clipPlaneVerts[0]);
//    glVertex3fv(clipPlaneVerts[1]);
//    glVertex3fv(clipPlaneVerts[2]);
//    glVertex3fv(clipPlaneVerts[3]);
//    glEnd();
}



void CWanGuanView::CreatePipeView()
{
	int i,iYbcNum;
	YBCArray tmpYBCArray;
	iYbcNum=gYBCs.GetSize();
	for(i=0;i<iYbcNum;i++)//产生前iYbcNum行个YBC
	{

		tmpYBCArray.Add(gYBCs[i]);
	}
	GLfloat ambient[4] = { 0.05F, 0.05F, 0.05F, 1.0F };
    GLfloat diffuse[4] = { 0.6F, 0.0F, 0.2F, 1.0F };
	GLfloat specular[4] = { 1.0F, 1.0F, 1.0F, 1.0F };
	GLfloat diffuse1[4] = { 1.0F, 1.0F, 0.0F, 1.0F };

	for( i=0 ;i<iYbcNum;i++)
	{	
	//设置材质

		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse);
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0F);
			drawCylinder(fGuanR,tmpYBCArray,i);
		
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse1);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse1);

			drawTorus(fGuanR,tmpYBCArray,i);	
		}

}

void CWanGuanView::FormingProcessView()
{
	int i,iGuanDuan,iGuanDuanNum,iYBCNum;
	CGuanDuan tmpGD;
	iGuanDuanNum=gGuanDuans.GetSize();
	for (i=0;i<iGuanDuanNum;i++)
	{
		tmpGD=gGuanDuans[i];

		if(fGuanCurrentPos>gGuanDuans[i].fStart && fGuanCurrentPos<=gGuanDuans[i].fEnd)
			break;
	}
//	if(fGuanCurrentPos==gGuanDuans[i].fEnd && gGuanDuans[i].fB!=0)
//	{
//		//绕B轴旋转
//	}
	if (fGuanCurrentPos==0){
		
		return;
	}
	if (fGuanCurrentPos>=fGuanTotalL){
		fGuanCurrentPos=0;
		return;
	}
	switch(gGuanDuans[i].iType){
	case 1:
			iYBCNum=i/2+1;
			FormingProcessViewSub(iYBCNum,i,1);
			break;
	case 2:
			iYBCNum=(i-1)/2+1;
			FormingProcessViewSub(iYBCNum,i,2);
			break;
	case 3:
			iYBCNum=i/2+1;
			FormingProcessViewSub(iYBCNum,i,3);
			break;

	}
	 
}

void CWanGuanView::CalCreatedPipe()
{
	int i,iybcsnum;
	float fGDL;
	CGuanDuan tmpGD;
	iybcsnum=gYBCs.GetSize();
	gGuanDuans.RemoveAll();
	fGuanTotalL=0;
	for (i=0;i<iybcsnum;i++){
		tmpGD.fStart=fGuanTotalL;
		fGuanTotalL=fGuanTotalL+gYBCs[i].fY;
		tmpGD.fEnd=fGuanTotalL;
		tmpGD.fTR=gYBCs[i].fR;

		tmpGD.fB=gYBCs[i].fB;			
		if(gYBCs[i].fB!=0)
		{
			tmpGD.iType=3;
		}else{
			tmpGD.iType=1;
		}
		gGuanDuans.Add(tmpGD);

		tmpGD.fStart=fGuanTotalL;
		fGuanTotalL=fGuanTotalL+gYBCs[i].fC*3.1415926/180*gYBCs[i].fR;
		tmpGD.fEnd=fGuanTotalL;
		tmpGD.iType=2;
		tmpGD.fTR=gYBCs[i].fR;
		gGuanDuans.Add(tmpGD);
		
	}

}


void CWanGuanView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	fGuanR=5;
	iViewMode=1;
	fGuanCurrentPos=0;
	bSingleB=false;
	fGuanDuanCurrentB=0;
	fSimulationSpeed=1;
	m_bRotateOperation=true;
	m_bMoveOperation=false;
	// TODO: Add your specialized code here and/or call the base class
}




void CWanGuanView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
//	fGuanCurrentPos=100;
	if (fGuanCurrentPos<fGuanTotalL && ! bSingleB)
		fGuanCurrentPos=fGuanCurrentPos+fSimulationSpeed;
	if (fGuanCurrentPos>fGuanTotalL)
		fGuanCurrentPos=fGuanTotalL;
	if(fGuanDuanCurrentB<fGuanDuanB)
		fGuanDuanCurrentB=fGuanDuanCurrentB+fSimulationSpeed;
//	fGuanCurrentPos=fGuanTotalL-80;
	CView::OnTimer(nIDEvent);
	InvalidateRect(NULL,FALSE);

}

void CWanGuanView::FormingProcessViewSub(int iYbcNum,int iCurrentGuanDuan, int iProcessType)
{
	int i;
	YBCArray tmpYBCArray;
	float fTmpC;
	float ftmp,fGanSheQu=0.5;//设定Y的几分之几为出干涉区
//	iYbcNum=gYBCs.GetSize();
	drawGuanNotFormed(fGuanCurrentPos,iCurrentGuanDuan);
	for(i=0;i<iYbcNum;i++)//产生前iYbcNum行个YBC
	{
		if(i==iYbcNum-1){

			switch(iProcessType){
			case 1:
				tmpYBCArray.Add(gYBCs[i]);
				tmpYBCArray[i].fY=fGuanCurrentPos-gGuanDuans[iCurrentGuanDuan].fStart;
				tmpYBCArray[i].fC=0;
				break;
			case 2:
				tmpYBCArray.Add(gYBCs[i]);
//				tmpYBCArray[i].fY=fGuanCurrentPos-gGuanDuans[iDuanNum].fStart;
				fTmpC=(fGuanCurrentPos-gGuanDuans[iCurrentGuanDuan].fStart)/tmpYBCArray[i].fR;
				fTmpC=fTmpC*180/3.1415926;
				tmpYBCArray[i].fC=fTmpC;
				break;
			case 3:
				tmpYBCArray.Add(gYBCs[i]);
				tmpYBCArray[i].fY=fGuanCurrentPos-gGuanDuans[iCurrentGuanDuan].fStart;
				tmpYBCArray[i].fC=0;
				fGuanDuanB=tmpYBCArray[i].fB;
				ftmp=(fGuanCurrentPos-gGuanDuans[iCurrentGuanDuan].fStart)/(gGuanDuans[iCurrentGuanDuan].fEnd-gGuanDuans[iCurrentGuanDuan].fStart);
				if (ftmp>fGanSheQu){
					if (fGuanDuanCurrentB<fGuanDuanB){
						tmpYBCArray[i].fB=fGuanDuanCurrentB;
						if( fGuanCurrentPos>gGuanDuans[iCurrentGuanDuan].fEnd-2 )
							bSingleB=true;
					}else{
							bSingleB=false;
					}
				}else{
					bSingleB=false;
					tmpYBCArray[i].fB=0;
					fGuanDuanCurrentB=0;
				}
				break;
			}
			break;
		}
		tmpYBCArray.Add(gYBCs[i]);
	}
	GLfloat ambient[4] = { 0.05F, 0.05F, 0.05F, 1.0F };
    GLfloat diffuse[4] = { 0.6F, 0.0F, 0.2F, 1.0F };
	GLfloat specular[4] = { 1.0F, 1.0F, 1.0F, 1.0F };
	GLfloat diffuse1[4] = { 1.0F, 1.0F, 0.0F, 1.0F };

	for( i=0 ;i<iYbcNum;i++)
	{	
	//设置材质
		if(i==iYbcNum-1){
			switch(iProcessType){
				case 3:
				   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
					glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
					glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse);
					glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0F);
					drawCylinder(fGuanR,tmpYBCArray,i);
					glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse1);
					glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse1);
					drawTorus(fGuanR,tmpYBCArray,i);
					break;

			case 2:
				   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
					glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
					glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse);
					glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0F);
					drawCylinder(fGuanR,tmpYBCArray,i);
					glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse1);
					glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse1);
					drawTorus(fGuanR,tmpYBCArray,i);
					break;
				case 1:
				   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
					glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
					glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse);
					glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0F);
					drawCylinder(fGuanR,tmpYBCArray,i);
					break;
			}
			return;
		}
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0F);
		drawCylinder(fGuanR,tmpYBCArray,i);
	
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse1);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse1);

		drawTorus(fGuanR,tmpYBCArray,i);	
	}

}

void CWanGuanView::drawGuanNotFormed(float fGuanCurrentPos,int iCurrentGuanDuan)
{

	int iGuanDuansnum,i;
	float fGuanL,fStart,fEnd;
	GLUquadricObj *obj = gluNewQuadric();
	gluQuadricDrawStyle(obj,GLU_FILL);
	gluQuadricNormals(obj,GLU_SMOOTH);
	gluQuadricOrientation(obj,GLU_OUTSIDE);
	float fb,fy,fc,ftr;
	GLfloat ambient[4] = { 0.05F, 0.05F, 0.05F, 1.0F };
    GLfloat diffuse[4] = { 0.6F, 0.0F, 0.2F, 1.0F };
	GLfloat specular[4] = { 1.0F, 1.0F, 1.0F, 1.0F };
	GLfloat diffuse1[4] = { 1.0F, 1.0F, 0.0F, 1.0F };
	iGuanDuansnum=gGuanDuans.GetSize();
	glPushMatrix();

	for ( i=iCurrentGuanDuan;i<iGuanDuansnum;i++)
	{
		if(gGuanDuans[i].iType==1 || gGuanDuans[i].iType==3){
			glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
			glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse);
			glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0F);
		}else{
			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse1);
			glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, diffuse1);
		}

	//		if(i!=iCurrentLine+1){
	//fy
	//		}
		if(i==iCurrentGuanDuan){
			fStart=fGuanCurrentPos;
			fEnd=gGuanDuans[i].fEnd;
			fGuanL=fEnd-fStart;
			ftr=gGuanDuans[i].fTR;
		//	glTranslatef(-fGuanL-fStart,0,0.0f);  //沿Y走fY

			glPushMatrix();	 
			glTranslatef(-fGuanL,ftr,0.0f);  //沿Y走fTR
			glRotatef(90.0f,0.0f,1.0f,0.0f);// 绕Y 轴旋转90
			gluCylinder(obj,fGuanR,fGuanR,fGuanL,90,1);
			glPopMatrix(); 
//			break;
		}else{
			fStart=gGuanDuans[i].fStart;
			fEnd=gGuanDuans[i].fEnd;
			fGuanL=fEnd-fStart;
			ftr=gGuanDuans[i].fTR;
		//	glTranslatef(-fGuanL-fStart,0,0.0f);  //沿Y走fY

			glPushMatrix();	 
			glTranslatef(-fGuanL-fStart+fGuanCurrentPos,ftr,0.0f);  //沿Y走fTR
			glRotatef(90.0f,0.0f,1.0f,0.0f);// 绕Y 轴旋转90
			gluCylinder(obj,fGuanR,fGuanR,fGuanL,90,1);
			glPopMatrix();
		}

	}
	glPopMatrix();  
	gluDeleteQuadric(obj);
}

⌨️ 快捷键说明

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