#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); }