2011-04-07 6 views
1
과 Y 축 작업

나는 현재 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(); 
모든 사람의 답변을

}

+0

그것은 도움이 될 수 있습니다. 그렇지 않으면 우리는 잘못된 것만을 추측 할 수 있습니다. – genpfault

답변

0

감사하지만 내가 가진 문제는이이었다. OpenGL 슈퍼 성경에서는 참조 클래스의 기본 프레임을 사용하고 있었고 문제는 rotate, rotateWorld라는 두 가지 함수였습니다.

나는 위/아래 이동을 회전 사용하는 데 필요한, 그리고 왼쪽에서 오른쪽으로 이동을위한 rotateWorld. 이로 인해 카메라가 올바르게 작동합니다 (카메라를 날립니다).

위/아래를보고있는 위치에 관계없이 전 세계가 항상 세로 축을 중심으로 회전하기를 원합니다. 휴! 당신이 GLFrame` '의 구현을 제공하는 경우

+0

이이 질문에 대한 당신의 허용 대답의 중복으로 표시했습니다 : http://stackoverflow.com/questions/5545867/how-to-implement-an-fps-camera-without-glu-on-osx-or- 교차 플랫폼 -C/6242673 # 6242673 또한 여기에서 "모든 사람의 답변"을 참조하지만 다른 게시물은 표시되지 않습니다. 어쩌면 해결할 수 있을까요? 감사. – Kev

관련 문제