1.mfc ʱ?钟源?Դ??
2.在VC 6.0用C或C++语言编写一个模拟图形时钟,
mfc ʱ??Դ??
一、程序窗口设计步骤
(1)用AppWizard生成一个名为Clock的钟源单文档(SDI)程序框架。为了简化应用程序,钟源在第四步时去掉Docking toolbar和Initial status bar选择项(不删除也可),钟源其他各选项均可用缺省设置。钟源
(2)编辑项目的钟源cms与源码区别菜单资源,在主框架窗口的钟源主菜单(IDR_MAINFRAME)中添加一个名为“时钟控制”的下拉菜单。在“时钟控制”菜单中添加三个菜单选项“启动时钟”、钟源“停止时钟”和“时间设置”。钟源并在菜单属性项中设定“启动时钟”菜单的钟源ID标号为ID_START,“停止时钟”菜单的钟源ID标号为ID_STOP,“时间设置”菜单的钟源ID标号为ID_SETTIME。为了简化菜单,钟源心情驿站源码可删除系统原有的钟源“文件”、“编辑”菜单项。钟源
(3)利用ClassWizard为视图类添加菜单命令处理函数。进入ClassWizard的Message Maps选项卡,选择Class Name项为CClockView类,在Object IDs列表框中分别选择新添加的菜单选项的ID,在Messages列表框中选择COMMAND,按下Add Function按钮添加成员函数。ClassWizard会为“启动时钟”、“停止时钟”和“时间设置”菜单选项添加相应的消息响应函数OnStart ( )、OnStop ( )和OnSettime ( )。
(4)利用ClassWizard为视图类添加定时器和鼠标消息处理函数。买源码站进入ClassWizard的Message Maps选项卡,选择Class Name项为 CClockView类,在Messages列表框中分别选择定时器消息WM_TIMER和鼠标消息WM_LBUTIONDOWN,按下Add Function按钮添加成员函数。ClassWizard会添加相应的定时器和鼠标消息响应函数OnTimer和OnLButtonDown。
(5)使用Developer Studio菜单的Insert / Resource…选项调出Insert Source对话框,为项目添加新的对话框资源。在对话框属性中,修改对话框名为“时间设定”。在对话框中增加用来输入年、月、日、御剑天涯源码时、分、秒的编辑框控件。
通过控件属性,将年、月、日、时、分、秒等编辑控件的ID改为IDC_YEAR、IDC_MONTH、IDC_DAY、织梦安装源码IDC_HOUR、IDC_MINUTE和IDC_SECOND。
(6)利用ClassWizard自动建立对话框类。进入ClassWizard后,弹出一个对话框询问是否要为该对话框模板建立类。按下“OK”按钮,会弹出New Class对话框,在Name栏填写对话框类的名称CSetTimeDlg后按“OK”按钮,即可为对话框创建一个对应的类。
(7) 利用ClassWizard为对话框类添加与各控件对应的数据成员。选择MemberVariables选项卡,确保Class Name项为对话框CSetTimeDlg类,然后在选项卡下方的窗口中选择各控件的ID并按下“Add Variable…”按钮,为其添加对应成员变量。
控制ID
变量类型
变量名
变量范围
IDC_YEAR
int
m_Year
0~
IDC_MONTH
int
m_Month
1~
IDC_DAY
int
m_Day
1~
IDC_HOUR
int
m_Hour
0~
IDC_MINUTE
int
m_Minute
0~
IDC_SECOND
int
m_Second
0~
最后一列为变量取值范围。
(8)编辑工程的图标资源,在Resource View选项窗口中修改Icon结点所包含的主框架图标(IDR_MAINFRAME)。此步非必须。
(9)完成以上工作后,即可修改程序框架,添加必要的代码。
二、主要源代码:
按以下步骤向视图类(CClockView)添加下列数据成员及成员函数。
(1) 添加表示年、月、日、时、分、秒的变量。
int year;
int month;
int day;
int hour;
int minute;
int second;
(2) 添加秒表的计数变量。
int watch;
(3) 添加时钟的画笔及画刷变量。
CPen m_HouPen, m_MinPen, m_SecPen; // 各种针的画笔
CBrush m_MarkBrush; // 表盘标记的画刷
(4) 添加时钟控制变量。
CPoint m_Center; // 表的中心
double m_Radius; // 表的半径
CPoint m_Hour [2], m_OldHour [2]; // 时针当前及前一次位置
CPoint m_Minute [2], m_OldMin [2]; // 分针当前及前一次位置
CPoint m_Second [2], m_OldSec [2]; // 秒针当前及前一次位置
(5) 添加秒表的两个按钮位置变量。
CRect m_WatchStart;
CRect m_WatchStop;
(6) 添加两个函数,计算时钟各指针位置。
void SetClock (int hour, int minute, int second);
CPoint GetPoint (int nLenth, int nValue);
(7) 在视图类构造函数中增加初始化语句,之前加上头文件
#include<ctime>
CClockView::CClockView()
{
// 设定时间
char time[];
SYSTEMTIME st;
GetLocalTime(&st);
day = st.wDay;
hour = st.wHour;
minute = st.wMinute;
month = st.wMonth;
second = st.wSecond;
year = st.wYear;
// 设定画笔/画刷
m_HouPen. CreatePen (PS_SOLID, 5, RGB (, 0, 0) ); // 时针画笔
m_MinPen. CreatePen (PS_SOLID, 3, RGB (0, 0, ) ); // 分针画笔
m_SecPen. CreatePen (PS_SOLID, 1, RGB (0, 0, 0) ); // 秒针画笔
m_MarkBrush. CreateSolidBrush (RGB (, , 0) );
// 设定表心位置
m_Center. x = ;
m_Center. y = ;
// 设定时钟半径
m_Radius = ;
// 计算指针位置
SetClock (hour, minute, second);
// 设定秒表计数器及按钮位置
watch = 0;
m_WatchStart = CRect (, , , ); // 启动钮
m_WatchStop = CRect (, , , ); // 停止钮
}
编写指针位置计算函数SetClock和GetPoint。首先在ClockView. cpp文件头部添加下面两行代码,以便进行数学计算。
#include "math.h"
#define PI 3.
然后添加下列代码:
//计算各个指针位置的函数
void CClockView::SetClock(int hour, int minute, int second)
{
hour=hour*5;
hour=hour+minute/;
// 保存时针原位置
m_OldHour [0] = m_Hour[0];
m_OldHour [1] = m_Hour[1];
// 计算时针当前位置
m_Hour[0]= GetPoint(int(m_Radius/2),hour);
m_Hour[1]= GetPoint(7,hour + );
// 保存分针原位置
m_OldMin[0]= m_Minute[0];
m_OldMin[1]= m_Minute[1];
// 计算分针当前位置
m_Minute[0]=GetPoint(int(m_Radius*7/), minute);
m_Minute[1]=GetPoint(, minute+);
// 保存秒针原位置
m_OldSec [0] = m_Second [0];
m_OldSec [1] = m_Second [1];
// 计算秒针当前位置
m_Second [0]= GetPoint (int(m_Radius * 8/), second);
m_Second [1] = GetPoint (, second + );
}
// 计算以表心为原点的指针的端点位置
CPoint CClockView ::GetPoint (int nLenth, int nValue)
{
CPoint p;
double angle = nValue* PI /-PI/2;
p.x = m_Center.x + (int) (nLenth * cos(angle));
p.y = m_Center.y + (int) (nLenth * sin(angle));
return p;
}
绘制表盘上的标记、时针、分针和秒针,并显示数字时钟及秒表,在OnDraw函数中添加下面代码:
void CClockView::OnDraw(CDC* pDC)
{
CClockDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// 绘制表盘上的标记
pDC->SelectObject(m_MarkBrush);
int k=0;
for(int i=0;i<;i++)
{
CPoint pt=GetPoint(,i);
if (i%5==0)
{
//显示表盘上的数字
CString str[]={ "","1","2","3","4","5","6","7","8","9","",""};
pDC->TextOut(pt.x-5,pt.y-5,str[k]);
k++;
}else
{
//显示数字之间的圆圈
pDC->Ellipse(pt.x-2,pt.y-2,pt.x+2,pt.y+2);
}
}
// 画时针
pDC->SelectObject (m_HouPen);
if (m_OldHour[0]!= m_Hour[0])
{
// 用白色覆盖原位置时针
pDC->SetROP2(R2_WHITE);
pDC->MoveTo(m_OldHour [0] );
pDC->LineTo(m_OldHour [1] );
pDC->SetROP2(R2_COPYPEN);
//时针绘制
pDC->MoveTo(m_Hour[0]);
pDC->LineTo(m_Hour[1]);
}
else
{
// 时针绘制
pDC->MoveTo(m_Hour[0]);
pDC->LineTo(m_Hour[1]);
}
// 画分针
pDC->SelectObject (m_MinPen);
if (m_OldMin[0]!=m_Minute[0])
{
// 用白色覆盖原位置分针
pDC->SetROP2(R2_WHITE);
pDC->MoveTo(m_OldMin[0]);
pDC->LineTo(m_OldMin[1]);
pDC->SetROP2(R2_COPYPEN);
// 分针绘制
pDC->MoveTo(m_Minute[0]);
pDC->LineTo(m_Minute[1]);
}
else
{
// 分针绘制
pDC->MoveTo(m_Minute[0]);
pDC->LineTo(m_Minute[1]);
}
// 用白色覆盖原位置秒针
pDC->SelectObject(m_SecPen);
pDC->SetROP2(R2_WHITE);
pDC->MoveTo(m_OldSec[0]);
pDC->LineTo(m_OldSec[1]);
pDC->SetROP2(R2_COPYPEN);
// 秒针绘制
pDC->MoveTo(m_Second[0]);
pDC->LineTo(m_Second[1]);
// 数字时钟显示
pDC->SelectStockObject(WHITE_BRUSH);
pDC->Rectangle(,,,);
pDC->TextOut(,,"当前时间");
CString m_Date,m_Time;
m_Date.Format ("% 4d年%4d月%4d日",year,month,day);
pDC->TextOut(,,m_Date);
m_Time.Format("%4d点%4d分%4d秒",hour,minute,second);
pDC->TextOut(,,m_Time);
// 秒表显示
pDC->Rectangle(,,,);
pDC->TextOut(,,"秒 表");
int minSec= watch%;
int Sec=(watch/)%;
int Min=(watch/)/;
m_Time.Format("% d: % d: % d",Min,Sec,minSec);
pDC->TextOut(,,m_Time);
pDC->Rectangle(&m_WatchStart);
pDC->Rectangle(&m_WatchStop);
pDC->TextOut(m_WatchStart.left + ,m_WatchStart.top + 5,"启动");
pDC->TextOut(m_WatchStop.left + ,m_WatchStop.top + 5,"停止");
}
请注意将表示时间的整数转换为CString字符串类型的方法以及秒表的显示方法。另外,watch计数器以1/秒为计数单位,每达到则秒数加1。
按照下列步骤增加时钟控制代码:
修改Onstart和OnStop函数,设置时钟运动消息。按比正常时钟快倍的假定,ms产生一个消息。本程序采用和正常时间同步,即ms产生一个消息, 其代码为:
void CClockView::OnStart()
{
SetTimer (1, , NULL);
}
void CClockView::OnStop()
{
KillTimer (1);
}
修改OnTimer函数,正确计算并处理年、月、日、时、分、秒等变量的联动变化 ,其代码为:
void CClockView::OnTimer(UINT nIDEvent)
{
if (nIDEvent == 1)
{
second++; // 秒增加
if (second>)
{
second=0;
minute++; // 分增加
}
if (minute>)
{
minute= 0;
hour++; // 小时增加
}
if (hour>)
{
hour=0;
day++; // 日增加
}
switch(month)
{
case 1: // 大月
case 3:
case 5:
case 7:
case 8:
case :
case :
if (day>)
{
day= 1;
month++; // 月增加
}
break;
case 4: // 小月
case 6:
case 9:
case :
if (day>)
{
day=1;
month++; // 月增加
}
break;
case 2:
if (year%4 ==0 && day>) // 润二月
{
day=1;
month++; // 月增加
}
if (year%4!=0 && day>) // 二月
{
day=1;
month++;
}
break;
}
if (month > )
{
// 年增加
year++;
month=1;
}
SetClock (hour, minute, second);
Invalidate (false);
}
// 秒表定时器消息处理
if (nIDEvent == 2)
{
watch++;
Invalidate (false);
}
CView::OnTimer(nIDEvent);
}
添加时间设置对话框代码。
首先在ClockView. cpp文件头部添加下列语句:
#include “SetTimeDlg. h”
在时间设定对话框类的构造函数中,做如下修改,将初始日期设为当前时间,之前要加上头文件
#include<ctime>
CSetTimeDlg::CSetTimeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSetTimeDlg::IDD, pParent)
{
//||AFX_DATA_INIT(CSetTimeDlg)
char time[];
SYSTEMTIME st;
GetLocalTime(&st);
m_Day = st.wDay;
m_Hour = st.wHour;
m_Minute = st.wMinute;
m_Month = st.wMonth;
m_Second = st.wSecond;
m_Year = st.wYear;// ||AFX_DATA_INIT
}
最后,在OnSettime函数中添加代码如下:
void CClockView::OnSettime()
{
CSetTimeDlg SetDlg;
if (SetDlg.DoModal ()==IDOK)
{
year=SetDlg.m_Year;
month= SetDlg.m_Month;
day= SetDlg.m_Day;
hour=SetDlg.m_Hour;
minute=SetDlg.m_Minute;
second=SetDlg.m_Second;
}
// 计算各指针位置
SetClock (hour,minute,second);
Invalidate (true);
}
按以下步骤设计秒表控制程序:
在OnLButtonDown函数中增加下列内容,以便响应单击秒表启动、停止框所发出的消息:
void CClockView::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_WatchStart.PtInRect(point))
{
watch=0;
SetTimer(2,,NULL);
}
if (m_WatchStop.PtInRect(point))
{
KillTimer (2);
}
CView::OnLButtonDown(nFlags, point);
}
编译,连接,运行程序。
运行结果:
在VC 6.0用C或C++语言编写一个模拟图形时钟,
#include "stdafx.h"
#include "MFCFrame1.h"
#include "MFCFrame1Doc.h"
#include "MFCFrame1View.h"
#include "PointDialog.h"
#include "math.h"
GLUquadricObj *objCylinder = gluNewQuadric();
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View
IMPLEMENT_DYNCREATE(CMFCFrame1View, CView)
BEGIN_MESSAGE_MAP(CMFCFrame1View, CView)
//{ { AFX_MSG_MAP(CMFCFrame1View)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_COMMAND(IDM_ZIXUAN, OnZixuan)
ON_WM_TIMER()
ON_COMMAND(IDM_ChangDirect, OnChangDirect)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View construction/destruction
CMFCFrame1View::CMFCFrame1View()
{
// TODO: add construction code here
this->m_GLPixelIndex = 0;
this->m_hGLContext = NULL;
Angle1=0.0;
Angle2=.0;
Timer=0;
x=0.0;
z=0.0;
juli=.0;
}
CMFCFrame1View::~CMFCFrame1View()
{
}
BOOL CMFCFrame1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View drawing
/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View printing
BOOL CMFCFrame1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMFCFrame1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMFCFrame1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View diagnostics
#ifdef _DEBUG
void CMFCFrame1View::AssertValid() const
{
CView::AssertValid();
}
void CMFCFrame1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMFCFrame1Doc* CMFCFrame1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCFrame1Doc)));
return (CMFCFrame1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View message handlers
BOOL CMFCFrame1View::SetWindowPixelFormat(HDC hDC)
{
PIXELFORMATDESCRIPTOR pixelDesc=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|
PFD_DOUBLEBUFFER|PFD_SUPPORT_GDI,
PFD_TYPE_RGBA,
,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
this->m_GLPixelIndex = ChoosePixelFormat(hDC,&pixelDesc);
if(this->m_GLPixelIndex==0)
{
this->m_GLPixelIndex = 1;
if(DescribePixelFormat(hDC,this->m_GLPixelIndex,sizeof(PIXELFORMATDESCRIPTOR),&pixelDesc)==0)
{
return FALSE;
}
}
if(SetPixelFormat(hDC,this->m_GLPixelIndex,&pixelDesc)==FALSE)
{
return FALSE;
}
return TRUE;
}
int CMFCFrame1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
HWND hWnd = this->GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);
if(this->SetWindowPixelFormat(hDC)==FALSE)
{
return 0;
}
if(this->CreateViewGLContext(hDC)==FALSE)
{
return 0;
}
return 0;
}
BOOL CMFCFrame1View::CreateViewGLContext(HDC hDC)
{
this->m_hGLContext = wglCreateContext(hDC);
if(this->m_hGLContext==NULL)
{ //创建失败
return FALSE;
}
if(wglMakeCurrent(hDC,this->m_hGLContext)==FALSE)
{ //选为当前RC失败
return FALSE;
}
return TRUE;
}
void CMFCFrame1View::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
if(wglGetCurrentContext()!=NULL)
{
wglMakeCurrent(NULL,NULL);
}
if(this->m_hGLContext!=NULL)
{
wglDeleteContext(this->m_hGLContext);
this->m_hGLContext = NULL;
}
}
void CMFCFrame1View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
GLsizei width,height;
GLdouble aspect;
width = cx;
height = cy;
if(cy==0)
{
aspect = (GLdouble)width;
}
else
{
aspect = (GLdouble)width/(GLdouble)height;
}
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(.0,aspect,5.0,.0);
}
void CMFCFrame1View::OnDraw(CDC* pDC)
{
CMFCFrame1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPaintDC dc(this);
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,.0,0.0,0.0,0.0,0.0,1.0,0.0);
glRotatef(-.0,1.0,0.0,0.0);/*返回原坐标*/
glTranslatef(-3.0,0.0,0.0);
SwapBuffers(dc.m_ps.hdc);
glDrawBuffer (GL_BACK);
glFlush();
}
void CMFCFrame1View::OnZixuan()
{
// TODO: Add your command handler code here
Timer=1;
SetTimer(1,,NULL);
}
void CMFCFrame1View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CPaintDC dc(this);
if (Timer==1)
{ Angle1=Angle1-1;
Angle2=Angle2-1;
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);/**/
glLoadIdentity();
gluLookAt(0.0,.0,0.,0.0,0.0,0.0,0.0,1.0,0.0);
glPushMatrix();
glColor3f(0.7,0.7,0.7);
glTranslatef(0.0,0.0,1.1);
glRotatef(-.0,1.0,0.0,0.0);
glutSolidCone(5.0,0.0,.0,.0); /*底盘*/
glPopMatrix();
glPushMatrix();
glColor3f(0.0,0.0,0.0);
glTranslatef(3.9,0.,1.0); /*刻度*/
glRotatef(.0,0.0,1.0,0.0);
gluCylinder(objCylinder, 0., 0., 0.8, , 9);
glPopMatrix();
glPushMatrix();
glColor3f(0.0,0.0,0.0);
glTranslatef(-4.7,0.,1.0); /*刻度*/
glRotatef(.0,0.0,1.0,0.0);
gluCylinder(objCylinder,0., 0., 0.8, , 9);
glPopMatrix();
glPushMatrix();
glColor3f(0.0,0.0,0.0);
glTranslatef(0.0,0.,-2.9); /*刻度*/
glRotatef(.0,0.0,1.0,0.0);
gluCylinder(objCylinder,0., 0., 0.8, , 9);
glPopMatrix();
glPushMatrix();
glColor3f(0.0,0.0,0.0);
glTranslatef(0.0,0.,5.8); /*刻度*/
glRotatef(.0,0.0,1.0,0.0);
gluCylinder(objCylinder,0., 0.,0.8, , 9);
glPopMatrix();
glPushMatrix();
glColor3f(0.0,1.0,0.0);
glRotatef(.0,0.0,1.0,0.0);
glTranslatef(-0.,0.,0.7); /*时针*/
glRotatef(Angle1/,0.0,1.0,0.0);
gluCylinder(objCylinder, 0., 0., 2.5, , 9);
glPopMatrix();
glPushMatrix();
glColor3f(1.0,0.0,0.0);
glTranslatef(0.0,0.,1.0); /*分针*/
glRotatef(Angle2/,0.0,1.0,0.0);
gluCylinder(objCylinder, 0., 0., 3.5, , 9);
glPopMatrix();
glPushMatrix();
glColor3f(0.0,0.0,0.5);
glTranslatef(0.0,0.,1.0); /*秒针*/
glRotatef(Angle1,0.0,1.0,0.0);
gluCylinder(objCylinder, 0., 0., 4.5, , 9);
glPopMatrix();
SwapBuffers(dc.m_ps.hdc);
glDrawBuffer (GL_BACK);
glFlush();
}
else if(Timer==2)
{ glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
if (juli>.0)
{
glMatrixMode(GL_MODELVIEW);/*建立了从世界坐标系到观察坐标系的转换矩阵*/
glLoadIdentity();
gluLookAt(0.0,8.0,juli,0.0,0.0,0.0,0.0,1.0,0.0);
juli=juli-0.1;
glPushMatrix();
glColor3f(0.0,0.0,0.0);
glRotatef(-.0,1.0,0.0,0.0);
glutWireCone(.0,0.0,.0,.0); /*画高度为0的圆锥*/
glPopMatrix();
glPushMatrix();
glColor3f(1.0,0.0,1.0);
glLineWidth(4.0);
glTranslatef(4.0,1.0,0.0);
glutWireOctahedron(); /*画八面体*/
glLineWidth(1.0);
glPopMatrix();
glPushMatrix();
glColor3f(1.0,0.0,1.0);
glTranslatef(0.0,1.1,0.0);
glRotatef(Angle2,0.0,1.0,0.0);
gluCylinder(objCylinder, 1.0, 1.0, .0, , 9); /*画壶*/
glPopMatrix();
}
else if(juli<=.0)
{
Angle2=Angle2+0.;
if (Angle2==.0)
Angle2=0.0;
glMatrixMode(GL_MODELVIEW);/*建立了从世界坐标系到观察坐标系的转换矩阵*/
glLoadIdentity();
x=.0*sin(Angle2);
z=.0*cos(Angle2);
gluLookAt(x,5.0,z,0.0,0.0,0.0,0.0,1.0,0.0);
glPushMatrix();
glColor3f(0.0,0.0,0.0);
glRotatef(-.0,1.0,0.0,0.0);
glutWireCone(.0,0.0,.0,.0); /*画高度为0的圆锥*/
glPopMatrix();
glPushMatrix();
glColor3f(1.0,0.0,1.0);
glLineWidth(4.0);
glTranslatef(4.0,1.0,0.0);
glutWireOctahedron(); /*画八面体*/
glLineWidth(1.0);
glPopMatrix();
glPushMatrix();
glColor3f(1.0,0.0,1.0);
glTranslatef(0.0,1.1,0.0);
gluCylinder(objCylinder, 1.0, 1.0, .0, , 9);
glPopMatrix();
}
SwapBuffers(dc.m_ps.hdc);
glDrawBuffer (GL_BACK);
glFlush();
}
CView::OnTimer(nIDEvent);
}
void CMFCFrame1View::OnChangDirect()
{
// TODO: Add your command handler code here
Timer=2;
SetTimer(1, ,NULL);
}