'Interesting/iPhone'에 해당되는 글 34

  1. 2010.01.19 [iPhone] OpenGL 프로그래밍..2
  2. 2010.01.17 [iPhone] iDarter v0.3 APP store 에 등록
  3. 2009.11.12 [iPhone] Hardware reset
Interesting/iPhone | Posted by hyena0 2010. 1. 19. 22:00

[iPhone] OpenGL 프로그래밍..2


  

  [iPhone] OpenGL 프로그래밍..2


  오랜만에 아이폰 포스팅을 하게 되었습니다.

  그간 작업하던 것을 마무리 하느라 어쩔 수 없었군요.

  이전 포스팅에서 참고하고 있던 simon maurice 의 블로그는 계정이

  만료되었는지 더이상 접근하기 어렵습니다.

  참고할 만한 사이트가 없어진게 좀 아쉬운 부분이지요.

  이번 포스팅에서는 GLGravity 프로젝트를 기준으로 설명해 보겠습니다.

  이 프로젝트 파일은 구글 개발자 사이트에서 다운로드 받을 수 있습니다.

  GLGravityAppDelegate.h
  GLGravityAppDelegate.m
  GLGravityView.h
  GLGravityView.m

  네 개의 클래스로 구성되는 이 프로젝트는 가속도 센서 값을 받아서 
 
  주전자 모양의 3차원 그래픽을 아이폰을 회전할때마다 중력반대방향으로

  세워놓는 구성을 가집니다. 물론 시뮬레이터일 경우는 빙글빙글 회전만 합니다.



  GLGravityAppDelegate 클래스는 센서값을 주기적으로 가져오도록 설정되어 있고,

  GLGravityView 클래스에서 다루려고 하는 3차원 도형을 그리게 됩니다.

  기존에 다루고 있는 tutorial 에서는 대부분 정육면체를 보여주기 때문에 이해가 가지 않는

  부분도 존재합니다. 물론 정육면체부터 이해하고 넘어가는게 순서겠지요.

  어쨌건, 해당 파일을 보면 다음의 메소드를 가집니다.

  - (id)initWithCoder:(NSCoder*)coder 
  - (void)setupView
  - (void)drawView
  - (void)layoutSubviews
 - (BOOL)createFramebuffer
 - (void)destroyFramebuffer 
  - (NSInteger) animationFrameInterval
 - (void) setAnimationFrameInterval:(NSInteger)frameInterval
 - (void) startAnimation
 - (void)stopAnimation
 - (void)dealloc

  이 메소드들 중에서 다뤄볼 부분은 drawView 입니다. 경우에 따라서는 다른 메소드를 수정할 수 있겠지만

  현재 3차원 도형을 다루는 부분을 볼 것이므로 이 메소드만 보겠습니다.

  해당 메소드를 그대로 옮겨보면 아래와 같습니다.

// Updates the OpenGL view

- (void)drawView

{

// Make sure that you are drawing to the current context

[EAGLContext setCurrentContext:context];

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

GLfloat matrix[4][4], length;

//Make sure we have a big enough acceleration vector

length = sqrtf(accel[0] * accel[0] + accel[1] * accel[1] + accel[2] * accel[2]);

//Setup model view matrix

glLoadIdentity();

glTranslatef(0.0, -0.1, -1.0);

glScalef(kTeapotScale, kTeapotScale, kTeapotScale);

if(length >= 0.1)

{

//Clear matrix to be used to rotate from the current referential to one based on the gravity vector

bzero(matrix, sizeof(matrix));

matrix[3][3] = 1.0;

//Setup first matrix column as gravity vector

matrix[0][0] = accel[0] / length;

matrix[0][1] = accel[1] / length;

matrix[0][2] = accel[2] / length;

//Setup second matrix column as an arbitrary vector in the plane perpendicular to the gravity vector {Gx, Gy, Gz} defined by by the equation "Gx * x + Gy * y + Gz * z = 0" in which we arbitrarily set x=0 and y=1

matrix[1][0] = 0.0;

matrix[1][1] = 1.0;

matrix[1][2] = -accel[1] / accel[2];

length = sqrtf(matrix[1][0] * matrix[1][0] + matrix[1][1] * matrix[1][1] + matrix[1][2] * matrix[1][2]);

matrix[1][0] /= length;

matrix[1][1] /= length;

matrix[1][2] /= length;

//Setup third matrix column as the cross product of the first two

matrix[2][0] = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];

matrix[2][1] = matrix[1][0] * matrix[0][2] - matrix[1][2] * matrix[0][0];

matrix[2][2] = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];

//Finally load matrix

glMultMatrixf((GLfloat*)matrix);

// Rotate a bit more so that its where we want it.

