OpenGL 2.0을 사용하여 직사각형을 그립니다. 처음에는 뷰포트가 위에서 보았고 예상대로 사각형을 볼 수 있습니다. 그런 다음 x 축을 중심으로이 직사각형을 회전하기 시작합니다. 회전 각도가 -90deg (또는 다른 방향으로 회전하면 +90 °) 일 때 사각형이 사라집니다. 내가 90deg/-90deg를 지나치게 회전했을 때 직사각형의 아래쪽 표면이 보이지만 대신 뷰가 사라지면 어떻게 될지 예상됩니다. 윗면이 거의 표시 될 준비가되었을 때 전체 회전 각은 -270도 (또는 + 270도)로 다시 나타납니다.회전 중에 OpenGL보기가 사라집니다.
내가 회전하는 동안 상단 및 하단 모두가 보일 수 있도록하려면 어떻게해야합니까? 여기
'코드 관련 부분 :
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
if ([touches count] == 1) {
CGPoint currLoc = [touch locationInView:self];
CGPoint lastLoc = [touch previousLocationInView:self];
CGPoint diff = CGPointMake(lastLoc.x - currLoc.x, lastLoc.y - currLoc.y);
rotX = -1 * GLKMathDegreesToRadians(diff.y/2.0);
rotY = -1 * GLKMathDegreesToRadians(diff.x/2.0);
totalRotationX += ((rotX * 180.0f)/3.141592f);
NSLog(@"rotX: %f, rotY: %f, totalRotationX: %f", rotX, rotY, totalRotationX);
//rotate around x axis
GLKVector3 xAxis = GLKMatrix4MultiplyVector3(GLKMatrix4Invert(_rotMatrix, &isInvertible), GLKVector3Make(1, 0, 0));
_rotMatrix = GLKMatrix4Rotate(_rotMatrix, rotX, xAxis.v[0], 0, 0);
}
}
-(void)update{
GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0, 0, -6.0f);
modelViewMatrix = GLKMatrix4Multiply(modelViewMatrix, _rotMatrix);
self.effect.transform.modelviewMatrix = modelViewMatrix;
float aspect = fabsf(self.bounds.size.width/self.bounds.size.height);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0, 10.0f);
self.effect.transform.projectionMatrix = projectionMatrix;
}
- (void)setupGL {
NSLog(@"setupGL");
isInvertible = YES;
totalRotationX = 0;
[EAGLContext setCurrentContext:self.context];
glEnable(GL_CULL_FACE);
self.effect = [[GLKBaseEffect alloc] init];
// New lines
glGenVertexArraysOES(1, &_vertexArray);
glBindVertexArrayOES(_vertexArray);
// Old stuff
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
glGenBuffers(1, &_indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
glViewport(0, 0, self.frame.size.width, self.frame.size.height);
// New lines (were previously in draw)
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position));
glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Color));
_rotMatrix = GLKMatrix4Identity;
// New line
glBindVertexArrayOES(0);
initialized = 1;
}
나는 OpenGL을에 초보자이고 내가 OpenGL을 2.0
감사와 함께 GLKit을 사용하고 있습니다.
가능한 원인은 후면면 제거 (일반적으로 기본적으로 사용하지 않도록 설정 됨)이거나 조명이 완전히 검은 색이어서 배경과 구별 할 수없는 원인 일 수 있습니다. – jozxyqk
니어 클리핑면은 0이 아니어야합니다. 'GLKMatrix4MakePerspective (GLKMathDegreesToRadians (65.0f), aspect, 0.01f, 10.0f);'로 변경해보십시오. 또한 단지'xAxis.v [0]'이 회전에 맞지 않습니다. 'rotX'는 회전이고 다음 세 값은 회전 할 축입니다. 'GLKMatrix4Rotate (_rotMatrix, rotX, 1, 0, 0);'만 시도해보십시오. – jozxyqk
@jozxyqk 내 얼굴 컬링이 내 코드에서 사용 가능합니다. 내 질문을 편집하고 다시 '도형 제거'가 가능한 'setupGL()'메서드를 추가했습니다. –