开发者

Android opengl problem with skewed frustum in the left/right directions

I am writing a simple gyro test app in which I want to be able different sides of a polygon by tilting the phone to different orientation. It is similar to the head-tracked rendering technique but I assume a fixed eye position and only the phone moves relative to the eye (camera).

To do this I used the skewed frustum trick in opengl es. I could offset the frustum in the top/bottom/near/far directions without problem. The really weird part came in when I only got the left/right directions to work if I divide the offset values by 2. Effectively 'shrinking' the frustum from what it really should be.

Here is the working sample code with the divide-by-2 bug in the left/right direction:

// xEyePhone is the transform of eye relative to the screen, note the /2.0f for the 3rd and 4th params. 
Matrix.frustumM(_ProjMatrix, 0, -ratio-xEyePhone[12]/2.0f, r开发者_如何转开发atio-xEyePhone[12]/2.0f, 1-xEyePhone[13], 1-xEyePhone[13], xEyePhone[14], xEyePhone[14]+10);

Matrix.setLookAtM(_VMatrix, 0, xEyePhone[12], xEyePhone[13], xEyePhone[14],
XEyeCenterWorld[12], xEyeCenterWorld[13], xEyeCenterWorld[14],
XUpVectorWorld[12], xUpVectorWorld[13], xUpVectorWorld[14]);

Anyone came across this?


You applying a look-at matrix to the projection. You shouldn't do this. The projection transformation only sets the properties of the "virtual lens". Placing the camera happens in the modelview transformation.

Not keeping those two separate causes problems when implementing lighting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