add torus

This commit is contained in:
Stefan Bühler 2009-01-12 15:18:26 +01:00
parent dd879a17f5
commit 5d54ba6d3d
2 changed files with 33 additions and 5 deletions

View File

@ -23,12 +23,14 @@
#include <GL/gl.h>
#include <math.h>
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);

View File

@ -52,9 +52,6 @@ namespace toruschess {
void freeTexture();
void updateTexture();
void createTorus();
void freeTorus();
Game *m_game;
PieceLibrary *m_lib;