0
이 질문은 Apple Dev 포럼에 게시되었지만 답변이 없으므로 여기 누군가가 내가 잘못하고있는 부분을 잡을 것입니다!GLKMathProject는 {NaN, y, z}를 반환합니다.
저는 OpenGLES와 GLKit에 비교적 익숙하며 객체 공간에서 {x, y, z}에 그린 객체의 화면 좌표를 얻으려고합니다. 나는 작은 간이 메소드를 작성했습니다 :
-(GLKVector3)projectX:(float)x Y:(float)y Z:(float)z zRot:(float)rot scale:(float)s
{
GLKVector3 retVal;
CGSize viewSize = self.view.bounds.size;
GLKVector3 object = GLKVector3Make(x, y, z);
int viewPort[4];
viewPort[0] = 0;
viewPort[1] = 0;
viewPort[2] = (int)viewSize.width;
viewPort[3] = (int)viewSize.height;
float aspect = fabsf(viewPort[2]/viewPort[3]);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65), aspect, 0.1f, 100);
GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0, 0.0, 0.0);
// _rotation is an iVar that takes the device angle into consideration.
baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0, 0.0, 1.0f);
GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(x, y, z);
modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, rot, 0.0, 0.0, 1.0);
modelViewMatrix = GLKMatrix4Scale(modelViewMatrix, s, s, 1.0);
modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);
retVal = GLKMathProject(object, modelViewMatrix, projectionMatrix, &viewPort[0]);
return retVal;
}
내가 개체 그릴 때 내가 다음에 전화 :
GLKVector3 t = [self projectX:myObject.x Y:myObject.y Z:myObject.z zRot:myObject.angle scale:1.0]; //typically myObject.angle=0.0
debugUITextView.text = NSStringFromGLKVector3(t);
을하지만 얻을 모두가 NaN { "의 라인을 따라 뭔가 , 100.23367, 0.99888} "- Y와 Z의 실제 값은 다양합니다. - X는 항상 NaN입니다. 나는 확장하고 matricies 회전뿐만 아니라
GLKVector3 object = GLKVector3Make(0.5, 1, 0);
그러나 항상 같은 결과 등
에 직접 숫자를 연결 라인을 제거하려고했습니다. y와 z 값은 정확 해 보입니다. 개체를 아래/위로 드래그하면 y가 감소/증가합니다. 누군가 GLKMathProject를 사용하는 데있어 마술 트릭이 있다고 말해 줄 수 있습니까? 감사합니다. Todd. 내가 얻을 다음float aspect = fabsf((float)viewPort[2]/(float)viewPort[3]);
과 :
float aspect = fabsf(viewPort[2]/viewPort[3]);
그것은 읽어야합니다, 나는 충분히 내 변수를 캐스팅하지 않은 밝혀 :