2017-08-14 06:14:45 +02:00
|
|
|
|
Public Class NewGameCamera
|
|
|
|
|
|
|
|
|
|
Inherits OverworldCamera
|
|
|
|
|
|
|
|
|
|
Public Sub New()
|
|
|
|
|
Me.Name = "New Game"
|
|
|
|
|
Core.Player.startThirdPerson = False
|
|
|
|
|
Me.Position = New Vector3(13, 2, 14)
|
|
|
|
|
Me.Speed = 0.0008F
|
|
|
|
|
|
|
|
|
|
Yaw = CSng(Core.Random.NextDouble() * MathHelper.TwoPi)
|
|
|
|
|
Pitch = -0.2F
|
|
|
|
|
|
|
|
|
|
View = Matrix.CreateLookAt(Position, Vector3.Zero, Vector3.Up)
|
|
|
|
|
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0), Core.GraphicsDevice.Viewport.AspectRatio, 0.01, 16)
|
2017-10-17 08:15:45 +02:00
|
|
|
|
FOV = 45
|
2017-08-14 06:14:45 +02:00
|
|
|
|
|
2017-10-17 08:15:45 +02:00
|
|
|
|
|
2019-01-13 18:06:43 +01:00
|
|
|
|
|
2017-10-17 08:15:45 +02:00
|
|
|
|
CreateProjectionMatrix()
|
2017-08-14 06:14:45 +02:00
|
|
|
|
Update()
|
2019-01-13 18:06:43 +01:00
|
|
|
|
Me._canToggleThirdPerson = False
|
2017-08-14 06:14:45 +02:00
|
|
|
|
End Sub
|
|
|
|
|
|
2017-10-17 08:15:45 +02:00
|
|
|
|
Private Sub CreateProjectionMatrix()
|
|
|
|
|
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(FOV), GraphicsDevice.Viewport.AspectRatio, 0.01, FarPlane)
|
|
|
|
|
End Sub
|
|
|
|
|
|
2017-08-14 06:14:45 +02:00
|
|
|
|
Public Overrides Sub Update()
|
|
|
|
|
Ray = createRay()
|
|
|
|
|
|
2017-10-17 08:15:45 +02:00
|
|
|
|
UpdateViewMatrix()
|
2017-08-14 06:14:45 +02:00
|
|
|
|
UpdateMatrices()
|
|
|
|
|
UpdateFrustrum()
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
Public Function createRay() As Ray
|
|
|
|
|
Dim centerX As Integer = CInt(Core.windowSize.Width / 2)
|
|
|
|
|
Dim centerY As Integer = CInt(Core.windowSize.Height / 2)
|
|
|
|
|
|
|
|
|
|
Dim nearSource As Vector3 = New Vector3(centerX, centerY, 0)
|
|
|
|
|
Dim farSource As Vector3 = New Vector3(centerX, centerY, 1)
|
|
|
|
|
|
|
|
|
|
Dim nearPoint As Vector3 = Core.GraphicsDevice.Viewport.Unproject(nearSource, Projection, View, Matrix.Identity)
|
|
|
|
|
Dim farPoint As Vector3 = Core.GraphicsDevice.Viewport.Unproject(farSource, Projection, View, Matrix.Identity)
|
|
|
|
|
|
|
|
|
|
Dim direction As Vector3 = farPoint - nearPoint
|
|
|
|
|
direction.Normalize()
|
|
|
|
|
|
|
|
|
|
Return New Ray(nearPoint, direction)
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Private Sub UpdateFrustrum()
|
|
|
|
|
Dim rotation As Matrix = Matrix.CreateRotationX(Pitch) * Matrix.CreateRotationY(Yaw)
|
|
|
|
|
|
|
|
|
|
Dim fPosition As New Vector3(Me.Position.X, Me.Position.Y, Me.Position.Z)
|
|
|
|
|
|
|
|
|
|
Dim transformed As Vector3 = Vector3.Transform(New Vector3(0, 0, -1), rotation)
|
|
|
|
|
Dim lookAt As Vector3 = fPosition + transformed
|
|
|
|
|
|
|
|
|
|
Me.BoundingFrustum = New BoundingFrustum(Matrix.CreateLookAt(fPosition, lookAt, Vector3.Up) * Projection)
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
Public Sub UpdateMatrices()
|
|
|
|
|
Dim rotation As Matrix = Matrix.CreateRotationX(Pitch) * Matrix.CreateRotationY(Yaw)
|
|
|
|
|
|
|
|
|
|
Dim transformed As Vector3 = Vector3.Transform(New Vector3(0, 0, -1), rotation)
|
|
|
|
|
Dim lookAt As Vector3 = Position + transformed
|
|
|
|
|
|
|
|
|
|
View = Matrix.CreateLookAt(Position, lookAt, Vector3.Up)
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
End Class
|