static GLfloat staticdegreesToradians(GLfloat tmpdegrees) { return tmpdegrees * ((std::atan(1.0f)*4)/180.0f);}voID LedPannelWidget::updateGL() { glMatrixMode(GL_PROJECTION); glLoadIDentity(); glVIEwport(0,mWIDth,mHeight); glOrtho(0,mHeight,-mBubbleDiameter,mBubbleDiameter); glMatrixMode(GL_MODELVIEW); glScissor(0,mHeight); glClear(GL_color_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearcolor(0.92f,0.92f,1.0); glLoadIDentity(); const GLfloat tmpRadius = mDiameter/2.0f; const GLfloat tmpDelta = 5.00f; const GLfloat tmpDeltaradians = staticdegreesToradians(tmpDelta); for (int32_t tmpTheta = 180; tmpTheta > 0; tmpTheta -= tmpDelta) { for (int32_t tmpPhi = 0; tmpPhi < 360; tmpPhi += tmpDelta) { GLfloat tmpThetaradians = staticdegreesToradians(tmpTheta); GLfloat tmpPhiradians = staticdegreesToradians(tmpTheta); GLfloat tmpX1 = tmpRadius * std::sin(tmpThetaradians) * std::cos(tmpPhiradians); GLfloat tmpY1 = tmpRadius * std::sin(tmpThetaradians) * std::cos(tmpPhiradians); GLfloat tmpZ1 = tmpRadius * std::cos(tmpThetaradians); GLfloat tmpX2 = tmpRadius * std::sin(tmpThetaradians - tmpDeltaradians) * std::cos(tmpPhiradians); GLfloat tmpY2 = tmpRadius * std::sin(tmpThetaradians - tmpDeltaradians) * std::cos(tmpPhiradians); GLfloat tmpZ2 = tmpRadius * std::cos(tmpThetaradians - tmpDeltaradians); GLfloat tmpX3 = tmpRadius * std::sin(tmpThetaradians - tmpDeltaradians) * std::cos(tmpPhiradians + tmpDeltaradians); GLfloat tmpY3 = tmpRadius * std::sin(tmpThetaradians - tmpDeltaradians) * std::cos(tmpPhiradians + tmpDeltaradians); GLfloat tmpZ3 = tmpRadius * std::cos(tmpThetaradians - tmpDeltaradians); GLfloat tmpX4 = tmpRadius * std::sin(tmpThetaradians) * std::cos(tmpPhiradians + tmpDeltaradians); GLfloat tmpY4 = tmpRadius * std::sin(tmpThetaradians) * std::cos(tmpPhiradians + tmpDeltaradians); GLfloat tmpZ4 = tmpRadius * std::cos(tmpThetaradians); glBegin(GL_QUADS); glVertex3f(tmpX1,tmpY1,tmpZ1); glVertex3f(tmpX2,tmpY2,tmpZ2); glVertex3f(tmpX3,tmpY3,tmpZ3); glVertex3f(tmpX4,tmpY4,tmpZ4); glEnd(); if (tmpGLError != GL_NO_ERROR) { QApplication::exit(0); } } } swapBuffers();}
工作GL算法:
const GLfloat r = mDiameter/2.0f;const GLfloat phID = 20.00f;const GLfloat thetad = 20.00f;const GLfloat x = mCenterXCoord;const GLfloat y = mCenterYCoord;using namespace std;for (int32_t phi = 180; phi > 0; phi -= phID) { int32_t theta = 0; GLfloat rphi = staticdegreesToradians(phi); GLfloat rtheta = staticdegreesToradians(theta); glBegin(GL_QUAD_STRIP); glcolor3f(mCurrentcolor.red()/255.0,mCurrentcolor.green()/255.0,mCurrentcolor.blue()/255.0); glVertex3f( (x + (r * sin(rphi) * cos(rtheta))),(y + (r * cos(rphi))),(0 + (r * sin(rphi) * cos(rtheta)))); glVertex3f( (x + (r * sin(rphi + phID) * cos(rtheta))),(y + (r * cos(rphi + phID))),(0 + (r * sin(rphi + phID) * cos(rtheta)))); for (; theta < 360; theta += thetad) { rtheta = staticdegreesToradians(theta); glVertex3f( (x + (r * sin(rphi + phID) * cos(rtheta + thetad))),(0 + (r * sin(rphi + phID) * cos(rtheta + thetad)))); glVertex3f( (x + (r * sin(rphi) * cos(rtheta + thetad))),(0 + (r * sin(rphi) * cos(rtheta + thetad)))); } glEnd();}解决方法 在这些行中检查您的代码
GLfloat tmpThetaradians = staticdegreesToradians(tmpTheta); GLfloat tmpPhiradians = staticdegreesToradians(tmpTheta); GLfloat tmpX1 = tmpRadius * std::sin(tmpThetaradians) * std::cos(tmpPhiradians); GLfloat tmpY1 = tmpRadius * std::sin(tmpThetaradians) * std::cos(tmpPhiradians); GLfloat tmpZ1 = tmpRadius * std::cos(tmpThetaradians);
您需要更改,请参阅下文
GLfloat tmpThetaradians = staticdegreesToradians(tmpTheta); GLfloat tmpPhiradians = staticdegreesToradians(tmpPhi); GLfloat tmpX1 = tmpRadius * std::sin(tmpThetaradians) * std::sin(tmpPhiradians); GLfloat tmpY1 = tmpRadius * std::sin(tmpThetaradians) * std::cos(tmpPhiradians); GLfloat tmpZ1 = tmpRadius * std::cos(tmpThetaradians);总结
以上是内存溢出为你收集整理的c – OpenGL Render Sphere Without Glut:这个实现有什么问题?全部内容,希望文章能够帮你解决c – OpenGL Render Sphere Without Glut:这个实现有什么问题?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)