www.pudn.com > final_6.rar > Column.cpp
#include "stdafx.h"
#include "CG.h"
#include "math.h"
#include "Shape.h"
#include "CGDoc.h"
#include "LeftView.h"
#include "Base.h"
#include "Operation.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_SERIAL(CColumn,CShape,0)
CColumn::CColumn(){
};
void CColumn::DrawTop(CDC *pDC,CRect *rc){
int x,y;
for (x=0;x<=7;x++)
{
for (y=0;y<=14;y++)
{
pDC->MoveTo((int)this->BPoint[x][y].x,(int)this->BPoint[x][y].z);
pDC->LineTo((int)this->BPoint[x][y+1].x,(int)this->BPoint[x][y+1].z);
pDC->MoveTo((int)this->BPoint[x][y].x,(int)this->BPoint[x][y].z);
pDC->LineTo((int)this->BPoint[x+1][y].x,(int)this->BPoint[x+1][y].z);
}
}
for (x=0;x<=7;x++)
{
pDC->MoveTo((int)this->BPoint[x][15].x,(int)this->BPoint[x][15].z);
pDC->LineTo((int)this->BPoint[x][0].x,(int)this->BPoint[x][0].z);
pDC->MoveTo((int)this->BPoint[x][15].x,(int)this->BPoint[x][15].z);
pDC->LineTo((int)this->BPoint[x+1][15].x,(int)this->BPoint[x+1][15].z);
}
for (x=0;x<=14;x++)
{
pDC->MoveTo((int)this->BPoint[8][x].x,(int)this->BPoint[8][x].z);
pDC->LineTo((int)this->BPoint[8][x+1].x,(int)this->BPoint[8][x+1].z);
}
pDC->MoveTo((int)this->BPoint[8][15].x,(int)this->BPoint[8][15].z);
pDC->LineTo((int)this->BPoint[8][0].x,(int)this->BPoint[8][0].z);
}
void CColumn::DrawLeft(CDC* pDC,CRect* rc){
int x,y;
for (x=0;x<=7;x++)
{
for (y=0;y<=14;y++)
{
pDC->MoveTo(-(int)this->BPoint[x][y].z,(int)this->BPoint[x][y].y);
pDC->LineTo(-(int)this->BPoint[x][y+1].z,(int)this->BPoint[x][y+1].y);
pDC->MoveTo(-(int)this->BPoint[x][y].z,(int)this->BPoint[x][y].y);
pDC->LineTo(-(int)this->BPoint[x+1][y].z,(int)this->BPoint[x+1][y].y);
}
}
for (x=0;x<=7;x++)
{
pDC->MoveTo(-(int)this->BPoint[x][15].z,(int)this->BPoint[x][15].y);
pDC->LineTo(-(int)this->BPoint[x][0].z,(int)this->BPoint[x][0].y);
pDC->MoveTo(-(int)this->BPoint[x][15].z,(int)this->BPoint[x][15].y);
pDC->LineTo(-(int)this->BPoint[x+1][15].z,(int)this->BPoint[x+1][15].y);
}
for (x=0;x<=14;x++)
{
pDC->MoveTo(-(int)this->BPoint[8][x].z,(int)this->BPoint[8][x].y);
pDC->LineTo(-(int)this->BPoint[8][x+1].z,(int)this->BPoint[8][x+1].y);
}
pDC->MoveTo(-(int)this->BPoint[8][15].z,(int)this->BPoint[8][15].y);
pDC->LineTo(-(int)this->BPoint[8][0].z,(int)this->BPoint[8][0].y);
}
void CColumn::DrawFront(CDC*pDC,CRect *rc){
int x,y;
for (x=0;x<=7;x++)
{
for (y=0;y<=14;y++)
{
pDC->MoveTo((int)this->BPoint[x][y].x,(int)this->BPoint[x][y].y);
pDC->LineTo((int)this->BPoint[x][y+1].x,(int)this->BPoint[x][y+1].y);
pDC->MoveTo((int)this->BPoint[x][y].x,(int)this->BPoint[x][y].y);
pDC->LineTo((int)this->BPoint[x+1][y].x,(int)this->BPoint[x+1][y].y);
}
}
for (x=0;x<=7;x++)
{
pDC->MoveTo((int)this->BPoint[x][15].x,(int)this->BPoint[x][15].y);
pDC->LineTo((int)this->BPoint[x][0].x,(int)this->BPoint[x][0].y);
pDC->MoveTo((int)this->BPoint[x][15].x,(int)this->BPoint[x][15].y);
pDC->LineTo((int)this->BPoint[x+1][15].x,(int)this->BPoint[x+1][15].y);
}
for (x=0;x<=14;x++)
{
pDC->MoveTo((int)this->BPoint[8][x].x,(int)this->BPoint[8][x].y);
pDC->LineTo((int)this->BPoint[8][x+1].x,(int)this->BPoint[8][x+1].y);
}
pDC->MoveTo((int)this->BPoint[8][15].x,(int)this->BPoint[8][15].y);
pDC->LineTo((int)this->BPoint[8][0].x,(int)this->BPoint[8][0].y);
}
void CColumn::DrawPer(CDC*pDC,CRect *rc){
int x,y;
for (x=0;x<=7;x++)
{
for (y=0;y<=14;y++)
{
pDC->MoveTo((int)BPer[x][y].x,(int)BPer[x][y].y);
pDC->LineTo((int)BPer[x][y+1].x,(int)BPer[x][y+1].y);
pDC->MoveTo((int)BPer[x][y].x,(int)BPer[x][y].y);
pDC->LineTo((int)BPer[x+1][y].x,(int)BPer[x+1][y].y);
}
}
for (x=0;x<=7;x++)
{
pDC->MoveTo((int)BPer[x][15].x,(int)BPer[x][15].y);
pDC->LineTo((int)BPer[x][0].x,(int)BPer[x][0].y);
pDC->MoveTo((int)BPer[x][15].x,(int)BPer[x][15].y);
pDC->LineTo((int)BPer[x+1][15].x,(int)BPer[x+1][15].y);
}
for (x=0;x<=14;x++)
{
pDC->MoveTo((int)BPer[8][x].x,(int)BPer[8][x].y);
pDC->LineTo((int)BPer[8][x+1].x,(int)BPer[8][x+1].y);
}
pDC->MoveTo((int)BPer[8][15].x,(int)BPer[8][15].y);
pDC->LineTo((int)BPer[8][0].x,(int)BPer[8][0].y);
}
void CColumn::Serialize(CArchive &ar){
CShape::Serialize(ar);
if (ar.IsStoring())
{
ar<>radius>>height;
}
center.Serialize(ar);
int x,y;
for (x=0;x<=8;x++)
for (y=0;y<=15;y++)
{
BPoint[x][y].Serialize(ar);
}
}
void CColumn::SetColumnPoint(double radius,double height,CColumn *pColumn)
{
int x,y;
for (x=0;x<=8;x++)
for (y=0;y<=15;y++)
{
pColumn->BPoint[x][y].x=radius*sin(y*PI/8-PI/2)+pColumn->center.x;
pColumn->BPoint[x][y].y=(x*height/8-height/2)+pColumn->center.y;
pColumn->BPoint[x][y].z=radius*sin(y*PI/8)+pColumn->center.z;
}
pColumn->tempCenter.x = center.x;
pColumn->tempCenter.y = center.y;
pColumn->tempCenter.z = center.z;
}
void CColumn::SetBodyFace()
{
int x,y;
CGPlane *face;
for (x=0;x<=7;x++)
for (y=0;y<=14;y++)
{
face=&BFace[x][y];
COperation::CaculateFace(face,BPoint[x][y],BPoint[x][y+1],BPoint[x+1][y+1],BPoint[x+1][y]);
}
for (x=0;x<=7;x++)
{
face=&BFace[x][15];
COperation::CaculateFace(face,BPoint[x][15],BPoint[x][0],BPoint[x+1][0],BPoint[x+1][15]);
}
face=&BFace[8][0];//top
COperation::CaculateFace(face,BPoint[0][0],BPoint[0][12],BPoint[0][8],BPoint[0][4]);
face=&BFace[8][1];//base
COperation::CaculateFace(face,BPoint[8][0],BPoint[8][4],BPoint[8][8],BPoint[8][12]);
}