1

私は現在、すばらしい本でGLFrameクラスを使用する方法を理解しようとしています。この本の第4版によると、参照クラスのフレームから派生したカメラマトリックスはGluLookAtと同じように機能するはずです。

これらの行を追加すると

cameraFrame.SetForwardVector(-0.5f, 0.0f,-0.5f);
cameraFrame.Normalize();

カメラは正しい方向を向いており、45度でヨーイングします(私はそれを正しく行っていますか?)

しかし、これを追加すると

cameraFrame.SetForwardVector(0.0f, 0.5f,-0.5f);

カメラは(0.0f、0.0f、1.0f)に設定されているように見えます

どうしてこれなの!それは私を3日間怒らせてきました。たぶん私はベクトルを正しく渡していないかもしれませんが、(前方の)位置/ベクトルを見るためにx、yを360度渡す方法がわかりません。ベクトルを渡す前に、ベクトルを正規化する必要がありますか?

最終的にはフルマウスルック(FPSスタイル)をやりたいと思っていますが、今のところ、カメラを単純にピッチアップできない理由を理解することは良いスタートです。

ありがとう!

これがその場でのコードです。

// Called to draw scene
void RenderScene(void)
{
// Color values
static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f};
static GLfloat vTorusColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
static GLfloat vSphereColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };

// Time Based animation
static CStopWatch   rotTimer;
float yRot = rotTimer.GetElapsedSeconds() * 60.0f;

// Clear the color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


// Save the current modelview matrix (the identity matrix)
modelViewMatrix.PushMatrix();   

M3DMatrix44f mCamera;

/////////
///////// My Code

cameraFrame.SetForwardVector(-0.5f,-0.5f,-0.5f);
cameraFrame.Normalize();

///////// End of my code
cameraFrame.GetCameraMatrix(mCamera);
modelViewMatrix.PushMatrix(mCamera);

// Transform the light position into eye coordinates
M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f };
M3DVector4f vLightEyePos;
m3dTransformVector4(vLightEyePos, vLightPos, mCamera);

// Draw the ground
shaderManager.UseStockShader(GLT_SHADER_FLAT,
                             transformPipeline.GetModelViewProjectionMatrix(),
                             vFloorColor);  
floorBatch.Draw();

for(int i = 0; i < NUM_SPHERES; i++) {
    modelViewMatrix.PushMatrix();
    modelViewMatrix.MultMatrix(spheres[i]);
    shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF,     transformPipeline.GetModelViewMatrix(), 
                            transformPipeline.GetProjectionMatrix(), vLightEyePos, vSphereColor);
    sphereBatch.Draw();
    modelViewMatrix.PopMatrix();
    }

// Draw the spinning Torus
modelViewMatrix.Translate(0.0f, 0.0f, -2.5f);

// Save the Translation
modelViewMatrix.PushMatrix();

    // Apply a rotation and draw the torus
    modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
    shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(), 
                                 transformPipeline.GetProjectionMatrix(), vLightEyePos, vTorusColor);
    torusBatch.Draw();
modelViewMatrix.PopMatrix(); // "Erase" the Rotation from before

// Apply another rotation, followed by a translation, then draw the sphere
modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f);
modelViewMatrix.Translate(0.8f, 0.0f, 0.0f);
shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(), 
                            transformPipeline.GetProjectionMatrix(), vLightEyePos, vSphereColor);
sphereBatch.Draw();

// Restore the previous modleview matrix (the identity matrix)
modelViewMatrix.PopMatrix();
modelViewMatrix.PopMatrix();    
// Do the buffer Swap
glutSwapBuffers();

// Tell GLUT to do it again
glutPostRedisplay();

}

4

1 に答える 1

0

皆さんの回答ありがとうございますが、私が抱えていた問題はこれでした。openGLスーパーバイブルでは、参照クラスの組み込みフレームを使用していましたが、問題は、rotateとrotateWorldという2つの関数でした。

上下の動きにはrotateを使用し、左右の動きにはrotateWorldを使用する必要がありました。これにより、カメラは正しく動作しました(フライカメラ)。

上/下を見ている場所に関係なく、全世界が常に垂直軸を中心に回転するようにしたいので、それは理にかなっています。ふぅ!

于 2011-06-05T11:42:40.050 に答える