ウィンドウの端のボールを跳ね返すプログラムを作成していますが、境界が歪んでいるという問題があります。
初期解像度を正方形のウィンドウに設定すると、
int windowWidth = 600;
int windowHeight = 600;
それは正常に動作します。ウィンドウの形状を変更するとすぐに、ウィンドウの境界が歪んでしまいます。
四角だとこんな感じ。
横に伸ばすとこんな感じ。
高さを伸ばすとこんな感じ。
基本的に、ウィンドウの境界を歪めずにウィンドウのサイズを変更することはできません。
reshape
これは私の関数のコードです:
void reshape(GLsizei weight, GLsizei height)
{
if (height == 0) height = 1; // To prevent divide by 0
GLfloat aspect = (GLfloat)weight / height; // Get aspect ratio
// Set the viewport to cover the entire window
glViewport(0, 0, weight, height);
// Adjust the aspect ratio of clipping area to match the viewport
glMatrixMode(GL_PROJECTION); // Select the Projection matrix
glLoadIdentity(); // Reset
for (int i = 0; i < numOfBalls; i++)
{
if (weight <= height)
{
balls[i].xLeft = -1.0;
balls[i].xRight = 1.0;
balls[i].yBottom = -1.0 / aspect;
balls[i].yTop = 1.0 / aspect;
}
else
{
balls[i].xLeft = -1.0 * aspect;
balls[i].xRight = 1.0 * aspect;
balls[i]. yBottom = -1.0;
balls[i]. yTop = 1.0;
}
gluOrtho2D(balls[i].xLeft, balls[i].xRight, balls[i].yBottom, balls[i].yTop);
balls[i].xPosMin = balls[i].xLeft + balls[i].ballRadius;
balls[i].xPosMax = balls[i].xRight - balls[i].ballRadius;
balls[i].yPosMin = balls[i].yBottom + balls[i].ballRadius;
balls[i].yPosMax = balls[i].yTop - balls[i].ballRadius;
}
glMatrixMode(GL_MODELVIEW); // Select the model-view matrix
glLoadIdentity(); // Reset
}
*注: 必要に応じてさらにコードを投稿できます...