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

📄 designdoc.cpp

📁 本文以数字图像处理、压缩技术和MATLAB应用为基础
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// DesignDoc.cpp : implementation of the CDesignDoc class
//
//		From String table
//		\nDesign\nDesign\n\n\nDesign.Document\nDesign Document
//
#include "stdafx.h"
#include "Design.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define HEIGHT 9
/////////////////////////////////////////////////////////////////////////////
// CDesignDoc

IMPLEMENT_DYNCREATE(CDesignDoc, CDocument)

BEGIN_MESSAGE_MAP(CDesignDoc, CDocument)
	//{{AFX_MSG_MAP(CDesignDoc)
	ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
	ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
	ON_COMMAND(ID_VIEW_TRANSPARENT, OnViewTransparent)
	ON_UPDATE_COMMAND_UI(ID_VIEW_TRANSPARENT, OnUpdateViewTransparent)
	ON_COMMAND(ID_ELEMENT_ROOM, OnElementRoom)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_ROOM, OnUpdateElementRoom)
	ON_COMMAND(ID_ELEMENT_CURSOR, OnElementCursor)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_CURSOR, OnUpdateElementCursor)
	ON_COMMAND(ID_ELEMENT_DOOR, OnElementDoor)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_DOOR, OnUpdateElementDoor)
	ON_COMMAND(ID_ELEMENT_WINDOW, OnElementWindow)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_WINDOW, OnUpdateElementWindow)
	ON_COMMAND(ID_ELEMENT_ROOF, OnElementRoof)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_ROOF, OnUpdateElementRoof)
	ON_COMMAND(ID_VIEW_WALKTHROUGH, OnViewWalkthrough)
	ON_UPDATE_COMMAND_UI(ID_VIEW_WALKTHROUGH, OnUpdateViewWalkthrough)
	ON_COMMAND(ID_VIEW_NORMAL, OnViewNormal)
	ON_UPDATE_COMMAND_UI(ID_VIEW_NORMAL, OnUpdateViewNormal)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDesignDoc construction/destruction

CDesignDoc::CDesignDoc()
{
	m_ElemSelected = -1;
	m_sel_pt_a = 0;
	m_sel_pt_b = 0;

	// TODO: add one-time construction code here
	m_xRotate = 0;
	m_yRotate = 90;
	m_sizeDoc = CSize(640, 640);

	m_Thickness = 2;
	m_Color = RGB(192,192,0);
	m_CurrentElement = 	ID_ELEMENT_CURSOR;
	m_Transparent = FALSE;
//////////////////////////////
	eyex = 0;
	eyey = 5;
	eyez = 100;

	centerx = 0;
	centery = 5;
	centerz = 99;

	m_xz_angle = 0;
	m_yz_angle = 0;

	m_CurrentMode = ID_VIEW_NORMAL;
}

CDesignDoc::~CDesignDoc()
{
}

BOOL CDesignDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CDesignDoc serialization

void CDesignDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		m_ElemArray.Serialize(ar);
	}
	else
	{
		// TODO: add loading code here
		m_ElemArray.Serialize(ar);
	}
}


/////////////////////////////////////////////////////////////////////////////
// CDesignDoc diagnostics

#ifdef _DEBUG
void CDesignDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CDesignDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDesignDoc commands
void CDesignDoc::RenderScene()
{
	GLfloat LightAmbient[] =  { 0.4f, 0.4f, 0.4f, 0.1f};
	GLfloat LightDiffuse[] =  { 1.0f, 1.0f, 1.0f, 0.7f};
	GLfloat LightSpecular[] = { 1.0f, 1.0f,	1.0f, 1.0f};
	GLfloat LightPosition[] = { eyex+3, eyey+3, eyez+3, 1.0f};
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular);
	glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
	glEnable(GL_LIGHT0);

	CRoof *pRoof;
	CPoint  topleft, bottomright;
	double top, left, bottom, right, height = 4; //, midpoint;
	double normalizex, normalizey;
	CElement *pElement;
	CRect	Temprect;
	int NumElem = GetNumElem();
	int i;


	glEnable(GL_COLOR_MATERIAL);
	if (m_Transparent)
	{
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	else
	{
		glDisable(GL_BLEND);
	}
	glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

	glPushMatrix();
////////Translate and rotate to the proper position
		gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, 0, 1, 0);
	
		glRotated(m_xRotate, 1.0, 0.0, 0.0);
		glRotated(m_yRotate, 0.0, 1.0, 0.0);
		glTranslated(-32, 0.0, -32);

