2014-04-11 22 views
1

내 프로그램에서 OpenTK C#을 사용합니다. 그리고 광원에 문제가 있습니다. 나는 그것을 카메라에 묶을 수 없다. 고정 된 위치에 머물러 있습니다.OpenGL. 움직이는 광원

 float[] light_ambient = { 0.2f, 0.2f, 0.2f, 1.0f }; 
     float[] light_diffuse = { 1.0f, 1.0f, 1.0f, 1.0f }; 
     float[] light_specular = { 1.0f, 1.0f, 1.0f, 1.0f }; 
     float[] spotdirection = { 0.0f, 0.0f, -1.0f }; 

     GL.Light(LightName.Light0, LightParameter.Ambient, light_ambient); 
     GL.Light(LightName.Light0, LightParameter.Diffuse, light_diffuse); 
     GL.Light(LightName.Light0, LightParameter.Specular, light_specular); 

     GL.Light(LightName.Light0, LightParameter.ConstantAttenuation, 1.8f); 
     GL.Light(LightName.Light0, LightParameter.SpotCutoff, 45.0f); 
     GL.Light(LightName.Light0, LightParameter.SpotDirection, spotdirection); 
     GL.Light(LightName.Light0, LightParameter.SpotExponent, 1.0f); 

     GL.LightModel(LightModelParameter.LightModelLocalViewer, 1.0f); 
     GL.LightModel(LightModelParameter.LightModelTwoSide, 1.0f); 
     GL.Enable(EnableCap.Light0); 
     GL.Enable(EnableCap.Lighting); 
     GL.Enable(EnableCap.DepthTest); 
     GL.Enable(EnableCap.ColorMaterial); 
     GL.ShadeModel(ShadingModel.Flat); 

glControl1_Paint() : 내가 잘못 아니에요 경우, 좌표 광원이 눈에 공간 COORD에 저장

 GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); 
     GL.MatrixMode(MatrixMode.Modelview); 
     GL.LoadMatrix(ref cameramatrix); 
     GL.Light(LightName.Light0, LightParameter.Position, new float[]{0.0f, 0.0f, 0.0f, 1.0f}); 

여기 는 glControl1_Load()의 코드입니다. 그래서, 무엇이 잘못 되었나요?

답변

0

모델 뷰의 카메라 매트릭스 대신 LoadIdentity. 광원은 항상 카메라를 기준으로 동일한 위치에 있습니다.

"w 값이 0이 아닌 경우 광원이 위치하며 (x, y, z) 값은 균질 한 개체 좌표로 빛의 위치를 ​​지정합니다 (부록 F 참조). modelview 매트릭스 및 눈 좌표에 저장됩니다. "

more details here "예 5-7"찾기

+0

그래, 나는 w 값에 대해 알고 있지만, LoadIdentity 및 LoadMatrix이 같은 일이하지? LoadIdentity를 사용할 수 없습니다. 내 카메라가 클래스로 구현되었습니다. – Ali

+0

카메라 뷰를 모델 뷰에 설정하면 조명 위치가 3D 공간에서 고정됩니다. 내 솔루션을 사용해 보셨습니까? 내가 링크 된 예를 확인 했습니까? –