The bird can move, rotate, and even grow or shrink. Whenever we specify points to OpenGL using glVertex, OpenGL interprets them relative to our bird.
새는 이동, 회전, 심지어 줄어들거나 자랄 수 있다. 우리가 glVertex를 사용하여 OpenGL에게 포인트를 명시하면, OpenGL은 우리의 새를 상대적으로 그것들을 해석한다.
If instead, we rotate the bird 90 degrees about the x-axis and move it 2 units up, the point (0, 0, -1) relative to the bird is (0, -1, -2) in world coordinates.
만약 대신에, 우리가 새를 x축으로 90도를 회전하고 2유닛 이동시긴다. 그 새의 관련있는 포인트(0, 0, -1)는 실제 좌표에서 (0, -1, -2)이다.
First of all, instead of using -5 for the z coordinates of all of the points, let's just translate our bird 5 units forward, and then use 0 for their z coordinates.
우선, 모든 포인트의 z축으로 -5를 사용하면, z 좌표들은 0으로 사용한다.
We translate by using a call to glTranslatef, with the amount that we want to translate in the x, y, and z directions.
우리는 x,y그리고 z축에서 변경하는 것을 원하는 것을 glTranslatef를 호출하여 사용함으로써 변경할 수 있다.
glTranslatef(0.0f, 0.0f, -5.0f); //Move forward 5 units
I'd glossed over the meaning of the call to glLoadIdentity() in the last lesson. What it does is it resets our bird, so that it is at the origin and is facing in the negative z direction.
이번 레슨에서 glLoadIdentity()를 호출하는 것의 의미는 얼버무리고 넘어간다. 오리진에 있고 -z축을 맞대기 위해 우리의 새를 리셋하는 것이다.
There are two new and important functions used in this code: glPushMatrix() and glPopMatrix().
새로운 2개의 중요한 함수가 사용되었다. glPushMatrix()와 glPopMatrix().
We use them to save and restore the state of our bird. glPushMatrix saves its state, and glPopMatrix restores it.
우리는 새의 상태를 복원하고 저장하기위해 그것을 사용한다. glPushMatrix 는 상태를 저장하고 glPopMatrix 는 그것을 복원한다.
Every time we call glPushMatrix, we add a state to the top of the stack, and every time we call glPopMatrix, we restore and remove the state at the top of the stack.
우리가 glPushMatrix를 호출할 때마다, 우리는 스택의 탑에 상태를 추가하고, glPopMatrix를 호출할 때마다 우리는 스택의 탑에서 상태를 제거하면서 복구한다.
The stack can store up to at least 32 different transformation states.
스택은 적어도 32개의 다른 변형 상태를 저장할 수 있다.
We also call glScalef(0.7f, 0.7f, 0.7f), which shrinks our bird to 70% of its original size in the x, y, and z directions.
우리는 또한 glScalef(0.7f, 0.7f, 0.7f)를 호출한다. 이 함수는 x,y z축의 오리지날 사이즈의 70%를 축소한다.
It is important to note that glTranslatef, glRotatef, and glScalef, may not be called in a glBegin-glEnd block.
glTranslatef, glRotatef, glScalef, 이것은 중요하다. glBegin-glEnd 블록에서 호출되지 않을지도 모르지만
Now, let's change the camera angle so that we look 10 degrees to the left.
이제, 왼쪽으로 10도로 보기 위해 카메라 각도를 바꿔보자.
float _cameraAngle = 10.0f;
glRotatef(-_cameraAngle, 0.0f, 1.0f, 0.0f); //Rotate the camera
glTranslatef(0.0f, 0.0f, -5.0f); //Move forward 5 units
Before we move on to timers, I'd like to explain glMatrixMode. If we call glMatrixMode(GL_MODEL_VIEW), we switch to setting transformations for the points in the scene.
우리가 타이머로 이동하기 전에, glMatrixMode를 설명하길 원한다. glMatrixMode(GL_MODEL_VIEW)를 호출 했다면, 우리는 화면에서의 점들을 변화하는 설정을 하기위해 스위치한다.
If we call glMatrixMode(GL_PROJECTION), like we did in handleResize, we switch to setting a special transformation that is applied to our points in addition to the normal transformations.
glMatrixMode(GL_PROJECTION)를 호출하면, handleResize에서 한것처럼, 90도 회전한 점을 추가 적용한 특별한 변환을 설정하기 위해 스위치 한다.
Take a look at handleResize. We switched to the projection matrix mode, called glLoadIdentity() to reset all of its transformation and called gluPerspective.
handleResize를 보라. 모든 변화와 gluPerspective를 호출한 것을 리셋하기 위해 glLoadIdentity()호출하고 projection matrix mode로 전환했다.
gluPerspective performs a weird transformation that gives our points "perspective". Don't worry about how exactly it works. You just have to know that we use GL_PROJECTION to set up our perspective and GL_MODEL_VIEW for everything else.
gluPerspective 는 우리의 점들에게 "perspective"를 주는 특이한 변화를 수행한다. 이것이 어떻게 하는지에 대해 걱정하지마라. 너는 단지 우리가 우리의 관점을 설정하기 위해 PROJECTION을 사용하는 것과 다른 것을 위한 MODEL를 사용하는 것을 아는 것이 중요하다.
GL_PROJECTION is sometimes described as the transformation for the camera, but this isn't exactly accurate, because light sources aren't affected by the transformations in "projection" mode.GL_PROJECTION 은 가끔 카메라의 변화로써 묘사된다. 하지만 이것은 정확하게 맞지 않다. 왜냐하면 light 자원은 projection모드에서 변화에의해 영향을 미치지 않는다.
Timers
And now, let's add some motion using GLUT timers. The basic idea behind timers is that we want some piece of code to execute every so often. In this case, let's rotate the shapes by 2 degrees every 25 milliseconds. Here's how we do it.
GLUT 타이머를 사용하는 몇가지 모션을 추가해보자. 타이머에 대한 기본 아이디어는 우리가 원하는 모든 것을 실행하기 위한 코드의 일부분이다. 이 경우에, 25msec마다 2도로 모양을 회전해보자. 여기에 우리의 방법이 있다.
void update(int value) { _angle += 2.0f; if (_angle > 360) { _angle -= 360; } glutPostRedisplay(); //Tell GLUT that the scene has changed //Tell GLUT to call update again in 25 milliseconds glutTimerFunc(25, update, 0); }
The value parameter is something that GLUT passes to our update function. It is the same as the last parameter we passed to glutTimerFunc for that function, so it will always be 0. We don't need to use the parameter, so we just ignore it.
value 파라미터는 GLUT우리의 업데이트 함수를 통해 가는 것이다. 이것은 glutTimerFunc을 지나간 마지막 파라미터와 같다. 그래서 이것은 항상 0이다. 우리는 이 파라미터를 사용하지 않는다. 우리는 무시하면 된다.
glutTimerFunc(25, update, 0); //Add a timerWe add another call to glutTimerFunc to our main function, so that GLUT calls it for the first time 25 milliseconds after the program starts.
우리는 메인 함수에서 glutTimerFunc 를 호출하도록 하는 다른 함수를 추가한다. GLUT가 프로그램을 시작한 후에 25msec 동안 호출하기 위한
Next is "Lesson 3: Color".
'작업 > opengl' 카테고리의 다른 글
| Lesson 5: Textures (0) | 2012.07.25 |
|---|---|
| Lesson 4: Lighting (0) | 2012.07.05 |
| Lesson 3: Color (0) | 2012.07.05 |
| Lesson 1: Basic Shapes (0) | 2012.06.22 |
| 설치환경셋업 (0) | 2012.06.22 |
main.cpp