Chapter 3. ??(Viewing) - PowerPoint PPT Presentation

1 / 86
About This Presentation
Title:

Chapter 3. ??(Viewing)

Description:

Chapter 3. (Viewing) – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 87
Provided by: VRL8
Category:
Tags: chapter | viewing

less

Transcript and Presenter's Notes

Title: Chapter 3. ??(Viewing)


1
Chapter 3. ??(Viewing)
2
3?? ???? ????
  • ??? ? ?? ??? ??? ????? ????? ??? ?? ??? ??
  • ???, ??, ?? ?? ?? ?? ?? ???? ??? ??
  • ?? ??, ???? ??, ?? ??, ??, ????, ?? ?? ?? ???
  • ??? ??? ???? ????? ??? ???? ?? ????? ??? ??? ??
    ???? ?? ???? ??? ??
  • ??? ??? ??? ??? ?? ?????? ??? ??

3
??(viewing)
  • ??? ??
  • ?? ? ??? ??
  • ?? ??
  • ??? ??
  • ??? ??? ?? ?? ??
  • ?? ?? ????
  • ???? ??? ??
  • ???? ?? ?? ????
  • ??? ??? ????? ????

4
??? ??
  • ??? ??? ???? ?? ??? ?? ??? ???? ??? ?? ?? ??
  • ???? ???, ???? ??? ???? ??(?? ??)
  • ??? ??? ??? ??? ??? ??(??? ??)
  • ??? ??? ??? ????? ?? ??(?? ??)
  • ??? ??? ????(??? ??).

5
?? ??? ??
  • ??, ???, ?? ??? ????? 4 4 ?? M? ??? ??? ? ?? v?
    ?? ??? ??? ??
  • v Mv
  • ???? ??? ?? ? ??? ??? ?? ?? ? ??? ?? ? ??? ??
    ??? ???? ??? ??, ???(eye coordinates) ??
  • ?? ??? ???? ?? ??(clip coordinate)? ??
  • ???? w? ??? ????(perspective division)? ???? ???
    ?? ??? ??
  • ??? ??? ??? ??? ?? ??? ??? ??

6
?? ??? ??
x y z w
Vertex
???
Modelview matrix
???? ??
Projection matrix
????
???????
Perspective matrix
Viewport transformation
?????
7
????? ??? ??? ?? 3 1 cube.c
  • include ltGL/glut.hgt
  • include ltstdlib.hgt
  • void init(void)
  • glClearColor (0.0, 0.0, 0.0, 0.0)
  • glShadeModel (GL_FLAT)
  • void display(void)
  • glClear (GL_COLOR_BUFFER_BIT)
  • glColor3f (1.0, 1.0, 1.0)
  • glLoadIdentity () / ??? ??? /
  • gluLookAt (0.0,0.0, 5.0, 0.0, 0.0, 0.0, 0.0,
    1.0, 0.0) /????/
  • glScalef (1.0, 2.0, 1.0) / ?? ?? /
  • glutWireCube (1.0)
  • glFlush ()

8
  • void reshape (int w, int h)
  • glViewport (0, 0, (GLsizei) w, (GLsizei) h)
  • glMatrixMode (GL_PROJECTION)
  • glLoadIdentity ()
  • glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
  • glMatrixMode (GL_MODELVIEW)
  • void keyboard(unsigned char key, int x, int y)
  • switch (key)
  • case 27
  • exit(0)
  • break

9
  • int main(int argc, char argv)
  • glutInit(argc, argv)
  • glutInitDisplayMode (GLUT_SINGLE GLUT_RGB)
  • glutInitWindowSize (500, 500)
  • glutInitWindowPosition (100, 100)
  • glutCreateWindow (argv0)
  • init ()
  • glutDisplayFunc(display)
  • glutReshapeFunc(reshape)
  • glutKeyboardFunc(keyboard)
  • glutMainLoop()
  • return 0

10
????
11
?? ??
  • ?? ??? ???? ??? ??? ???? ?? ??
  • ?? ?? 3 1
  • glLoadIdentity()? ??, ?? ??? ????? ??
  • ??? ??? ?, gluLookAt()?? ?? ?? ??
  • gluLookAt()? ???? ??? ??? ??? ????
  • ??? ??, ??? ??, ???? ????? ??
  • ??? ?? (0, 0, 5)
  • ??? ?? (0, 0, 0)
  • ???(up-vector) (0, 1, 0)

12
??? ??
  • ??? ??? ??? ??? ???? ??
  • ??? ?? ??, ???? ??, ?? ?? ?? ??
  • ?? 3 1 ?? glScalef()? ???? ??? ??
  • ????? ? ? ??? ?? ???? ???? ???? ?? ??? ????
    ?????? ????? ?? ??
  • ???(duality) ??? ?? ??? ??? ??? ??? ???
    ??(modelview matrix) ? ??

