Create HouseTextureMapping

This commit is contained in:
xixu-me committed 2024-11-26 10:51:13 +08:00
1 parent 9f322bccba
commit de8a8e8d2b
80 files changed
+4942

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
// AET.cpp: implementation of the CAET class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "AET.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAET::CAET()
{
}
CAET::~CAET()
{
}
+32
View File
@@ -0,0 +1,32 @@
// AET.h: interface for the CAET class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CAET_H__D7F2123F_A3AE_40D6_81D8_E403C7E50447__INCLUDED_)
#define AFX_CAET_H__D7F2123F_A3AE_40D6_81D8_E403C7E50447__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "T2.h"
#include "Vector.h"
class CAET
{
public:
CAET();
virtual ~CAET();
public:
double x;//当前x
int yMax;//边的最大y值
double k;//斜率的倒数(x的增量)
CPi2 ps;//起点坐标
CPi2 pe;//终点坐标
CVector ns;//起点法矢量
CVector ne;//终点法矢量
CT2 ts;//起点纹理坐标
CT2 te;//终点纹理坐标
CAET *pNext;
};
#endif // !defined(AFX_CAET_H__D7F2123F_A3AE_40D6_81D8_E403C7E50447__INCLUDED_)
+27
View File
@@ -0,0 +1,27 @@
// Bucket.cpp: implementation of the CBucket class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Bucket.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBucket::CBucket()
{
}
CBucket::~CBucket()
{
}
+24
View File
@@ -0,0 +1,24 @@
// Bucket.h: interface for the CBucket class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CBUCKET_H__B36B2287_DDD5_4BE9_B57A_D359001CB0C5__INCLUDED_)
#define AFX_CBUCKET_H__B36B2287_DDD5_4BE9_B57A_D359001CB0C5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "AET.h"
class CBucket
{
public:
CBucket();
virtual ~CBucket();
public:
int ScanLine;
CAET *pET;
CBucket *pNext;
};
#endif // !defined(AFX_CBUCKET_H__B36B2287_DDD5_4BE9_B57A_D359001CB0C5__INCLUDED_)
+52
View File
@@ -0,0 +1,52 @@
// Face.cpp: implementation of the CFace class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Face.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFace::CFace()
{
vI=NULL;
t=NULL;
fNormal=CVector(CP3(0.0,0.0,1.0));
}
CFace::~CFace()
{
if(vI!=NULL)
{
delete []vI;
vI=NULL;
}
if(t!=NULL)
{
delete[] t;
t=NULL;
}
}
void CFace::SetNum(int n)
{
vN=n;
vI=new int[n];
t=new CT2[n];
}
void CFace::SetFaceNormal(CP3 pt0,CP3 pt1,CP3 pt2)//¼ÆËãÐ¡Ãæ·¨Ê¸Á¿
{
CVector V01(pt0,pt1);
CVector V02(pt0,pt2);
fNormal=Cross(V01,V02);
}
+28
View File
@@ -0,0 +1,28 @@
// Face.h: interface for the CFace class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_FACE_H__82BF93AE_A82E_407D_AF42_6E6608253C1C__INCLUDED_)
#define AFX_FACE_H__82BF93AE_A82E_407D_AF42_6E6608253C1C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "T2.h"
#include "Vector.h"
class CFace
{
public:
CFace();
virtual ~CFace();
void SetNum(int);//设置小面的顶点数
void SetFaceNormal(CP3,CP3,CP3);//设置小面法矢量
public:
int vN; //小面的顶点数
int *vI; //小面的顶点索引
CVector fNormal; //小面的法矢量
CT2 *t; //纹理顶点动态数组
};
#endif // !defined(AFX_FACE_H__82BF93AE_A82E_407D_AF42_6E6608253C1C__INCLUDED_)
+79
View File
@@ -0,0 +1,79 @@
// Light.cpp: implementation of the CLight class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Light.h"
#include "math.h"
#define PI 3.14159265
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLight::CLight()
{
L_Diffuse=CRGB(0.0,0.0,0.0);//光源的漫反射颜色
L_Specular=CRGB(1.0,1.0,1.0);//光源镜面高光颜色
L_Position.x=0.0,L_Position.y=0.0,L_Position.z=1000;//光源位置直角坐标
L_R=1000,L_Phi=0,L_Theta=0;//光源位置球坐标
L_C0=1.0;//常数衰减系数
L_C1=0.0;//线性衰减系数
L_C2=0.0;//二次衰减系数
L_OnOff=TRUE;//光源开启
}
CLight::~CLight()
{
}
void CLight::SetDiffuse(CRGB dif)
{
L_Diffuse=dif;
}
void CLight::SetSpecular(CRGB spe)
{
L_Specular=spe;
}
void CLight::SetPosition(double x,double y,double z)
{
L_Position.x=x;
L_Position.y=y;
L_Position.z=z;
}
void CLight::SetGlobal(double r,double phi,double theta)
{
L_R=r;
L_Phi=phi;
L_Theta=theta;
}
void CLight::SetOnOff(BOOL onoff)
{
L_OnOff=onoff;
}
void CLight::SetCoef(double c0,double c1,double c2)
{
L_C0=c0;
L_C1=c1;
L_C2=c2;
}
void CLight::GlobalToXYZ()
{
L_Position.x=L_R*sin(L_Phi*PI/180)*sin(L_Theta*PI/180);
L_Position.y=L_R*cos(L_Phi*PI/180);
L_Position.z=L_R*sin(L_Phi*PI/180)*cos(L_Theta*PI/180);
}
+36
View File
@@ -0,0 +1,36 @@
// Light.h: interface for the CLight class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_LIGHT_H__ACA1A2A6_E72D_4EBC_B919_5C0AC538F456__INCLUDED_)
#define AFX_LIGHT_H__ACA1A2A6_E72D_4EBC_B919_5C0AC538F456__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "P3.h"
class CLight
{
public:
CLight();
virtual ~CLight();
void SetDiffuse(CRGB);//设置光源的漫反射光
void SetSpecular(CRGB);//设置光源的镜面反射光
void SetPosition(double,double,double);//设置光源的直角坐标位置
void SetGlobal(double,double,double);//设置光源的球坐标位置
void SetCoef(double,double,double);//设置光强的衰减系数
void SetOnOff(BOOL);//设置光源开关状态
void GlobalToXYZ();//球坐标转换为直角坐标
public:
CRGB L_Diffuse;//光的漫反射颜色
CRGB L_Specular;//光的镜面高光颜色
CP3 L_Position;//光源的位置
double L_R,L_Phi,L_Theta;//光源球坐标
double L_C0;//常数衰减系数
double L_C1;//线性衰减系数
double L_C2;//二次衰减系数
BOOL L_OnOff;//光源开关
};
#endif // !defined(AFX_LIGHT_H__ACA1A2A6_E72D_4EBC_B919_5C0AC538F456__INCLUDED_)
+100
View File
@@ -0,0 +1,100 @@
// Lighting.cpp: implementation of the CLighting class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Lighting.h"
#include "math.h"
#define PI 3.14159265
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a>b)?(a):(b))
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLighting::CLighting()
{
LightNum=1;
Light=new CLight[LightNum];
Ambient=CRGB(0.3,0.3,0.3);//环境光恒定不变
}
CLighting::~CLighting()
{
if(Light)
{
delete []Light;
Light=NULL;
}
}
void CLighting::SetLightNumber(int lnum)
{
if(Light)
{
delete []Light;
}
LightNum=lnum;
Light=new CLight[lnum];
}
CLighting::CLighting(int lnum)
{
LightNum=lnum;
Light=new CLight[lnum];
Ambient=CRGB(0.3,0.3,0.3);
}
CRGB CLighting::Lighting(CP3 ViewPoint,CP3 Point,CVector Normal,CMaterial *pMaterial)
{
CRGB LastC=pMaterial->M_Emit;//材质自身发散色为初始值
for(int i=0;i<LightNum;i++)//来自光源
{
if(Light[i].L_OnOff)
{
CRGB InitC;
InitC.red=0,InitC.green=0,InitC.blue=0;
CVector VL(Point,Light[i].L_Position);//VL为指向光源的矢量
double d=VL.Mag();//d为光传播的距离,等于光矢量VL的模
VL=VL.Normalize();//单位化光矢量
CVector VN=Normal;
VN=VN.Normalize();//单位化法矢量
//第1步,加入漫反射光
double CosTheta=MAX(Dot(VL,VN),0);
InitC.red+=Light[i].L_Diffuse.red*pMaterial->M_Diffuse.red*CosTheta;
InitC.green+=Light[i].L_Diffuse.green*pMaterial->M_Diffuse.green*CosTheta;
InitC.blue+=Light[i].L_Diffuse.blue*pMaterial->M_Diffuse.blue*CosTheta;
//第2步,加入镜面反射光
CVector VV(Point,ViewPoint);//VV为视矢量
VV=VV.Normalize();//单位化视矢量
CVector VH=(VL+VV)/(VL+VV).Mag();//VH为平分矢量
double nHN=pow(MAX(Dot(VH,VN),0),pMaterial->M_n);
InitC.red+=Light[i].L_Specular.red*pMaterial->M_Specular.red*nHN;
InitC.green+=Light[i].L_Specular.green*pMaterial->M_Specular.green*nHN;
InitC.blue+=Light[i].L_Specular.blue*pMaterial->M_Specular.blue*nHN;
//第3步,光强衰减
double c0=Light[i].L_C0;//c0为常数衰减因子
double c1=Light[i].L_C1;//c1线性衰减因子
double c2=Light[i].L_C2;//c2二次衰减因子
double f=(1.0/(c0+c1*d+c2*d*d));//光强衰减函数
f=MIN(1.0,f);
LastC+=InitC*f;
}
else
{
LastC+=Point.c;//物体自身颜色
}
}
//第4步,加入环境光
LastC+=Ambient*pMaterial->M_Ambient;
//第5步,颜色归一化到[0,1]区间
LastC.Normalize();
//第6步,返回所计算顶点的光强颜色
return LastC;
}
+29
View File
@@ -0,0 +1,29 @@
// Lighting.h: interface for the CLighting class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_LIGHTING_H__4E9D1F90_7696_4D33_999F_6417C555CB36__INCLUDED_)
#define AFX_LIGHTING_H__4E9D1F90_7696_4D33_999F_6417C555CB36__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Light.h"
#include "Material.h"
#include "Vector.h"
class CLighting
{
public:
CLighting();
CLighting(int);
virtual ~CLighting();
void SetLightNumber(int);//设置光源数量
CRGB Lighting(CP3,CP3,CVector,CMaterial *);//光照
public:
int LightNum;//光源数量
CLight *Light;//光源数组
CRGB Ambient;//环境光
};
#endif // !defined(AFX_LIGHTING_H__4E9D1F90_7696_4D33_999F_6417C555CB36__INCLUDED_)
+107
View File
@@ -0,0 +1,107 @@
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Test.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
+58
View File
@@ -0,0 +1,58 @@
// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_MAINFRM_H__7BDF38E2_1C35_4E15_804B_2AB491FCC818__INCLUDED_)
#define AFX_MAINFRM_H__7BDF38E2_1C35_4E15_804B_2AB491FCC818__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MAINFRM_H__7BDF38E2_1C35_4E15_804B_2AB491FCC818__INCLUDED_)
+56
View File
@@ -0,0 +1,56 @@
// Material.cpp: implementation of the CMaterial class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Material.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMaterial::CMaterial()
{
M_Ambient=CRGB(0.2,0.2,0.2);//材质对环境光的反射率
M_Diffuse=CRGB(0.8,0.8,0.8);//材质对漫反射光的反射率
M_Specular=CRGB(0.0,0.0,0.0);//材质对镜面反射光的反射率
M_Emit=CRGB(0.0,0.0,0.0);//材质自身发散的颜色
M_n=1.0;//高光指数
}
CMaterial::~CMaterial()
{
}
void CMaterial::SetAmbient(CRGB c)
{
M_Ambient=c;
}
void CMaterial::SetDiffuse(CRGB c)
{
M_Diffuse=c;
}
void CMaterial::SetSpecular(CRGB c)
{
M_Specular=c;
}
void CMaterial::SetEmit(CRGB emi)
{
M_Emit=emi;
}
void CMaterial::SetExp(double n)
{
M_n=n;
}
+31
View File
@@ -0,0 +1,31 @@
// Material.h: interface for the CMaterial class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MATERIAL_H__1161180E_9A92_4DAE_AB2E_757671AB6E12__INCLUDED_)
#define AFX_MATERIAL_H__1161180E_9A92_4DAE_AB2E_757671AB6E12__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "RGB.h"
class CMaterial
{
public:
CMaterial();
virtual ~CMaterial();
void SetAmbient(CRGB);//设置材质对环境光的反射率
void SetDiffuse(CRGB);//设置材质对漫反射光的反射率
void SetSpecular(CRGB);//设置材质对镜面反射光的反射率
void SetEmit(CRGB);//设置材质自身辐射的颜色
void SetExp(double);//设置材质的高光指数
public:
CRGB M_Ambient;//材质对环境光的反射率
CRGB M_Diffuse;//材质对漫反射光的反射率
CRGB M_Specular;//材质对镜面反射光的反射率
CRGB M_Emit;//材质自身发散的颜色
double M_n;//材质的高光指数
};
#endif // !defined(AFX_MATERIAL_H__1161180E_9A92_4DAE_AB2E_757671AB6E12__INCLUDED_)
+104
View File
@@ -0,0 +1,104 @@
// P2.cpp: implementation of the CP2 class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "P2.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CP2::CP2()
{
x=0;
y=0;
w=1.0;
}
CP2::~CP2()
{
}
CP2::CP2(double x,double y)
{
this->x=x;
this->y=y;
this->w=1.0;
}
CP2 operator +(const CP2 &p1,const CP2 &p2)//和
{
CP2 p;
p.x=p1.x+p2.x;
p.y=p1.y+p2.y;
return p;
}
CP2 operator -(const CP2 &p1,const CP2 &p2)//差
{
CP2 p;
p.x=p1.x-p2.x;
p.y=p1.y-p2.y;
return p;
}
CP2 operator *(const CP2 &p,double k)//点和常量的积
{
return CP2(p.x*k,p.y*k);
}
CP2 operator *(double k,const CP2 &p)//点和常量的积
{
return CP2(p.x*k,p.y*k);
}
CP2 operator /(const CP2 &p1,double k)//数除
{
if(fabs(k)<1e-6)
k=1.0;
CP2 p;
p.x=p1.x/k;
p.y=p1.y/k;
return p;
}
CP2 operator+=(CP2 &p1,CP2 &p2)
{
p1.x=p1.x+p2.x;
p1.y=p1.y+p2.y;
return p1;
}
CP2 operator-=(CP2 &p1,CP2 &p2)
{
p1.x=p1.x-p2.x;
p1.y=p1.y-p2.y;
return p1;
}
CP2 operator*=(CP2 &p1,double k)
{
p1.x=p1.x*k;
p1.y=p1.y*k;
return p1;
}
CP2 operator/=(CP2 &p1,double k)
{
if(fabs(k)<1e-6)
k=1.0;
p1.x=p1.x/k;
p1.y=p1.y/k;
return p1;
}
+36
View File
@@ -0,0 +1,36 @@
// P2.h: interface for the CP2 class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_P2_H__F5B8C5D7_BC9B_4346_817B_F55E89EE7598__INCLUDED_)
#define AFX_P2_H__F5B8C5D7_BC9B_4346_817B_F55E89EE7598__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "RGB.h"
class CP2
{
public:
CP2();
virtual ~CP2();
CP2(double, double);
friend CP2 operator+(const CP2 &, const CP2 &); // ÔËËã·ûÖØÔØ
friend CP2 operator-(const CP2 &, const CP2 &);
friend CP2 operator*(const CP2 &, const double);
friend CP2 operator*(const double, const CP2 &);
friend CP2 operator/(const CP2 &, double);
friend CP2 operator+=(CP2 &, CP2 &);
friend CP2 operator-=(CP2 &, CP2 &);
friend CP2 operator*=(CP2 &, double);
friend CP2 operator/=(CP2 &, double);
public:
double x;
double y;
double w;
CRGB c;
};
#endif // !defined(AFX_P2_H__F5B8C5D7_BC9B_4346_817B_F55E89EE7598__INCLUDED_)
+110
View File
@@ -0,0 +1,110 @@
// P3.cpp: implementation of the CP3 class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "P3.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CP3::CP3()
{
z=0.0;
}
CP3::~CP3()
{
}
CP3::CP3(double x,double y,double z):CP2(x,y)
{
this->z=z;
}
CP3 operator +(const CP3 &p0,const CP3 &p1)//和
{
CP3 p;
p.x=p0.x+p1.x;
p.y=p0.y+p1.y;
p.z=p0.z+p1.z;
return p;
}
CP3 operator -(const CP3 &p0,const CP3 &p1)//差
{
CP3 p;
p.x=p0.x-p1.x;
p.y=p0.y-p1.y;
p.z=p0.z-p1.z;
return p;
}
CP3 operator *(const CP3 &p,double k)//点和常量的积
{
return CP3(p.x*k,p.y*k,p.z*k);
}
CP3 operator *(double k,const CP3 &p)//点和常量的积
{
return CP3(p.x*k,p.y*k,p.z*k);
}
CP3 operator /(const CP3 &p0,double k)//数除
{
if(fabs(k)<1e-6)
k=1.0;
CP3 p;
p.x=p0.x/k;
p.y=p0.y/k;
p.z=p0.z/k;
return p;
}
CP3 operator+=(CP3 &p0,CP3 &p1)
{
p0.x=p0.x+p1.x;
p0.y=p0.y+p1.y;
p0.z=p0.z+p1.z;
return p0;
}
CP3 operator-=(CP3 &p0,CP3 &p1)
{
p0.x=p0.x-p1.x;
p0.y=p0.y-p1.y;
p0.z=p0.z-p1.z;
return p0;
}
CP3 operator*=(CP3 &p0,double k)
{
p0.x=p0.x*k;
p0.y=p0.y*k;
p0.z=p0.z*k;
return p0;
}
CP3 operator/=(CP3 &p0,double k)
{
if(fabs(k)<1e-6)
k=1.0;
p0.x=p0.x/k;
p0.y=p0.y/k;
p0.z=p0.z/k;
return p0;
}
double CP3::Mag()//长度
{
return sqrt(x*x+y*y+z*z);
}
+33
View File
@@ -0,0 +1,33 @@
// P3.h: interface for the CP3 class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_P3_H__5B85FC65_6516_4259_941E_FAB30D13824E__INCLUDED_)
#define AFX_P3_H__5B85FC65_6516_4259_941E_FAB30D13824E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "P2.h"
class CP3 : public CP2
{
public:
CP3();
virtual ~CP3();
CP3(double, double, double);
friend CP3 operator+(const CP3 &, const CP3 &); // ÔËËã·ûÖØÔØ
friend CP3 operator-(const CP3 &, const CP3 &);
friend CP3 operator*(const CP3 &, double);
friend CP3 operator*(double, const CP3 &);
friend CP3 operator/(const CP3 &, double);
friend CP3 operator+=(CP3 &, CP3 &);
friend CP3 operator-=(CP3 &, CP3 &);
friend CP3 operator*=(CP3 &, double);
friend CP3 operator/=(CP3 &, double);
double Mag(); // ³¤¶È
public:
double z;
};
#endif // !defined(AFX_P3_H__5B85FC65_6516_4259_941E_FAB30D13824E__INCLUDED_)
+35
View File
@@ -0,0 +1,35 @@
// Pi2.cpp: implementation of the CPi2 class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Pi2.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPi2::CPi2()
{
x=0.0;
y=0;
c=CRGB(1.0,1.0,1.0);
}
CPi2::~CPi2()
{
}
CPi2::CPi2(double x,int y)
{
this->x=x;
this->y=y;
}
+24
View File
@@ -0,0 +1,24 @@
// Pi2.h: interface for the CPi2 class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_PI2_H__B80DAA04_DDC9_4F35_8BC8_B3DDDE62F21D__INCLUDED_)
#define AFX_PI2_H__B80DAA04_DDC9_4F35_8BC8_B3DDDE62F21D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "RGB.h"
class CPi2
{
public:
CPi2();
virtual ~CPi2();
CPi2(double,int);
double x;
int y;
CRGB c;
};
#endif // !defined(AFX_PI2_H__B80DAA04_DDC9_4F35_8BC8_B3DDDE62F21D__INCLUDED_)
+32
View File
@@ -0,0 +1,32 @@
// Pi3.cpp: implementation of the CPi3 class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Pi3.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPi3::CPi3()
{
z=0.0;
}
CPi3::~CPi3()
{
}
CPi3::CPi3(double x,int y,double z):CPi2(x,y)
{
this->z=z;
}
+22
View File
@@ -0,0 +1,22 @@
// Pi3.h: interface for the CPi3 class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_PI3_H__1DC85C9B_C92E_4165_9851_4C61236BF305__INCLUDED_)
#define AFX_PI3_H__1DC85C9B_C92E_4165_9851_4C61236BF305__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Pi2.h"
class CPi3:public CPi2
{
public:
CPi3();
virtual ~CPi3();
CPi3(double,int,double);
double z;
};
#endif // !defined(AFX_PI3_H__1DC85C9B_C92E_4165_9851_4C61236BF305__INCLUDED_)
Binary file not shown.