////////Locate Doors
		glColor4f(0.6f, 0.4f, 0.1f, 1.0f);
		for (i = 0; i < NumElem; ++i)
		{
			pElement = GetElem(i);
			if (pElement->m_ElemType == DOOR)	// if it is a room
			{
				Temprect = pElement->GetDimRect();
				topleft = Temprect.TopLeft();
				top = (640 - topleft.y)/10.0;
				left = topleft.x/10.0;
				bottomright = Temprect.BottomRight();
				bottom = (640 - bottomright.y)/10.0;
				right = bottomright.x/10.0;
				if (abs(top - bottom) > abs(right - left))
				{
					glTranslated(bottom, 0.0, left + 0.8);
					glCallList(DOOR);
					glTranslated(-bottom, 0.0, -(left + 0.8));
				}
				else
				{
					glTranslated(bottom + 0.8, 0.0, left);
					glRotated(-90.0, 0.0, 1.0, 0.0);
					glCallList(DOOR);
					glRotated(90.0, 0.0, 1.0, 0.0);
					glTranslated(-(bottom + 0.8), 0.0, -left);
				}
			}

		}
////////Locate Windows
		glColor4f(0.5f, 0.5f, 0.9f, 1.0f);
		for (i = 0; i < NumElem; ++i)
		{
			pElement = GetElem(i);
			if (pElement->m_ElemType == WINDOW)	// if it is a room
			{
				Temprect = pElement->GetDimRect();
				topleft = Temprect.TopLeft();
				top = (640 - topleft.y)/10.0;
				left = (topleft.x)/10.0;
				bottomright = Temprect.BottomRight();
				bottom = (640 - bottomright.y)/10.0;
				right = (bottomright.x)/10.0;
				if (abs(top - bottom) > abs(right - left))
				{
					glTranslated(bottom, 2.4, (left + 0.8));
					glCallList(WINDOW);
					glTranslated(-bottom, -2.4, -(left + 0.8));
				}
				else
				{
					glTranslated((bottom + 0.8), 2.4, left);
					glRotated(-90.0, 0.0, 1.0, 0.0);
					glCallList(WINDOW);
					glRotated(90.0, 0.0, 1.0, 0.0);
					glTranslated(-(bottom + 0.8), -2.4, -left);
				}
			}
		}


////////Locate Rooms
		glColor4f(1.0f, 1.0f, 0.4f, 0.5f);
		for (i = 0; i < NumElem; ++i)
		{	
////////////Cannot use List because of distortion of lighting due to scaling
			pElement = GetElem(i);
			if (pElement->m_ElemType == ROOM)	// if it is a room
			{
				Temprect = pElement->GetDimRect();
				topleft = Temprect.TopLeft();
				top = (640 - topleft.y)/10.0;
				left = topleft.x/10.0;
				bottomright = Temprect.BottomRight();
				bottom = (640 - bottomright.y)/10.0;
				right = bottomright.x/10.0;
				glBegin(GL_QUADS);
					glNormal3d(  0.0,  0.0,  -1.0);
					glVertex3d(  top - 0.001,  0.0, left + 0.001);
					glVertex3d(  top - 0.001,  0.8*HEIGHT, left + 0.001);
					glVertex3d(  bottom + 0.001,  0.8*HEIGHT, left + 0.001);
					glVertex3d(  bottom + 0.001,  0.0, left + 0.001);
				glEnd();
				glBegin(GL_QUADS);
					glNormal3d(  0.0,  0.0,  1.0);
					glVertex3d(  top - 0.001,  0.0, right - 0.001);
					glVertex3d(  top - 0.001,  0.8*HEIGHT, right - 0.001);
					glVertex3d(  bottom + 0.001,  0.8*HEIGHT, right - 0.001);
					glVertex3d(  bottom + 0.001,  0.0, right - 0.001);
				glEnd();
				glBegin(GL_QUADS);
					glNormal3d(  1.0,  0.0,  0.0);
					glVertex3d(  top - 0.001,  0.0, left + 0.001);
					glVertex3d(  top - 0.001,  0.8*HEIGHT, left + 0.001);
					glVertex3d(  top - 0.001,  0.8*HEIGHT, right - 0.001);
					glVertex3d(  top - 0.001,  0.0, right - 0.001);
				glEnd();
				glBegin(GL_QUADS);
					glNormal3d(  -1.0,  0.0,  0.0);
					glVertex3d(  bottom + 0.001,  0.0, left + 0.001);
					glVertex3d(  bottom + 0.001,  0.8*HEIGHT, left + 0.001);
					glVertex3d(  bottom + 0.001,  0.8*HEIGHT, right - 0.001);
					glVertex3d(  bottom + 0.001,  0.0, right - 0.001);
				glEnd();

				glBegin(GL_QUADS);
					glNormal3d(  0.0,  0.0,  1.0);
					glVertex3d(  top - 0.003,  0.0, left + 0.003);
					glVertex3d(  top - 0.003,  0.8*HEIGHT, left + 0.003);
					glVertex3d(  bottom + 0.003,  0.8*HEIGHT , left + 0.003);
					glVertex3d(  bottom + 0.003,  0.0, left +0.003);
				glEnd();
				glBegin(GL_QUADS);
					glNormal3d(  0.0,  0.0,  -1.0);
					glVertex3d(  top - 0.003,  0.0, right - 0.003);
					glVertex3d(  top - 0.003,  0.8*HEIGHT, right - 0.003);
					glVertex3d(  bottom + 0.003,  0.8*HEIGHT, right - 0.003);
					glVertex3d(  bottom + 0.003,  0.0, right - 0.003);
				glEnd();
				glBegin(GL_QUADS);
					glNormal3d(  -1.0,  0.0,  0.0);
					glVertex3d(  top - 0.003,  0.0, left + 0.003);
					glVertex3d(  top - 0.003,  0.8*HEIGHT, left + 0.003);
					glVertex3d(  top - 0.003,  0.8*HEIGHT, right - 0.003);
					glVertex3d(  top - 0.003,  0.0, right - 0.003);
				glEnd();
				glBegin(GL_QUADS);
					glNormal3d(  1.0,  0.0,  0.0);
					glVertex3d(  bottom + 0.003,  0.0, left + 0.003);
					glVertex3d(  bottom + 0.003,  0.8*HEIGHT, left + 0.003);
					glVertex3d(  bottom + 0.003,  0.8*HEIGHT, right - 0.003);
					glVertex3d(  bottom + 0.003,  0.0, right - 0.003);
				glEnd();
			}
		}

