資源簡介
Qt Creator+opengl實現鼠標交互,控制模型任意旋轉,實現軌跡球,
里面的void Widget::drawarrow(GLdouble x0, GLdouble y0, GLdouble z0, GLdouble x1, GLdouble y1, GLdouble z1)這個函數實現,空間任意兩點繪制箭頭的。
里面的void Widget::drawarrow(GLdouble x0, GLdouble y0, GLdouble z0, GLdouble x1, GLdouble y1, GLdouble z1)這個函數實現,空間任意兩點繪制箭頭的。
代碼片段和文件信息
#include?
#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?????=0.0f;
????this->StVec.s.Y?????=?0.0f;
????this->StVec.s.Z?????=?0.0f;
????this->EnVec.s.X?????=0.0f;
????this->EnVec.s.Y?????=?0.0f;
????this->EnVec.s.Z?????=?0.0f;
????Matrix4fSetIdentity(&Transform);
????Matrix3fSetIdentity(&LastRot);
????Matrix3fSetIdentity(&ThisRot);
????this->isDragging=false;
????this->isClicked=?false;
????this->isRClicked?=?false;
????this->isZooming?=?false;
????this->zoomRate?=?1;
????this->setBounds(NewWidth?NewHeight);
}
void?ArcBall_t::upstate()
{
????if(!this->isZooming?&&?this->isRClicked){?//?開始拖動
????????this->isZooming?=?true;?//?設置拖動為變量為true
????????this->LastPt?=?this->MousePt;
????????this->lastZoomRate?=?this->zoomRate;
????}
????else?if(this->isZooming){//正在拖動
????????if(this->isRClicked){????????????????//拖動
????????????Point2fSub(&this->MousePt?&this->LastPt);
????????????this->zoomRate?=?this->lastZoomRate?+?this->MousePt.s.X?*?this->AdjustWidth?*?2;
????????}
????????else{//停止拖動
????????????this->isZooming?=?false;
????????}
????}
????else?if?(!this->isDragging?&&?this->isClicked){?????????????????????//?如果沒有拖動
????????this->isDragging?=?true;????????????????????????????????????????//?設置拖動為變量為true
????????this->LastRot?=?this->ThisRot;
????????this->click(&this->MousePt);
????}
????else?if(this->isDragging){
????????if?(this->isClicked){????????????????????????????????????????????//如果按住拖動
????????????Quat4fT?????ThisQuat;
????????????this->drag(&this->MousePt?&ThisQuat);????????????????????????//?更新軌跡球的變量
????????????Matrix3fSetRotationFromQuat4f(&this->ThisRot?&ThisQuat);????????//?計算旋轉量
????????????Matrix3fMulMatrix3f(&this->ThisRot?&this->LastRot);
????????????Matrix4fSetRotationFromMatrix3f(&this->Transform?&this->ThisRot);
????????}
????????else??//?如果放開鼠標,設置拖動為false
????????????this->isDragging?=?false;
????}
}
//按下鼠標記錄當前對應的軌跡球的位置
void????ArcBall_t::click(co
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4299??2014-03-13?11:14??guijiqiu\ArcBall.cpp
?????文件??????12735??2014-03-13?11:08??guijiqiu\ArcBall.h
?????文件????????387??2014-03-12?22:24??guijiqiu\guijiqiu.pro
?????文件??????17903??2014-03-14?10:46??guijiqiu\guijiqiu.pro.user
?????文件????????175??2014-03-12?22:22??guijiqiu\main.cpp
?????文件???????6100??2014-03-14?10:46??guijiqiu\widget.cpp
?????文件???????6062??2014-03-14?15:05??guijiqiu\widget.cpp.autosave
?????文件????????546??2014-03-13?09:49??guijiqiu\widget.h
?????目錄??????????0??2014-03-14?15:05??guijiqiu
-----------?---------??----------?-----??----
????????????????48207????????????????????9
- 上一篇:一個人臉識別程序源碼
- 下一篇:Y450 BIOS白名單
評論
共有 條評論