13
?? ??
  • ?? ??? ???? ?? ??? ??? ??? ?? ??
  • ??(field of view)?? ?? ??(viewing volume)? ??
  • ?? ????? ?? ?? ?? ?? ?? ???, ?? ?? ??? ??? ??
  • ??? ?? ( glFrustum() ?? )
  • ??(perspective) ??
  • ?? ?? ??? ??? ?? ??? ?? ???
  • glFrustum() ??? ??
  • ??(orthographic) ??
  • ???? ??? ?? ?? ??? ???? ??? ??
  • ???? ? CAD ??? ?? ?????? ?? ????, ??? ??? ???
    ????? ??? ?

14
??? ??
  • ?? ??? ??? ??? ??? ??? ???? ???? ??? ??
  • ????? ??? ????? ??? ?????? ??
  • ??? ??? ???? ??? ??? ??? ?? ???
  • glViewport()? ??? ??? ??? ?? ??, ??? ?? ?? ??, ??
    ??? ??
  • ? ???? reshape()?? ??? ????? ?
  • ???? ??? ???? ??? ?? ???? ?

15
?? ???
  • ??? ?? ?? ????? ? ??? ??? ? ?? ??? ?? ??
  • ??? ???? ?? ??? ?? ??
  • ?? ???? ??? ??? ???? ?????? ???(Clip)
  • ??? ???? w? ?? ? ???? ??

16
?? ?? ???
  • ??? ?? ????? ??? ???
  • glMatrixMode()
  • glLoadIdentity()
  • glLoadMatrix()
  • glMultMatrix()
  • gluLookAt()
  • glScale()
  • void glMatrixMode(GLenum mode)
  • ?? ???? ???? ?? ???, ??, ??? ??? ???? ?? ??
  • mode GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE
  • void glLoadIdentity(void)
  • ??? ??? ?? ???? ?? ?? ??? ??? ???
  • ?? ?? ??? ??? 4x4 ?? ??? ??

17
  • ?? ??? ??? ??? ????? ???? ?? ???
  • void glLoadMatrixfd(const TYPE m)
  • ?? ??? 16? ?(4 4)? m?? ??? ??? ??? ??
  • void glMultMatrixfd(const TYPE m)
  • m? ???? 16? ??? ??? ??? ?? ??? ???, ? ??? ??
    ??? ??

m1 m5 m9 m13
???? ??? m44? ????? mij ??? OpenGL
?? ??? j?, i ?? ??. C?? ??
m2 m6 m10 m14
M
m3 m7 m11 m15
m4 m8 m12 m16
18
?? ? ??? ??
  • ??? ???? ?? ??? ???? ???? ??? glMatrixMode()?
    GL_MODELVIEW ? ??? ?? ???? ?.
  • ?? ????
  • ?? ?? ?? ? ??? ??? 4 4??? ??
  • glMultMatrix()? ?? ?? ????? ?? ??? 4 4?? M? ??
    ??? ?? C? ??? CM? ??
  • ? ??, ?? v? ?? ??? ??? ??
  • ?, ???? ??? ?? ?? ??? ?? ???? ??? ?? ?? ??(CMv)

19
  • ??
  • glMatrixMode (GL_MODELVIEW)
  • glLoadIdentity()
  • glMultMatrix(N)
  • glMultMatrix(M)
  • glMultMtrix(L)
  • glBegin(GL_POINTS)
  • glVertex3f(v)
  • glEnd()
  • ??? ??? I, N, NM, NML ??? ??
  • ????? N(M(Lv)) ? ?? ??
  • v? ?? ??? ??? ??? ??? ??? ???? ??? ???.
  • ???? ??? ?? ??? ??? ??? ???. L, M, N ???? ??? ??
    ? v ? ??.

20
?? ???
  • ??? ??, ??, ?? ?? ??? ??? ?? ??? ?? ???(Grand,
    Fixed Coordinate System) ???? ??? ??, ??? ?? ???
    ??? ??? ??
  • ??(??, ?? ??)? ??? ? ????? ???? ?? ??? ??
    ????(????? ???? ??)
  • ??? ?? ? ?, ???? ??? ?
  • ??? ?(???? ????)
  • glMatrixMode(GL_MODELVIEW)
  • glLoadIdentity()
  • glMultMatrixf(T) / ???? /
  • glMultMatrixf(R) / ? ? /
  • Draw_the_object()

