From 5d54ba6d3da5fb56ad4155a1bf281f3011b3c167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Mon, 12 Jan 2009 15:18:26 +0100 Subject: [PATCH] add torus --- src/field3d.cpp | 35 +++++++++++++++++++++++++++++++++-- src/field3d.h | 3 --- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/field3d.cpp b/src/field3d.cpp index 5146b13..d447ab1 100644 --- a/src/field3d.cpp +++ b/src/field3d.cpp @@ -23,12 +23,14 @@ #include +#include + namespace toruschess { Field3D::Field3D(Game *game, QWidget *parent) : QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba), parent), m_game(game), m_lib(new PieceLibrary(this)), m_textureBuffer(0), m_textureID(0), - m_camDist(10) ,m_camRotX(90), m_camRotY(0), m_camRotZ(0) { + m_camDist(10) ,m_camRotX(45), m_camRotY(0), m_camRotZ(0) { qDebug("Field3d::Field3D"); for (int x = 0; x < 8; x++) for (int y = 0; y < 8; y++) m_marked[x][y] = false; m_lib->setSize(m_textureSize / 8, m_textureSize / 8); @@ -60,7 +62,6 @@ namespace toruschess { glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); createTexture(); - createTorus(); } void Field3D::resizeGL(int w, int h) { @@ -76,6 +77,36 @@ namespace toruschess { void Field3D::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBindTexture(GL_TEXTURE_2D, m_textureID); + glEnable(GL_TEXTURE_2D); + { + const int numc = 16, numt = 16; + const double rad1 = 4.0, rad2 = 2.0; + int i, j, k; + double s, t, x, y, z, twopi; + + twopi = 2 * M_PI; + for (i = 0; i < numc; i++) { + glBegin(GL_QUAD_STRIP); + for (j = 0; j <= numt; j++) { + for (k = 1; k >= 0; k--) { + s = (i + k) % numc + 0.5; + t = j % numt; + + x = (rad1+rad2*cos(s*twopi/numc))*cos(t*twopi/numt); + y = (rad1+rad2*cos(s*twopi/numc))*sin(t*twopi/numt); + z = rad2 * sin(s * twopi / numc); + glTexCoord2f(double(i+k)/numc, double(j)/numt); + glVertex3f(x, z, y); + } + } + glEnd(); + } + } + glDisable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 0); + return; + glBindTexture(GL_TEXTURE_2D, m_textureID); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); diff --git a/src/field3d.h b/src/field3d.h index 28ea9ee..65299f4 100644 --- a/src/field3d.h +++ b/src/field3d.h @@ -52,9 +52,6 @@ namespace toruschess { void freeTexture(); void updateTexture(); - void createTorus(); - void freeTorus(); - Game *m_game; PieceLibrary *m_lib;