// paint_cylinderView.cpp : Cpaint_cylinderView 类的实现
//
#include "ArcBall.h"
#include "stdafx.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "paint_cylinder.h"
#endif
#include "paint_cylinderDoc.h"
#include "paint_cylinderView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Cpaint_cylinderView
IMPLEMENT_DYNCREATE(Cpaint_cylinderView, CView)
BEGIN_MESSAGE_MAP(Cpaint_cylinderView, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &Cpaint_cylinderView::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_DESTROY()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_MOUSEHWHEEL()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()
// Cpaint_cylinderView 构造/析构
Cpaint_cylinderView::Cpaint_cylinderView()
{
// TODO: 在此处添加构造代码
m_dScale=1.0;
}
Cpaint_cylinderView::~Cpaint_cylinderView()
{
}
BOOL Cpaint_cylinderView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
cs.style |= (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
return CView::PreCreateWindow(cs);
}
// Cpaint_cylinderView 绘制
void Cpaint_cylinderView::OnDraw(CDC* /*pDC*/)
{
Cpaint_cylinderDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // Reset The Current Modelview Matrix
gluLookAt(0, 0,3, 0, 0, 0, 0, 1, 0);
double *data=m_arcball.GetRotationData();
glMultMatrixd(data);
glScaled(m_dScale, m_dScale, m_dScale);
glTranslated(m_translate[0], m_translate[1], m_translate[2]);
RenderScene();
glFinish();
SwapBuffers( m_pDC->GetSafeHdc() );
}
// Cpaint_cylinderView 打印
void Cpaint_cylinderView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL Cpaint_cylinderView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void Cpaint_cylinderView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void Cpaint_cylinderView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清理过程
}
void Cpaint_cylinderView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// Cpaint_cylinderView 诊断
#ifdef _DEBUG
void Cpaint_cylinderView::AssertValid() const
{
CView::AssertValid();
}
void Cpaint_cylinderView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
Cpaint_cylinderDoc* Cpaint_cylinderView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Cpaint_cylinderDoc)));
return (Cpaint_cylinderDoc*)m_pDocument;
}
#endif //_DEBUG
// Cpaint_cylinderView 消息处理程序
int Cpaint_cylinderView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
InitializeOpenGL();
return 0;
}
BOOL Cpaint_cylinderView::InitializeOpenGL()
{
m_pDC = new CClientDC(this);
if(m_pDC == NULL)
{
AfxMessageBox(_T("Error Obtaining DC"));
return FALSE;
}
if(!SetupPixelFormat())
{ return FALSE;}
m_hRC = ::wglCreateContext (m_pDC->GetSafeHdc ());
if(m_hRC == 0)
{
MessageBox(_T("Error Creating RC"));
return FALSE;
}
if(::wglMakeCurrent (m_pDC->GetSafeHdc (), m_hRC)==FALSE)
{
MessageBox(_T("Error making RC Current"));
return FALSE;
}
::glClearColor(1.0f,1.0f,1.0f,1.0f);
::glClearDepth(1.0f);
::glEnable(GL_DEPTH_TEST);
GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
GLfloat mat_ambient[] = {0.7, 0.7, 0.7, 1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
return TRUE;
}
BOOL Cpaint_cylinderView::SetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
16, // 16-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int nPixelFormat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
if ( nPixelFormat == 0 )
{ return FALSE;}
if ( ::SetPixelFormat(m_pDC->GetSafeHdc(), nPixelFormat, &pfd) == FALSE)
{
return FALSE;
}
return TRUE;
}
void Cpaint_cylinderView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if ( 0 >= cx || 0 >= cy )
{
return;
}
m_arcball.SetBound(cx, cy);
// select the full client area
m_nWinWidth = cx;
m_nWinHeight = cy;
//m_render.SetWindowSize(cx, cy);
glViewport(0, 0, cx, cy);
// compute the aspect ratio
// this will keep all dimension scales equal
GLdouble aspect_ratio = (GLdouble)m_nWinWidth/(GLdouble)m_nWinHeight;
// select the projection matrix and clear it
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// select the viewing volume
double width = 1, height = 1;
if (m_nWinWidth > m_nWinHeight)
width *= aspect_ratio;
else
height /= aspect_ratio;
glOrtho(-width, width, -height, height, 1.0, 6.0);
//glFrustum(-width, width, -height, height, 1, 3);
// switch back to the modelview matrix and clear it
glMatrixMode(GL_MODELVIEW);
}
void Cpaint_cylinderView::OnDestroy()
{
CView::OnDestroy();
// TODO: 在此处添加消息处理程序代码
//绘制完成后断开dc和rc的绑定
if(::wglMakeCurrent (NULL, NULL) == FALSE)
{
MessageBox(_T("Could not make RC non-current"));
}
//删除rc
if(::wglDeleteContext (m_hRC)==FALSE)
{
MessageBox(_T("Could not delete RC"));
}
//删除dc
if(m_pDC)
{
delete m_pDC;
}
//Set it to NULL
m_pDC = NULL;
}
void Cpaint_cylinderView::RenderScene()
{
/* glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glRotatef(45,0.0f,4.0f,-1.0f);
*/ #define PI 3.1415926
// glEnable(GL_COLOR_MATERIAL);
int nSlice=32;
double r=0.5,h=2.5;
double delta = PI * 2 / nSlice;
double angle = delta;
glColor3f(1.0f, 0.0f, 0.0f);
//top
glBegin(GL_TRIANGLE_FAN);
glNormal3f(0, 0, 1);
glVertex3d(0, 0, h);
glVertex3d
没有合适的资源?快使用搜索试试~ 我知道了~
OpenGL+MFC实现旋转、缩放、平移
共95个文件
tlog:43个
h:10个
cpp:8个
4星 · 超过85%的资源 需积分: 48 97 下载量 179 浏览量
2018-01-02
09:15:39
上传
评论 8
收藏 12.95MB ZIP 举报
温馨提示
软件平台VS2010,使用的是MFC+OpenGL,旋转是通过ArcBall实现。左键按下旋转,鼠标滚轮实现缩放,右键平移。
资源推荐
资源详情
资源评论
收起资源包目录
paint_cylinder.zip (95个子文件)
paint_cylinder
paint_cylinder
stdafx.cpp 147B
paint_cylinder.vcxproj.user 143B
Resource.h 1KB
res
Toolbar256.bmp 6KB
paint_cylinder.ico 66KB
paint_cylinderDoc.ico 5KB
paint_cylinder.rc2 684B
Toolbar.bmp 1KB
ArcBall.h 384B
paint_cylinder.aps 108KB
stdafx.h 2KB
Point3D.cpp 1KB
paint_cylinderView.cpp 10KB
paint_cylinder.rc 24KB
paint_cylinderDoc.cpp 3KB
targetver.h 234B
Matrix.cpp 3KB
ArcBall.cpp 2KB
Point3D.h 481B
paint_cylinder.h 706B
Matrix.h 414B
MainFrm.cpp 8KB
paint_cylinderView.h 2KB
MainFrm.h 1KB
paint_cylinder.cpp 5KB
paint_cylinder.vcxproj.filters 3KB
Debug
vc100.idb 1.92MB
link.4832-cvtres.write.1.tlog 2B
paint_cylinder.write.1.tlog 0B
CL.write.1.tlog 7KB
paint_cylinder.log 3KB
paint_cylinder_manifest.rc 218B
CL.read.1.tlog 66KB
link.2924.read.1.tlog 2B
mt.read.1.tlog 636B
rc.write.1.tlog 590B
Matrix.obj 15KB
paint_cylinder.exe.intermediate.manifest 640B
link.8476.read.1.tlog 2B
link.13012.read.1.tlog 2B
stdafx.obj 623KB
link.1364-cvtres.read.1.tlog 2B
link.1364-cvtres.write.1.tlog 2B
link.5428-cvtres.read.1.tlog 2B
rc.read.1.tlog 4KB
paint_cylinder.exe.embed.manifest.res 980B
link.4832.write.1.tlog 2B
ArcBall.obj 16KB
paint_cylinder.vcxprojResolveAssemblyReference.cache 713B
link.2924-cvtres.write.1.tlog 2B
link.2472-cvtres.read.1.tlog 2B
link.5428.read.1.tlog 2B
mt.command.1.tlog 716B
link.2924.write.1.tlog 2B
link.2472-cvtres.write.1.tlog 2B
paint_cylinder.obj 57KB
cl.command.1.tlog 6KB
link-cvtres.read.1.tlog 2B
link.13012-cvtres.write.1.tlog 2B
link.1364.write.1.tlog 2B
link.8476-cvtres.read.1.tlog 2B
paint_cylinder.exe.embed.manifest 915B
link.13012-cvtres.read.1.tlog 2B
paint_cylinder.pch 32.06MB
paint_cylinder.lastbuildstate 70B
link.write.1.tlog 2KB
paint_cylinder.res 83KB
link-cvtres.write.1.tlog 2B
link.8476-cvtres.write.1.tlog 2B
link.command.1.tlog 3KB
paint_cylinderView.obj 63KB
rc.command.1.tlog 1KB
link.read.1.tlog 7KB
link.2472.write.1.tlog 2B
link.5428.write.1.tlog 2B
link.2924-cvtres.read.1.tlog 2B
link.5428-cvtres.write.1.tlog 2B
mt.write.1.tlog 492B
link.2472.read.1.tlog 2B
MainFrm.obj 87KB
link.4832.read.1.tlog 2B
link.1364.read.1.tlog 2B
link.8476.write.1.tlog 2B
paint_cylinderDoc.obj 55KB
Point3D.obj 9KB
link.4832-cvtres.read.1.tlog 2B
vc100.pdb 3.32MB
link.13012.write.1.tlog 2B
paint_cylinderDoc.h 895B
paint_cylinder.vcxproj 6KB
paint_cylinder.sln 909B
paint_cylinder.suo 21KB
ipch
paint_cylinder-3829da0b
Debug
paint_cylinder.exe 247KB
paint_cylinder.pdb 5.27MB
paint_cylinder.ilk 1.81MB
共 95 条
- 1
资源评论
- IT刚哥2018-10-10很不错的例子,谢谢楼主
- 机器的创造者2018-04-21很好,非常棒的资源,谢谢楼主分享
- qq_180192112018-08-15不错的资源
- 机器视觉大师2020-12-01有些借鉴作用
Litmal
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功