1-Rotate
2-Translate
21
?? ??? ????
  • ?? ??? ??? ? ??? ????? ?? ???? ?? ??, ????? ??
    ???? ?? ?? ??? ??
  • ?? ???? ??? ???? ????? ??
  • ??? ?? ????? ?? ??? ???? ??? ???? ??
  • ?? ??? ??? ?? ???? ??.
  • ???? ?? ????? ???
  • ????? ????? ??? ???? X??? ?? ?????.
  • ??? ?? ????? ????? X??? ?? ??? ???? ???? ?.

22
??? ??
  • ??? ??? ?? ??? ????? ??
  • ????
  • void glTranslatefd(TYPE x, TYPE y, TYPE z)
  • ??
  • void glRotatefd(TYPE angle, TYPE x, TYPE y,
    TYPE z)
  • ????(?? ?????)? ???? (x, y, z) ? ??? ?? ???? ???
    ???? angle ?? ?? ??
  • ????
  • void glScalefd(TYPE x, TYPE y, TYPE z)
  • ????, ??, ???? ?? ?? ??? ?? glMultMatrix()? ???
    ???? ???? ?? ????.
  • glMultMatrix() ????? ?? ? ?? ??? ? ? ??? ???.

23
??? ?? ??
  • ??? ?????? ???? ??? ??? ??? ?? ??
  • ???? ?? ??? ?? ???? ???? ??? ??
  • ??(y?)? ?? ??? ?(x?)? 50 ?? ? ?? ??? ?? ???
  • ???? ???? ??, ??

24
  • include ltGL/glut.hgt
  • include ltstdlib.hgt
  • void init(void)
  • glClearColor (0.0, 0.0, 0.0, 0.0)
  • glShadeModel (GL_FLAT)
  • void draw_triangle(void)
  • glBegin (GL_LINE_LOOP)
  • glVertex2f(0.0, 25.0)
  • glVertex2f(25.0, -25.0)
  • glVertex2f(-25.0, -25.0)
  • glEnd()

25
?? ? ??? ??
  • void display(void)
  • glClear (GL_COLOR_BUFFER_BIT)
  • glColor3f (1.0, 1.0, 1.0)
  • glLoadIdentity ()
  • glColor3f (1.0, 1.0, 1.0)
  • draw_triangle ()
  • glEnable (GL_LINE_STIPPLE)
  • glLineStipple (1, 0xF0F0)
  • glLoadIdentity ()
  • glTranslatef (-20.0, 0.0, 0.0)
  • draw_triangle ()

26
  • glLineStipple (1, 0xF00F)
  • glLoadIdentity ()
  • glScalef (1.5, 0.5, 1.0)
  • draw_triangle ()
  • glLineStipple (1, 0x8888)
  • glLoadIdentity ()
  • glRotatef (90.0, 0.0, 0.0, 1.0)
  • draw_triangle ()
  • glDisable (GL_LINE_STIPPLE)
  • glFlush ()

27
  • void reshape (int w, int h)
  • glViewport (0, 0, (GLsizei) w, (GLsizei) h)
  • glMatrixMode (GL_PROJECTION)
  • glLoadIdentity ()
  • if (w lt h)
  • glOrtho (-50.0, 50.0, -50.0(GLfloat)h/(GLfl
    oat)w,
  • 50.0(GLfloat)h/(GLfloat)w, -1.0, 1.0)
  • else
  • glOrtho (-50.0(GLfloat)w/(GLfloat)h,
  • 50.0(GLfloat)w/(GLfloat)h, -50.0, 50.0,
    -1.0, 1.0)
  • glMatrixMode(GL_MODELVIEW)

28
  • void keyboard(unsigned char key, int x, int y)
  • switch (key)
  • case 27
  • exit(0)
  • break

29
  • int main(int argc, char argv)
  • glutInit(argc, argv)
  • glutInitDisplayMode (GLUT_SINGLE GLUT_RGB)
  • glutInitWindowSize (500, 500)
  • glutInitWindowPosition (100, 100)
  • glutCreateWindow (argv0)
  • init ()
  • glutDisplayFunc(display)
  • glutReshapeFunc(reshape)
  • glutKeyboardFunc (keyboard)
  • glutMainLoop()
  • return 0

30
????
31
Nate Robins ? ???? ????
  • http//www.cs.utah.edu/narobins/opengl.html
  • transformation ???? ??

32
?? ??
  • ?? ??? ???? ??? ??? ??? ??
  • ??? ???? ? ??? ?? ??? ???? ???? ??, ??? ???? ????
    ??
  • ?? ??? ????? ?? ??? ?????? ??
  • ??? ???? ????? ????? ??? ??? ???? ?? ???? ?????
    ?? ??? ??? ??? ?? ? ??.
  • ?? ??? ??? ????? ??? ??? ??? ???? ?? ????? ?????
    ?? ??? ??? ??? ?? ???? ??.
  • ?? ??? ??? ??
  • ? ? ??? ??? ?? ??? ??
  • glTranslate(), glRotate() ?
  • ???? ????? ??? gluLookAt() ??, ??? ??
  • ?? ??, ?? ??? ??? ?? ????? ?? ??

