19,469
社区成员
发帖
与我相关
我的任务
分享void CMy2012302590190Doc::OnDrawBall()
{
// TODO: Add your command handler code here
CBallDlg dlg;
if(dlg.DoModal()==IDOK)
{
}
}



m_spin.SetRange(-200,200);,所以我去掉这个旋钮项就好了,太感谢你了


#if !defined(AFX_BALLDLG_H__0049B66C_23A9_4D09_9987_6118267BCCDE__INCLUDED_)
#define AFX_BALLDLG_H__0049B66C_23A9_4D09_9987_6118267BCCDE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// BallDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CBallDlg dialog
class CBallDlg : public CDialog
{
// Construction
public:
CBallDlg(CWnd* pParent = NULL); // standard constructor
double CalculateCos(int a,int b,int c);
double CalculateCosi(int a,int b,int c);
void Draw();
// Dialog Data
//{{AFX_DATA(CBallDlg)
enum { IDD = IDD_BALL };
CSpinButtonCtrl m_spin;
int m_tt;
int m_R;
int m_lightX;
int m_lightY;
int m_lightZ;
double m_man;
double m_jing;
double m_hjgq;
double m_gdgq;
int m_colorR;
int m_colorG;
int m_colorB;
//}}AFX_DATA
public:
double guangqiang(int a,int b,int c);
int n;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBallDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CBallDlg)
afx_msg void OnPaint();
virtual void OnOK();
afx_msg void OnReset();
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_BALLDLG_H__0049B66C_23A9_4D09_9987_6118267BCCDE__INCLUDED_)
这是BallDlg.cpp:
// BallDlg.cpp : implementation file
//
#include "stdafx.h"
#include "2012302590190.h"
#include "BallDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBallDlg dialog
CBallDlg::CBallDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBallDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBallDlg)
m_tt = 0;
m_R = 0;
m_lightX = 0;
m_lightY = 0;
m_lightZ = 0;
m_man = 0.0;
m_jing = 0.0;
m_hjgq = 0.0;
m_gdgq = 0.0;
m_colorR = 0;
m_colorG = 0;
m_colorB = 0;
//}}AFX_DATA_INIT
}
void CBallDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBallDlg)
DDX_Text(pDX, IDC_LightVar, m_tt);
DDV_MinMaxInt(pDX, m_tt, 0, 255);
DDX_Text(pDX, IDC_Radius, m_R);
DDV_MinMaxInt(pDX, m_R, 30, 110);
DDX_Text(pDX, IDC_X, m_lightX);
DDV_MinMaxInt(pDX, m_lightX, -200, 200);
DDX_Text(pDX, IDC_Y, m_lightY);
DDV_MinMaxInt(pDX, m_lightY, -200, 200);
DDX_Text(pDX, IDC_Z, m_lightZ);
DDV_MinMaxInt(pDX, m_lightZ, 30, 200);
DDX_Text(pDX, IDC_Diffuse, m_man);
DDV_MinMaxDouble(pDX, m_man, 0., 1.);
DDX_Text(pDX, IDC_Mirror, m_jing);
DDV_MinMaxDouble(pDX, m_jing, 0., 1.);
DDX_Text(pDX, IDC_EnvLight, m_hjgq);
DDV_MinMaxDouble(pDX, m_hjgq, 0., 1.);
DDX_Text(pDX, IDC_LightPoint, m_gdgq);
DDV_MinMaxDouble(pDX, m_gdgq, 0., 1.);
DDX_Text(pDX, IDC_R, m_colorR);
DDV_MinMaxInt(pDX, m_colorR, 0, 255);
DDX_Text(pDX, IDC_G, m_colorG);
DDV_MinMaxInt(pDX, m_colorG, 0, 255);
DDX_Text(pDX, IDC_B, m_colorB);
DDV_MinMaxInt(pDX, m_colorB, 0, 255);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBallDlg, CDialog)
//{{AFX_MSG_MAP(CBallDlg)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_Reset, OnReset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBallDlg message handlers
void CBallDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CWnd *pWnd=GetDlgItem(IDC_DRAW);
pWnd->UpdateWindow();
Draw();
// Do not call CDialog::OnPaint() for painting messages
}
void CBallDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData();
Draw();
}
void CBallDlg::Draw()
{
CWnd *pWnd=GetDlgItem(IDC_DRAW);
pWnd->UpdateWindow();
CDC *pDC=pWnd->GetDC();
CRect rect;
pWnd->GetClientRect(rect);
/* int cx,cy;
cx=rect.Width();
cy=rect.Height();
for (int i=0;i<=cx;i++)
for (int j=0;j<=cy;j++)
{
t1=j*m_colorR/cy;
t2=((cy-j)*m_colorG/cy+(cx-i)*m_colorG/cx)/2;
t3=((cy-j)*m_colorB/cy+(cx-i)*m_colorB/cx)/2;
pDC->SetPixel(i,j,RGB(127,127,127));
}*/
CBrush brush(RGB(127,127,200));
CBrush *oldbrush=pDC->SelectObject(&brush);
pDC->Rectangle(rect);
pDC->SelectObject(oldbrush);
brush.DeleteObject();
POINT p;
p=rect.CenterPoint();
int t1,t2,t3;
for (int k=0;k<=m_R;k+=2)
for (int i=-m_R; i<=m_R; i+=2)
for (int j=-m_R; j<=m_R; j++)
{
t1=(int)(m_colorR+guangqiang(i,j,k));
t2=(int)(m_colorG+guangqiang(i,j,k));
t3=(int)(m_colorB+guangqiang(i,j,k));
if (t1>255)t1=255;
if (t2>255)t2=255;
if (t3>255)t3=255;
/* if (0==CalculateCos(i,j,k))
{
pDC->SetPixel((int)(i*m_R/sqrt(i*i+j*j+k*k))+p.x,
(int)(j*m_R/sqrt(i*i+j*j+k*k))+p.y,
RGB(200,guangqiang(i,j,k),guangqiang(i,j,k)));
} else*/
pDC->SetPixel((int)(i*m_R/sqrt(i*i+j*j+k*k))+p.x,
(int)(j*m_R/sqrt(i*i+j*j+k*k))+p.y,
RGB(t1,t2,t3));
}
ReleaseDC(pDC);
}
double CBallDlg::CalculateCos(int a,int b,int c)
{
double x,xn,yn,zn;
xn=a*60/sqrt(a*a+b*b+c*c);
yn=b*60/sqrt(a*a+b*b+c*c);
zn=c*60/sqrt(a*a+b*b+c*c);
x=(double)((m_lightX-xn)*xn+(m_lightY-yn)*yn+(m_lightZ-zn)*zn)/(sqrt(xn*xn+yn*yn+zn*zn)*sqrt((m_lightX-xn)*(m_lightX-xn)+
(m_lightY-yn)*(m_lightY-yn)+(m_lightZ-zn)*(m_lightZ-zn)));
if (x<0)x=0;
return x;
}
double CBallDlg::CalculateCosi(int a,int b,int c)
{
double x,xn,yn,zn;
xn=a*60/sqrt(a*a+b*b+c*c);
yn=b*60/sqrt(a*a+b*b+c*c);
zn=c*60/sqrt(a*a+b*b+c*c);
x=(double)((m_lightX+0-2*xn)*xn+(m_lightY+0-2*yn)*yn+(m_lightZ+90-2*zn)*zn)/(sqrt((m_lightX+0-2*xn)*(m_lightX+0-2*xn)
+(m_lightY+0-2*yn)*(m_lightY+0-2*yn)+(m_lightZ+90-2*zn)*(m_lightZ+90-2*zn))*sqrt(xn*xn+yn*yn+zn*zn));
if (x<0)x=0;
return x;
}
double CBallDlg::guangqiang(int a,int b,int c)
{
// I=Ka*Ia+Kd*Il*cos0+Ks*Il*cosi*cosi*cosi......
// Ka=0.8;Ia=0.6;Kd=0.8;Il=1;Ks=0.85;n=3
double x;
x=m_man*m_hjgq*m_tt+m_man*m_gdgq*m_tt*CalculateCos(a,b,c)+
m_jing*m_gdgq*m_tt*CalculateCosi(a,b,c)*CalculateCosi(a,b,c)*CalculateCosi(a,b,c);
if (x>255)x=255;
return x;
}
void CBallDlg::OnReset()
{
// TODO: Add your control notification handler code here
OnInitDialog();
Draw();
}
BOOL CBallDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_R=50;
m_lightX=100;
m_lightY=0;
m_lightZ=95;
m_man=0.6;
m_jing=0.8;
m_hjgq=0.3;
m_gdgq=0.9;
m_colorR=50;
m_colorG=50;
m_colorB=50;
m_tt=135;
m_spin.SetRange(-200,200);
UpdateData(FALSE);
return TRUE;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}