After

Width:  |  Height:  |  Size: 563 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

+13
View File
@@ -0,0 +1,13 @@
//
// TEST.RC2 - resources Microsoft Visual C++ does not edit directly
//
#ifdef APSTUDIO_INVOKED
#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
// Add manually edited resources here...
/////////////////////////////////////////////////////////////////////////////
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 KiB

+139
View File
@@ -0,0 +1,139 @@
// CRGB.cpp: implementation of the CRGB class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "RGB.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRGB::CRGB()
{
red=1.0;
green=1.0;
blue=1.0;
alpha=0.0;
}
CRGB::CRGB(double r,double g,double b)//重载构造函数
{
red=r;
green=g;
blue=b;
}
CRGB::CRGB(double r,double g,double b,double a)//重载构造函数
{
red=r;
green=g;
blue=b;
alpha=a;
}
CRGB::~CRGB()
{
}
CRGB operator +(const CRGB &c1,const CRGB &c2)//+运算符重载
{
CRGB c;
c.red=c1.red+c2.red;
c.green=c1.green+c2.green;
c.blue=c1.blue+c2.blue;
return c;
}
CRGB operator -(const CRGB &c1,const CRGB &c2)//-运算符重载
{
CRGB c;
c.red=c1.red-c2.red;
c.green=c1.green-c2.green;
c.blue=c1.blue-c2.blue;
return c;
}
CRGB operator *(const CRGB &c1,const CRGB &c2)//*运算符重载
{
CRGB c;
c.red=c1.red*c2.red;
c.green=c1.green*c2.green;
c.blue=c1.blue*c2.blue;
return c;
}
CRGB operator *(const CRGB &c1,double k)//*运算符重载
{
CRGB c;
c.red=k*c1.red;
c.green=k*c1.green;
c.blue=k*c1.blue;
return c;
}
CRGB operator *(double k,const CRGB &c1)//*运算符重载
{
CRGB c;
c.red=k*c1.red;
c.green=k*c1.green;
c.blue=k*c1.blue;
return c;
}
CRGB operator /(const CRGB &c1,double k)///运算符重载
{
CRGB c;
c.red=c1.red/k;
c.green=c1.green/k;
c.blue=c1.blue/k;
return c;
}
CRGB operator +=(CRGB &c1,CRGB &c2)//+=运算符重载
{
c1.red=c1.red+c2.red;
c1.green=c1.green+c2.green;
c1.blue=c1.blue+c2.blue;
return c1;
}
CRGB operator -=(CRGB &c1,CRGB &c2)//-=运算符重载
{
c1.red=c1.red-c2.red;
c1.green=c1.green-c2.green;
c1.blue=c1.blue-c2.blue;
return c1;
}
CRGB operator *=(CRGB &c1,CRGB &c2)//*=运算符重载
{
c1.red=c1.red*c2.red;
c1.green=c1.green*c2.green;
c1.blue=c1.blue*c2.blue;
return c1;
}
CRGB operator /=(CRGB &c1,double k)///=运算符重载
{
c1.red=c1.red/k;
c1.green=c1.green/k;
c1.blue=c1.blue/k;
return c1;
}
void CRGB::Normalize()//归一化
{
red=(red < 0.0) ? 0.0 : ((red > 1.0) ? 1.0 : red);
green=(green < 0.0) ? 0.0 : ((green > 1.0) ? 1.0 : green);
blue=(blue < 0.0) ? 0.0 : ((blue > 1.0) ? 1.0 : blue);
}
+37
View File
@@ -0,0 +1,37 @@
// CRGB.h: interface for the CRGB class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CRGB_H__F14E5B6C_E5FA_4DD9_8051_EB943E4929E7__INCLUDED_)
#define AFX_CRGB_H__F14E5B6C_E5FA_4DD9_8051_EB943E4929E7__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CRGB
{
public:
CRGB();
CRGB(double,double,double);
CRGB(double,double,double,double a);
virtual ~CRGB();
friend CRGB operator+(const CRGB &,const CRGB &);//运算符重载
friend CRGB operator-(const CRGB &,const CRGB &);
friend CRGB operator*(const CRGB &,const CRGB &);
friend CRGB operator*(const CRGB &,double);
friend CRGB operator*(double,const CRGB &);
friend CRGB operator/(const CRGB &,double);
friend CRGB operator+=(CRGB &,CRGB &);
friend CRGB operator-=(CRGB &,CRGB &);
friend CRGB operator*=(CRGB &,CRGB &);
friend CRGB operator/=(CRGB &,double);
void Normalize(); //归一化到[0,1]区间
public:
double red;//红色分量
double green;//绿色分量
double blue;//蓝色分量
double alpha;//透射系数
};
#endif // !defined(AFX_CRGB_H__F14E5B6C_E5FA_4DD9_8051_EB943E4929E7__INCLUDED_)
+105
View File
@@ -0,0 +1,105 @@
========================================================================
MICROSOFT FOUNDATION CLASS LIBRARY : Test
========================================================================
AppWizard has created this Test application for you. This application
not only demonstrates the basics of using the Microsoft Foundation classes
but is also a starting point for writing your application.
This file contains a summary of what you will find in each of the files that
make up your Test application.
Test.dsp
This file (the project file) contains information at the project level and
is used to build a single project or subproject. Other users can share the
project (.dsp) file, but they should export the makefiles locally.
Test.h
This is the main header file for the application. It includes other
project specific headers (including Resource.h) and declares the
CTestApp application class.
Test.cpp
This is the main application source file that contains the application
class CTestApp.
Test.rc
This is a listing of all of the Microsoft Windows resources that the
program uses. It includes the icons, bitmaps, and cursors that are stored
in the RES subdirectory. This file can be directly edited in Microsoft
Visual C++.
Test.clw
This file contains information used by ClassWizard to edit existing
classes or add new classes. ClassWizard also uses this file to store
information needed to create and edit message maps and dialog data
maps and to create prototype member functions.
res\Test.ico
This is an icon file, which is used as the application's icon. This
icon is included by the main resource file Test.rc.
res\Test.rc2
This file contains resources that are not edited by Microsoft
Visual C++. You should place all resources not editable by
the resource editor in this file.
/////////////////////////////////////////////////////////////////////////////
For the main frame window:
MainFrm.h, MainFrm.cpp
These files contain the frame class CMainFrame, which is derived from
CFrameWnd and controls all SDI frame features.
res\Toolbar.bmp
This bitmap file is used to create tiled images for the toolbar.
The initial toolbar and status bar are constructed in the CMainFrame
class. Edit this toolbar bitmap using the resource editor, and
update the IDR_MAINFRAME TOOLBAR array in Test.rc to add
toolbar buttons.
/////////////////////////////////////////////////////////////////////////////
AppWizard creates one document type and one view:
TestDoc.h, TestDoc.cpp - the document
These files contain your CTestDoc class. Edit these files to
add your special document data and to implement file saving and loading
(via CTestDoc::Serialize).
TestView.h, TestView.cpp - the view of the document
These files contain your CTestView class.
CTestView objects are used to view CTestDoc objects.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named Test.pch and a precompiled types file named StdAfx.obj.
Resource.h
This is the standard header file, which defines new resource IDs.
Microsoft Visual C++ reads and updates this file.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" to indicate parts of the source code you
should add to or customize.
If your application uses MFC in a shared DLL, and your application is
in a language other than the operating system's current language, you
will need to copy the corresponding localized resources MFC42XXX.DLL
from the Microsoft Visual C++ CD-ROM onto the system or system32 directory,
and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation.
For example, MFC42DEU.DLL contains resources translated to German.) If you
don't do this, some of the UI elements of your application will remain in the
language of the operating system.
/////////////////////////////////////////////////////////////////////////////
+8
View File
@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// Test.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
+33
View File
@@ -0,0 +1,33 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__40591CFA_4C1D_4FD7_8414_6EA0BBACA787__INCLUDED_)
#define AFX_STDAFX_H__40591CFA_4C1D_4FD7_8414_6EA0BBACA787__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
// 版权所有(2013)
// Copyright(2013)
// 编写者: 孔令德
// Author: Kong Lingde
// 网址:www.klingde.com
// QQ:997796978
// 地址:太原工业学院 计算机工程系
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__40591CFA_4C1D_4FD7_8414_6EA0BBACA787__INCLUDED_)
+101
View File
@@ -0,0 +1,101 @@
// T2.cpp: implementation of the CT2 class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "T2.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CT2::CT2()
{
u=0;
v=0;
}
CT2::~CT2()
{
}
CT2::CT2(double u,double v)
{
this->u=u;
this->v=v;
}
CT2 operator +(const CT2 &t1,const CT2 &t2)//和
{
CT2 t;
t.u=t1.u+t2.u;
t.v=t1.v+t2.v;
return t;
}
CT2 operator -(const CT2 &t1,const CT2 &t2)//差
{
CT2 t;
t.u=t1.u-t2.u;
t.v=t1.v-t2.v;
return t;
}
CT2 operator *(const CT2 &t,double k)//点和常量的积
{
return CT2(t.u*k,t.v*k);
}
CT2 operator *(double k,const CT2 &t)//点和常量的积
{
return CT2(t.u*k,t.v*k);
}
CT2 operator /(const CT2 &t1,double k)//数除
{
if(fabs(k)<1e-6)
k=1.0;
CT2 t;
t.u=t1.u/k;
t.v=t1.v/k;
return t;
}
CT2 operator+=(CT2 &t1,CT2 &t2)
{
t1.u=t1.u+t2.u;
t1.v=t1.v+t2.v;
return t1;
}
CT2 operator-=(CT2 &t1,CT2 &t2)
{
t1.u=t1.u-t2.u;
t1.v=t1.v-t2.v;
return t1;
}
CT2 operator*=(CT2 &t1,double k)
{
t1.u=t1.u*k;
t1.v=t1.v*k;
return t1;
}
CT2 operator/=(CT2 &t1,double k)
{
if(fabs(k)<1e-6)
k=1.0;
t1.u=t1.u/k;
t1.v=t1.v/k;
return t1;
}
+32
View File
@@ -0,0 +1,32 @@
// T2.h: interface for the CT2 class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_T2_H__D2AA007F_2727_41E9_A00C_AC75B51F24AA__INCLUDED_)
#define AFX_T2_H__D2AA007F_2727_41E9_A00C_AC75B51F24AA__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CT2
{
public:
CT2();
virtual ~CT2();
CT2(double,double);
friend CT2 operator +(const CT2 &,const CT2 &);//ÔËËã·ûÖØÔØ
friend CT2 operator -(const CT2 &,const CT2 &);
friend CT2 operator *(const CT2 &,double);
friend CT2 operator *(double,const CT2 &);
friend CT2 operator /(const CT2 &,double);
friend CT2 operator+=(CT2 &,CT2 &);
friend CT2 operator-=(CT2 &,CT2 &);
friend CT2 operator*=(CT2 &,double);
friend CT2 operator/=(CT2 &,double);
public:
double u;
double v;
};
#endif // !defined(AFX_T2_H__D2AA007F_2727_41E9_A00C_AC75B51F24AA__INCLUDED_)
Binary file not shown.
+101
View File
@@ -0,0 +1,101 @@
; CLW file contains information for the MFC ClassWizard
[General Info]
Version=1
LastClass=CTestView
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "Test.h"
LastPage=0
ClassCount=5
Class1=CTestApp
Class2=CTestDoc
Class3=CTestView
Class4=CMainFrame
ResourceCount=2
Resource1=IDR_MAINFRAME
Class5=CAboutDlg
Resource2=IDD_ABOUTBOX
[CLS:CTestApp]
Type=0
HeaderFile=Test.h
ImplementationFile=Test.cpp
Filter=N
[CLS:CTestDoc]
Type=0
HeaderFile=TestDoc.h
ImplementationFile=TestDoc.cpp
Filter=N
[CLS:CTestView]
Type=0
HeaderFile=TestView.h
ImplementationFile=TestView.cpp
Filter=C
BaseClass=CView
VirtualFilter=VWC
LastObject=CTestView
[CLS:CMainFrame]
Type=0
HeaderFile=MainFrm.h
ImplementationFile=MainFrm.cpp
Filter=T
LastObject=IDM_PLAY
[CLS:CAboutDlg]
Type=0
HeaderFile=Test.cpp
ImplementationFile=Test.cpp
Filter=D
[DLG:IDD_ABOUTBOX]
Type=1
Class=CAboutDlg
ControlCount=2
Control1=IDOK,button,1342373889
Control2=IDB_BITMAP1,static,1342177294
[MNU:IDR_MAINFRAME]
Type=1
Class=CMainFrame
Command1=ID_APP_EXIT
Command2=IDM_PLAY
Command3=ID_APP_ABOUT
CommandCount=3
[ACL:IDR_MAINFRAME]
Type=1
Class=CMainFrame
Command1=ID_FILE_NEW
Command2=ID_FILE_OPEN
Command3=ID_FILE_SAVE
Command4=ID_FILE_PRINT
Command5=ID_EDIT_UNDO
Command6=ID_EDIT_CUT
Command7=ID_EDIT_COPY
Command8=ID_EDIT_PASTE
Command9=ID_EDIT_UNDO
Command10=ID_EDIT_CUT
Command11=ID_EDIT_COPY
Command12=ID_EDIT_PASTE
Command13=ID_NEXT_PANE
Command14=ID_PREV_PANE
CommandCount=14
[TB:IDR_MAINFRAME]
Type=1
Class=?
Command1=ID_APP_EXIT
Command2=IDM_PLAY
Command3=ID_APP_ABOUT
CommandCount=3
+154
View File
@@ -0,0 +1,154 @@
// Test.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Test.h"
#include "MainFrm.h"
#include "TestDoc.h"
#include "TestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestApp
BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
//{{AFX_MSG_MAP(CTestApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestApp construction
CTestApp::CTestApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CTestApp object
CTestApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CTestApp initialization
BOOL CTestApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CTestDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CTestView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_MAXIMIZE);
m_pMainWnd->SetWindowText("案例55:长方体图像纹理映射算法");
m_pMainWnd->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// 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)
// No message handlers
//}}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()
// App command to run the dialog
void CTestApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CTestApp message handlers
+338
View File
@@ -0,0 +1,338 @@
# Microsoft Developer Studio Project File - Name="Test" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Test - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Test.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Test.mak" CFG="Test - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Test - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Test - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Test - Win32 Release"
# PROP BASE Use_MFC 6
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 6
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Yu"stdafx.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x804 /d "NDEBUG" /d "_AFXDLL"
# ADD RSC /l 0x804 /d "NDEBUG" /d "_AFXDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386
# ADD LINK32 /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "Test - Win32 Debug"
# PROP BASE Use_MFC 6
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 6
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /Yu"stdafx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x804 /d "_DEBUG" /d "_AFXDLL"
# ADD RSC /l 0x804 /d "_DEBUG" /d "_AFXDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "Test - Win32 Release"
# Name "Test - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\AET.cpp
# End Source File
# Begin Source File
SOURCE=.\Bucket.cpp
# End Source File
# Begin Source File
SOURCE=.\Face.cpp
# End Source File
# Begin Source File
SOURCE=.\Light.cpp
# End Source File
# Begin Source File
SOURCE=.\Lighting.cpp
# End Source File
# Begin Source File
SOURCE=.\MainFrm.cpp
# End Source File
# Begin Source File
SOURCE=.\Material.cpp
# End Source File
# Begin Source File
SOURCE=.\P2.cpp
# End Source File
# Begin Source File
SOURCE=.\P3.cpp
# End Source File
# Begin Source File
SOURCE=.\Pi2.cpp
# End Source File
# Begin Source File
SOURCE=.\Pi3.cpp
# End Source File
# Begin Source File
SOURCE=.\RGB.cpp
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"stdafx.h"
# End Source File
# Begin Source File
SOURCE=.\T2.cpp
# End Source File
# Begin Source File
SOURCE=.\Test.cpp
# End Source File
# Begin Source File
SOURCE=.\Test.rc
# End Source File
# Begin Source File
SOURCE=.\TestDoc.cpp
# End Source File
# Begin Source File
SOURCE=.\TestView.cpp
# End Source File
# Begin Source File
SOURCE=".\Transform .cpp"
# End Source File
# Begin Source File
SOURCE=.\Vector.cpp
# End Source File
# Begin Source File
SOURCE=.\ZBuffer.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\AET.h
# End Source File
# Begin Source File
SOURCE=.\Bucket.h
# End Source File
# Begin Source File
SOURCE=.\Face.h
# End Source File
# Begin Source File
SOURCE=.\Light.h
# End Source File
# Begin Source File
SOURCE=.\Lighting.h
# End Source File
# Begin Source File
SOURCE=.\MainFrm.h
# End Source File
# Begin Source File
SOURCE=.\Material.h
# End Source File
# Begin Source File
SOURCE=.\P2.h
# End Source File
# Begin Source File
SOURCE=.\P3.h
# End Source File
# Begin Source File
SOURCE=.\Pi2.h
# End Source File
# Begin Source File
SOURCE=.\Pi3.h
# End Source File
# Begin Source File
SOURCE=.\Resource.h
# End Source File
# Begin Source File
SOURCE=.\RGB.h
# End Source File
# Begin Source File
SOURCE=.\StdAfx.h
# End Source File
# Begin Source File
SOURCE=.\T2.h
# End Source File
# Begin Source File
SOURCE=.\Test.h
# End Source File
# Begin Source File
SOURCE=.\TestDoc.h
# End Source File
# Begin Source File
SOURCE=.\TestView.h
# End Source File
# Begin Source File
SOURCE=.\Transform.h
# End Source File
# Begin Source File
SOURCE=.\Vector.h
# End Source File
# Begin Source File
SOURCE=.\ZBuffer.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\RES\1.bmp
# End Source File
# Begin Source File
SOURCE=.\RES\2.bmp
# End Source File
# Begin Source File
SOURCE=.\RES\3.bmp
# End Source File
# Begin Source File
SOURCE=.\RES\3.ico
# End Source File
# Begin Source File
SOURCE=.\RES\4.bmp
# End Source File
# Begin Source File
SOURCE=.\RES\5.bmp
# End Source File
# Begin Source File
SOURCE=.\RES\6.bmp
# End Source File
# Begin Source File
SOURCE=.\RES\about.bmp
# End Source File
# Begin Source File
SOURCE=.\res\app.ico
# End Source File
# Begin Source File
SOURCE=.\res\draw.ico
# End Source File
# Begin Source File
SOURCE=.\res\exit.ico
# End Source File
# Begin Source File
SOURCE=.\res\Help.ico
# End Source File
# Begin Source File
SOURCE=.\res\Test.ico
# End Source File
# Begin Source File
SOURCE=.\res\Test.rc2
# End Source File
# Begin Source File
SOURCE=.\res\TestDoc.ico
# End Source File
# Begin Source File
SOURCE=.\res\Toolbar.bmp
# End Source File
# End Group
# Begin Source File
SOURCE=.\ReadMe.txt
# End Source File
# End Target
# End Project
+29
View File
@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Test"=.\Test.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################
+49
View File
@@ -0,0 +1,49 @@
// Test.h : main header file for the TEST application
//
#if !defined(AFX_TEST_H__687EC7D4_477F_4BD3_BCC6_BD41AD64322D__INCLUDED_)
#define AFX_TEST_H__687EC7D4_477F_4BD3_BCC6_BD41AD64322D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CTestApp:
// See Test.cpp for the implementation of this class
//
class CTestApp : public CWinApp
{
public:
CTestApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CTestApp)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TEST_H__687EC7D4_477F_4BD3_BCC6_BD41AD64322D__INCLUDED_)
Binary file not shown.
Binary file not shown.
+42
View File
@@ -0,0 +1,42 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: Test - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\Users\csq-n\AppData\Local\Temp\RSPABF9.tmp" with contents
[
/nologo /o"Debug/Test.bsc"
".\Debug\StdAfx.sbr"
".\Debug\AET.sbr"
".\Debug\Bucket.sbr"
".\Debug\Face.sbr"
".\Debug\Light.sbr"
".\Debug\Lighting.sbr"
".\Debug\MainFrm.sbr"
".\Debug\Material.sbr"
".\Debug\P2.sbr"
".\Debug\P3.sbr"
".\Debug\Pi2.sbr"
".\Debug\Pi3.sbr"
".\Debug\RGB.sbr"
".\Debug\T2.sbr"
".\Debug\Test.sbr"
".\Debug\TestDoc.sbr"
".\Debug\TestView.sbr"
".\Debug\Transform .sbr"
".\Debug\Vector.sbr"
".\Debug\ZBuffer.sbr"]
Creating command line "bscmake.exe @"C:\Users\csq-n\AppData\Local\Temp\RSPABF9.tmp""
Creating browse info file...
<h3>Output Window</h3>
<h3>Results</h3>
Test.exe - 0 error(s), 0 warning(s)
</pre>
</body>
</html>
+416
View File
@@ -0,0 +1,416 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Chinese (Simplified, China) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 4, 2\r\n"
"#pragma code_page(936)\r\n"
"#endif //_WIN32\r\n"
"#include ""res\\Test.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""l.chs\\afxres.rc"" // Standard components\r\n"
"#include ""l.chs\\afxprint.rc"" // printing/print preview resources\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON "res\\Test.ico"
IDR_TESTTYPE ICON "res\\TestDoc.ico"
IDI_ICON1 ICON "res\\Help.ico"
IDI_ICON2 ICON "res\\app.ico"
IDI_ICON5 ICON "res\\exit.ico"
IDI_ICON6 ICON "res\\draw.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDR_MAINFRAME BITMAP "res\\Toolbar.bmp"
IDB_ABOUT BITMAP "res\\about.bmp"
IDB_FRONT BITMAP "res\\1.bmp"
IDB_LEFT BITMAP "res\\4.bmp"
IDB_RIGHT BITMAP "res\\5.bmp"
IDB_TOP BITMAP "res\\2.bmp"
IDB_BOTTOM BITMAP "res\\3.bmp"
IDB_BACK BITMAP "res\\6.bmp"
IDB_GROUND BITMAP "RES\\ground.bmp"
/////////////////////////////////////////////////////////////////////////////
//
// Toolbar
//
IDR_MAINFRAME TOOLBAR 32, 32
BEGIN
BUTTON ID_APP_EXIT
BUTTON IDM_PLAY
BUTTON ID_APP_ABOUT
END
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MAINFRAME MENU
BEGIN
POPUP "文件(&F)"
BEGIN
MENUITEM "退出(&X)", ID_APP_EXIT
END
POPUP "绘图(&D)"
BEGIN
MENUITEM "Play", IDM_PLAY
END
POPUP "帮助(&H)"
BEGIN
MENUITEM "关于 Test(&A)...", ID_APP_ABOUT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAINFRAME ACCELERATORS
BEGIN
"N", ID_FILE_NEW, VIRTKEY, CONTROL
"O", ID_FILE_OPEN, VIRTKEY, CONTROL
"S", ID_FILE_SAVE, VIRTKEY, CONTROL
"P", ID_FILE_PRINT, VIRTKEY, CONTROL
"Z", ID_EDIT_UNDO, VIRTKEY, CONTROL
"X", ID_EDIT_CUT, VIRTKEY, CONTROL
"C", ID_EDIT_COPY, VIRTKEY, CONTROL
"V", ID_EDIT_PASTE, VIRTKEY, CONTROL
VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT
VK_DELETE, ID_EDIT_CUT, VIRTKEY, SHIFT
VK_INSERT, ID_EDIT_COPY, VIRTKEY, CONTROL
VK_INSERT, ID_EDIT_PASTE, VIRTKEY, SHIFT
VK_F6, ID_NEXT_PANE, VIRTKEY
VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOG 0, 0, 215, 180
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "关于 Test"
FONT 9, "宋体"
BEGIN
DEFPUSHBUTTON "确定",IDOK,85,159,50,14,WS_GROUP
CONTROL IDB_BITMAP1,IDB_BITMAP1,"Static",SS_BITMAP,7,7,200,150
END
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080404B0"
BEGIN
VALUE "FileDescription", "Test Microsoft 基础类应用程序"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "InternalName", "Test"
VALUE "LegalCopyright", "版权所有 (C) 2006"
VALUE "OriginalFilename", "Test.EXE"
VALUE "ProductName", "Test 应用程序"
VALUE "ProductVersion", "1, 0, 0, 1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x804, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 207
TOPMARGIN, 7
BOTTOMMARGIN, 173
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDR_MAINFRAME "Test\n\nTest\n\n\nTest.Document\nTest Document"
END
STRINGTABLE
BEGIN
AFX_IDS_APP_TITLE "Test"
AFX_IDS_IDLEMESSAGE "就绪"
END
STRINGTABLE
BEGIN
ID_INDICATOR_EXT "扩展名"
ID_INDICATOR_CAPS "大写"
ID_INDICATOR_NUM "数字"
ID_INDICATOR_SCRL "滚动"
ID_INDICATOR_OVR "改写"
ID_INDICATOR_REC "记录"
END
STRINGTABLE
BEGIN
ID_FILE_NEW "建立新文档\n新建"
ID_FILE_OPEN "打开一个现有文档\n打开"
ID_FILE_CLOSE "关闭活动文档\n关闭"
ID_FILE_SAVE "保存活动文档\n保存"
ID_FILE_SAVE_AS "将活动文档以一个新文件名保存\n另存为"
ID_FILE_PAGE_SETUP "改变打印选项\n页面设置"
ID_FILE_PRINT_SETUP "改变打印机及打印选项\n打印设置"
ID_FILE_PRINT "打印活动文档\n打印"
ID_FILE_PRINT_PREVIEW "显示整页\n打印预览"
END
STRINGTABLE
BEGIN
ID_APP_ABOUT "开发人员信息\n关于"
ID_APP_EXIT "退出应用程序\n退出"
END
STRINGTABLE
BEGIN
ID_FILE_MRU_FILE1 "打开该文档"
ID_FILE_MRU_FILE2 "打开该文档"
ID_FILE_MRU_FILE3 "打开该文档"
ID_FILE_MRU_FILE4 "打开该文档"
ID_FILE_MRU_FILE5 "打开该文档"
ID_FILE_MRU_FILE6 "打开该文档"
ID_FILE_MRU_FILE7 "打开该文档"
ID_FILE_MRU_FILE8 "打开该文档"
ID_FILE_MRU_FILE9 "打开该文档"
ID_FILE_MRU_FILE10 "打开该文档"
ID_FILE_MRU_FILE11 "打开该文档"
ID_FILE_MRU_FILE12 "打开该文档"
ID_FILE_MRU_FILE13 "打开该文档"
ID_FILE_MRU_FILE14 "打开该文档"
ID_FILE_MRU_FILE15 "打开该文档"
ID_FILE_MRU_FILE16 "打开该文档"
END
STRINGTABLE
BEGIN
ID_NEXT_PANE "切换到下一个窗格\n下一窗格"
ID_PREV_PANE "切换回前一个窗格\n前一窗格"
END
STRINGTABLE
BEGIN
ID_WINDOW_SPLIT "将活动的窗口分隔成窗格\n分隔"
END
STRINGTABLE
BEGIN
ID_EDIT_CLEAR "删除被选对象\n删除"
ID_EDIT_CLEAR_ALL "全部删除\n全部删除"
ID_EDIT_COPY "复制被选对象并将其置于剪贴板上\n复制"
ID_EDIT_CUT "剪切被选对象并将其置于剪贴板上\n剪切"
ID_EDIT_FIND "查找指定的正文\n查找"
ID_EDIT_PASTE "插入剪贴板内容\n粘贴"
ID_EDIT_REPEAT "重复上一步操作\n重复"
ID_EDIT_REPLACE "用不同的正文替换指定的正文\n替换"
ID_EDIT_SELECT_ALL "选择整个文档\n选择全部"
ID_EDIT_UNDO "撤消最后一步操作\n撤消"
ID_EDIT_REDO "重新执行先前已撤消的操作\n重新执行"
END
STRINGTABLE
BEGIN
ID_VIEW_TOOLBAR "显示或隐藏工具栏\n显隐工具栏"
ID_VIEW_STATUS_BAR "显示或隐藏状态栏\n显隐状态栏"
END
STRINGTABLE
BEGIN
AFX_IDS_SCSIZE "改变窗口大小"
AFX_IDS_SCMOVE "改变窗口位置"
AFX_IDS_SCMINIMIZE "将窗口缩小成图标"
AFX_IDS_SCMAXIMIZE "把窗口放大到最大尺寸"
AFX_IDS_SCNEXTWINDOW "切换到下一个文档窗口"
AFX_IDS_SCPREVWINDOW "切换到先前的文档窗口"
AFX_IDS_SCCLOSE "关闭活动的窗口并提示保存所有文档"
END
STRINGTABLE
BEGIN
AFX_IDS_SCRESTORE "把窗口恢复到正常大小"
AFX_IDS_SCTASKLIST "激活任务表"
END
STRINGTABLE
BEGIN
AFX_IDS_PREVIEW_CLOSE "关闭打印预览模式\n取消预阅"
END
STRINGTABLE
BEGIN
ID_MENUPlay "动画演示\n动画"
IDM_PLAY "动画演示\n动画"
END
#endif // Chinese (Simplified, China) resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_FRONTWALL BITMAP "RES\\front-wall.bmp"
IDB_REARWALL BITMAP "RES\\rear-wall.bmp"
IDB_LEFTWALL BITMAP "RES\\left-wall.bmp"
IDB_RIGHTWALL BITMAP "RES\\right-wall.bmp"
IDB_FRONTROOF BITMAP "RES\\front-roof.bmp"
IDB_REARROOF BITMAP "RES\\rear-roof.bmp"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE 4, 2
#pragma code_page(936)
#endif //_WIN32
#include "res\Test.rc2" // non-Microsoft Visual C++ edited resources
#include "l.chs\afxres.rc" // Standard components
#include "l.chs\afxprint.rc" // printing/print preview resources
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcxproj", "{AE6E8B99-AD3B-AEED-DEFA-52050A3A6B13}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AE6E8B99-AD3B-AEED-DEFA-52050A3A6B13}.Debug|Win32.ActiveCfg = Debug|Win32
{AE6E8B99-AD3B-AEED-DEFA-52050A3A6B13}.Debug|Win32.Build.0 = Debug|Win32
{AE6E8B99-AD3B-AEED-DEFA-52050A3A6B13}.Release|Win32.ActiveCfg = Release|Win32
{AE6E8B99-AD3B-AEED-DEFA-52050A3A6B13}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
+226
View File
@@ -0,0 +1,226 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<SccProjectName />
<SccLocalPath />
<Keyword>MFCProj</Keyword>
<ProjectGuid>{AE6E8B99-AD3B-AEED-DEFA-52050A3A6B13}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>Dynamic</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>Dynamic</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>.\Release\</OutDir>
<IntDir>.\Release\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\Debug\</OutDir>
<IntDir>.\Debug\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<StringPooling>true</StringPooling>
<FunctionLevelLinking>true</FunctionLevelLinking>
<Optimization>MaxSpeed</Optimization>
<SuppressStartupBanner>true</SuppressStartupBanner>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>.\Release\</AssemblerListingLocation>
<PrecompiledHeaderOutputFile>.\Release\Test.pch</PrecompiledHeaderOutputFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<ObjectFileName>.\Release\</ObjectFileName>
<ProgramDataBaseFileName>.\Release\</ProgramDataBaseFileName>
</ClCompile>
<Midl>
<SuppressStartupBanner>true</SuppressStartupBanner>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TypeLibraryName>.\Release\Test.tlb</TypeLibraryName>
<MkTypLibCompatible>true</MkTypLibCompatible>
<TargetEnvironment>Win32</TargetEnvironment>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
<OutputFile>.\Release\Test.bsc</OutputFile>
</Bscmake>
<Link>
<SuppressStartupBanner>true</SuppressStartupBanner>
<SubSystem>Windows</SubSystem>
<OutputFile>.\Release\Test.exe</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<FunctionLevelLinking>true</FunctionLevelLinking>
<Optimization>Disabled</Optimization>
<SuppressStartupBanner>true</SuppressStartupBanner>
<WarningLevel>Level3</WarningLevel>
<MinimalRebuild>true</MinimalRebuild>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>.\Debug\</AssemblerListingLocation>
<BrowseInformation>true</BrowseInformation>
<PrecompiledHeaderOutputFile>.\Debug\Test.pch</PrecompiledHeaderOutputFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<ObjectFileName>.\Debug\</ObjectFileName>
<ProgramDataBaseFileName>.\Debug\</ProgramDataBaseFileName>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Midl>
<SuppressStartupBanner>true</SuppressStartupBanner>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TypeLibraryName>.\Debug\Test.tlb</TypeLibraryName>
<MkTypLibCompatible>true</MkTypLibCompatible>
<TargetEnvironment>Win32</TargetEnvironment>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
<OutputFile>.\Debug\Test.bsc</OutputFile>
</Bscmake>
<Link>
<SuppressStartupBanner>true</SuppressStartupBanner>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OutputFile>.\Debug\Test.exe</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="AET.cpp" />
<ClCompile Include="Bucket.cpp" />
<ClCompile Include="Face.cpp" />
<ClCompile Include="Light.cpp" />
<ClCompile Include="Lighting.cpp" />
<ClCompile Include="MainFrm.cpp" />
<ClCompile Include="Material.cpp" />
<ClCompile Include="P2.cpp" />
<ClCompile Include="P3.cpp" />
<ClCompile Include="Pi2.cpp" />
<ClCompile Include="Pi3.cpp" />
<ClCompile Include="RGB.cpp" />
<ClCompile Include="StdAfx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">stdafx.h</PrecompiledHeaderFile>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">stdafx.h</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="T2.cpp" />
<ClCompile Include="Test.cpp" />
<ClCompile Include="TestDoc.cpp" />
<ClCompile Include="TestView.cpp" />
<ClCompile Include="Transform .cpp" />
<ClCompile Include="Vector.cpp" />
<ClCompile Include="ZBuffer.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Test.rc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AET.h" />
<ClInclude Include="Bucket.h" />
<ClInclude Include="Face.h" />
<ClInclude Include="Light.h" />
<ClInclude Include="Lighting.h" />
<ClInclude Include="MainFrm.h" />
<ClInclude Include="Material.h" />
<ClInclude Include="P2.h" />
<ClInclude Include="P3.h" />
<ClInclude Include="Pi2.h" />
<ClInclude Include="Pi3.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="RGB.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="T2.h" />
<ClInclude Include="Test.h" />
<ClInclude Include="TestDoc.h" />
<ClInclude Include="TestView.h" />
<ClInclude Include="Transform.h" />
<ClInclude Include="Vector.h" />
<ClInclude Include="ZBuffer.h" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="RES\1.bmp" />
<CustomBuild Include="RES\2.bmp" />
<CustomBuild Include="RES\3.bmp" />
<CustomBuild Include="RES\3.ico" />
<CustomBuild Include="RES\4.bmp" />
<CustomBuild Include="RES\5.bmp" />
<CustomBuild Include="RES\6.bmp" />
<CustomBuild Include="RES\about.bmp" />
<CustomBuild Include="res\app.ico" />
<CustomBuild Include="res\draw.ico" />
<CustomBuild Include="res\exit.ico" />
<CustomBuild Include="res\Help.ico" />
<CustomBuild Include="res\Test.ico" />
<CustomBuild Include="res\Test.rc2">
<FileType>RC</FileType>
</CustomBuild>
<CustomBuild Include="res\TestDoc.ico" />
<CustomBuild Include="res\Toolbar.bmp" />
<CustomBuild Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<None Include="RES\ground.bmp" />
</ItemGroup>
<ItemGroup>
<Image Include="..\front.bmp" />
<Image Include="RES\back.bmp" />
<Image Include="res\bitmap4.bmp" />
<Image Include="RES\front-roof.bmp" />
<Image Include="RES\front-wall.bmp" />
<Image Include="RES\left-wall.bmp" />
<Image Include="RES\rear-roof.bmp" />
<Image Include="RES\rear-wall.bmp" />
<Image Include="RES\right-wall.bmp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+234
View File
@@ -0,0 +1,234 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{6c767958-7f3c-44df-9741-5c39c2655a3e}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{c99ece9c-b873-4e5e-8d30-3bb46e33f81c}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{d4b351c0-cd8e-463c-b81e-4a52b96f1e1b}</UniqueIdentifier>
<Extensions>ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AET.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Bucket.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Face.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Light.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Lighting.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MainFrm.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Material.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="P2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="P3.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Pi2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Pi3.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RGB.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StdAfx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="T2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Test.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TestDoc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TestView.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Transform .cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Vector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ZBuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Test.rc">
<Filter>Source Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AET.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Bucket.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Face.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Light.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Lighting.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MainFrm.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Material.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="P2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="P3.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Pi2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Pi3.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RGB.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="StdAfx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="T2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Test.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TestDoc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TestView.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Transform.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Vector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ZBuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="RES\1.bmp">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="RES\2.bmp">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="RES\3.bmp">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="RES\3.ico">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="RES\4.bmp">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="RES\5.bmp">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="RES\6.bmp">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="RES\about.bmp">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="res\app.ico">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="res\draw.ico">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="res\exit.ico">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="res\Help.ico">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="res\Test.ico">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="res\Test.rc2">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="res\TestDoc.ico">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="res\Toolbar.bmp">
<Filter>Resource Files</Filter>
</CustomBuild>
<CustomBuild Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<None Include="RES\ground.bmp">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="..\front.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\bitmap4.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="RES\back.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="RES\front-wall.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="RES\rear-wall.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="RES\left-wall.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="RES\right-wall.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="RES\front-roof.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="RES\rear-roof.bmp">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
+3
View File
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
+84
View File
@@ -0,0 +1,84 @@
// TestDoc.cpp : implementation of the CTestDoc class
//
#include "stdafx.h"
#include "Test.h"
#include "TestDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestDoc
IMPLEMENT_DYNCREATE(CTestDoc, CDocument)
BEGIN_MESSAGE_MAP(CTestDoc, CDocument)
//{{AFX_MSG_MAP(CTestDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDoc construction/destruction
CTestDoc::CTestDoc()
{
// TODO: add one-time construction code here
}
CTestDoc::~CTestDoc()
{
}
BOOL CTestDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CTestDoc serialization
void CTestDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CTestDoc diagnostics
#ifdef _DEBUG
void CTestDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CTestDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestDoc commands
+57
View File
@@ -0,0 +1,57 @@
// TestDoc.h : interface of the CTestDoc class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_TESTDOC_H__72DBD624_92AB_462A_B0FD_D3F54BA45097__INCLUDED_)
#define AFX_TESTDOC_H__72DBD624_92AB_462A_B0FD_D3F54BA45097__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CTestDoc : public CDocument
{
protected: // create from serialization only
CTestDoc();
DECLARE_DYNCREATE(CTestDoc)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CTestDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CTestDoc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TESTDOC_H__72DBD624_92AB_462A_B0FD_D3F54BA45097__INCLUDED_)
+578
View File
@@ -0,0 +1,578 @@
// TestView.cpp : implementation of the CTestView class
//
#include "stdafx.h"
#include "Test.h"
#include "TestDoc.h"
#include "TestView.h"
#include "math.h"
#define Round(d) int(floor(d + 0.5)) // 四舍五入宏定义
#define PI 3.1415926 // 圆周率
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestView
IMPLEMENT_DYNCREATE(CTestView, CView)
BEGIN_MESSAGE_MAP(CTestView, CView)
//{{AFX_MSG_MAP(CTestView)
ON_WM_TIMER()
ON_WM_KEYDOWN()
ON_WM_ERASEBKGND()
ON_COMMAND(IDM_PLAY, OnPlay)
ON_UPDATE_COMMAND_UI(IDM_PLAY, OnUpdatePlay)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestView construction/destruction
CTestView::CTestView()
{
// TODO: add construction code here
bPlay = FALSE;
R = 1000.0, d = 800.0, Phi = 70.0, Theta = 0.0; // 视点位于正前方
Near = 200.0, Far = 1200.0; // 近剪切面与远剪切面
Alpha = 0.0, Beta = 0.0; // 旋转角
LightNum = 1; // 光源个数
pLight = new CLighting(LightNum); // 一维光源动态数组
pLight->Light[0].SetPosition(0, 0, 800); // 设置光源位置坐标
for (int i = 0; i < LightNum; i++)
{
pLight->Light[i].L_Diffuse = CRGB(0.7, 0.7, 0.7); // 光源的漫反射颜色
pLight->Light[i].L_Specular = CRGB(0.5, 0.5, 0.5); // 光源镜面高光颜色
pLight->Light[i].L_C0 = 1.0; // 常数衰减系数
pLight->Light[i].L_C1 = 0.0000001; // 线性衰减系数
pLight->Light[i].L_C2 = 0.00000001; // 二次衰减系数
pLight->Light[i].L_OnOff = TRUE; // 光源开启
}
pMaterial = new CMaterial; // 一维材质动态数组
pMaterial->SetAmbient(CRGB(0.247, 0.200, 0.075)); // 材质对环境光光的反射率
pMaterial->SetDiffuse(CRGB(0.752, 0.606, 0.226)); // 材质对漫反射光的反射率
pMaterial->SetSpecular(CRGB(1.0, 1.0, 1.0)); // 材质对镜面反射光的反射率
pMaterial->SetEmit(CRGB(0.0, 0.0, 0.0)); // 材质自身发散的颜色
pMaterial->M_n = 30.0; // 高光指数
}
CTestView::~CTestView()
{
if (pLight != NULL)
{
delete pLight;
pLight = NULL;
}
if (pMaterial != NULL)
{
delete pMaterial;
pMaterial = NULL;
}
}
BOOL CTestView::PreCreateWindow(CREATESTRUCT &cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTestView drawing
void CTestView::OnDraw(CDC *pDC)
{
CTestDoc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
DoubleBuffer();
}
/////////////////////////////////////////////////////////////////////////////
// CTestView printing
BOOL CTestView::OnPreparePrinting(CPrintInfo *pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTestView::OnBeginPrinting(CDC * /*pDC*/, CPrintInfo * /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTestView::OnEndPrinting(CDC * /*pDC*/, CPrintInfo * /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTestView diagnostics
#ifdef _DEBUG
void CTestView::AssertValid() const
{
CView::AssertValid();
}
void CTestView::Dump(CDumpContext &dc) const
{
CView::Dump(dc);
}
CTestDoc *CTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc)));
return (CTestDoc *)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestView message handlers
void CTestView::ReadVertex() // 点表
{
// double a = 200, b = 200, c = 50; // 长方体边长
// // 顶点的三维坐标(x,y,z)
// V[0].x = -a;
// V[0].y = -b;
// V[0].z = -c;
// V[1].x = +a;
// V[1].y = -b;
// V[1].z = -c;
// V[2].x = +a;
// V[2].y = +b;
// V[2].z = -c;
// V[3].x = -a;
// V[3].y = +b;
// V[3].z = -c;
// V[4].x = -a;
// V[4].y = -b;
// V[4].z = +c;
// V[5].x = +a;
// V[5].y = -b;
// V[5].z = +c;
// V[6].x = +a;
// V[6].y = +b;
// V[6].z = +c;
// V[7].x = -a;
// V[7].y = +b;
// V[7].z = +c;
V[0].z = 200;
V[0].x = -200;
V[0].y = 0;
V[1].z = 400;
V[1].x = -200;
V[1].y = 0;
V[2].z = 400;
V[2].x = 200;
V[2].y = 0;
V[3].z = 200;
V[3].x = 200;
V[3].y = 0;
V[4].z = 200;
V[4].x = -200;
V[4].y = 200;
V[5].z = 400;
V[5].x = -200;
V[5].y = 200;
V[6].z = 400;
V[6].x = 200;
V[6].y = 200;
V[7].z = 200;
V[7].x = 200;
V[7].y = 200;
V[8].z = 300;
V[8].x = -200;
V[8].y = 300;
V[9].z = 300;
V[9].x = 200;
V[9].y = 300;
}
void CTestView::ReadFace() // 面表
{
// // 面的边数、面的顶点编号
// F[0].SetNum(4);
// F[0].vI[0] = 4;
// F[0].vI[1] = 5;
// F[0].vI[2] = 6;
// F[0].vI[3] = 7; // 前面顶点索引
// F[0].t[0] = CT2(0, 0);
// F[0].t[1] = CT2(437, 0);
// F[0].t[2] = CT2(437, 437);
// F[0].t[3] = CT2(0, 437); // 前面纹理坐标
// F[1].SetNum(4);
// F[1].vI[0] = 0;
// F[1].vI[1] = 3;
// F[1].vI[2] = 2;
// F[1].vI[3] = 1; // 后面顶点索引
// F[1].t[0] = CT2(437, 0);
// F[1].t[1] = CT2(437, 437);
// F[1].t[2] = CT2(0, 437);
// F[1].t[3] = CT2(0, 0); // 后面纹理坐标
// F[2].SetNum(4);
// F[2].vI[0] = 0;
// F[2].vI[1] = 4;
// F[2].vI[2] = 7;
// F[2].vI[3] = 3; // 左面顶点索引
// F[2].t[0] = CT2(0, 0);
// F[2].t[1] = CT2(107, 0);
// F[2].t[2] = CT2(107, 437);
// F[2].t[3] = CT2(0, 437); // 左面纹理坐标
// F[3].SetNum(4);
// F[3].vI[0] = 1;
// F[3].vI[1] = 2;
// F[3].vI[2] = 6;
// F[3].vI[3] = 5; // 右面顶点索引
// F[3].t[0] = CT2(107, 0);
// F[3].t[1] = CT2(107, 437);
// F[3].t[2] = CT2(0, 437);
// F[3].t[3] = CT2(0, 0); // 右面纹理坐标
// F[4].SetNum(4);
// F[4].vI[0] = 2;
// F[4].vI[1] = 3;
// F[4].vI[2] = 7;
// F[4].vI[3] = 6; // 顶面顶点索引
// F[4].t[0] = CT2(0, 0);
// F[4].t[1] = CT2(437, 0);
// F[4].t[2] = CT2(437, 107);
// F[4].t[3] = CT2(0, 107); // 顶面纹理坐标
// F[5].SetNum(4);
// F[5].vI[0] = 0;
// F[5].vI[1] = 1;
// F[5].vI[2] = 5;
// F[5].vI[3] = 4; // 底面顶点索引
// F[5].t[0] = CT2(0, 0);
// F[5].t[1] = CT2(437, 0);
// F[5].t[2] = CT2(437, 107);
// F[5].t[3] = CT2(0, 107); // 底面纹理坐标
F[0].SetNum(4);
F[0].vI[0] = 1;
F[0].vI[1] = 2;
F[0].vI[2] = 6;
F[0].vI[3] = 5; // 前面
F[0].t[0] = CT2(0, 0);
F[0].t[1] = CT2(579, 0);
F[0].t[2] = CT2(579, 325);
F[0].t[3] = CT2(0, 325); // 前面纹理坐标
F[1].SetNum(4);
F[1].vI[0] = 0;
F[1].vI[1] = 4;
F[1].vI[2] = 7;
F[1].vI[3] = 3; // 后面
F[1].t[0] = CT2(0, 0);
F[1].t[1] = CT2(0, 289);
F[1].t[2] = CT2(579, 289);
F[1].t[3] = CT2(579, 0); // 后面纹理坐标
F[2].SetNum(5);
F[2].vI[0] = 0;
F[2].vI[1] = 1;
F[2].vI[2] = 5;
F[2].vI[3] = 8;
F[2].vI[4] = 4; // 左面
F[2].t[0] = CT2(0, 0);
F[2].t[1] = CT2(289, 0);
F[2].t[2] = CT2(289, 289);
F[2].t[3] = CT2(145, 434); // 左面纹理坐标
F[2].t[4] = CT2(0, 289);
F[3].SetNum(5);
F[3].vI[0] = 2;
F[3].vI[1] = 3;
F[3].vI[2] = 7;
F[3].vI[3] = 9;
F[3].vI[4] = 6; // 右面
F[3].t[0] = CT2(0, 0);
F[3].t[1] = CT2(289, 0);
F[3].t[2] = CT2(289, 289);
F[3].t[3] = CT2(145, 434); // 右面纹理坐标
F[3].t[4] = CT2(0, 289);
F[4].SetNum(4);
F[4].vI[0] = 4;
F[4].vI[1] = 8;
F[4].vI[2] = 9;
F[4].vI[3] = 7; // 顶面1
F[4].t[0] = CT2(0, 0);
F[4].t[1] = CT2(0, 385);
F[4].t[2] = CT2(579, 385);
F[4].t[3] = CT2(579, 0); // 顶面1纹理坐标
F[5].SetNum(4);
F[5].vI[0] = 5;
F[5].vI[1] = 6;
F[5].vI[2] = 9;
F[5].vI[3] = 8; // 顶面2
F[5].t[0] = CT2(0, 0);
F[5].t[1] = CT2(579, 0);
F[5].t[2] = CT2(579, 385);
F[5].t[3] = CT2(0, 385); // 顶面2纹理坐标
F[6].SetNum(4);
F[6].vI[0] = 0;
F[6].vI[1] = 3;
F[6].vI[2] = 2;
F[6].vI[3] = 1; // 底面
}
void CTestView::ReadGroundVertex() // 点表
{
double a = 500, b = 200, c = 500; // 长方体边长
// 顶点的三维坐标(x,y,z)
VGround[0].x = -a;
VGround[3].y = -b;
VGround[3].z = +c;
VGround[1].x = +a;
VGround[2].y = -b;
VGround[2].z = +c;
VGround[2].x = +a;
VGround[1].y = -b;
VGround[1].z = -c;
VGround[3].x = -a;
VGround[0].y = -b;
VGround[0].z = -c;
}
void CTestView::ReadGroundFace() // 面表
{
// 面的边数、面的顶点编号
FGround.SetNum(4);
FGround.vI[0] = 0;
FGround.vI[1] = 1;
FGround.vI[2] = 2;
FGround.vI[3] = 3; // 底面顶点索引
FGround.t[0] = CT2(0, 0);
FGround.t[1] = CT2(755, 0);
FGround.t[2] = CT2(755, 497);
FGround.t[3] = CT2(0, 497); // 底面纹理坐标
}
void CTestView::InitParameter() // 透视变换参数初始化
{
k[1] = sin(PI * Theta / 180);
k[2] = sin(PI * Phi / 180);
k[3] = cos(PI * Theta / 180);
k[4] = cos(PI * Phi / 180);
k[5] = k[2] * k[3];
k[6] = k[2] * k[1];
k[7] = k[4] * k[3];
k[8] = k[4] * k[1];
ViewPoint.x = R * k[6];
ViewPoint.y = R * k[4];
ViewPoint.z = R * k[5];
}
void CTestView::PerProject(CP3 P) // 透视变换
{
CP3 ViewP;
ViewP.x = P.x * k[3] - P.z * k[1]; // 观察坐标系三维坐标
ViewP.y = -P.x * k[8] + P.y * k[2] - P.z * k[7];
ViewP.z = -P.x * k[6] - P.y * k[4] - P.z * k[5] + R;
ViewP.c = P.c;
ScreenP.x = d * ViewP.x / ViewP.z; // 屏幕坐标系三维坐标
ScreenP.y = Round(d * ViewP.y / ViewP.z);
ScreenP.z = Far * (1 - Near / ViewP.z) / (Far - Near);
ScreenP.c = ViewP.c;
}
void CTestView::DoubleBuffer() // 双缓冲
{
CDC *pDC = GetDC();
CRect rect; // 定义客户区
GetClientRect(&rect); // 获得客户区的大小
pDC->SetMapMode(MM_ANISOTROPIC); // pDC自定义坐标系
pDC->SetWindowExt(rect.Width(), rect.Height()); // 设置窗口范围
pDC->SetViewportExt(rect.Width(), -rect.Height()); // x轴水平向右,y轴垂直向上
pDC->SetViewportOrg(rect.Width() / 2, rect.Height() / 2); // 屏幕中心为原点
CDC MemDC; // 内存DC
CBitmap NewBitmap, *pOldBitmap; // 内存中承载图像的临时位图
MemDC.CreateCompatibleDC(pDC); // 建立与屏幕pDC兼容的MemDC
NewBitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()); // 创建兼容位图
pOldBitmap = MemDC.SelectObject(&NewBitmap); // 将兼容位图选入MemDC
MemDC.SetMapMode(MM_ANISOTROPIC); // MemDC自定义坐标系
MemDC.SetWindowExt(rect.Width(), rect.Height());
MemDC.SetViewportExt(rect.Width(), -rect.Height());
MemDC.SetViewportOrg(rect.Width() / 2, rect.Height() / 2);
zbuf = new CZBuffer;
zbuf->InitDeepBuffer(1500, 1500, 1000); // 初始化深度缓冲器
DrawGround(&MemDC);
DrawObject(&MemDC);
pDC->BitBlt(-rect.Width() / 2, -rect.Height() / 2, rect.Width(), rect.Height(), &MemDC, -rect.Width() / 2, -rect.Height() / 2, SRCCOPY); // 将内存位图拷贝到屏幕
MemDC.SelectObject(pOldBitmap); // 恢复位图
NewBitmap.DeleteObject(); // 删除位图
ReleaseDC(pDC); // 释放DC
}
void CTestView::DrawGround(CDC *pDC) // 绘制地
{
CPi3 Point[4]; // 面的顶点坐标
CT2 Texture[4]; // 面的纹理坐标
CVector Normal4[4];
FGround.SetFaceNormal(VGround[0], VGround[1], VGround[2]);
FGround.fNormal.Normalize(); // 单位化法矢量
for (int nVertex = 0; nVertex < 4; nVertex++) // 边循环
{
PerProject(VGround[nVertex]);
Point[nVertex] = ScreenP;
Normal4[nVertex] = FGround.fNormal;
Texture[nVertex] = FGround.t[nVertex];
}
ReadImage(6);
zbuf->SetPoint(Point, Normal4, Texture, 4); // 初始化
zbuf->CreateBucket(); // 创建桶表
zbuf->CreateEdge(); // 创建边表
zbuf->Phong(pDC, ViewPoint, pLight, pMaterial, Image); // 纹理映射
zbuf->ClearMemory();
ClearImageMemory();
}
void CTestView::DrawObject(CDC *pDC) // 绘制物体
{
CPi3 Point[5]; // 面的顶点坐标
CT2 Texture[5]; // 面的纹理坐标
CVector Normal4[5];
for (int nFace = 0; nFace < 7; nFace++)
{
CVector ViewVector(V[F[nFace].vI[0]], ViewPoint); // 面的视矢量
ViewVector = ViewVector.Normalize(); // 单位化视矢量
F[nFace].SetFaceNormal(V[F[nFace].vI[0]], V[F[nFace].vI[1]], V[F[nFace].vI[2]]);
F[nFace].fNormal.Normalize(); // 单位化法矢量
if (Dot(ViewVector, F[nFace].fNormal) >= 0) // 背面剔除
{
for (int nVertex = 0; nVertex < F[nFace].vN; nVertex++) // 边循环
{
PerProject(V[F[nFace].vI[nVertex]]);
Point[nVertex] = ScreenP;
Normal4[nVertex] = F[nFace].fNormal;
Texture[nVertex] = F[nFace].t[nVertex];
}
ReadImage(nFace);
zbuf->SetPoint(Point, Normal4, Texture, F[nFace].vN); // 初始化
zbuf->CreateBucket(); // 创建桶表
zbuf->CreateEdge(); // 创建边表
zbuf->Phong(pDC, ViewPoint, pLight, pMaterial, Image); // 纹理映射
zbuf->ClearMemory();
ClearImageMemory();
}
}
delete zbuf;
}
void CTestView::ReadImage(int nface) // 读入纹理
{
int n1;
BYTE Texture[] = {IDB_FRONTWALL, IDB_REARWALL, IDB_LEFTWALL, IDB_RIGHTWALL, IDB_FRONTROOF, IDB_REARROOF, IDB_GROUND};
CBitmap NewBitmap;
NewBitmap.LoadBitmap(Texture[nface]); // 调入DDB位图
NewBitmap.GetBitmap(&bmp); // 将CBitmap的信息保存到Bitmap结构体中
int nbytesize = bmp.bmWidthBytes * bmp.bmHeight;
im = new BYTE[nbytesize];
NewBitmap.GetBitmapBits(nbytesize, (LPVOID)im);
Image = new COLORREF *[bmp.bmHeight];
for (int n1 = 0; n1 < bmp.bmHeight; n1++)
Image[n1] = new COLORREF[bmp.bmWidth];
for (n1 = 0; n1 < bmp.bmHeight; n1++)
{
for (int n2 = 0; n2 < bmp.bmWidth; n2++)
{
int pos = n1 * bmp.bmWidthBytes + 4 * n2; // 颜色分量位置
n1 = bmp.bmHeight - 1 - n1; // 位图从左下角向右上角绘制
Image[n1][n2] = RGB(im[pos + 2], im[pos + 1], im[pos]);
}
}
delete[] im;
}
void CTestView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CP3 center(0, 150, 300); // Center point of the cabin
switch (nChar)
{
case VK_UP:
tran.RotateX(Alpha, center);
break;
case VK_DOWN:
tran.RotateX(-Alpha, center);
break;
case VK_LEFT:
tran.RotateY(Beta, center);
break;
case VK_RIGHT:
tran.RotateY(-Beta, center);
break;
}
Invalidate(FALSE);
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CTestView::OnPlay()
{
// TODO: Add your command handler code here
bPlay = bPlay ? FALSE : TRUE;
if (bPlay) // 设置定时器
SetTimer(1, 150, NULL);
else
KillTimer(1);
}
void CTestView::OnTimer(UINT nIDEvent)
{
Alpha = 5;
Beta = 5;
CP3 center(0, 150, 300);
tran.RotateY(Beta, center);
Invalidate(FALSE);
CView::OnTimer(nIDEvent);
}
void CTestView::OnUpdatePlay(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
if (bPlay)
{
pCmdUI->SetCheck(TRUE);
pCmdUI->SetText("停止");
}
else
{
pCmdUI->SetCheck(FALSE);
pCmdUI->SetText("开始");
}
}
BOOL CTestView::OnEraseBkgnd(CDC *pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
}
void CTestView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
ReadVertex();
ReadFace();
ReadGroundVertex();
ReadGroundFace();
tran.SetMat(V, 10);
InitParameter();
}
void CTestView::ClearImageMemory()
{
for (int n = 0; n < bmp.bmHeight; n++) // 注意撤销次序,先列后行,与设置相反
{
delete[] Image[n];
Image[n] = NULL;
}
delete[] Image;
Image = NULL;
}
+104
View File
@@ -0,0 +1,104 @@
// TestView.h : interface of the CTestView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_TESTVIEW_H__A75FDCFB_621C_4E38_A154_C344803E6372__INCLUDED_)
#define AFX_TESTVIEW_H__A75FDCFB_621C_4E38_A154_C344803E6372__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Face.h"
#include "Vector.h"
#include "ZBuffer.h"
#include "Lighting.h"
#include "Transform.h"
class CTestView : public CView
{
protected: // create from serialization only
CTestView();
DECLARE_DYNCREATE(CTestView)
// Attributes
public:
CTestDoc* GetDocument();
// Operations
public:
void ReadImage(int);//读入纹理
void ReadVertex();//读入点表
void ReadFace();//读入面表
void ReadGroundVertex();//读入点表
void ReadGroundFace();//读入面表
void InitParameter();//参数初始化
void PerProject(CP3);//透视投影
void DoubleBuffer();//双缓冲绘图
void DrawObject(CDC *);//绘制长方体表面
void DrawGround(CDC* pDC);//绘制地
void ClearImageMemory();//清理位图内存
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void OnInitialUpdate();
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CTestView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
CP3 V[10];//点表
CFace F[7];//面表
CP3 VGround[4];//点表
CFace FGround;//面表
CZBuffer *zbuf;
double R,Theta,Phi;//视点在用户坐标系中的球坐标
double d;//视距
double Near,Far;//远近剪切面
double k[9];//运算常量
CP3 ViewPoint;//视点球坐标
CPi3 ScreenP;//屏幕坐标系的三维坐标点
double Alpha,Beta;//x方向旋转α角,y方向旋转β角
int LightNum;//光源数量
CLighting *pLight;//光照环境
CMaterial *pMaterial;//物体材质
BOOL bPlay;//动画开关
COLORREF **Image;//二维动态数组
CTransform tran;//变换对象
BITMAP bmp;//BITMAP结构体变量
BYTE *im;
// Generated message map functions
protected:
//{{AFX_MSG(CTestView)
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPlay();
afx_msg void OnUpdatePlay(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in TestView.cpp
inline CTestDoc* CTestView::GetDocument()
{ return (CTestDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TESTVIEW_H__A75FDCFB_621C_4E38_A154_C344803E6372__INCLUDED_)
+216
View File
@@ -0,0 +1,216 @@
// Transform.cpp: implementation of the CTransForm class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Transform.h"
#include "math.h"
#define PI 3.14159
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTransform::CTransform()
{
}
CTransform::~CTransform()
{
}
void CTransform::SetMat(CP3 *p, int n)
{
POld = p;
num = n;
}
void CTransform::Identity() // 单位矩阵
{
T[0][0] = 1.0;
T[0][1] = 0.0;
T[0][2] = 0.0;
T[0][3] = 0.0;
T[1][0] = 0.0;
T[1][1] = 1.0;
T[1][2] = 0.0;
T[1][3] = 0.0;
T[2][0] = 0.0;
T[2][1] = 0.0;
T[2][2] = 1.0;
T[2][3] = 0.0;
T[3][0] = 0.0;
T[3][1] = 0.0;
T[3][2] = 0.0;
T[3][3] = 1.0;
}
void CTransform::Translate(double tx, double ty, double tz) // 平移变换矩阵
{
Identity();
T[3][0] = tx;
T[3][1] = ty;
T[3][2] = tz;
MultiMatrix();
}
void CTransform::Scale(double sx, double sy, double sz) // 比例变换矩阵
{
Identity();
T[0][0] = sx;
T[1][1] = sy;
T[2][2] = sz;
MultiMatrix();
}
void CTransform::Scale(double sx, double sy, double sz, CP3 p) // 相对于任意点的比例变换矩阵
{
Translate(-p.x, -p.y, -p.z);
Scale(sx, sy, sz);
Translate(p.x, p.y, p.z);
}
void CTransform::RotateX(double beta) // 绕X轴旋转变换矩阵
{
Identity();
double rad = beta * PI / 180;
T[1][1] = cos(rad);
T[1][2] = sin(rad);
T[2][1] = -sin(rad);
T[2][2] = cos(rad);
MultiMatrix();
}
void CTransform::RotateX(double beta, CP3 p) // 相对于任意点的绕X轴旋转变换矩阵
{
Translate(-p.x, -p.y, -p.z);
RotateX(beta);
Translate(p.x, p.y, p.z);
}
void CTransform::RotateY(double beta) // 绕Y轴旋转变换矩阵
{
Identity();
double rad = beta * PI / 180;
T[0][0] = cos(rad);
T[0][2] = -sin(rad);
T[2][0] = sin(rad);
T[2][2] = cos(rad);
MultiMatrix();
}
void CTransform::RotateY(double beta, CP3 p) // 相对于任意点的绕Y轴旋转变换矩阵
{
Translate(-p.x, -p.y, -p.z);
RotateY(beta);
Translate(p.x, p.y, p.z);
}
void CTransform::RotateZ(double beta) // 绕Z轴旋转变换矩阵
{
Identity();
double rad = beta * PI / 180;
T[0][0] = cos(rad);
T[0][1] = sin(rad);
T[1][0] = -sin(rad);
T[1][1] = cos(rad);
MultiMatrix();
}
void CTransform::RotateZ(double beta, CP3 p) // 相对于任意点的绕Z轴旋转变换矩阵
{
Translate(-p.x, -p.y, -p.z);
RotateZ(beta);
Translate(p.x, p.y, p.z);
}
void CTransform::ReflectX() // X轴反射变换矩阵
{
Identity();
T[1][1] = -1;
T[2][2] = -1;
MultiMatrix();
}
void CTransform::ReflectY() // Y轴反射变换矩阵
{
Identity();
T[0][0] = -1;
T[2][2] = -1;
MultiMatrix();
}
void CTransform::ReflectZ() // Z轴反射变换矩阵
{
Identity();
T[0][0] = -1;
T[1][1] = -1;
MultiMatrix();
}
void CTransform::ReflectXOY() // XOY面反射变换矩阵
{
Identity();
T[2][2] = -1;
MultiMatrix();
}
void CTransform::ReflectYOZ() // YOZ面反射变换矩阵
{
Identity();
T[0][0] = -1;
MultiMatrix();
}
void CTransform::ReflectZOX() // ZOX面反射变换矩阵
{
Identity();
T[1][1] = -1;
MultiMatrix();
}
void CTransform::ShearX(double d, double g) // X方向错切变换矩阵
{
Identity();
T[1][0] = d;
T[2][0] = g;
MultiMatrix();
}
void CTransform::ShearY(double b, double h) // Y方向错切变换矩阵
{
Identity();
T[0][1] = b;
T[2][1] = h;
MultiMatrix();
}
void CTransform::ShearZ(double c, double f) // Z方向错切变换矩阵
{
Identity();
T[0][2] = c;
T[1][2] = f;
MultiMatrix();
}
void CTransform::MultiMatrix() // 矩阵相乘
{
CP3 *PNew = new CP3[num];
for (int i = 0; i < num; i++)
{
PNew[i] = POld[i];
}
for (int j = 0; j < num; j++)
{
POld[j].x = PNew[j].x * T[0][0] + PNew[j].y * T[1][0] + PNew[j].z * T[2][0] + PNew[j].w * T[3][0];
POld[j].y = PNew[j].x * T[0][1] + PNew[j].y * T[1][1] + PNew[j].z * T[2][1] + PNew[j].w * T[3][1];
POld[j].z = PNew[j].x * T[0][2] + PNew[j].y * T[1][2] + PNew[j].z * T[2][2] + PNew[j].w * T[3][2];
POld[j].w = PNew[j].x * T[0][3] + PNew[j].y * T[1][3] + PNew[j].z * T[2][3] + PNew[j].w * T[3][3];
}
delete[] PNew;
}
+44
View File
@@ -0,0 +1,44 @@
// Transform.h: interface for the CTransform class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TRANSFORM_H__C4FA86B2_0AF5_409A_94EB_B02A1EE13E05__INCLUDED_)
#define AFX_TRANSFORM_H__C4FA86B2_0AF5_409A_94EB_B02A1EE13E05__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "P3.h"
class CTransform//三维变换
{
public:
CTransform();
virtual ~CTransform();
void SetMat(CP3 *,int);
void Identity();
void Translate(double,double,double);//平移变换矩阵
void Scale(double,double,double);//比例变换矩阵
void Scale(double,double,double,CP3);//相对于任意点的比例变换矩阵
void RotateX(double);//旋转变换矩阵
void RotateX(double,CP3);//相对于任意点的X旋转变换矩阵
void RotateY(double);//旋转变换矩阵
void RotateY(double,CP3);//相对于任意点的Y旋转变换矩阵
void RotateZ(double);//旋转变换矩阵
void RotateZ(double,CP3);//相对于任意点的Z旋转变换矩阵
void ReflectX();//X轴反射变换矩阵
void ReflectY();//Y轴反射变换矩阵
void ReflectZ();//Z轴反射变换矩阵
void ReflectXOY();//XOY面反射变换矩阵
void ReflectYOZ();//YOZ面反射变换矩阵
void ReflectZOX();//ZOX面反射变换矩阵
void ShearX(double,double);//X方向错切变换矩阵
void ShearY(double,double);//Y方向错切变换矩阵
void ShearZ(double,double);//Z方向错切变换矩阵
void MultiMatrix();//矩阵相乘
public:
double T[4][4];
CP3 *POld;
int num;
};
#endif // !defined(AFX_TRANSFORM_H__C4FA86B2_0AF5_409A_94EB_B02A1EE13E05__INCLUDED_)
+175
View File
@@ -0,0 +1,175 @@
// Vector.cpp: implementation of the CVector class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "Vector.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CVector::CVector()//z轴正向
{
x=0.0;
y=0.0;
z=1.0;
}
CVector::~CVector()
{
}
CVector::CVector(const CP3 &p)
{
x=p.x;
y=p.y;
z=p.z;
}
CVector::CVector(const CPi3 &p)
{
x=p.x;
y=p.y;
z=p.z;
}
CVector::CVector(double x,double y,double z)
{
this->x=x;
this->y=y;
this->z=z;
}
CVector::CVector(const CP3 &p0,const CP3 &p1)
{
x=p1.x-p0.x;
y=p1.y-p0.y;
z=p1.z-p0.z;
}
CVector::CVector(const CPi3 &p0,const CPi3 &p1)
{
x=p1.x-p0.x;
y=p1.y-p0.y;
z=p1.z-p0.z;
}
double CVector::Mag()//矢量的模
{
return sqrt(x*x+y*y+z*z);
}
CVector CVector::Normalize()//归一化到单位矢量
{
CVector vector;
double Mag=sqrt(x*x+y*y+z*z);
if(fabs(Mag)<1e-6)
Mag=1.0;
vector.x=x/Mag;
vector.y=y/Mag;
vector.z=z/Mag;
return vector;
}
CVector operator +(const CVector &v0,const CVector &v1)//矢量的和
{
CVector vector;
vector.x=v0.x+v1.x;
vector.y=v0.y+v1.y;
vector.z=v0.z+v1.z;
return vector;
}
CVector operator -(const CVector &v0,const CVector &v1)//矢量的差
{
CVector vector;
vector.x=v0.x-v1.x;
vector.y=v0.y-v1.y;
vector.z=v0.z-v1.z;
return vector;
}
CVector operator *(const CVector &v,double k)//矢量与常量的积
{
CVector vector;
vector.x=v.x*k;
vector.y=v.y*k;
vector.z=v.z*k;
return vector;
}
CVector operator *(double k,const CVector &v)//常量与矢量的积
{
CVector vector;
vector.x=v.x*k;
vector.y=v.y*k;
vector.z=v.z*k;
return vector;
}
CVector operator /(const CVector &v,double k)//矢量数除
{
if(fabs(k)<1e-6)
k=1.0;
CVector vector;
vector.x=v.x/k;
vector.y=v.y/k;
vector.z=v.z/k;
return vector;
}
CVector operator +=(CVector &v0,CVector &v1)//+=运算符重载
{
v0.x=v0.x+v1.x;
v0.y=v0.y+v1.y;
v0.z=v0.z+v1.z;
return v1;
}
CVector operator -=(CVector &v0,CVector &v1)//-=运算符重载
{
v0.x=v0.x-v1.x;
v0.y=v0.y-v1.y;
v0.z=v0.z-v1.z;
return v0;
}
CVector operator *=(CVector &v0,CVector &v1)//*=运算符重载
{
v0.x=v0.x*v1.x;
v0.y=v0.y*v1.y;
v0.z=v0.z*v1.z;
return v0;
}
CVector operator /=(CVector &v,double k)///=运算符重载
{
v.x=v.x/k;
v.y=v.y/k;
v.z=v.z/k;
return v;
}
double Dot(const CVector &v0,const CVector &v1)//矢量的点积
{
return(v0.x*v1.x+v0.y*v1.y+v0.z*v1.z);
}
CVector Cross(const CVector &v0,const CVector &v1)//矢量的叉积
{
CVector vector;
vector.x=v0.y*v1.z-v0.z*v1.y;
vector.y=v0.z*v1.x-v0.x*v1.z;
vector.z=v0.x*v1.y-v0.y*v1.x;
return vector;
}
+41
View File
@@ -0,0 +1,41 @@
// Vector.h: interface for the CVector class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_VECTOR_H__8C972371_1C22_4E15_A2A8_3CE42319C9CB__INCLUDED_)
#define AFX_VECTOR_H__8C972371_1C22_4E15_A2A8_3CE42319C9CB__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "P3.h"
#include "Pi3.h"
class CVector
{
public:
CVector();
virtual ~CVector();
CVector(double x,double y,double z);
CVector(const CP3 &);
CVector(const CPi3 &);
CVector(const CP3 &,const CP3 &);
CVector(const CPi3 &,const CPi3 &);
double Mag();//矢量的模
CVector Normalize();//单位矢量
friend CVector operator +(const CVector &,const CVector &);//运算符重载
friend CVector operator -(const CVector &,const CVector &);
friend CVector operator *(const CVector &,double);
friend CVector operator *(double,const CVector &);
friend CVector operator /(const CVector &,double);
friend CVector operator+=(CVector &,CVector &);
friend CVector operator-=(CVector &,CVector &);
friend CVector operator*=(CVector &,CVector &);
friend CVector operator/=(CVector &,double);
friend double Dot(const CVector &,const CVector &); //矢量点积
friend CVector Cross(const CVector &,const CVector &);//矢量叉积
public:
double x,y,z;//公有数据成员,方便外部访问
};
#endif // !defined(AFX_VECTOR_H__8C972371_1C22_4E15_A2A8_3CE42319C9CB__INCLUDED_)
+389
View File
@@ -0,0 +1,389 @@
// ZBuffer.cpp: implementation of the CZBuffer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test.h"
#include "ZBuffer.h"
#include "math.h"
#define Round(d) int(floor(d+0.5))
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CZBuffer::CZBuffer()
{
P=NULL;
N=NULL;
T=NULL;
pHeadE=NULL;
pCurrentB=NULL;
pEdge=NULL;
pCurrentE=NULL;
pHeadB=NULL;
zBuffer=NULL;
}
CZBuffer::~CZBuffer()
{
for(int i=0;i<Width;i++)
{
delete[] zBuffer[i];
zBuffer[i]=NULL;
}
if(zBuffer!=NULL)
{
delete zBuffer;
zBuffer=NULL;
}
ClearMemory();
}
void CZBuffer::SetPoint(CPi3 *p,CVector *n,CT2 *t,int m)
{
P=new CPi3[m];
N=new CVector[m];
T=new CT2[m];
for(int i=0;i<m;i++)
{
P[i]=p[i];
N[i]=n[i];
T[i]=t[i];
}
PNum=m;
}
void CZBuffer::CreateBucket()//创建桶表
{
int yMin,yMax;
yMin=yMax=P[0].y;
for(int i=1;i<PNum;i++)//查找多边形所覆盖的最小和最大扫描线
{
if(P[i].y<yMin)
yMin=P[i].y;//扫描线的最小值
if(P[i].y>yMax)
yMax=P[i].y;//扫描线的最大值
}
for(int y=yMin;y<=yMax;y++)
{
if(yMin==y)//建立桶头结点
{
pHeadB=new CBucket;//建立桶的头结点
pCurrentB=pHeadB;//pCurrentB为CBucket当前结点指针
pCurrentB->ScanLine=yMin;
pCurrentB->pET=NULL;//没有链接边表
pCurrentB->pNext=NULL;
}
else//其他扫描线
{
pCurrentB->pNext=new CBucket;//建立桶的其他结点
pCurrentB=pCurrentB->pNext;
pCurrentB->ScanLine=y;
pCurrentB->pET=NULL;
pCurrentB->pNext=NULL;
}
}
}
void CZBuffer::CreateEdge()//创建边表
{
for(int i=0;i<PNum;i++)
{
pCurrentB=pHeadB;
int j=(i+1)%PNum;//边的第二个顶点,P[i]和P[j]构成边
if(P[i].y<P[j].y)//边的终点比起点高
{
pEdge=new CAET;
pEdge->x=P[i].x;//计算ET表的值
pEdge->yMax=P[j].y;
pEdge->k=(P[j].x-P[i].x)/(P[j].y-P[i].y);//代表1/k
pEdge->ps=P[i];//绑定顶点和颜色
pEdge->pe=P[j];
pEdge->ns=N[i];//绑定法矢量
pEdge->ne=N[j];
pEdge->ts=T[i];//绑定纹理
pEdge->te=T[j];
pEdge->pNext=NULL;
while(pCurrentB->ScanLine!=P[i].y)//在桶内寻找该边的yMin
{
pCurrentB=pCurrentB->pNext;//移到yMin所在的桶结点
}
}
if(P[j].y<P[i].y)//边的终点比起点低
{
pEdge=new CAET;
pEdge->x=P[j].x;
pEdge->yMax=P[i].y;
pEdge->k=(P[i].x-P[j].x)/(P[i].y-P[j].y);
pEdge->ps=P[i];
pEdge->pe=P[j];
pEdge->ns=N[i];
pEdge->ne=N[j];
pEdge->ts=T[i];
pEdge->te=T[j];
pEdge->pNext=NULL;
while(pCurrentB->ScanLine!=P[j].y)
{
pCurrentB=pCurrentB->pNext;
}
}
if(int(P[j].y)!=P[i].y)
{
pCurrentE=pCurrentB->pET;
if(pCurrentE==NULL)
{
pCurrentE=pEdge;
pCurrentB->pET=pCurrentE;
}
else
{
while(pCurrentE->pNext!=NULL)
{
pCurrentE=pCurrentE->pNext;
}
pCurrentE->pNext=pEdge;
}
}
}
}
void CZBuffer::Phong(CDC *pDC,CP3 ViewPoint,CLighting *pLight,CMaterial *pMaterial,COLORREF **Image)//填充多边形
{
double z=0.0;//当前扫描线的z
double zStep=0.0;//当前扫描线随着x增长的z步长
double A,B,C,D;//平面方程Ax+By+Cz+D=0的系数
CVector V01(P[0],P[1]),V02(P[0],P[2]);
CVector VN=Cross(V01,V02);
A=VN.x;B=VN.y;C=VN.z;
D=-A*P[0].x-B*P[0].y-C*P[0].z;
zStep=-A/C;//计算直线z增量
CAET *pT1,*pT2;
pHeadE=NULL;
for(pCurrentB=pHeadB;pCurrentB!=NULL;pCurrentB=pCurrentB->pNext)
{
for(pCurrentE=pCurrentB->pET;pCurrentE!=NULL;pCurrentE=pCurrentE->pNext)
{
pEdge=new CAET;
pEdge->x=pCurrentE->x;
pEdge->yMax=pCurrentE->yMax;
pEdge->k=pCurrentE->k;
pEdge->ps=pCurrentE->ps;
pEdge->pe=pCurrentE->pe;
pEdge->ns=pCurrentE->ns;
pEdge->ne=pCurrentE->ne;
pEdge->ts=pCurrentE->ts;
pEdge->te=pCurrentE->te;
pEdge->pNext=NULL;
AddEt(pEdge);
}
ETOrder();
pT1=pHeadE;
if(pT1==NULL)
return;
while(pCurrentB->ScanLine>=pT1->yMax)//下闭上开
{
CAET * pAETTEmp=pT1;
pT1=pT1->pNext;
delete pAETTEmp;
pHeadE=pT1;
if(pHeadE==NULL)
return;
}
if(pT1->pNext!=NULL)
{
pT2=pT1;
pT1=pT2->pNext;
}
while(pT1!=NULL)
{
if(pCurrentB->ScanLine>=pT1->yMax)//下闭上开
{
CAET* pAETTemp =pT1;
pT2->pNext=pT1->pNext;
pT1=pT2->pNext;
delete pAETTemp;
}
else
{
pT2=pT1;
pT1=pT2->pNext;
}
}
CVector na,nb,nf;//na、nb代表边上任意点的法矢量,nf代表面上任意点的法矢量
na=Interpolation(pCurrentB->ScanLine,pHeadE->ps.y,pHeadE->pe.y,pHeadE->ns,pHeadE->ne);
nb=Interpolation(pCurrentB->ScanLine,pHeadE->pNext->ps.y,pHeadE->pNext->pe.y,pHeadE->pNext->ns,pHeadE->pNext->ne);
CT2 ta,tb,tf;//ta和tb代表边上任意点的纹理,tf代表面上任意点的纹理
ta=Interpolation(pCurrentB->ScanLine,pHeadE->ps.y,pHeadE->pe.y,pHeadE->ts,pHeadE->te);
tb=Interpolation(pCurrentB->ScanLine,pHeadE->pNext->ps.y,pHeadE->pNext->pe.y,pHeadE->pNext->ts,pHeadE->pNext->te);
BOOL bInFlag=FALSE;//区间内外测试标志,初始值为假表示区间外部
double xb,xe;//扫描线和有效边相交区间的起点和终点坐标
for(pT1=pHeadE;pT1!=NULL;pT1=pT1->pNext)
{
if(FALSE==bInFlag)
{
xb=pT1->x;
z=-(xb*A+pCurrentB->ScanLine*B+D)/C;//z=-(Ax+By+D)/C
bInFlag=TRUE;
}
else
{
xe=pT1->x;
for(double x=xb;x<xe;x++)//左闭右开
{
nf=Interpolation(x,xb,xe,na,nb);
tf=Interpolation(x,xb,xe,ta,tb);
COLORREF clr=Image[Round(tf.v)][Round(tf.u)];
CRGB Textureclr=CRGB(GetRValue(clr)/255.0,GetGValue(clr)/255.0,GetBValue(clr)/255.0);
// pMaterial->SetDiffuse(Textureclr);//用纹理颜色作为材质的漫反射光反射率
//pMaterial->SetAmbient(Textureclr);//用纹理颜色作为材质的环境光反射率
CRGB c=Textureclr;//pLight->Lighting(ViewPoint,CP3(Round(x),pCurrentB->ScanLine,z),nf,pMaterial);
if(z<=zBuffer[Round(x)+Width/2][pCurrentB->ScanLine+Height/2])//如果新采样点的深度小于原采样点的深度
{
zBuffer[Round(x)+Width/2][pCurrentB->ScanLine+Height/2]=z;//xy坐标与数组下标保持一致
pDC->SetPixelV(Round(x),pCurrentB->ScanLine,RGB(c.red*255,c.green*255,c.blue*255));
}
z+=zStep;
}
bInFlag=FALSE;
}
}
for(pT1=pHeadE;pT1!=NULL;pT1=pT1->pNext)//边的连续性
pT1->x=pT1->x+pT1->k;
}
}
void CZBuffer::AddEt(CAET *pNewEdge)//合并ET表
{
CAET *pCE;
pCE=pHeadE;
if(pCE==NULL)
{
pHeadE=pNewEdge;
pCE=pHeadE;
}
else
{
while(pCE->pNext!=NULL)
{
pCE=pCE->pNext;
}
pCE->pNext=pNewEdge;
}
}
void CZBuffer::ETOrder()//边表的冒泡排序算法
{
CAET *pT1,*pT2;
int Count=1;
pT1=pHeadE;
if(pT1==NULL)
return;
if(pT1->pNext==NULL)//如果该ET表没有再连ET表
return;//桶结点只有一条边,不需要排序
while(pT1->pNext!=NULL)//统计边结点的个数
{
Count++;
pT1=pT1->pNext;
}
for(int i=0;i<Count-1;i++)//冒泡排序
{
CAET **pPre=&pHeadE;
pT1=pHeadE;
for(int j=0;j<Count-1-i;j++)
{
pT2=pT1->pNext;
if ((pT1->x>pT2->x)||((pT1->x==pT2->x)&&(pT1->k>pT2->k)))
{
pT1->pNext=pT2->pNext;
pT2->pNext=pT1;
*pPre=pT2;
pPre=&(pT2->pNext);//调整位置为下次遍历准备
}
else
{
pPre=&(pT1->pNext);
pT1=pT1->pNext;
}
}
}
}
CRGB CZBuffer::Interpolation(double t,double t1,double t2,CRGB clr1,CRGB clr2)//颜色线性插值
{
CRGB color;
color=(t-t2)/(t1-t2)*clr1+(t-t1)/(t2-t1)*clr2;
return color;
}
CVector CZBuffer::Interpolation(double t,double t1,double t2,CVector vec1,CVector vec2)//矢量线性插值
{
CVector vector;
vector=(t-t2)/(t1-t2)*vec1+(t-t1)/(t2-t1)*vec2;
return vector;
}
CT2 CZBuffer::Interpolation(double t,double t1,double t2,CT2 tex1,CT2 tex2)//纹理线性插值
{
CT2 texture;
texture=(t-t2)/(t1-t2)*tex1+(t-t1)/(t2-t1)*tex2;
return texture;
}
void CZBuffer::InitDeepBuffer(int Width,int Height,double Depth)//初始化深度缓冲
{
int i;
this->Width=Width,this->Height=Height;
zBuffer=new double *[Width];
for(int i=0;i<Width;i++)
zBuffer[i]=new double[Height];
for(i=0;i<Width;i++)//初始化深度缓冲
for(int j=0;j<Height;j++)
zBuffer[i][j]=Depth;
}
void CZBuffer::ClearMemory()
{
DeleteAETChain(pHeadE);
CBucket *pBucket=pHeadB;
while (pBucket !=NULL)//针对每一个桶
{
CBucket * pBucketTemp = pBucket->pNext;
DeleteAETChain(pBucket->pET);
delete pBucket;
pBucket=pBucketTemp;
}
pHeadB=NULL;
pHeadE=NULL;
if(P!=NULL)
{
delete []P;
P=NULL;
}
if(N!=NULL)
{
delete []N;
N=NULL;
}
if (T!=NULL)
{
delete []T;
T=NULL;
}
}
void CZBuffer::DeleteAETChain(CAET* pAET)
{
while (pAET!=NULL)
{
CAET* pAETTemp=pAET->pNext;
delete pAET;
pAET=pAETTemp;
}
}
+45
View File
@@ -0,0 +1,45 @@
// ZBuffer.h: interface for the CZBuffer class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZBUFFER_H__ED93E842_7399_49B8_B579_6A52FBA1289D__INCLUDED_)
#define AFX_ZBUFFER_H__ED93E842_7399_49B8_B579_6A52FBA1289D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Pi3.h"//三维点头文件
#include "Bucket.h"//桶头文件
#include "Vector.h"//矢量头文件
#include "Lighting.h"
#include "Material.h"
class CZBuffer
{
public:
CZBuffer();
virtual ~CZBuffer();
void CreateBucket();//创建桶
void CreateEdge();//边表
void AddEt(CAET *);//合并ET表
void ETOrder();//ET表排序
void Phong(CDC *,CP3,CLighting *,CMaterial *,COLORREF **);//Phong填充函数
void InitDeepBuffer(int,int,double);//初始化深度缓冲器
CRGB Interpolation(double,double,double,CRGB,CRGB);//颜色线性插值
CVector Interpolation(double,double,double,CVector,CVector);//法矢线性插值
CT2 Interpolation(double,double,double,CT2,CT2);//纹理线性插值
void SetPoint(CPi3 *,CVector *,CT2 *,int);
void ClearMemory();//清理内存
void DeleteAETChain(CAET* pAET);//删除边表
protected:
int PNum;//顶点个数
CPi3 *P;//顶点数组
CVector *N;//顶点的法矢量动态数组
CT2 *T;//纹理动态数组
CAET *pHeadE,*pCurrentE,*pEdge;//有效边表结点指针
CBucket *pCurrentB,*pHeadB;
double **zBuffer;//缓深度冲区
int Width,Height;//缓冲区参数
};
#endif // !defined(AFX_ZBUFFER_H__ED93E842_7399_49B8_B579_6A52FBA1289D__INCLUDED_)
+47
View File
@@ -0,0 +1,47 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Test.rc
//
#define IDD_ABOUTBOX 100
#define IDR_MAINFRAME 128
#define IDR_TESTTYPE 129
#define IDI_ICON1 130
#define IDI_ICON2 131
#define IDI_ICON3 132
#define IDI_ICON4 133
#define IDB_BITMAP1 134
#define IDB_ABOUT 134
#define IDI_ICON5 138
#define IDB_BITMAP2 139
#define IDI_ICON6 142
#define IDB_BACK 145
#define IDB_BOTTOM 146
#define IDB_FRONT 147
#define IDB_LEFT 148
#define IDB_TOP 149
#define IDB_RIGHT 150
#define IDB_BITMAP3 159
#define IDB_GROUND 159
#define IDB_FRONTWALL 160
#define IDB_BITMAP4 162
#define IDB_BACKWALL 162
#define IDB_REARWALL 164
#define IDB_LEFTWALL 165
#define IDB_RIGHTWALL 166
#define IDB_FRONTROOF 167
#define IDB_BITMAP6 168
#define IDB_REARROOF 168
#define ID_MENUPlay 32781
#define IDM_PLAY 32783
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 169
#define _APS_NEXT_COMMAND_VALUE 32784
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif