解決したい課題は簡単です:テクスチャリングされたOBJファイルをロードし、最大限のイメージスペースを占めるように表示します。カメラが負のz軸を見下ろし、y軸が上のベクトルである限り、メッシュを回転させる必要はありません。私はそれを行うためにpygletを使用しています。gluLookAtを使用して表示されると思われるビューがレンダリングされたイメージに表示されないのはなぜですか?
カメラを希望する位置に設定するには、以下のコードを実行します(コード参照)。メッシュの中心で定義されるメッシュの境界球と、最も離れた点までの半径センター。次に、例えば、説明したような錐台を計算する。 hereとし、それに応じて正射影を設定します。次に、私はgluLookAt
を使ってmodelviewmatrixを次のように更新します:カメラは正のz軸上にあり、メッシュの中心に向かって見え、y軸は上のベクトルです。
問題は、私のレンダリングされた画像が、私がそうであると思うように全く見えないことです。次の図のように、メッシュの中心が画像の中心にはありません。画像には、境界ボックスと、メッシュの計算中心から始まる座標軸(赤:x軸、緑:y軸、青:z軸)が表示されます。
カメラを設定するためのコードは次のとおりです。
center:
[ 8.51203675 -1.95199815 0.35396978]
radius: 10.462382
znear 1.000000, zfar 21.924764
left -1.950345, right 18.974419
bottom -12.414380, top 8.510384
eye:
10.8163515441
を印刷し
# get the bounding sphere
center, radius = self._mesh.compute_bounding_sphere()
diam = radius*2.0
print 'center:'
print center
print 'radius: %f' % radius
# set up near and far clipping plane
z_near = 1.0
z_far = z_near + diam
# construct params for orthographic projection matrix
left = center[0] - radius
right = center[0] + radius
bottom = center[1] - radius
top = center[1] + radius
# if we are not rendering a square image, must correct for aspect ratio
aspect_ratio = float(self.width)/float(self.height)
if aspect_ratio < 1.0:
bottom /= aspect_ratio
top /= aspect_ratio
else:
left *= aspect_ratio
right *= aspect_ratio
print 'znear %f, zfar %f' % (z_near, z_far)
print 'left %f, right %f' % (left, right)
print 'bottom %f, top %f' % (bottom, top)
# specify a parallel projection with clipping planes as computed above
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(left, right, bottom, top, z_near, z_far)
# gluPerspective(50.0, aspect_ratio, z_near, z_far)
# construct a viewing transform as follows: we look at the center of the mesh, the eye is located on the
# positive z-axis, and the 3D y-axis is the up-vector, i.e. it will be mapped to the y-axis in image space.
eye = center[2] + radius
print 'eye:'
print eye
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(0.0, 0.0, eye, center[0], center[1], center[2], 0.0, 1.0, 0.0)
は、あなたは私が私が間違っているの何識別するのに役立つことはできますか?