33
glTranslate() ? glRotate() ????
  • ???? ??? ?? ??? ??? ??? ?
  • ????? ?? ??? ?????? ??? ????? ?? ??? ??.
  • ???? ??? ??? ??, ??? ????? ??? ???? ?? ??? ? ??
    ?? ??
  • ???? ??? z ?? ?? ??? ??? ??
  • ??? ???? ??? ???? ?? ??
  • glTranslatef(0.0, 0.0, -5.0)
  • ????? ?????? z? ???? 5?? ?????.
  • ???? z? ???? 5?? ???? ?? ?? ??

34
  • ??? ???? ?? glTranslate(0.0, 0.0, -5.0) ? ?

y
y
x
x
z
z
35
  • ????? ??? ??? ???? ??
  • ?? ??? ???? ??? ??
  • ????? ??
  • ?????? ?? ????? ??
  • ?? ?????? ?? ?? ??? ???? ??? ??
  • ?? ??? ???? ??? ??
  • ????? ?? ???? ?????? ??
  • ? ? ?? ??? ??? ???? ???? ??
  • ?? ???? ???? ??? ??

36
gluLookAt() ???? ????
  • ???? ? ?? ??? ???? ??? ??? ?? ?? ??? ???? ?????
    ??? ??
  • ? ??? ??? ??? ???? ? ?? ??? ??? ???? ???
    ???(reference point)? ????? ???? ??
  • gluLookAt() ??? ???? ??, ??? ???? ??? ? ?? ??
  • ????? x, y ??? ??? ?? ?(eyex, eyey, eyez) ? ??
    ???? ??? ???? ??? ? ?? ????? ???? ?? ?? ??? ?????
    ??? ???.
  • void gluLookAt(GLdouble eyex, GLdouble eyey,
    GLdouble eyez, GLdouble centerx, GLdouble
    centery, GLdouble centerz, GLdouble upx, GLdouble
    upy, GLdouble upz)
  • ??? ?? eyex, eyey, eyez
  • ???? ??? ??? ?? centerx, centery, centerz
  • ????? ???? ??? ?? upx, upy, upz

37
  • ???? ??? ??? ???? ??? ??? z ?? ?? ???? ??? ??
    ???? y?? ?? ??? ?,
  • gluLookAt(0,0, 0.0, 0.0, 0.0, 0.0, -100, 0.0,
    1.0, 0.0)
  • ???? z ?? ??? ???? ?? ??. ?? ??.

y
y
???
x
x
z
38
  • gluLookAt(4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 2.0,
    2.0, -1.0)

y
(2.0, 4.0, -3.0)
(2,0, 2.0, -1.0)
(4.0, 2.0, 1.0)
x
z
39
  • Nate Robins ? ?? ?? ????
  • projection ????

40
?? ??
  • ?? ??? ?? ??? ????? ??
  • ? ?? ??
  • ????? ???? ?? ?? ??(??, ?? ??)
  • ?? ????? ?? ????? ??? ??? ??
  • ???? ???? ???? ???? ?? ??? ??? ?? ???? ??
  • glMatrixMode(GL_PROJECTION)
  • glLoadIdentity()

41
?? ??(perspective projection)
  • ????? ?? ? ??? ?? ????(foreshortening)
  • Foreshortening ???, ????? ?????? ?? ????? ??
    ??? ??
  • ?? ??? ?? ??? ????? ???? ??? ? ???
  • ??? frustum, ??? ???? ?? ??? ??? ????
  • ?????? ????? ??(apex)???? ???? ? ??? ??? ?? ?? ??
  • ??? ??? ??? ?????? ? ??? ?? ??

Wikipedia ? Figure shows two different
projections of a stack of two cubes, illustrating
oblique parallel projection foreshortening ("A")
and perspective foreshortening ("B").
42
  • void glFrustum(GLdouble left, GLdouble right,
    GLdouble bottom, GLdouble top, GLdouble near,
    GLdouble far)
  • ?? ??? ???? ??? ???? ?? ?? ??? ???.
  • ?? ??(???)? ? ?? ?? ?? ?????? ??? ??? ???
  • ??? ??
  • (left, bottom, -near)? (right, top, -near)
  • ?? ???? ??? ?? ??? ??? ??? ?? ?? ???? ?? ?? ???
    ??? ???
  • near ? far ??? ?? ??? ??? ?

