用opgl绘制的兔子,支持放大缩小,旋转等功能,开发环境是vs2005
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7719936 2009-04-26 12:44 bunny48_ArcBall.ncb
文件 4537 2009-05-15 09:54 bunny48_ArcBall.vcproj
文件 1423 2009-05-15 15:18 bunny48_ArcBall.vcproj.20090401-1254.Administrator.user
文件 2516 2006-08-21 07:18 bunnyArcBall.cpp
文件 13088 2006-08-13 12:53 bunnyArcBall.h
文件 32904 2009-05-15 09:54 bunnyunny.aps
文件 9361 2009-05-15 10:38 bunnyunny.cpp
文件 2417019 2000-10-11 01:34 bunnyunny.dat
文件 9415680 2009-05-15 15:18 bunnyunny.ncb
文件 1418 2009-05-15 09:54 bunnyunny.rc
文件 879 2009-04-26 10:04 bunnyunny.sln
..A..H. 25600 2009-05-15 15:18 bunnyunny.suo
文件 593920 2009-05-15 10:38 bunnyDebug48_ArcBall.exe
文件 146 2009-04-26 10:05 bunnyDebug48_ArcBall.exe.embed.manifest
文件 212 2009-04-26 10:05 bunnyDebug48_ArcBall.exe.embed.manifest.res
文件 145 2009-05-15 10:38 bunnyDebug48_ArcBall.exe.intermediate.manifest
文件 1296180 2009-05-15 10:38 bunnyDebug48_ArcBall.ilk
文件 48332 2009-04-26 11:15 bunnyDebug48_ArcBall.obj
文件 2345984 2009-05-15 10:38 bunnyDebug48_ArcBall.pdb
文件 28647 2009-04-26 10:05 bunnyDebugArcBall.obj
文件 10062 2009-05-15 10:38 bunnyDebugBuildLog.htm
文件 2417019 2000-10-11 01:34 bunnyDebugunny.dat
文件 55068 2009-05-15 10:38 bunnyDebugunny.obj
文件 192512 2006-03-04 03:19 bunnyDebugglew32.dll
文件 121856 2004-08-04 08:52 bunnyDebugglu32.dll
文件 169984 1998-08-18 23:25 bunnyDebugglut32.dll
文件 67 2009-05-15 10:38 bunnyDebugmt.dep
文件 39995 2009-05-15 09:41 bunnyDebugNeHeGL.obj
文件 713728 2004-08-04 08:52 bunnyDebugopengl32.dll
文件 396288 2009-05-15 10:38 bunnyDebugvc80.idb
............此处省略26个文件信息
#include
#include “glew.h“
#include “glaux.h“
#include “math.h“
#include “ArcBall.h“
//轨迹球参数:
//直径 2.0f
//半径 1.0f
//半径平方 1.0f
void ArcBall_t::_mapToSphere(const Point2fT* NewPt Vector3fT* NewVec) const
{
Point2fT TempPt;
GLfloat length;
//复制到临时变量
TempPt = *NewPt;
//把长宽调整到[-1 ... 1]区间
TempPt.s.X = (TempPt.s.X * this->AdjustWidth) - 1.0f;
TempPt.s.Y = 1.0f - (TempPt.s.Y * this->AdjustHeight);
//计算长度的平方
length = (TempPt.s.X * TempPt.s.X) + (TempPt.s.Y * TempPt.s.Y);
//如果点映射到球的外面
if (length > 1.0f)
{
GLfloat norm;
//缩放到球上
norm = 1.0f / FuncSqrt(length);
//设置z坐标为0
NewVec->s.X = TempPt.s.X * norm;
NewVec->s.Y = TempPt.s.Y * norm;
NewVec->s.Z = 0.0f;
}
//如果在球内
else
{
//利用半径的平方为1求出z坐标
NewVec->s.X = TempPt.s.X;
NewVec->s.Y = TempPt.s.Y;
NewVec->s.Z = FuncSqrt(1.0f - length);
}
}
ArcBall_t::ArcBall_t(GLfloat NewWidth GLfloat NewHeight)
{
this->StVec.s.X =
this->StVec.s.Y =
this->StVec.s.Z =
this->EnVec.s.X =
this->EnVec.s.Y =
this->EnVec.s.Z = 0.0f;
this->setBounds(NewWidth NewHeight);
}
//按下鼠标记录当前对应的轨迹球的位置
void ArcBall_t::click(const Point2fT* NewPt)
{
this->_mapToSphere(NewPt &this->StVec);
}
//鼠标拖动计算旋转四元数
void ArcBall_t::drag(const Point2fT* NewPt Quat4fT* NewRot)
{
//新的位置
this->_mapToSphere(NewPt &this->EnVec);
//计算旋转
if (NewRot)
{
Vector3fT Perp;
//计算旋转轴
Vector3fCross(&Perp &this->StVec &this->EnVec);
//如果不为0
if (Vector3fLength(&Perp) > Epsilon)
{
//记录旋转轴
NewRot->s.X = Perp.s.X;
NewRot->s.Y = Perp.s.Y;
NewRot->s.Z = Perp.s.Z;
//在四元数中w=cos(a/2),a为旋转的角度
NewRot->s.W= Vector3fDot(&this->StVec &this->EnVec);
}
//是0,说明没有旋转
else
{
NewRot->s.X =
NewRot->s.Y =
NewRot->s.Z =
NewRot->s.W = 0.0f;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7719936 2009-04-26 12:44 bunny48_ArcBall.ncb
文件 4537 2009-05-15 09:54 bunny48_ArcBall.vcproj
文件 1423 2009-05-15 15:18 bunny48_ArcBall.vcproj.20090401-1254.Administrator.user
文件 2516 2006-08-21 07:18 bunnyArcBall.cpp
文件 13088 2006-08-13 12:53 bunnyArcBall.h
文件 32904 2009-05-15 09:54 bunnyunny.aps
文件 9361 2009-05-15 10:38 bunnyunny.cpp
文件 2417019 2000-10-11 01:34 bunnyunny.dat
文件 9415680 2009-05-15 15:18 bunnyunny.ncb
文件 1418 2009-05-15 09:54 bunnyunny.rc
文件 879 2009-04-26 10:04 bunnyunny.sln
..A..H. 25600 2009-05-15 15:18 bunnyunny.suo
文件 593920 2009-05-15 10:38 bunnyDebug48_ArcBall.exe
文件 146 2009-04-26 10:05 bunnyDebug48_ArcBall.exe.em
文件 212 2009-04-26 10:05 bunnyDebug48_ArcBall.exe.em
文件 145 2009-05-15 10:38 bunnyDebug48_ArcBall.exe.intermediate.manifest
文件 1296180 2009-05-15 10:38 bunnyDebug48_ArcBall.ilk
文件 48332 2009-04-26 11:15 bunnyDebug48_ArcBall.obj
文件 2345984 2009-05-15 10:38 bunnyDebug48_ArcBall.pdb
文件 28647 2009-04-26 10:05 bunnyDebugArcBall.obj
文件 10062 2009-05-15 10:38 bunnyDebugBuildLog.htm
文件 2417019 2000-10-11 01:34 bunnyDebugunny.dat
文件 55068 2009-05-15 10:38 bunnyDebugunny.obj
文件 192512 2006-03-04 03:19 bunnyDebugglew32.dll
文件 121856 2004-08-04 08:52 bunnyDebugglu32.dll
文件 169984 1998-08-18 23:25 bunnyDebugglut32.dll
文件 67 2009-05-15 10:38 bunnyDebugmt.dep
文件 39995 2009-05-15 09:41 bunnyDebugNeHeGL.obj
文件 713728 2004-08-04 08:52 bunnyDebugopengl32.dll
文件 396288 2009-05-15 10:38 bunnyDebugvc80.idb
............此处省略26个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)