私はQMatrix4x4 :: ortho(左、右、下、上、近、遠)に対してどのような値を使うべきかを理解するのが難しいです。Qt/OpenGLを使用して正投影を比例に保つ問題
具体的には、left、right、bottom、およびtopの値のドキュメントは分かりません。私は、投影行列を使ってOpenGLサルを描くことができる作業デモを持っています。デモをセットアップして、キーボードの「O」を押すと、投影行列を視点から正射影に切り替えます。透視投影は、モデルのアスペクト比を一定に保つ(すなわち、幅または高さが伸びない)という点で有効である。 'O'または 'P'キーが呼び出され、m_projが更新されたときに呼び出される関数を次に示します。私はたくさんのアイデアを試してみましたが、どれも本当に好きなように動作していないことがわかります。
これを理解するのに役立つ洞察をいただき、ありがとうございます。その他の有用な詳細:私のビューの目は、z = 2の中心(0,0,0)に面し、上に(0,1,0)です。
void AppGLScene::setProjectionMatrix(void)
{
m_projectionMatrix.setToIdentity();
float windowWidth = rect().width();
float windowHeight = rect().height();
float left, right, bottom, top;
float aratio = (float) windowWidth/(float) windowHeight;
qDebug() << "win wid, win hei" << windowWidth << windowHeight;
// I modify the vertical FOV in an attempt to keep the size of the
// model the same as the vertical size of the window changes.
//
float vFov = 90 * ((float)windowHeight/m_initialWinHeight);
qDebug() << "vFov" << vFov;
switch (m_proj)
{
case PROJ_PERSP:
m_projectionMatrix.perspective(vFov, qreal(windowWidth)/qreal(windowHeight), 0.5, 40);
break;
case PROJ_ORTHO:
default:
// left = rect().x();
// right = rect().x() + rect().width();
// bottom = rect().y();
// top = rect().y() + rect().height();
if (windowWidth > windowHeight)
{
left = -(3.0 - ((float)windowHeight/(float)windowWidth));
right = -left;
bottom = -3.0;
top = 3.0;
}
else
{
left = -3.0;
right = 3.0;
bottom = -(3.0 - ((float)windowWidth/(float)windowHeight));
top = -bottom;
}
qDebug() << "l r b t = " << left << right << bottom << top;
m_projectionMatrix.ortho(left, right, bottom, top, 0.5, 40);
// m_projectionMatrix.ortho(-3.0, 3.0, -3.0, 3.0, 0.5, 40);
// m_projectionMatrix.ortho(-aratio, aratio, -aratio, aratio, 0.5, 40);
break;
}
}
返信ありがとうございます。あなたの応答はそれをクリアします。私はテストし、この方法で私のモデルの元の幅/高さの比率を維持することができます。私は答えられた質問を考えます。今私は、正投影投影画像を透視投影画像とおおよそ同じ大きさにするために出発値(つまり3.0)がどのようなものでなければならないかを理解することになりそうです。私はOpenGLプログラミングガイドを読んできましたが、本で使用する独自のコード(vmath.h、.cpp)を持っています。 –
オルソ投影を「透視投影画像とおおよそ同じサイズ」にすることはできません。カメラから選択した距離にあるイメージプレーンに平行な任意の平面を見てみることができます。 – derhass