43
  • void gluPerspective(GLdouble fovy, GLdouble
    aspect, GLdouble near, GLdouble far)
  • glFrustum()? ?? ?? ?? ??, ????? ??? ??.
  • fovy? y? ??? FOV ??? ???
  • aspect ??? ???? ???(x/y, ????? ?? ???? 1.0??)

fovy
h
w
?
near
far
Aspect w/h
44
?? ??(Orthogonal projection)
  • ?? ??? ??? ?? ??? ??.
  • ?? ??? ?? ?? ??? ? ??? ??? ??.
  • ???? ??? ????? ??? ??? ? ??.
  • ?? ???? CAD ?? ?? ?? ????? ??? ??? ??? ???? ?? ??
    ?????? ?? ??

top
left
far
????
right
????
bottom
near
45
  • ??? ?? ??? ??
  • glOrtho() ???? ??
  • void glOrtho(GLdouble left, GLdouble right,
    GLdouble bottom, GLdouble top, GLdouble near,
    GLdouble far)
  • ??????? ??? ???? ?? ?? ??? ???.
  • glFrustum()? ??? ??? ??.
  • near ??? ??? ?? ?? ???? ?? ?? ???? ???? ??
    (left, bottom, -near)? (right, top, -near)? ??
    ??? ???? ?? ?? ? ?? ?? ???? ????.
  • ??? ??? z?? ????, ??? z?? ?? ??

46
  • ???? 2?? ???? ???? ??? ??
  • void gluOrtho2D(GLdouble left, GLdouble right,
    GLdouble bottom, GLdouble top)
  • 2?? ??? ???? ???? ??? ???? ?? ??? ???.
  • ??? ??
  • ?? ?? ??? (left, bottom)
  • ?? ?? ??? (right, top)
  • Nate Robins ? ?? ?? ????
  • projection ????
  • ?? ?? ???(clipping)
  • ??? ?? ???? ???? ??? ??? ?? ??? ?? ?????? ??? ??
    ?? ?? ????? ?? ?????.

47
??? ??
  • ??? ??
  • ???? ????, ??? ??? ??? ??? ??? ???? ??
  • ??? ?????? ???? ??? ???? ???? ??? ??
  • ???? ??? ??? ??
  • ??? ??? ???? ?? ?? ???? ???? ??? ?? ?? ??? ??

48
??? ????
  • ??? ?? ???? ???? ??? OpenGL? ?? ??? ???? ??
  • ???? ?? ??? ? ?? ???? ???? ?? ??? ???? ??
  • ??? ?? ??? ???? ??? ?? glViewport() ??? ??
  • void glViewport(GLint x, GLint y, Glsizei width,
    Glsizei height)
  • ?? ???? ??? ???? ?? ???? ????.
  • x, y ????? ??? ???? ?? ?? ??? ???
  • width, ? height ??? ???? ??? ??
  • ???? ???? ????? ???? ????. ? ??? ?? ??? ??? ????
    ?? ???? ??.

49
??? ?? ??
  • ??? ??? ???? ?? ??(z) ??? ???
  • Z ?? ??? ?? ??? ????? glDepthRange()??
  • ???? x, y ???? ?? OpenGL ?? z ??? ?? 0.0? 1.0 ???
    ?? ??? ????.
  • void glDepthRange(GLclampd near, GLclampd far)
  • ??? ???? ??? z ??? ?????.
  • near, far ??? ?? ??? ??? ?? ? ?? ?? ??
  • ????? ? ?? 0.0 ? 1.0 ?? ??

50
?? ?? ????
  • ?? ??? ??? ??? ?? ??? ??? ???? ??? ??? ????? ???
    ? ??
  • ????(glLoadMatrix(), glMultMatrix(),
    glLoadIdentity())? ??? ????? ???? ????? ?? ????
    ??? top??? ??.
  • ?? ??? ?? ???? ??? top? ???? glPushMatrix()?, ???
    top??? ??? glPopMatrix()? ?? ???? ??, top ? ???
    ??
  • glPushMatrix() ?? ??? ??
  • glPopMatrix() ?? ??? ??? ???.
  • void glPushMatrix(void)
  • ?? ??? ?? ?? ???? ? ?? ??? ??(push)
  • void glPopMatrix(void)
  • ??? top??(??) ? ????(pop)
  • ?? ??? glMatrixMode()? ????.

51
?? 3-4 ??? push ?? pop ??
  • draw_wheel_and_bolts()
  • long i
  • draw_wheel()
  • for (i 0 i lt 5 i)
  • glPushMatrix()
  • glRotatef(72.0i, 0.0, 0.0, 1.0)
  • glTranslatef(3.0, 0.0, 0.0)
  • draw_bolt()
  • glPopMatrix()

