Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
Public Class Form1
Dim camX As Single = 200
Dim camY As Single = 200
Dim camZ As Single = 150
Dim ox As Single = 0
Dim oy As Single = 0
Dim alpha As Single = 0
Dim glLoaded As Boolean = False
Private Sub GlControl1_KeyDown(sender As Object, e As KeyEventArgs) Handles _
GlControl1.KeyDown
If glLoaded Then
If e.KeyCode = Keys.D Then ox += 5
If e.KeyCode = Keys.A Then ox -= 5
If e.KeyCode = Keys.W Then oy += 5
If e.KeyCode = Keys.S Then oy -= 5
If e.KeyCode = Keys.Y Then alpha += 3.6
If e.KeyCode = Keys.X Then alpha -= 3.6
GlControl1.Invalidate()
End If
End Sub
Private Sub GlControl1_Load(sender As Object, e As EventArgs) Handles _
GlControl1.Load
glLoaded = True
End Sub
Private Sub GlControl1_Paint(sender As Object, e As PaintEventArgs) Handles _
GlControl1.Paint
GL.ClearColor(Color.WhiteSmoke)
GL.Clear(ClearBufferMask.ColorBufferBit + _
ClearBufferMask.DepthBufferBit)
GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height)
Dim w As Integer = GlControl1.Width
Dim h As Integer = GlControl1.Height
Dim aspect As Single = w / h
Dim persp As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(0.45, _
aspect, 0.1, 10000)
Dim lookat As Matrix4 = Matrix4.LookAt(camX, camY, camZ, 0, 0, 0, 0, 0, _
1)
Dim sw As Stopwatch = New Stopwatch
GL.MatrixMode(MatrixMode.Projection)
GL.LoadIdentity()
GL.LoadMatrix(lookat * persp)
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
GL.Translate(ox, oy, 0)
GL.Rotate(alpha, Vector3.UnitZ)
'GL.Enable(EnableCap.CullFace)
'GL.Disable(EnableCap.CullFace)
GL.Enable(EnableCap.DepthTest)
GL.DepthFunc(DepthFunction.Lequal)
'Lighting
GL.Light(LightName.Light0, LightParameter.Ambient, Color4.White)
GL.Light(LightName.Light0, LightParameter.Diffuse, Color4.White)
GL.Light(LightName.Light0, LightParameter.Position, (New Vector4(100, _
100, 100, 0)))
'GL.Light(LightName.Light0, LightParameter.SpotDirection, New Vector4(
' -1, -1, -1, 0))
GL.Enable(EnableCap.Light0)
GL.Enable(EnableCap.Lighting)
'GL.Enable(EnableCap.ColorMaterial) '<--- schaltet Lichtberechnung ab?
GL.ShadeModel(ShadingModel.Smooth)
GL.Enable(EnableCap.Normalize)
'Drawing Objects -----------------------------
GL.Begin(PrimitiveType.Triangles)
GL.Color3(Color.Blue)
GL.Normal3(1, 1, 1)
GL.Vertex3(30, 0, 0)
GL.Vertex3(0, 30, 0)
GL.Vertex3(0, 0, 30)
GL.Normal3(1, -1, 1)
GL.Vertex3(30, 0, 0)
GL.Vertex3(0, -30, 0)
GL.Vertex3(0, 0, 30)
GL.Normal3(-1, -1, 1)
GL.Vertex3(-30, 0, 0)
GL.Vertex3(0, -30, 0)
GL.Vertex3(0, 0, 30)
'GL.Normal3(-1, 1, 1)
'GL.Vertex3(-30, 0, 0)
'GL.Vertex3(0, 30, 0)
'GL.Vertex3(0, 0, 30)
GL.End()
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
GL.Disable(EnableCap.Lighting)
'Grid ------------------------------------
GL.Begin(PrimitiveType.Lines)
For i = -100 To 100 Step 10
GL.Color3(Color.Gray)
GL.Vertex3(-100, i, 0)
GL.Color3(Color.Gray)
GL.Vertex3(100, i, 0)
GL.Color3(Color.Gray)
GL.Vertex3(i, -100, 0)
GL.Color3(Color.Gray)
GL.Vertex3(i, 100, 0)
Next
'Axes
GL.Disable(EnableCap.LineSmooth)
'GL.Enable(EnableCap.LineSmooth)
GL.LineWidth(15) '<---- macht nix?
GL.Color3(Color.Red)
GL.Vertex3(-80, 0, 0)
GL.Vertex3(100, 0, 0)
GL.Color3(Color.Green)
GL.Vertex3(0, -80, 0)
GL.Vertex3(0, 100, 0)
GL.Color3(Color.Blue)
GL.Vertex3(0, 0, -80)
GL.Vertex3(0, 0, 100)
GL.End()
'GraphicsContext.CurrentContext.VSync = True
GlControl1.SwapBuffers()
End Sub
End Class |