나는 현재 superbible 책에 GLFrame 클래스를 사용하는 방법을 이해하려고 노력하고, 책의 4 판 주문에 따라거야하지 않는 카메라 매트릭스에서 파생 된 나는 45도왜 SuperBible 프레임 참조 또는하는 gluLookAt
cameraFrame.SetForwardVector(-0.5f, 0.0f,-0.5f);
cameraFrame.Normalize();
카메라가 올바른 방향으로 보이는, 요는이 라인을 추가 할 때 참조 클래스의 프레임하는 gluLookAt
과 동일하게 작동합니다 (I 잘 것을하고 있습니까!)를
그러나 이것을 추가하면
이 (0.0f로, 0.0f를, 1.0F)로 설정된 것처럼 카메라가 바로 보이는cameraFrame.SetForwardVector(0.0f, 0.5f,-0.5f);
왜이입니다! 3 일 동안 나를 미치게 만들었 어. 어쩌면 벡터를 올바르게 전달하지 못하고 있지만 (앞으로) 위치/벡터를보기 위해 x, y 360도를 전달하는 방법을 모르겠습니다. 벡터를 전달하기 전에 벡터를 정규화해야합니까?
은 결국 나는 전체 마우스보기 (FPS 스타일을) 할 수 있도록 노력하겠습니다,하지만 난 카메라를 만들 수없는 이유를 이제 막 이해하기위한 단순히 좋은 시작이 될 것입니다 최대 피치.
Thansk! 여기
은 현장에서 코드입니다.// 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();
모든 사람의 답변을
}
그것은 도움이 될 수 있습니다. 그렇지 않으면 우리는 잘못된 것만을 추측 할 수 있습니다. – genpfault