資源簡介
用opgl繪制的兔子,支持放大縮小,旋轉等功能,開發環境是vs2005

代碼片段和文件信息
#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??bunny\48_ArcBall.ncb
?????文件???????4537??2009-05-15?09:54??bunny\48_ArcBall.vcproj
?????文件???????1423??2009-05-15?15:18??bunny\48_ArcBall.vcproj.20090401-1254.Administrator.user
?????文件???????2516??2006-08-21?07:18??bunny\ArcBall.cpp
?????文件??????13088??2006-08-13?12:53??bunny\ArcBall.h
?????文件??????32904??2009-05-15?09:54??bunny\bunny.aps
?????文件???????9361??2009-05-15?10:38??bunny\bunny.cpp
?????文件????2417019??2000-10-11?01:34??bunny\bunny.dat
?????文件????9415680??2009-05-15?15:18??bunny\bunny.ncb
?????文件???????1418??2009-05-15?09:54??bunny\bunny.rc
?????文件????????879??2009-04-26?10:04??bunny\bunny.sln
????..A..H.?????25600??2009-05-15?15:18??bunny\bunny.suo
?????文件?????593920??2009-05-15?10:38??bunny\Debug\48_ArcBall.exe
?????文件????????146??2009-04-26?10:05??bunny\Debug\48_ArcBall.exe.em
?????文件????????212??2009-04-26?10:05??bunny\Debug\48_ArcBall.exe.em
?????文件????????145??2009-05-15?10:38??bunny\Debug\48_ArcBall.exe.intermediate.manifest
?????文件????1296180??2009-05-15?10:38??bunny\Debug\48_ArcBall.ilk
?????文件??????48332??2009-04-26?11:15??bunny\Debug\48_ArcBall.obj
?????文件????2345984??2009-05-15?10:38??bunny\Debug\48_ArcBall.pdb
?????文件??????28647??2009-04-26?10:05??bunny\Debug\ArcBall.obj
?????文件??????10062??2009-05-15?10:38??bunny\Debug\BuildLog.htm
?????文件????2417019??2000-10-11?01:34??bunny\Debug\bunny.dat
?????文件??????55068??2009-05-15?10:38??bunny\Debug\bunny.obj
?????文件?????192512??2006-03-04?03:19??bunny\Debug\glew32.dll
?????文件?????121856??2004-08-04?08:52??bunny\Debug\glu32.dll
?????文件?????169984??1998-08-18?23:25??bunny\Debug\glut32.dll
?????文件?????????67??2009-05-15?10:38??bunny\Debug\mt.dep
?????文件??????39995??2009-05-15?09:41??bunny\Debug\NeHeGL.obj
?????文件?????713728??2004-08-04?08:52??bunny\Debug\opengl32.dll
?????文件?????396288??2009-05-15?10:38??bunny\Debug\vc80.idb
............此處省略26個文件信息
評論
共有 條評論