📄 dialogdlg.cpp
字号:
// DialogDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Dialog.h"
#include "DialogDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogDlg dialog
CDialogDlg::CDialogDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDialogDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogDlg)
m_X = 20;
m_LONG = 100;
m_LMDA = 0.625f;
RAD = 3.141592654/180;
mode=flag_line;
m_i=20;
m_j=20;
m_red=0.0;
m_green=0.0;
m_blue=0.0;
angle1=200;
angle2=-15.0;
a=m_X*m_LMDA;
time=0;
m_count = 150;
tiao_ping=flag_tiao;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
for(int i=0;i<M;i++)
{
u1[i].Init_point(-a+2*a*i/M,1,0,1,0);
u2[i].Init_point(-a+2*a*i/M,0,0,0,0);
}
L=m_LMDA*m_LONG;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDialogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogDlg)
DDX_Control(pDX, IDC_SLIDER_R, m_R);
DDX_Control(pDX, IDC_SLIDER_G, m_G);
DDX_Control(pDX, IDC_SLIDER_B, m_B);
DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
DDX_Control(pDX, IDC_OPENGLCTRL, m_opengl);
DDX_Text(pDX, IDC_X, m_X);
DDX_Text(pDX, IDC_LONG, m_LONG);
DDX_Text(pDX, IDC_LMDA, m_LMDA);
DDX_Text(pDX, IDC_TIME, m_count);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialogDlg, CDialog)
//{{AFX_MSG_MAP(CDialogDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDI_EXIT, OnExit)
ON_COMMAND(IDI_ABOUT, OnAbout)
ON_BN_CLICKED(IDOK, OnRun)
ON_BN_CLICKED(IDC_RADIO1, OnRadio_P)
ON_BN_CLICKED(IDC_RADIO2, OnRadio_L)
ON_BN_CLICKED(IDC_RADIO3, OnRadio_F)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_B, OnReleasedcaptureSliderB)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_G, OnReleasedcaptureSliderG)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_R, OnReleasedcaptureSliderR)
ON_BN_CLICKED(IDC_BUTTON_LEFT, OnButtonLeft)
ON_BN_CLICKED(IDC_BUTTON_RIGHT, OnButtonRight)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_UP, OnUp)
ON_BN_CLICKED(IDC_DOWN, OnDown)
ON_BN_CLICKED(IDCLEAR, OnClear)
ON_BN_CLICKED(IDC_RADIO_LINE, OnRadioLine)
ON_BN_CLICKED(IDC_RADIO_PINGXING, OnRadioPingxing)
ON_EN_CHANGE(IDC_LMDA, OnChangeLmda)
ON_EN_CHANGE(IDC_LONG, OnChangeLong)
ON_EN_CHANGE(IDC_X, OnChangeX)
ON_EN_CHANGE(IDC_TIME, OnChangeTimes)
ON_BN_CLICKED(IDC_PAUSE, OnPause)
ON_BN_CLICKED(IDC_CONTINUE, OnContinue)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogDlg message handlers
BOOL CDialogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_R.SetRange(0,100,false);
m_G.SetRange(0,100,false);
m_B.SetRange(0,100,false);
m_R.SetTicFreq(1);
m_G.SetTicFreq(1);
m_B.SetTicFreq(1);
m_R.SetPos(m_red*100);
m_G.SetPos(m_green*100);
m_B.SetPos(m_blue*100);
m_Progress.SetRange(0,m_count);
m_Progress.SetPos(0);
m_Progress.SetStep(1);
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDialogDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDialogDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDialogDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CDialogDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::Create(IDD, pParentWnd);
}
void CDialogDlg::OnExit()
{
// TODO: Add your command handler code here
OnOK();
}
void CDialogDlg::OnAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
BEGIN_EVENTSINK_MAP(CDialogDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CDialogDlg)
ON_EVENT(CDialogDlg, IDC_OPENGLCTRL, 4 /* ReDraw */, OnReDrawOpengl, VTS_NONE)
ON_EVENT(CDialogDlg, IDC_OPENGLCTRL, 2 /* InitOpengl */, OnInitOpengl, VTS_NONE)
ON_EVENT(CDialogDlg, IDC_OPENGLCTRL, 6 /* ReSize */, OnReSizeOpengl, VTS_I2 VTS_I2)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CDialogDlg::OnReDrawOpengl()
{
// TODO: Add your control notification handler code here
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enable Alpha Mixtrue
glEnable(GL_BLEND);
GLUquadricObj *obj; // Inital to Draw 3D Object
obj = gluNewQuadric(); // Set Quadric Object
gluQuadricDrawStyle(obj,GLU_FILL); // Set 3D Object Properties
gluQuadricNormals(obj,GLU_SMOOTH); // Set Normals
gluQuadricTexture(obj,GL_FALSE); // Disable Texture
glDisable(GL_CULL_FACE); // Close Cull Face
glClearColor(m_red,m_green,m_blue,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glLineWidth(1.0f);
glPointSize(1.0f);
glScalef(0.06f,0.25f,0.03f);
translate_2D_3D();
if(tiao_ping==flag_ping)
{
if(mode==flag_point)
DrawPoint();
else if(mode==flag_line)DrawLine();
else DrawSurface();
}
else Draw_tiao();
SwapBuffers(::wglGetCurrentDC());
}
void CDialogDlg::OnReSizeOpengl(short x, short y)
{
// TODO: Add your control notification handler code here
}
void CDialogDlg::OnInitOpengl()
{
// TODO: Add your control notification handler code here
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glEnable(GL_BLEND);
glPolygonMode(GL_FRONT,GL_FILL);
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0,10.0,-6.0,6.0,-50.0,50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-90,1,0,0); // Rotate -90 round X
glRotatef(-90,0,0,1); // Rotate -90 round Z
}
void CDialogDlg::OnClear()
{
// TODO: Add your control notification handler code here
glClearColor(m_red,m_green,m_blue,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
for(int i=0;i<M;i++)
{
u1[i].Init_point(-a+2*a*i/M,1,0,1,0);
u2[i].Init_point(-a+2*a*i/M,1,0,1,0);
}
time=0;
tiao_ping=flag_tiao;
KillTimer(1);
SwapBuffers(::wglGetCurrentDC());
}
void CDialogDlg::OnRun()
{
// TODO: Add your control notification handler code here
m_opengl.Invalidate();
for(int i=0;i<M;i++)
{
u1[i].Init_point(-a+2*a*i/M,1,0,1,0);
u2[i].Init_point(-a+2*a*i/M,1,0,1,0);
}
m_Progress.SetPos(0);
SetTimer(1,300,NULL);
}
void CDialogDlg::ReShape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-4.0, 4.0, -4.0*(GLfloat)h/(GLfloat)w,
4.0*(GLfloat)h/(GLfloat)w, -4.0, 4.0);
else
glOrtho(-4.0*(GLfloat)w/(GLfloat)h,
4.0*(GLfloat)w/(GLfloat)h, -4.0, 4.0, -4.0, 4.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CDialogDlg::SetupLighting()
{
GLfloat mat_ambient[]= { 0.2, 0.2, 0.2, 1.0 };
GLfloat mat_diffuse[]= { 0.8, 0.8, 0.8, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat mat_shininess[] = { 50.0 };
GLfloat light0_diffuse[]= { 0.0, 0.0, 1.0, 1.0};
GLfloat light0_position[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat spot_direction[]={ 1.0,1.0,-1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION,light0_position);
glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,0.5);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
}
void CDialogDlg::DrawPoint()
{
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);
glBegin(GL_POINTS);
for(i=0;i<M;i++)
for(j=0;j<M;j++)
{
glColor3f(1,E_A2[i][j].z,0.0);
glVertex3f(E_A2[i][j].x,E_A2[i][j].y,E_A2[i][j].z+1.5);
}
glEnd();
glBegin(GL_POINTS);
for(i=0;i<M;i++)
for(j=0;j<M;j++)
{
glColor3f(1,1.0f-E_P2[i][j].z-1,0.0);
glVertex3f(E_P2[i][j].x,E_P2[i][j].y,E_P2[i][j].z-1.0);
}
glEnd();
}
void CDialogDlg::DrawLine()
{
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;i++)
{
for(j=0;j<M-1;j++)
{
glColor3f(1,E_A2[i][j].z,0.0);
glBegin(GL_LINE_STRIP);
glVertex3f(E_A2[i][j].x,E_A2[i][j].y,E_A2[i][j].z+1.5);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -