GLKMathProject给了我异化数字

时间:2014-04-22 17:33:04

标签: ios xcode opengl-es coordinates glkit

我无法获得屏幕坐标,当我使用下面的代码时,我只得到大数字,有人可以告诉我为什么,x,y的位置是弧度,这是错误的吗?

float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(_overture),
                                                        aspect,
                                                        0.1f,
                                                        400.0f);
projectionMatrix = GLKMatrix4Rotate(projectionMatrix, ES_PI, 1.0f, 0.0f, 0.0f);


GLKMatrix4 modelViewMatrix = GLKMatrix4Identity;
modelViewMatrix = GLKMatrix4Scale(modelViewMatrix, 300.0, 300.0, 300.0);

modelViewMatrix = GLKMatrix4RotateX(modelViewMatrix, 0.296706);
modelViewMatrix = GLKMatrix4RotateY(modelViewMatrix, -0.858702);

_modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);

CGSize viewSize = self.view.bounds.size;
int viewPort[4];
viewPort[0] = 0;
viewPort[1] = 0;
viewPort[2] = (int)viewSize.width;
viewPort[3] = (int)viewSize.height;

pos.x = 0.296706; //radians
pos.y = -0.858702; //radians
GLKVector3 coor2 = GLKVector3Make(pos.x, pos.y, 0);

GLKVector3 windowVector = GLKMathProject(coor2, modelViewMatrix, projectionMatrix, viewPort);
  

projectionMatrix      0.818481,0.000000,0.000000,0.000000      0.000000,-1.091309,0.000000,0.000000      0.000000,0.000000,1.000500,1.000000      0.000000,0.000000,-0.200050,0.000000

     

modelviewmatrix      196.026169,-66.397179,217.175415,0.000000      0.000000,286.891449,87.711510,0.000000 -227.098526,-57.312504,187.460770,0.000000      0.000000,0.000000,0.000000,1.000000

     

_modelViewProjectionMatrix:      160.443787,72.459831,217.284042,217.175415      0.000000,-313.087097,87.755409,87.711533 -185.875931,62.545647,187.554535,187.460770      0.000000,0.000000,-0.200050,0.000000

1 个答案:

答案 0 :(得分:0)

看起来你的相机在(0,0,0)看你的modelViewMatrix的m41,m42,m43和你的对象的coor2.z = 0.你的位于对象的中心。这可能是问题吗?