C++ (Qt)float h; // высота цилиндраy_image = (h / 2 - p.y) / h * image_height;x_image = atan2(p.z, p.x) / (PI * 2) * image_width;
void Ploskost::paintGL(){ glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_QUADS); for(GLfloat v = 0.0; v < 10.0; v++) for(GLfloat u = 0.0; u < 10.0; u++) { qglColor(Qt::green); glVertex3f(u, v, 0.0f); qglColor(Qt::red); glVertex3f(u, v+1, 0.0f); qglColor(Qt::green); glVertex3f(u+1, v+1.0f, 0.0f); qglColor(Qt::red); glVertex3f(u+1.0f, v, 0.0f); } glEnd();
#include "scene3D.h"#include <math.h>#include <QtGui>const static float PI2 = 3.141593 * 2;scene3D::scene3D(QWidget *parent) : QGLWidget(parent){ yRotate = 0.0; angle = 0.0; radius = 500; // ? quad = 30; // ? hight = radius; //?}void scene3D::initializeGL(){ qglClearColor(Qt::gray); LoadTextures(); glEnable(GL_TEXTURE_2D);}void scene3D::resizeGL(int w, int h){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, (GLint)w, (GLint)h); glOrtho(-w, w, -h, h, -w, w);}void scene3D::paintGL(){ glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(yRotate, 0.0f, 1.0f, 0.0f); drawCylinder(); }void scene3D::drawCylinder(){ glBindTexture(GL_TEXTURE_2D, text[0]); float x = 32.0f; float y = 32.0f; glBegin(GL_QUADS); glTexCoord2f(0.0f, -1.0f); glVertex3f(-x, y, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-x, -y, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(x, -y, 0.0f); glTexCoord2f(1.0f, -1.0f); glVertex3f(x, y, 0.0f); glEnd();// float y = 1024.0f;// float x = 4096.0f;// glBegin(GL_TRIANGLE_STRIP);// for(float i = 0.0; i <= quad; i++)// {// angle = PI2 * (float)i / (float)quad;// qglColor(Qt::green);// glVertex3f(radius*cos(angle), y0, radius*sin(angle));// qglColor(Qt::blue);// glVertex3f(radius*cos(angle), hight, radius*sin(angle));// }// glEnd();}void scene3D::mousePressEvent(QMouseEvent *mousePress){ mouseLastPosition = mousePress->pos();}void scene3D::mouseMoveEvent(QMouseEvent *mouseMove){ yRotate += (mouseMove->y() - mouseLastPosition.y()); updateGL(); mouseLastPosition = mouseMove->pos();}void scene3D::LoadTextures(){ QImage im = QImage(":/Icons/64x64.jpg"); if (!im.isNull()) { glGenTextures(1, &text[0]); glBindTexture(GL_TEXTURE_2D, text[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 4, im.width(), im.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im.bits()); } else { QMessageBox::warning(this, "ERROR", "error", 0, 1); }}