add torus
This commit is contained in:
parent
dd879a17f5
commit
5d54ba6d3d
@ -23,12 +23,14 @@
|
|||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
namespace toruschess {
|
namespace toruschess {
|
||||||
|
|
||||||
Field3D::Field3D(Game *game, QWidget *parent)
|
Field3D::Field3D(Game *game, QWidget *parent)
|
||||||
: QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba), parent), m_game(game), m_lib(new PieceLibrary(this)),
|
: QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba), parent), m_game(game), m_lib(new PieceLibrary(this)),
|
||||||
m_textureBuffer(0), m_textureID(0),
|
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");
|
qDebug("Field3d::Field3D");
|
||||||
for (int x = 0; x < 8; x++) for (int y = 0; y < 8; y++) m_marked[x][y] = false;
|
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);
|
m_lib->setSize(m_textureSize / 8, m_textureSize / 8);
|
||||||
@ -60,7 +62,6 @@ namespace toruschess {
|
|||||||
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
createTexture();
|
createTexture();
|
||||||
createTorus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Field3D::resizeGL(int w, int h) {
|
void Field3D::resizeGL(int w, int h) {
|
||||||
@ -76,6 +77,36 @@ namespace toruschess {
|
|||||||
void Field3D::paintGL() {
|
void Field3D::paintGL() {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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);
|
glBindTexture(GL_TEXTURE_2D, m_textureID);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
@ -52,9 +52,6 @@ namespace toruschess {
|
|||||||
void freeTexture();
|
void freeTexture();
|
||||||
void updateTexture();
|
void updateTexture();
|
||||||
|
|
||||||
void createTorus();
|
|
||||||
void freeTorus();
|
|
||||||
|
|
||||||
Game *m_game;
|
Game *m_game;
|
||||||
PieceLibrary *m_lib;
|
PieceLibrary *m_lib;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user