我有一个有趣的问题。我正在使用矩阵乘法来旋转和缩放我的游戏图像。当我将图像缩小一半或更多时,它的效果很好,但如果图像保持原始尺寸,则会出现孔。我在下面附上了一些问题的图片。我的绘图代码也在下面。
void Graphics::drawImage(Graphics::Image i, float x, float y, float rot, float xScale, float yScale)
{
unsigned char r = 0, g = 0, b = 0;
Vector<float> pos = Vector<float>::create(0, 0);
i.setRotation(rot);
i.setXScale(xScale);
i.setYScale(yScale);
for (int j = 0; j < i.getWidth() * i.getHeight(); j++)
{
i.getPixel((j % i.getWidth()), (j / i.getWidth()), r, g, b);
SDL_SetRenderDrawColor(renderer, r, g, b, 255);
pos.elements[0] = (j % i.getWidth());
pos.elements[1] = (j / i.getWidth());
Vector<float> transPos = pos - Vector<float>::create(i.getCenterX(), i.getCenterY());
Matrix<float> trans = math::scale<float>(i.getXScale(), i.getYScale()) * math::rot<float>((double)i.getRot());
transPos = math::mult<float, float>(trans, transPos);
SDL_RenderDrawPoint(renderer, (int)x + transPos.elements[0] + (i.getCenterX() * i.getXScale()), (int)y + transPos.elements[1] + (i.getCenterY() * i.getYScale()));
}
}