void Drawer::drawPieces(const Board::ConstStackHandle& s) const { startTexture(); glPushMatrix(); translateTo(s.stackCoord()); glTranslatef(0.5f*caseD,0.5f*caseD,0.0f); for (Stack::const_iterator iter = s->begin(), istop= s->end(); iter != istop;++iter) { drawPiece((*iter)->color()); glTranslatef(0.0f,0.0f,pieceH); } glPopMatrix(); endTexture(); }
void Drawer::drawMove(const Board& b,const Game::Move m,float t) const { const float L = caseD*estimateDrawMoveLength(b,m); const float t0 = (b.heightMax()+1-b.stackAt(m.src)->height())*pieceH/L; const float t1 = 1.0f-(b.heightMax()+1-b.stackAt(m.dst)->height())*pieceH/L; Board::ConstStackHandle src = b.stackAt(m.src); glPushMatrix(); startTexture(); if (t<=t0) { t /= t0; float srcH = src->height()*pieceH; float dstH = b.heightMax()*pieceH+pieceH; translateTo(m.src); glTranslatef(0.5f*caseD,0.5f*caseD, (1-t)*srcH+t*dstH); for (Stack::const_iterator iter = src->begin(), istop= src->end(); iter != istop;++iter) { drawPiece((*iter)->color()); glTranslatef(0.0f,0.0f,pieceH); } } else if (t<=t1) { t = (t-t0)/(t1-t0); static const float shifts[5] = { 1.0f,0.5f,0.0f,-0.5f,-1.0f }; float srcX = boardB+vLabelW+m.src.x()*caseD+shifts[m.src.y()]*caseD; float srcY = boardB+hLabelH+m.src.y()*caseD; float dstX = boardB+vLabelW+m.dst.x()*caseD+shifts[m.dst.y()]*caseD; float dstY = boardB+hLabelH+m.dst.y()*caseD; glTranslatef((1.0f-t)*srcX+t*dstX+0.5f*caseD, (1.0f-t)*srcY+t*dstY+0.5f*caseD, b.heightMax()*pieceH+pieceH); for (Stack::const_iterator iter = src->begin(), istop= src->end(); iter != istop;++iter) { drawPiece((*iter)->color()); glTranslatef(0.0f,0.0f,pieceH); } } else { t = (t-t1)/(1.0f-t1); float srcH = b.heightMax()*pieceH+pieceH; float dstH = b.stackAt(m.dst)->height()*pieceH; translateTo(m.dst); glTranslatef(0.5f*caseD,0.5f*caseD, (1-t)*srcH+t*dstH); for (Stack::const_iterator iter = src->begin(), istop= src->end(); iter != istop;++iter) { drawPiece((*iter)->color()); glTranslatef(0.0f,0.0f,pieceH); } } endTexture(); glPopMatrix(); }