52
  • draw_body_and_wheel_and_bolts()
  • draw_car_body()
  • glPushMatrix()
  • glTranslatef(40, 0, 30) / ??? ??? ??? ?? /
  • draw_wheel_and_bolts()
  • glPopMatrix()
  • glPushMatrix()
  • glTranslatef(40, 0, -30) / ? ?? ??? ??? ?? /
  • draw_wheel_and_bolts()
  • glPopMatrix()

53
??? ?? ??
  • ??? ???? ?? ? ??? ?? ??? ?? ??? ???? ??.
  • ??? ?? ?? ??? ???? ?? ??? ??? ?? ??? ??? ??
  • ??? ??? ??? ??? ??? ?? ??? ??
  • ??? ?? ???? ?? 32?? 4x4 ???? ??? ? ??.
  • ???? ??? Top??? ?? ??? ??
  • ??? ?? ?? ?? ??
  • glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, GLint
    params)

54
?? ?? ??
  • ???? ??? ?? ??? ???? ?? ??? ?? ??? ??
  • ?? ??? ?? ???? ?? ??? ?? ??? ???? ??
    glLoadIdentity()? ??
  • ??? ??? ??
  • glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH,
    GLlint params)

55
???? ??? ??
  • ????? ???? ?? ?? ??? ??(left, right, bottom, top,
    near, far)???, ???? ??? ??? ?? ?? ? ?? ???? ??
    ??? ?? ??? ?? ? ??.
  • ????? ??? ??? ?? ?? (cutaway view) ????? ???? ???
    ??? ? ????.
  • ? ??? ??? ?? ???? ??? ??
  • Ax By Cz D 0
  • void glClipPlane(GLenum plane, const GLdouble
    equation)
  • ??? ??? ????.
  • equation ??? ?????? 4 ?? ??? ????.
  • plane ??? GL_CLIP_PLANEi ?? i? ?? ??? ??? ???
    ????.
  • ??? ??? ???? ??? ?? ??????.
  • glEnable(GL_CLIP_PLANEi)
  • ?????? ??
  • glDisable(GL_CLIP_PLANEi)

56
??? ??? ?? ?? ?? 3 5 clip.c
  • include ltGL/glut.hgt
  • include ltstdlib.hgt
  • void init(void)
  • glClearColor (0.0, 0.0, 0.0, 0.0)
  • glShadeModel (GL_FLAT)
  • void display(void)
  • GLdouble eqn4 0.0, 1.0, 0.0, 0.0
  • GLdouble eqn24 1.0, 0.0, 0.0, 0.0
  • glClear(GL_COLOR_BUFFER_BIT)

57
  • glColor3f (1.0, 1.0, 1.0)
  • glPushMatrix()
  • glTranslatef (0.0, 0.0, -5.0)
  • / ??? ?? ??? -- y lt 0 /
  • glClipPlane (GL_CLIP_PLANE0, eqn)
  • glEnable (GL_CLIP_PLANE0)
  • / ?? ?? ??? -- x lt 0 /
  • glClipPlane (GL_CLIP_PLANE1, eqn2)
  • glEnable (GL_CLIP_PLANE1)
  • glRotatef (90.0, 1.0, 0.0, 0.0)
  • glutWireSphere(1.0, 20, 16)
  • glPopMatrix()
  • glFlush ()

58
  • void reshape (int w, int h)
  • glViewport (0, 0, (GLsizei) w, (GLsizei) h)
  • glMatrixMode (GL_PROJECTION)
  • glLoadIdentity ()
  • gluPerspective(60.0, (GLfloat) w/(GLfloat) h,
    1.0, 20.0)
  • glMatrixMode (GL_MODELVIEW)
  • void keyboard(unsigned char key, int x, int y)
  • switch (key)
  • case 27
  • exit(0)
  • break

59
  • int main(int argc, char argv)
  • glutInit(argc, argv)
  • glutInitDisplayMode (GLUT_SINGLE GLUT_RGB)
  • glutInitWindowSize (500, 500)
  • glutInitWindowPosition (100, 100)
  • glutCreateWindow (argv0)
  • init ()
  • glutDisplayFunc(display)
  • glutReshapeFunc(reshape)
  • glutKeyboardFunc(keyboard)
  • glutMainLoop()
  • return 0

60
????
61
???? ?? ?? ????
  • ??? ???
  • include ltGL/glut.hgt
  • include ltstdlib.hgt
  • static int year 0, day 0
  • void init(void)
  • glClearColor (0.0, 0.0, 0.0, 0.0)
  • glShadeModel (GL_FLAT)