////////Locate Roofs
		glColor4f(0.8f, 0.2f, 0.1f, 0.5f);
		for (i = 0; i < NumElem; ++i)
		{	
////////////Cannot use List because of distortion of lighting due to scaling
			pElement = GetElem(i);
			if (pElement->m_ElemType == ROOF)	// if it is a roof
			{
				pRoof = (CRoof*)GetElem(i);
				Temprect = pRoof->GetDimRect();

				topleft = Temprect.TopLeft();
				top = (640 - topleft.y)/10.0;
				left = topleft.x/10.0;
				bottomright = Temprect.BottomRight();
				bottom = (640 - bottomright.y)/10.0;
				right = bottomright.x/10.0;

				glBegin(GL_QUADS);
					glNormal3d(  0.0,  -1.0,  0.0);
					glVertex3d(  top,  0.8*HEIGHT, left);
					glVertex3d(  top,  0.8*HEIGHT, right);
					glVertex3d(  bottom,  0.8*HEIGHT, right);
					glVertex3d(  bottom,  0.8*HEIGHT, left);
				glEnd();

				switch(pRoof->m_Dir)
				{
				case UP:
					normalizey = sqrt(height*height + (0.5*abs(top-bottom))*(0.5*abs(top-bottom)) );
					glBegin(GL_QUADS);
						glNormal3d(-1.0, 0.0, 0.0);
						glVertex3d(bottom , 0.8*HEIGHT , right );
						glVertex3d(bottom , 0.8*HEIGHT , left );
						glVertex3d(bottom , (0.8*HEIGHT + height) , left );
						glVertex3d(bottom , (0.8*HEIGHT + height) , right );
					glEnd();
					glBegin(GL_QUADS);
						glNormal3d( 0.5*abs(top-bottom)/normalizey, height/normalizey, 0.0);
						glVertex3d(bottom , (0.8*HEIGHT + height) , right );
						glVertex3d(bottom , (0.8*HEIGHT + height) , left );
						glVertex3d(top , 0.8*HEIGHT , left );
						glVertex3d(top , 0.8*HEIGHT , right );
					glEnd();
					glBegin(GL_TRIANGLES);
						glNormal3d(0.0, 0.0, 1.0);
						glVertex3d(bottom , 0.8*HEIGHT , right );
						glVertex3d(top , 0.8*HEIGHT , right );
						glVertex3d(bottom , (0.8*HEIGHT + height) , right );
						glNormal3d(0.0, 0.0, -1.0);
						glVertex3d(bottom , 0.8*HEIGHT , left );
						glVertex3d(bottom , (0.8*HEIGHT + height) , left );
						glVertex3d(top , 0.8*HEIGHT , left );
					glEnd();
					break;
				case DOWN:
					normalizey = sqrt(height*height + (0.5*abs(top-bottom))*(0.5*abs(top-bottom)) );
					glBegin(GL_QUADS);
						glNormal3d(1.0, 0.0, 0.0);
						glVertex3d(top , 0.8*HEIGHT , right );
						glVertex3d(top , 0.8*HEIGHT , left );
						glVertex3d(top , (0.8*HEIGHT + height) , left );
						glVertex3d(top , (0.8*HEIGHT + height) , right );
					glEnd();
					glBegin(GL_QUADS);

⌨️ 快捷键说明

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