• 大小: 12.95MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-20
  • 语言: C/C++
  • 标签: OpenGL、MFC  

资源简介

软件平台VS2010,使用的是MFC+OpenGL,旋转是通过ArcBall实现。左键按下旋转,鼠标滚轮实现缩放,右键平移。

资源截图

代码片段和文件信息

#include “StdAfx.h“
#include “ArcBall.h“
#include“Matrix.h“
#include

ArcBall::ArcBall(void)
{
m_rotation.SetIdentity();
}

ArcBall::~ArcBall(void)
{
}

void ArcBall::SetBound(int Width int height)
{

m_winWidth=Width;
m_winHeight=height;
}

Point3D ArcBall::CoordToSphere(int x int y)
{
double xScale = 2.0 / m_winWidth;
double yScale = 2.0 / m_winHeight;

double xPos = x * xScale - 1;
double yPos = 1 - y * yScale;
double zPos = 0.0;

double len = xPos * xPos + yPos * yPos;
if (len < 1.0)
{
zPos = sqrt(1.0 - len);
}

return Point3D(xPos yPos zPos);
}
void ArcBall::click(const CPoint &pt)
{
m_ptlast = CoordToSphere(pt.xpt.y);
}

void ArcBall::drag(const CPoint &pt)
{
Point3D ptCur =  CoordToSphere(pt.xpt.y);
CVector3D axis = m_ptlast * ptCur;
m_ptlast.Normalize();
ptCur.Normalize();

double c = m_ptlast % ptCur;
double angle = 2*acos(c);

CMatrix matrix = CMatrix::GetRotationMatrix(angleaxis[0]axis[1]axis[2]);
m_rotation = matrix * m_rotation;
m_ptlast = ptCur;
}
double *ArcBall::GetRotationData()
{
static double data[16];

data[0] =m_rotation[0][0];
data[1] =m_rotation[1][0];
data[2] =m_rotation[2][0];
data[3] = 0;

data[4] = m_rotation[0][1];
data[5] = m_rotation[1][1];
data[6] = m_rotation[2][1];
data[7] = 0;

data[8] =m_rotation[0][2];
data[9] = m_rotation[1][2];
data[10] = m_rotation[2][2];
data[11] = 0;

data[12] = 0;
data[13] = 0;
data[14] = 0;
data[15] = 1;

return data;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-02 09:14  paint_cylinder\
     目录           0  2017-12-13 00:34  paint_cylinder\Debug\
     文件      252416  2017-12-13 00:34  paint_cylinder\Debug\paint_cylinder.exe
     文件     1897296  2017-12-13 00:34  paint_cylinder\Debug\paint_cylinder.ilk
     文件     5524480  2017-12-13 00:34  paint_cylinder\Debug\paint_cylinder.pdb
     目录           0  2017-12-27 08:08  paint_cylinder\ipch\
     目录           0  2018-01-02 09:14  paint_cylinder\ipch\paint_cylinder-3829da0b\
     目录           0  2018-01-02 09:12  paint_cylinder\paint_cylinder\
     文件        1548  2017-12-12 21:00  paint_cylinder\paint_cylinder\ArcBall.cpp
     文件         384  2017-12-12 21:00  paint_cylinder\paint_cylinder\ArcBall.h
     目录           0  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\
     文件       16563  2017-12-12 21:08  paint_cylinder\paint_cylinder\Debug\ArcBall.obj
     文件       67236  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\CL.read.1.tlog
     文件        7588  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\CL.write.1.tlog
     文件       89298  2017-12-12 21:08  paint_cylinder\paint_cylinder\Debug\MainFrm.obj
     文件       15162  2017-12-12 21:08  paint_cylinder\paint_cylinder\Debug\Matrix.obj
     文件        9680  2017-12-12 21:09  paint_cylinder\paint_cylinder\Debug\Point3D.obj
     文件        6298  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\cl.command.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link-cvtres.read.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link-cvtres.write.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.13012-cvtres.read.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.13012-cvtres.write.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.13012.read.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.13012.write.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.1364-cvtres.read.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.1364-cvtres.write.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.1364.read.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.1364.write.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.2472-cvtres.read.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.2472-cvtres.write.1.tlog
     文件           2  2017-12-13 00:34  paint_cylinder\paint_cylinder\Debug\link.2472.read.1.tlog
............此处省略71个文件信息

评论

共有 条评论

相关资源