62
  • void display(void)
  • glClear (GL_COLOR_BUFFER_BIT)
  • glColor3f (1.0, 1.0, 1.0)
  • glPushMatrix()
  • glutWireSphere(1.0, 20, 16) / ??? ??? /
  • glRotatef ((GLfloat) year, 0.0, 1.0, 0.0)
  • glTranslatef (2.0, 0.0, 0.0)
  • glRotatef ((GLfloat) day, 0.0, 1.0, 0.0)
  • glutWireSphere(0.2, 10, 8) / ?? ??? ???
    /
  • glPopMatrix()
  • glutSwapBuffers()

63
  • void reshape (int w, int h)
  • glViewport (0, 0, (GLsizei) w, (GLsizei) h)
  • glMatrixMode (GL_PROJECTION)
  • glLoadIdentity ()
  • gluPerspective(60.0, (GLfloat) w/(GLfloat) h,
    1.0, 20.0)
  • glMatrixMode(GL_MODELVIEW)
  • glLoadIdentity()
  • gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0,
    1.0, 0.0)

64
  • void keyboard (unsigned char key, int x, int y)
  • switch (key)
  • case 'd'
  • day (day 10) 360
  • glutPostRedisplay()
  • break
  • case 'D'
  • day (day - 10) 360
  • glutPostRedisplay()
  • break

65
  • case 'y'
  • year (year 5) 360
  • glutPostRedisplay()
  • break
  • case 'Y'
  • year (year - 5) 360
  • glutPostRedisplay()
  • break
  • case 27
  • exit(0)
  • break
  • default
  • break

66
  • int main(int argc, char argv)
  • glutInit(argc, argv)
  • glutInitDisplayMode (GLUT_DOUBLE GLUT_RGB)
  • glutInitWindowSize (500, 500)
  • glutInitWindowPosition (100, 100)
  • glutCreateWindow (argv0)
  • init ()
  • glutDisplayFunc(display)
  • glutReshapeFunc(reshape)
  • glutKeyboardFunc(keyboard)
  • glutMainLoop()
  • return 0

67
?? ??
68
??? ???
  • include ltGL/glut.hgt
  • include ltstdlib.hgt
  • static int shoulder 0, elbow 0
  • void init(void)
  • glClearColor (0.0, 0.0, 0.0, 0.0)
  • glShadeModel (GL_FLAT)

69
  • void display(void)
  • glClear (GL_COLOR_BUFFER_BIT)
  • glPushMatrix()
  • glTranslatef (-1.0, 0.0, 0.0)
  • glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0)
  • glTranslatef (1.0, 0.0, 0.0)
  • glPushMatrix()
  • glScalef (2.0, 0.4, 1.0)
  • glutWireCube (1.0)
  • glPopMatrix()

70
  • glTranslatef (1.0, 0.0, 0.0)
  • glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0)
  • glTranslatef (1.0, 0.0, 0.0)
  • glPushMatrix()
  • glScalef (2.0, 0.4, 1.0)
  • glutWireCube (1.0)
  • glPopMatrix()
  • glPopMatrix()
  • glutSwapBuffers()

71
  • void reshape (int w, int h)
  • glViewport (0, 0, (GLsizei) w, (GLsizei) h)
  • glMatrixMode (GL_PROJECTION)
  • glLoadIdentity ()
  • gluPerspective(65.0, (GLfloat) w/(GLfloat) h,
    1.0, 20.0)
  • glMatrixMode(GL_MODELVIEW)
  • glLoadIdentity()
  • glTranslatef (0.0, 0.0, -5.0)

72
  • void keyboard (unsigned char key, int x, int y)
  • switch (key)
  • case 's'
  • shoulder (shoulder 5) 360
  • glutPostRedisplay()
  • break
  • case 'S'
  • shoulder (shoulder - 5) 360
  • glutPostRedisplay()
  • break
  • case 'e'
  • elbow (elbow 5) 360
  • glutPostRedisplay()
  • break

73
  • case 'E'
  • elbow (elbow - 5) 360
  • glutPostRedisplay()
  • break
  • case 27
  • exit(0)
  • break
  • default
  • break

74
  • int main(int argc, char argv)
  • glutInit(argc, argv)
  • glutInitDisplayMode (GLUT_DOUBLE GLUT_RGB)
  • glutInitWindowSize (500, 500)
  • glutInitWindowPosition (100, 100)
  • glutCreateWindow (argv0)
  • init ()
  • glutDisplayFunc(display)
  • glutReshapeFunc(reshape)
  • glutKeyboardFunc(keyboard)
  • glutMainLoop()
  • return 0

75
?? ??
76
??? ??? ????? ????
  • ?? ?? ??? ??? ?? ? ?? ??, ???? ?? ??? ??(??
    ????)??? ???(?? ???)??? ??
  • ??? ?? ??? ??? ???? ?? ??? ??
  • 3???? ??? ???? ???? ??
  • ???? ????? ??? ??? ???? 2?? ?? ??
  • ????? ????? ??? ???? ???? ??? ???? ??? ?? 3??
    ???? ???? ??.
  • gluUnProject() ? gluUnProject4() ??

