資源簡介
axes.zip

代碼片段和文件信息
#include?“axes.h“
Axes::Axes(QWidget?*parent)?:?QOpenGLWidget(parent)?_eye(0?0?20)?_center(0?0?0)?_up(0?1?0)
{
}
void?Axes::initializeGL()
{
????initializeOpenGLFunctions();
//????glClearColor(0.75?0.75?0.75?1.0);
????glClearColor(0.0?0.0?0.0?1.0);
????glPolygonMode(GL_FRONT_AND_BACK?GL_FILL);
????glDepthFunc(GL_LEQUAL);
????glEnable(GL_DEPTH_TEST);
????glColorMaterial(GL_FRONT_AND_BACK?GL_AMBIENT_AND_DIFFUSE);
????glEnable(GL_COLOR_MATERIAL);
????glEnable(GL_LIGHT0);
????glDisable(GL_LIGHTING);
????//?We?need?a?valid?OpenGL?context?before?building?the?3D?font?display?lists.
????float?glyphWidth?=?3;
????int?numGlyphs?=?256;
????QFont?font?=?QFont(“Sans“?20?QFont::Normal);
????_textRender.setFont(font?glyphWidth?numGlyphs);
}
void?Axes::resizeGL(int?w?int?h)
{
????glViewport(0?0?width()?height());
????glMatrixMode(GL_PROJECTION);
????glLoadIdentity();
????perspective(10?float(w)?/?h?2?200);
????glMatrixMode(GL_MODELVIEW);
}
void?Axes::paintGL()
{
????glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
????glMatrixMode(GL_MODELVIEW);
????glLoadIdentity();
????lookAt(_eye?_center?_up);
????DrawSpaceAxes();
}
void?Axes::DrawSpaceAxes()
{
????GLdouble?axesLen?=?0.1;
????GLdouble?radius?=?0.03;
????GLdouble?base?=?0.01;
????GLdouble?top?=?0.01;
????GLdouble?baseRadius?=?0.03;
????GLdouble?topRadius?=?0.0;
????GLUquadricObj?*objCylinder?=?gluNewQuadric();
//---------------------------------------------------------------------z
????glPushMatrix();
????glColor3f(1.0f?0.0f?0.0f);
????glutSolidSphere(radius66);
????glColor3f(0.0f0.0f?1.0f);
????gluCylinder(objCylinderbase?top?axesLen?10?5);?????????//Z
????glTranslatef(00axesLen);
????gluCylinder(objCylinderbaseRadius?topRadius?baseRadius?10?5);?????????????????//Z
????glPopMatrix();
????glPushMatrix();
????glTranslatef(0?axesLen?/?2axesLen);
????DrawSpaceText(“Z“);
????glPopMatrix();
//---------------------------------------------------------------------y
????glPushMatrix();
????glColor3f(0.0f1.0f?0.0f);
????glRotatef(-901.00.00.0);
????gluCylinder(objCylinderbase?top?axesLen?10?5);?????????//Y
????glTranslatef(00axesLen);
????gluCylinder(objCylinderbaseRadius?topRadius?baseRadius?10?5);?????????????????//Y
????glPopMatrix();
????glPushMatrix();
????glTranslatef(axesLen?/?2axesLen0);
????DrawSpaceText(“Y“);
????glPopMatrix();
//---------------------------------------------------------------------x
????glPushMatrix();
????glColor3f(1.0f0.0f?0.0f);
????glRotatef(900.01.00.0);
????gluCylinder(objCylinderbase?top?axesLen?10?5);?????????//X
????glTranslatef(00axesLen);
????gluCylinder(objCylinderbaseRadius?topRadius?baseRadius?10?5);?????????????????//X
????glPopMatrix();
????glPushMatrix();
????glTranslatef(axesLenaxesLen?/?20);
????DrawSpaceText(“X“);
????glPopMatrix();
}
void?Axes::DrawSpaceText(QString?text)
{
????//?Draw?3D?text.
????QVector3D?position(0?0?0);
????int?align?=?Qt::AlignHCenter?|?Qt::Al
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-12-03?07:54??axes\
?????文件????????4981??2019-03-18?15:06??axes\QtFont3D.cpp
?????文件????????1539??2019-03-18?15:06??axes\QtFont3D.h
?????文件????????7381??2020-12-03?07:54??axes\axes.cpp
?????文件????????1251??2020-12-03?15:57??axes\axes.h
?????文件????????1166??2020-12-03?05:25??axes\axes.pro
?????文件???????24192??2020-12-03?05:41??axes\axes.pro.user
?????目錄???????????0??2020-12-03?07:54??axes\build\
?????文件?????????739??2020-12-03?04:53??axes\build\.qmake.stash
?????文件???????25180??2020-12-03?05:25??axes\build\Makefile
?????文件??????919608??2020-12-03?04:59??axes\build\QtFont3D.o
?????文件?????1321504??2020-12-03?07:54??axes\build\axes
?????文件??????784248??2020-12-03?07:54??axes\build\axes.o
?????文件??????914232??2020-12-03?07:54??axes\build\main.o
?????文件????????2614??2020-12-03?07:54??axes\build\moc_axes.cpp
?????文件??????826992??2020-12-03?07:54??axes\build\moc_axes.o
?????文件???????13992??2020-12-03?04:59??axes\build\moc_predefs.h
?????文件?????????347??2020-12-03?05:55??axes\main.cpp
評論
共有 條評論