glRotatef(90.0, 0.0, 0.0, 1.0);

}

// If we're in the simulator we'd like to do something more interesting than just sit there

// But if we're on a device, we want to just let the accelerometer do the work for us without a fallback.

#if TARGET_IPHONE_SIMULATOR

else

{

static GLfloat spinX = 0.0, spinY = 0.0;

glRotatef(spinX, 0.0, 0.0, 1.0);

glRotatef(spinY, 0.0, 1.0, 0.0);

glRotatef(90.0, 1.0, 0.0, 0.0);

spinX += 1.0;

spinY += 0.25;

}

#endif

// Draw teapot. The new_teapot_indicies array is an RLE (run-length encoded) version of the teapot_indices array in teapot.h

for(int i = 0; i < num_teapot_indices; i += new_teapot_indicies[i] + 1)

{

glDrawElements(GL_TRIANGLE_STRIP, new_teapot_indicies[i], GL_UNSIGNED_SHORT, &new_teapot_indicies[i+1]);

}

 

glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

[context presentRenderbuffer:GL_RENDERBUFFER_OES];

}


  주석에서 설명이 되어있으므로 주요한 설명은 안해도 될 것 같습니다.


  여기서 3차원 도형을 그리기 위한 주요한 내용만 다시 보겠습니다.


  단순히 도형만 그린다면 아래와 같이 고쳐볼 수 있습니다.


- (void)drawView

{

        [EAGLContext setCurrentContext:context];

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


//Setup model view matrix

glLoadIdentity();

glTranslatef(0.0, -0.1, -1.0);

glScalef(kTeapotScale, kTeapotScale, kTeapotScale);


// Draw teapot. The new_teapot_indicies array is an RLE (run-length encoded) version of the teapot_indices array in teapot.h

for(int i = 0; i < num_teapot_indices; i += new_teapot_indicies[i] + 1)

{

glDrawElements(GL_TRIANGLE_STRIP, new_teapot_indicies[i], GL_UNSIGNED_SHORT, &new_teapot_indicies[i+1]);

}

 

glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

[context presentRenderbuffer:GL_RENDERBUFFER_OES];

}


  위에서 glDrawElements 함수가 도형정보를 그리는 부분입니다. 


  주석에서처럼 teapot.h 파일에 num_teapot_indices, new_teapot_indices[i] 가 정의되어 있지요.


  이 부분이 어떻게 정의되는 지는 다음 포스트에서 봅시다.



 [Next] OpenGL 프로그래밍..3

Interesting/iPhone | Posted by hyena0 2010. 1. 17. 02:00

[iPhone] iDarter v0.3 APP store 에 등록


  iDarter v0.3 APP store 에 등록

정식으로 첫 개발을 완료한 앱인 iDarter 를

아이디어 낸지 거의 4개월 만에 완성해서

오늘 앱스토어에 등록했답니다.

Provisioning Profile 을 Distribution 용으로 다시 다운로드 받고

다시 컴파일하는 등의 의외로 까다로운 부분이 있어서

거의 오늘 내내 작업을 했답니다.

불행히도 등록페이지에서 "The binary you uploaded was invalid. The signature was invalid, or it was not signed with an Apple submission certificate."

이런 에러도 나와서 알고 봤더니 등록절차를 진행할때 빌드하기 전에 Adhoc distribution 방법대로 진행했더니 안되더군요.

개발자 웹에는 12번으로 건너뛰고 진행하라고 되어 있는데, 그걸 무시하고 단순하게 죽 절차대로 했더니 등록오류가 났었습니다.

12번으로 바로 건너뛰고 진행하니 등록이 되었습니다.

이제 애플측의 평가만 끝나면 어플이 앱스토어에서 보일 수 있겠군요.

안드로이드 마켓에서 무료어플을 등록해 본 경험은 있지만 앱스토어에선 어떨지 기대되는 군요.

이제 차분한 마음으로 OpenGL ES 를 아이폰용 어플에서 적용하는 방법을 포스팅해봐야 겠군요.




Interesting/iPhone | Posted by hyena0 2009. 11. 12. 02:30

[iPhone] Hardware reset



  [iPhone] Hardware reset

  아이폰을 하드웨어 리셋하는 방법은

  전면패널 하단의 홈 버튼과 상단의 파워버튼을 

  동시에 누릅니다.

  그러면 화면이 꺼지고 사과모양이 나타나며

  리부팅이 됩니다.

  단, 싱크케이블을 연결한 상태에서는 사과모양으로 정지되어 있네요.

  케이블을 제거하면 다시 동작합니다.

  센서와 관련된 프로그래밍을 하다가 먹통이 되어서

  하드웨어 리셋을 찾아보게 되었네요.