원근투영을 나타낼때

opengles 에는 gluPerspective 함수가 없고, glFrustumf 함수만 있다.

이거 참 이해하기 어렵다. ㅠㅠ 돌머리

남이 짜놓은 소스 보고, 설명 보고도 이해가 잘 안된다.

참고1

http://iphonedevelopment.blogspot.kr


참고2

http://skyfe.tistory.com/entry/iOS-OpenGLES-%ED%8A%9C%ED%86%A0%EB%A6%AC%EC%96%BC-13%ED%8E%B8



//------------------------------------------------------------------------------

// gluPerspective 함수 구현

//

// opengles 에는 gluPerspective 함수가 없고, glFrustumf 함수만 있다.

// gluPerspective 함수가 더 직관적이고, 사용하기 편하므로,

// 

// iFovy : 시야의 각도. (0.0 ~ 180.0)

//         이 값이 크면 넓게 보는것임 (오브젝트들이 작게 보임)

//         이 값이 작으면 좁게 보는것임 (오브젝트들이 크게 보임.

//                                                   각도 밖의 오브젝트는 시야에서 벗어나서 안보임)

// iAspect : 시야의 종횡비 (w / h)

// iNear : 시점에서 관측공간 (=절두체) 앞부분의 거리 (앞쪽 투상평면까지의 거리)

// iFar : 시점에서 관측공간 (=절두체) 뒷부분의 거리 (뒤쪽 투상평면까지의 거리)

//------------------------------------------------------------------------------

- (void)setPerspectiveWithFovy:(GLfloat)iFovy withAspect:(GLfloat)iAspect withNear:(GLfloat)iNear withFar:(GLfloat)iFar

{

  // 시야의 종횡비

  if(iAspect == 0.0) iAspect = self.bounds.size.width / self.bounds.size.height;

  

  GLfloat iLeftRight = iNear * tanf(DEGREES_TO_RADIANS(iFovy) / 2.0);

  GLfloat iTopBottom = iLeftRight / iAspect;

  glFrustumf(-iLeftRight, iLeftRight, -iTopBottom, iTopBottom, iNear, iFar);

  glViewport(0, 0, self.bounds.size.width, self.bounds.size.height);

}

반응형

'OpenGLES 초보' 카테고리의 다른 글

blender, wavefront obj export 옵션  (0) 2014.07.04
object picking, color picking  (1) 2014.07.04
어파인 공간 (Affine Space)  (0) 2014.07.04
3차원 물체의 표현  (0) 2014.07.04
Program(프로그램) 객체  (0) 2014.07.04
Posted by 돌비
,