Question

I can not get the screen coordinates, I only get big numbers when I use the code below, can somebody tell me why, the position of x, y is in radians, is that a wrong ?

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

Was it helpful?

Solution

It looks like your camera is at (0,0,0) looking at m41,m42,m43 of your modelViewMatrix and your object's coor2.z = 0. Your are at the center of the object. This might be the problem?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top