问题描述
- glGetFloatv不能查询到modelview 矩阵。
-
这个bug困扰我很久。
我用基于glkit编程,pan手势识别之后程序需要讲对应的顶点坐标计算出来。.手势这边的代码是这样的:
if ([gestureRecognizer state] == UIGestureRecognizerStateChanged) { NSLog(@"pan2"); CGPoint location = [gestureRecognizer locationOfTouch:0 inView:nil]; GLKVector3 obj; GLfloat winZ=-1.0f; **gluGetObjectLocation**( location.x,location.y, winZ,obj); initialLine[i].Position=obj; initialLine[i].normal=obj; i++; }
里面的函数 gluGetObjectLocation 是下面这样的:
void gluGetObjectLocation(GLfloat screenX,GLfloat screenY,GLfloat winZ,GLKVector3 obj) { NSLog(@"location: %f,%f",screenX,screenY); GLfloat winX,winY; GLfloat mvmatrix[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; GLfloat projmatrix[16]; GLint viewport[4]; NSLog(@"modleview matrix1:n,%f,%f,%f,%f,n,%f,%f,%f,%f,n,%f,%f,%f,%f,n,%f,%f,%f,%f,",mvmatrix[0],mvmatrix[1],mvmatrix[2],mvmatrix[3],mvmatrix[4],mvmatrix[5],mvmatrix[6],mvmatrix[7],mvmatrix[8],mvmatrix[9],mvmatrix[10],mvmatrix[11],mvmatrix[12],mvmatrix[13],mvmatrix[14],mvmatrix[15]); glGetFloatv(GL_MODELVIEW_MATRIX,mvmatrix); glGetFloatv(GL_PROJECTION_MATRIX,projmatrix); glGetIntegerv(GL_VIEWPORT,viewport); NSLog(@"modleview matrix2:n,%f,%f,%f,%f,n,%f,%f,%f,%f,n,%f,%f,%f,%f,n,%f,%f,%f,%f,",mvmatrix[0],mvmatrix[1],mvmatrix[2],mvmatrix[3],mvmatrix[4],mvmatrix[5],mvmatrix[6],mvmatrix[7],mvmatrix[8],mvmatrix[9],mvmatrix[10],mvmatrix[11],mvmatrix[12],mvmatrix[13],mvmatrix[14],mvmatrix[15]); winX=screenX; winY=viewport[3]-screenY; gluUnProject(winX,winY,winZ,mvmatrix,projmatrix,viewport,obj); NSLog(@"obj:%f,%f,%f",obj.x,obj.y,obj.z); }
run.我发现glGetFloatv(GL_MODELVIEW_MATRIX,mvmatrix) 不工作.
modleview matrix1 是0, 没错.
modleview matrix2 还是 0, 就不对了.它应该已经读取了值出来,不能再是0.
2014-02-06 00:40:26.088 lianxi[467:70b] Cannot find executable for CFBundle 0x8b7f740 (not loaded) 2014-02-06 00:40:32.171 lianxi[467:70b] pan2 2014-02-06 00:40:32.172 lianxi[467:70b] location: 192.000000,574.500000 2014-02-06 00:40:32.173 lianxi[467:70b] modleview matrix1: ,0.000000,0.000000,0.000000,0.000000, ,0.000000,0.000000,0.000000,0.000000, ,0.000000,0.000000,0.000000,0.000000, ,0.000000,0.000000,0.000000,0.000000, 2014-02-06 00:40:32.173 lianxi[467:70b] modleview matrix2: ,0.000000,0.000000,0.000000,0.000000, ,0.000000,0.000000,0.000000,0.000000, ,0.000000,0.000000,0.000000,0.000000, ,0.000000,0.000000,0.000000,0.000000, 2014-02-06 00:40:32.174 lianxi[467:70b] obj:0.000000,0.000000,0.000000
请帮忙看看,这到底怎么回事啊,头都想痛了。谢谢!
解决方案
刚猪八戒上看到了你的问题。你都没设置这些矩阵拿到的当然都是0
时间: 2024-09-07 11:09:46