summaryrefslogtreecommitdiffstats
path: root/src/glchessboard.cpp
blob: c47fea5e3b43ab2e147f41b170f1487201f41e5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "glchessboard.h"

GLChessboard::GLChessboard(float width, float height)
{
    m_width = width;
    m_height = height;
}

void GLChessboard::createBoard()
{
    double fieldWidth = m_width / 8;
    double fieldHeight = m_height / 8;

    for(int fieldY = 0; fieldY < 8; fieldY++)
    {
        for(int fieldX = 0; fieldX < 8; fieldX++)
        {
            if((fieldY+fieldX) % 2)
            {
                m_fields.append(GLCube(QVector3D(fieldX * fieldWidth, fieldY * fieldHeight, 0.0), QVector3D((fieldX + 1) * fieldWidth, (fieldY + 1) * fieldHeight, 0.0)));
            }
        }
    }
}

void GLChessboard::drawBoard(GLESRenderer *renderer)
{
    foreach(GLCube field, m_fields)
    {
        field.draw(renderer);
    }
}

QVector3D GLChessboard::fieldToPosition(const QPoint &field)
{
    double fieldWidth = m_width / 8;
    double fieldHeight = m_height / 8;

    return QVector3D(fieldWidth/2 + field.x() * fieldWidth, fieldHeight/2 + field.y() * fieldHeight, 0.0);
}