77
  • int gluUnProject(GLdouble winx, GLdouble winy,
    GLdouble winz, const GLdouble modelMatrix16,
    const GLdouble projMatrix16, const GLint
    viewport4, GLdouble objx, GLdouble objy,
    GLdouble objz)
  • ??? ??(modelMatrix)? ????(projMatrix),
    ???(viewport)? ??? ??? ???? ??? ??? ??(winx,
    winy, winz)? ???? ??(objx, objy, objz)? ????.
  • ??? ????? GL_TRUE, ??? ???? GL_FALSE? ????.

78
  • Int gluUnProject4(GLdouble winx, GLdouble winy,
    GLdouble winz, gldouble clipw, const GLdouble
    modelMatrix16, const GLdouble projMatrix16,
    const GLint viewport4, Glclampd zNear, Glclampd
    zFar, GLdouble objx, GLdouble objy, GLdouble
    objz)
  • gluUnProject()? ??. GLU1.3?? ????
    gluUnProject4()? ???? ?? glDepthRange ??? ??? 1??
    ? w ???? ??? ? ??.

79
  • Int gluProject(GLdouble objx, GLdouble objy,
    GLdouble objz, const GLdouble modelMatrix16,
    const GLdouble projMatrix16, const GLint
    viewport4, GLdouble winx, GLdouble winy,
    GLdouble winz)
  • ??? ??(modelMatrix), ????(projMatrix),
    ???(viewport) ? ??? ??? ?? ??? ???? ??(objx,
    objy, objz)? ??? ??? ????.
  • ??? ????? ???? GL_TRUE, ??? ???? GL_FALSE? ????.

80
?? ???? ?????? ??? ???? ?? 3 8 unproject.c
  • include ltGL/glut.hgt
  • include ltstdlib.hgt
  • include ltstdio.hgt
  • void display(void)
  • glClear(GL_COLOR_BUFFER_BIT)
  • glFlush()
  • void reshape(int w, int h)
  • glViewport (0, 0, (GLsizei) w, (GLsizei) h)
  • glMatrixMode(GL_PROJECTION)
  • glLoadIdentity()

81
  • gluPerspective (45.0, (GLfloat) w/(GLfloat) h,
    1.0, 100.0)
  • glMatrixMode(GL_MODELVIEW)
  • glLoadIdentity()
  • void mouse(int button, int state, int x, int y)
  • GLint viewport4
  • GLdouble mvmatrix16, projmatrix16
  • GLint realy / OpenGL y ?? ?? /
  • GLdouble wx, wy, wz / ??? x, y ,z ?? ?? /

82
  • switch (button)
  • case GLUT_LEFT_BUTTON
  • if (state GLUT_DOWN)
  • glGetIntegerv (GL_VIEWPORT,
    viewport)
  • glGetDoublev (GL_MODELVIEW_MATRIX,
    mvmatrix)
  • glGetDoublev (GL_PROJECTION_MATRIX,
    projmatrix)
  • / viewport3? ???? ??? ?? ??? ????? ? ?? /
  • realy viewport3 - (GLint) y - 1
  • printf ("Coordinates at cursor are
    (4d, 4d)\n", x, realy)
  • gluUnProject ((GLdouble) x,
    (GLdouble) realy, 0.0,
  • mvmatrix, projmatrix, viewport, wx, wy, wz)
  • printf ("World coords at z0.0 are
    (f, f, f)\n",
  • wx, wy, wz)

83
  • gluUnProject ((GLdouble) x, (GLdouble) realy,
    1.0,
  • mvmatrix, projmatrix, viewport,
    wx, wy, wz)
  • printf ("World coords at z1.0 are
    (f, f, f)\n",
  • wx, wy, wz)
  • break
  • case GLUT_RIGHT_BUTTON
  • if (state GLUT_DOWN)
  • exit(0)
  • break
  • default
  • break

84
  • void keyboard(unsigned char key, int x, int y)
  • switch (key)
  • case 27
  • exit(0)
  • break

85
  • int main(int argc, char argv)
  • glutInit(argc, argv)
  • glutInitDisplayMode (GLUT_SINGLE GLUT_RGB)
  • glutInitWindowSize (500, 500)
  • glutInitWindowPosition (100, 100)
  • glutCreateWindow (argv0)
  • glutDisplayFunc(display)
  • glutReshapeFunc(reshape)
  • glutKeyboardFunc (keyboard)
  • glutMouseFunc(mouse)
  • glutMainLoop()
  • return 0

86
?? ??
Write a Comment
User Comments (0)
About PowerShow.com