Анимация с помощью OpenGl (разрываемая форма)
Небольшой пример анимациии формы. Сам вид формы зависит от того, в каком
месте находится указатель мыши.
Платформы: Windows , Linux.
Автор: Innova
и Kristopher Windsor. Создано: 2008 год.
' Torus OpenGL Demo! v1.0 ' (C) 2008 Innova and Kristopher Windsor #INCLUDE "GL/gl.bi" #INCLUDE "GL/glu.bi" Const screenx = 800, screeny = 600 Const true = -1, false = 0, pi = Atn(1) * 4 Type camera_type As Double eye(1 To 3) As Double see(1 To 3) As Double up(1 To 3) End Type Type coord_type As Double x, y End Type Dim Shared As String Key Dim Shared As camera_type camera Sub start Screenres screenx, screeny, 32,, 2 glMatrixMode GL_PROJECTION glLoadIdentity gluPerspective 35.0, screenx / screeny, .01, 8 glMatrixMode GL_MODELVIEW glLoadIdentity glClearColor 0, 0, 0, 1 glEnable GL_DEPTH_TEST 'properly handles overlapping polygons (draw order for layering) Randomize Timer End Sub Sub main Const torus_width = .3 Dim As Integer mx, my Dim As Double angle_x, angle_y, angle_z, step_major = pi / 32, step_minor = pi / 2 Dim As Double x1, y1, x2, y2, x3, y3, x4, y4 start Do If Getmouse(mx, my) Then mx = screenx: my = screeny Select Case key Case Chr(255, 72): If step_major < pi / 2 - .01 Then step_major *= 2 Case Chr(255, 80): step_major /= 2 Case Chr(255, 75): If step_minor < pi / 2 - .01 Then step_minor *= 2 Case Chr(255, 77): step_minor /= 2 End Select glClear GL_DEPTH_BUFFER_BIT Or GL_COLOR_BUFFER_BIT glLoadIdentity With camera .eye(1) = 4: .eye(2) = 0: .eye(3) = 0 .see(1) = 0: .see(2) = 0: .see(3) = 0 .up(1) = 0: .up(2) = 0: .up(3) = 1 gluLookat .eye(1), .eye(2), .eye(3), .see(1), .see(2), .see(3), .up(1), .up(2), .up(3) End With 'random spinning (instead of walking around the ground) angle_x += .4: glRotatef angle_x, 1, 0, 0 angle_y += .6: glRotatef angle_y, 0, 1, 0 angle_z += .7: glRotatef angle_z, 0, 0, 1 glBegin GL_QUADS 'loop around the circumference of the torus For d1 As Double = 0 To pi * 2 * mx / screenx Step step_major x1 = Cos(d1) y1 = Sin(d1) x2 = Cos(d1 + step_major) y2 = Sin(d1 + step_major) 'loop around a circle on the torus For d2 As Double = 0 To pi * 2 * my / screeny Step step_minor x3 = Cos(d2) * torus_width y3 = Sin(d2) * torus_width x4 = Cos(d2 + step_minor) * torus_width y4 = Sin(d2 + step_minor) * torus_width glColor3d d1 / (pi * 2), d2 / (pi * 2), 1 - (d1 + d2) / (pi * 4) '2 points at v1 glVertex3d x1 + x3 * x1, y1 + x3 * y1, y3 glVertex3d x1 + x4 * x1, y1 + x4 * y1, y4 '2 points at v2 glVertex3d x2 + x4 * x2, y2 + x4 * y2, y4 glVertex3d x2 + x3 * x2, y2 + x3 * y2, y3 Next d2 Next d1 glEnd Flip Sleep 10, 1 Key = Inkey Loop Until Key = Chr(27) End Sub main