Hi leute, ich möchte in genau die richtung mit der Kamera gehen in die ich sie rotiere...
wie kann ich das machen?
Erst habe ich versuch das mit grad-zahlen zu realisieren, aber ohne erfolg..:/
DEG*0,02222222222222222=StepX
2-Stepx=StepY
Danke für jeden Tipp!
Hier noch der Code:
wie kann ich das machen?
Erst habe ich versuch das mit grad-zahlen zu realisieren, aber ohne erfolg..:/
DEG*0,02222222222222222=StepX
2-Stepx=StepY
Danke für jeden Tipp!
Hier noch der Code:
VB.NET-Quellcode
- Imports Microsoft
- Imports Microsoft.DirectX
- Imports Microsoft.DirectX.Direct3D
- Imports Microsoft.DirectX.Direct3D.LightsCollection
- Imports Microsoft.DirectX.DirectPlay
- Public Class Form
- Dim Camerax As Integer
- Dim Cameraposx As Integer
- Dim Cameraposy As Integer
- Dim Cameraposz As Integer
- Dim Cameray As Integer
- Dim Cameray2 As Integer
- Dim Cameraz As Integer
- Private player As Mesh
- Private player_Textures() As Texture
- Private player_Materials() As Material
- Private m As Mesh
- Private m_Textures() As Texture
- Private m_Materials() As Material
- Dim Frames As Integer = 0
- Public Mouse As DirectInput.Device
- Public MouseState As DirectInput.MouseState
- Public KeyBoard As DirectInput.Device
- Public KeyBoardState As DirectInput.KeyboardState
- Public Camera As Camera
- Private VertexBuf As VertexBuffer
- Public Dev As Device 'Variable für DX Device
- Public Parameter As PresentParameters 'Parameter für das DX Device
- Sub Loadxfile(ByVal filename As String)
- Dim extMat() As ExtendedMaterial = Nothing
- m = Mesh.FromFile(filename, MeshFlags.Managed, Dev, extMat)
- ReDim m_Materials(extMat.Length - 1)
- ReDim m_Textures(extMat.Length - 1)
- For x As Integer = 0 To extMat.Length - 1
- m_Materials(x) = extMat(x).Material3D
- Dim exists As Integer = 1
- If exists = 1 Then
- m_Textures(x) = TextureLoader.FromFile(Dev, "C:\bild1.bmp")
- End If
- Next
- End Sub
- Public Sub initialsieren()
- Label2.Text = "Parameter der Engine"
- Parameter = New PresentParameters
- Parameter.Windowed = True ' Fenstermodus wird genutzt
- Parameter.SwapEffect = SwapEffect.Discard ' SwapEffect
- Parameter.EnableAutoDepthStencil = True ' Autotiefe
- Parameter.AutoDepthStencilFormat = DepthFormat.D16 ' Format der Autotiefe
- Label2.Text = "Starten der Device mit den Parametern"
- Dev = New Device(0, DeviceType.Hardware, Me.Handle, _
- CreateFlags.SoftwareVertexProcessing, Parameter)
- Label2.Text = "Camera"
- 'Ist noch in Arbeit
- Label2.Text = "Tastartur"
- KeyBoard = New DirectInput.Device(DirectInput.SystemGuid.Keyboard)
- KeyBoard.SetCooperativeLevel(Me, DirectInput.CooperativeLevelFlags.Background Or _
- DirectInput.CooperativeLevelFlags.NonExclusive)
- KeyBoard.Acquire()
- Label2.Text = "Maus"
- Mouse = New DirectInput.Device(DirectInput.SystemGuid.Mouse)
- Mouse.SetCooperativeLevel(Me, DirectInput.CooperativeLevelFlags.Background Or _
- DirectInput.CooperativeLevelFlags.NonExclusive)
- Mouse.Acquire()
- Label2.Text = "READY and OK"
- 'Lights
- Dev.RenderState.Lighting = True
- Dev.Lights(0).Type = LightType.Directional
- Dev.Lights(0).Diffuse = Color.WhiteSmoke
- Dev.Lights(0).Direction = New Vector3(0.8F, 0, -5)
- Dev.Lights(0).Enabled = True
- Cursor.Hide()
- End Sub
- Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
- Handles Me.Load
- initialsieren()
- load_xfiles()
- Timer1.Start()
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
- Handles Timer1.Tick
- Frames += 1
- Label5.Text = Frames
- Dev.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.CornflowerBlue, 1, 0)
- Dev.RenderState.CullMode = Cull.Clockwise & Cull.CounterClockwise
- VertexBuf = New VertexBuffer(GetType(CustomVertex.PositionColored), 3, _
- Dev, Usage.None, _
- CustomVertex.PositionColored.Format, Pool.Default)
- Motion_Mouse()
- Motion_Keyboard()
- Keyboard_Events()
- updating()
- Dev.VertexFormat = CustomVertex.PositionColored.Format
- Dev.BeginScene()
- rendern()
- Dev.DrawPrimitives(PrimitiveType.TriangleList, 0, 1)
- Dev.EndScene()
- Dev.Present()
- End Sub
- Public Sub updating()
- Camera = New Camera(Dev, Me, 1, 50, _
- New Vector3(0, 0, 5), _
- New Vector3(Val(Camerax) / 80, Val(Cameray) / 80, Val(Cameraz) / 80))
- End Sub
- Public Sub Motion_Mouse()
- 'Maus auslesen mit Direct Input:
- MouseState = Mouse.CurrentMouseState
- Label10.Text = MouseState.X
- Label11.Text = MouseState.Y
- Label12.Text = MouseState.Z
- 'Neu Rendern der Camera Vektoren
- Label11.Text = Label11.Text * -1
- Camerax += Val(Label10.Text)
- Cameray += Val(Label11.Text)
- Cameraz += Val(Label12.Text)
- TextBox2.Text = Camerax
- TextBox3.Text = Cameray
- TextBox4.Text = Cameraz
- End Sub
- Public Sub Motion_Keyboard()
- KeyBoardState = KeyBoard.GetCurrentKeyboardState
- If KeyBoardState(DirectInput.Key.Left) Then
- Cameraposx += 1
- ElseIf KeyBoardState(DirectInput.Key.Right) Then
- End If
- End Sub
- Public Sub load_xfiles()
- 'Die Objeckte der Reihe nach laden
- For i As Integer = 0 To RichTextBox1.Lines.Count - 1 Step 1
- Loadxfile("C:\town.x")
- Next
- End Sub
- Public Sub rendern()
- For x As Integer = 0 To m_Materials.Length - 1
- Dev.SetTexture(0, m_Textures(x))
- Dev.Material = m_Materials(x)
- m.DrawSubset(x)
- Next
- End Sub
- Public Sub Keyboard_Events()
- If Timer1.Enabled = False Then
- Else
- If KeyBoardState(DirectInput.Key.Escape) Then
- Timer1.Stop()
- Cursor.Show()
- Timer2.Start()
- End If
- End If
- If KeyBoardState(DirectInput.Key.F1) Then
- Timer2.Stop()
- Cursor.Hide()
- Timer1.Start()
- End If
- End Sub
- Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
- KeyBoardState = KeyBoard.GetCurrentKeyboardState
- Keyboard_Events()
- End Sub
- End Class