📄 dialogdlg.cpp
字号:
glVertex3f(E_A2[i][j+1].x,E_A2[i][j+1].y,E_A2[i][j+1].z+1.5);
glEnd();
}
}
for(i=0;i<M;i++)
{
for(j=0;j<M-1;j++)
{
glBegin(GL_LINE_STRIP);
glVertex3f(E_A2[j][i].x,E_A2[j][i].y,E_A2[j][i].z+1.5);
glVertex3f(E_A2[j+1][i].x,E_A2[j+1][i].y,E_A2[j+1][i].z+1.5);
glEnd();
}
}
for(i=0;i<M;i++)
{
for(j=0;j<M-1;j++)
{
glBegin(GL_LINE_STRIP);
glColor3f(1,1.0f-E_P2[i][j].z*5-1,0.0);
glVertex3f(E_P2[i][j].x,E_P2[i][j].y,E_P2[i][j].z-1.5);
glVertex3f(E_P2[i][j+1].x,E_P2[i][j+1].y,E_P2[i][j+1].z-1.5);
glEnd();
}
}
for(i=0;i<M;i++)
{
for(j=0;j<M-1;j++)
{
glBegin(GL_LINE_STRIP);
glColor3f(1,1.0f-E_P2[i][j].z*5-1,0.0);
glVertex3f(E_P2[j][i].x,E_P2[j][i].y,E_P2[j][i].z-1.5);
glVertex3f(E_P2[j+1][i].x,E_P2[j+1][i].y,E_P2[j+1][i].z-1.5);
glEnd();
}
}
}
void CDialogDlg::DrawSurface()
{
int i,j;
glRotatef(-30,1.0,0,0);
glRotatef(angle1,0.0,1.0,0.1);
glRotatef(angle2,1.0,0.0,0.1);
for(i=0;i<M-1;i++)
{
for(j=0;j<M-1;j++)
{
glColor3f(1,E_A2[i][j].z,0.0);
glBegin(GL_POLYGON);
glVertex3f(E_A2[i][j].x,E_A2[i][j].y,E_A2[i][j].z+1.5);
glVertex3f(E_A2[i][j+1].x,E_A2[i][j+1].y,E_A2[i][j+1].z+1.5);
glVertex3f(E_A2[i+1][j+1].x,E_A2[i+1][j+1].y,E_A2[i+1][j+1].z+1.5);
glVertex3f(E_A2[i+1][j].x,E_A2[i+1][j].y,E_A2[i+1][j].z+1.5);
glEnd();
}
}
for(i=0;i<M-1;i++)
{
for(j=0;j<M-1;j++)
{
glBegin(GL_POLYGON);
glColor3f(1,1.0f-E_P2[i][j].z*5-1,0.0);
glVertex3f(E_P2[i][j].x,E_P2[i][j].y,E_P2[i][j].z-1.5);
glVertex3f(E_P2[i][j+1].x,E_P2[i][j+1].y,E_P2[i][j+1].z-1.5);
glVertex3f(E_P2[i+1][j+1].x,E_P2[i+1][j+1].y,E_P2[i+1][j+1].z-1.5);
glVertex3f(E_P2[i+1][j].x,E_P2[i+1][j].y,E_P2[i+1][j].z-1.5);
glEnd();
}
}
}
void CDialogDlg::Draw_tiao()
{
int j;
for(j=0;j<M-1;j++)
{
glColor3f(1,E_A2[M/2][j].z,0.0);
glBegin(GL_LINE_STRIP);
glVertex3f(0,E_A2[M/2][j].y,E_A2[M/2][j].z+1.5);
glVertex3f(0,E_A2[M/2][j+1].y,E_A2[M/2][j+1].z+1.5);
glEnd();
}
for(j=0;j<M-1;j++)
{
glBegin(GL_LINE_STRIP);
glColor3f(1,1.0f-E_P2[M/2][j].z*5-1,0.0);
glVertex3f(0,E_P2[M/2][j].y,E_P2[M/2][j].z-1.5);
glVertex3f(0,E_P2[M/2][j+1].y,E_P2[M/2][j+1].z-1.5);
glEnd();
}
}
void CDialogDlg::OnRadio_P()
{
// TODO: Add your control notification handler code here
mode=flag_point;
UpdateData(TRUE);
m_opengl.Invalidate(false);
}
void CDialogDlg::OnRadio_L()
{
// TODO: Add your control notification handler code here
mode=flag_line;
UpdateData(TRUE);
m_opengl.Invalidate(false);
}
void CDialogDlg::OnRadio_F()
{
// TODO: Add your control notification handler code here
mode=flag_surface;
UpdateData(TRUE);
m_opengl.Invalidate(false);
}
void CDialogDlg::OnRadioLine()
{
// TODO: Add your control notification handler code here
tiao_ping=flag_tiao;
}
void CDialogDlg::OnRadioPingxing()
{
// TODO: Add your control notification handler code here
tiao_ping=flag_ping;
}
void CDialogDlg::OnReleasedcaptureSliderB(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_blue=m_B.GetPos()/100.0;
UpdateData(false);
m_opengl.Invalidate(false);
*pResult = 0;
}
void CDialogDlg::OnReleasedcaptureSliderG(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_green=m_G.GetPos()/100.0;
UpdateData(false);
m_opengl.Invalidate(false);
*pResult = 0;
}
void CDialogDlg::OnReleasedcaptureSliderR(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_red=m_R.GetPos()/100.0;
UpdateData(false);
m_opengl.Invalidate(false);
*pResult = 0;
}
void CDialogDlg::OnButtonLeft()
{
// TODO: Add your control notification handler code here
angle1+=5;
UpdateData(false);
m_opengl.Invalidate(false);
}
void CDialogDlg::OnButtonRight()
{
// TODO: Add your control notification handler code here
angle1-=5;
UpdateData(false);
m_opengl.Invalidate(false);
}
void CDialogDlg::Init_Curve(float *ctrlpoints_a1)
{
// 定义一个二维求值器
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 10,
0, 1, 12, 10, ctrlpoints_a1);
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
// 定义二维网格坐标
glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
SetupLighting();
}
void CDialogDlg::Diedai()
{
//diff_min=...
int i,m;
float buffer_cos=0;
float buffer_sin=0;
float buffer_Re=0;
float buffer_Im=0;
float theta;
float c=0;
float step;
float cnst=2*a/(M*sqrt(m_LMDA*L));
float K;
float guiyi;
K=2*PI/m_LMDA;
L=m_LMDA*m_LONG;
c=K/(2*L);
theta=-K*L/2+PI/4;
step=2*a/M;
/////////////u1---->u2的衍射//////////
for(i=0;i<M;i++)
{
buffer_Re=0;
buffer_Im=0;
for(m=0;m<M;m++)
{
buffer_Re+=step*(u1[m].Re*cos(c*(u2[i].x-u1[m].x)*(u2[i].x-u1[m].x))
+u1[m].Im*sin(c*(u2[i].x-u1[m].x)*(u2[i].x-u1[m].x)));
buffer_Im+=step*(-u1[m].Re*sin(c*(u2[i].x-u1[m].x)*(u2[i].x-u1[m].x))
+u1[m].Im*cos(c*(u2[i].x-u1[m].x)*(u2[i].x-u1[m].x)));
}
u2[i].x=-a+2*a*i/M;
u2[i].Re=buffer_Re;
u2[i].Im=buffer_Im;
}
guiyi=sqrt(u2[M/2].Re*u2[M/2].Re + u2[M/2].Im*u2[M/2].Im);
//归一化
for(i=0;i<M;i++)
{
u2[i].Re/=guiyi;
u2[i].Im/=guiyi;
u2[i].A=u2[i].GetAmplitude(u2[i].Re,u2[i].Im);
u2[i].P=u2[i].GetPhrase(u2[i].Im,u2[i].Re);
}
for(i=0;i<m-1;i++)
{
if(u2[i+1].P-u2[i].P>PI)
for(int k=0;k<=i;k++)
u2[k].P+=2*PI;
if(u2[i+1].P-u2[i].P<-PI)
for(int k=0;k<=i;k++)
u2[k].P-=2*PI;
}
for(i=0;i<M;i++)
u2[i].P-=u2[M/2].P;
/////////////u2---->u1的衍射//////////
for(i=0;i<M;i++)
{
buffer_Re=0;
buffer_Im=0;
for(m=0;m<M;m++)
{
buffer_Re+=step*(u2[m].Re*cos(c*(u1[i].x-u2[m].x)*(u1[i].x-u2[m].x))
+u2[m].Im*sin(c*(u1[i].x-u2[m].x)*(u1[i].x-u2[m].x)));
buffer_Im+=step*(-u2[m].Re*sin(c*(u1[i].x-u2[m].x)*(u1[i].x-u2[m].x))
+u2[m].Im*cos(c*(u1[i].x-u2[m].x)*(u1[i].x-u2[m].x)));
}
u1[i].x=-a+2*a*i/M;
u1[i].Re=buffer_Re;
u1[i].Im=buffer_Im;
}
guiyi=sqrt(u1[M/2].Re*u1[M/2].Re+u1[M/2].Im*u1[M/2].Im);
//归一化
for(i=0;i<M;i++)
{
u1[i].Re/=guiyi;
u1[i].Im/=guiyi;
u1[i].A=u1[i].GetAmplitude(u1[i].Re,u1[i].Im);
u1[i].P=u1[i].GetPhrase(u1[i].Im,u1[i].Re);
}
for(i=0;i<m-1;i++)
{
if(u1[i+1].P-u1[i].P>PI)
for(int k=0;k<=i;k++)
u1[k].P+=2*PI;
if(u1[i+1].P-u1[i].P<-PI)
for(int k=0;k<=i;k++)
u1[k].P-=2*PI;
}
for(i=0;i<M;i++)
u1[i].P-=u1[M/2].P;
}
void CDialogDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
time++;
m_Progress.StepIt();
if(time<m_count)
{
Diedai();
}
else
{
time=0;
KillTimer(1);
MessageBox("Complete!");
}
m_opengl.Invalidate();
CDialog::OnTimer(nIDEvent);
}
void CDialogDlg::OnUp()
{
// TODO: Add your control notification handler code here
angle2+=2;
UpdateData(false);
m_opengl.Invalidate(false);
}
void CDialogDlg::OnDown()
{
// TODO: Add your control notification handler code here
angle2-=2;
UpdateData(false);
m_opengl.Invalidate(false);
}
void CDialogDlg::translate_2D_3D()
{
int i,j;
for(i=0;i<M;i++)
for(j=0;j<M;j++)
{
E_A2[i][j].x=-a+2*a*i/M;
E_A2[i][j].y=-a+2*a*j/M;
E_A2[i][j].z=(u2[i].A)*(u2[j].A);
E_P2[i][j].x=-a+2*a*i/M;
E_P2[i][j].y=-a+2*a*j/M;
E_P2[i][j].z=(u2[i].P+u2[j].P);
}
for(i=M/2+1;i<M;i++)
for(j=0;j<M/2+1;j++)
{
E_P2[i][j].z-=E_P2[M/2][M/2+1].z;
}
for(i=0;i<M/2+1;i++)
for(j=M/2+1;j<M;j++)
{
E_P2[i][j].z-=E_P2[M/2][M/2+1].z;
}
for(i=M/2+2;i<M;i++)
for(j=M/2+1;j<M;j++)
{
E_P2[i][j].z-=E_P2[M/2+1][M/2+1].z;
}
for(i=M/2+1;i<M;i++)
{
E_P2[M/2+1][i].z=E_P2[M/2+2][i].z;
}
for(i=M/2+2;i<M;i++)
{
E_P2[M/2][i].z=E_P2[M/2-1][i].z;
}
}
void CDialogDlg::OnChangeLmda()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CDialogDlg::OnChangeLong()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CDialogDlg::OnChangeX()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
a=m_X*m_LMDA;
}
void CDialogDlg::OnChangeTimes()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_Progress.SetRange(0,m_count);
}
void CDialogDlg::OnPause()
{
// TODO: Add your control notification handler code here
KillTimer(1);
}
void CDialogDlg::OnContinue()
{
// TODO: Add your control notification handler code here
SetTimer(1,300,NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -