VERSION 5.00
Begin VB.Form frm3D 
   ClientHeight    =   4260
   ClientLeft      =   5175
   ClientTop       =   4305
   ClientWidth     =   6660
   LinkTopic       =   "Form1"
   ScaleHeight     =   4260
   ScaleWidth      =   6660
   Visible         =   0   'False
   Begin VB.Timer Timer5 
      Enabled         =   0   'False
      Interval        =   1
      Left            =   2880
      Top             =   240
   End
   Begin VB.Timer Timer4 
      Enabled         =   0   'False
      Interval        =   500
      Left            =   2040
      Top             =   240
   End
   Begin VB.Timer Timer3 
      Enabled         =   0   'False
      Interval        =   10
      Left            =   1320
      Top             =   240
   End
   Begin VB.Timer Timer2 
      Enabled         =   0   'False
      Interval        =   30
      Left            =   720
      Top             =   240
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   30
      Left            =   120
      Top             =   240
   End
End
Attribute VB_Name = "frm3D"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Virtual Hypnotist
'Copyright (C) 2006-2008 FollowTheWatch55
'Contact - followthewatch55@yahoo.com

'This program is free software; you can redistribute it and/or
'modify it under the terms of the GNU General Public License
'as published by the Free Software Foundation; either version 2
'of the License, or (at your option) any later version.

'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

'This code is originally from HypnoHouse 0.2

Public TV As TVEngine
Private Scene As TVScene
Private Room As TVMesh
Private HypnoRoom As TVMesh
Private HypnoDoor As TVMesh
Private HypnoChair As TVMesh
Private BackChair As TVMesh
Private HypnoTV As TVMesh
Private HypnoRide As TVMesh
Private HypnoRide2 As TVMesh
Private RideCar As TVMesh
Private RideDoor As TVMesh
Private HypnoSpiral As TVMesh
Private HypnoSpiral2 As TVMesh
Private HypnoSpiral3 As TVMesh
Private HypnoSpiral4 As TVMesh
Private HypnoSpiral5 As TVMesh
Private HypnoSpiral6 As TVMesh
Private HypnoSpiral7 As TVMesh
Private HypnoSpiral8 As TVMesh
Private HypnoSpiral9 As TVMesh
Private HypnoSpiral10 As TVMesh
Private HypnoSpiral11 As TVMesh
Private Eyes As TVMesh
Private Shaft As TVMesh
'Private Inp As TVInputEngine
Private TextureFactory As TVTextureFactory
Private linestart As D3DVECTOR
Private lineend As D3DVECTOR
Private LineTest As D3DVECTOR
Public isRunning As Boolean
Private Camera As TVCamera
Private ColRes As TV_COLLISIONRESULT
Private IsFalling As Boolean
Private Gravity As Integer
Private FallRate As Single
Private lngOldTick As Long
Private CameraOriginalPos As Single
Private Atmos As New TVAtmosphere
Private MatFactory As TVMaterialFactory
Private LightEngine As TVLightEngine
Private GraphicEffect As TVGraphicEffect
'Private SoundEngine As New TV3DMedia.TVSoundEngine
'Private Listener As TVListener
'Private HypnoSound As New TV3DMedia.TVSoundWave3D
Private Light(12) As D3DLIGHT8
Private Cycle As Integer
Private Started As Boolean
Private GoCar As Boolean
Private CarSpeed As Single
Private HypnoMachineOn As Boolean
Private HypnoMachineRotate1 As Single
Private HypnoMachineRotate2 As Single
Private otherway As Boolean
Private SectionID As Integer
Private Stuff As Boolean

Option Explicit

Public Sub Start3D()
If ExceptionHandlers = True Then On Error GoTo ErrorHandler

  HypnoDoor.Enable False
  HypnoMachineOn = False
  GoCar = False
  otherway = False
  
  HypnoMachineRotate1 = 0
  HypnoMachineRotate2 = 0
  
  'HypnoSound.SetPosition HypnoSpiral.GetPosition.X / 100, HypnoSpiral.GetPosition.Y / 100, HypnoSpiral.GetPosition.z / 100
            
  'Camera.SetPosition 70, 310, 180 'front
  If frmSession.optHypnoMachine = True Then
    Camera.SetPosition -155, 10, -20 'left of the hypno machine
    Camera.SetRotation 0, -180, 0
  End If
  If frmSession.optHypnoCoaster = True Then
    Camera.SetPosition 160, 310, 60 'right of the coaster
    Camera.SetRotation 0, -180, 0
  End If
  'Camera.SetPosition 160, 310, -15030 'coaster, other end of line
  'Camera.SetRotation 0, -143, 0
  
  LightEngine.EnableLight(6) = False
  LightEngine.EnableLight(7) = False
  LightEngine.EnableLight(8) = False
  LightEngine.EnableLight(9) = False
  LightEngine.EnableLight(10) = False
  LightEngine.EnableLight(11) = False
  
  GraphicEffect.FadeIn 2000

  SectionID = 0
  
  Timer5.Interval = 1000 / 30
  Timer5.Enabled = True
  
Exit Sub
ErrorHandler:
err.Source = "3D Subsystem - Start3D"
Call ErrorReport("An error occurred in the 3D graphics system.", vbCritical)
Quit = True
isRunning = False
Unload Me
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
isRunning = False
Call Cleanup
End Sub

Private Sub Timer1_Timer()
'Spiral and Eyes rotational code
HypnoMachineRotate1 = HypnoMachineRotate1 + 0.1
HypnoMachineRotate2 = HypnoMachineRotate2 + 0.05
If HypnoMachineRotate1 > 17 Then HypnoMachineRotate1 = 17
If HypnoMachineRotate2 > 8.6 Then HypnoMachineRotate2 = 8.6

HypnoSpiral.RotateY -HypnoMachineRotate1
HypnoSpiral2.RotateX HypnoMachineRotate1
HypnoSpiral3.RotateX -HypnoMachineRotate1
HypnoSpiral4.RotateX -HypnoMachineRotate1
HypnoSpiral5.RotateX HypnoMachineRotate1
HypnoSpiral6.RotateX HypnoMachineRotate1
HypnoSpiral7.RotateZ HypnoMachineRotate1
HypnoSpiral8.RotateZ -HypnoMachineRotate1
HypnoSpiral9.RotateY -HypnoMachineRotate1
HypnoSpiral10.RotateY HypnoMachineRotate1
Eyes.RotateY -HypnoMachineRotate2
End Sub

Private Sub Timer2_Timer()
Cycle = Cycle + 1
If Cycle = 7 Then Cycle = 1
If Cycle = 1 Then LightEngine.EnableLight(6) = True: LightEngine.EnableLight(7) = False: LightEngine.EnableLight(8) = False: LightEngine.EnableLight(9) = False: LightEngine.EnableLight(10) = False: LightEngine.EnableLight(11) = False
If Cycle = 2 Then LightEngine.EnableLight(6) = False: LightEngine.EnableLight(7) = True: LightEngine.EnableLight(8) = False: LightEngine.EnableLight(9) = False: LightEngine.EnableLight(10) = False: LightEngine.EnableLight(11) = False
If Cycle = 3 Then LightEngine.EnableLight(6) = False: LightEngine.EnableLight(7) = False: LightEngine.EnableLight(8) = True: LightEngine.EnableLight(9) = False: LightEngine.EnableLight(10) = False: LightEngine.EnableLight(11) = False
If Cycle = 4 Then LightEngine.EnableLight(6) = False: LightEngine.EnableLight(7) = False: LightEngine.EnableLight(8) = False: LightEngine.EnableLight(9) = True: LightEngine.EnableLight(10) = False: LightEngine.EnableLight(11) = False
If Cycle = 5 Then LightEngine.EnableLight(6) = False: LightEngine.EnableLight(7) = False: LightEngine.EnableLight(8) = False: LightEngine.EnableLight(9) = False: LightEngine.EnableLight(10) = True: LightEngine.EnableLight(11) = False
If Cycle = 6 Then LightEngine.EnableLight(6) = False: LightEngine.EnableLight(7) = False: LightEngine.EnableLight(8) = False: LightEngine.EnableLight(9) = False: LightEngine.EnableLight(10) = False: LightEngine.EnableLight(11) = True
End Sub

Private Sub Timer3_Timer()
HypnoDoor.SetPosition HypnoDoor.GetPosition.X, HypnoDoor.GetPosition.Y - 0.5, HypnoDoor.GetPosition.z
If HypnoDoor.GetPosition.Y < 0.5 Then Timer3.Enabled = False
End Sub

Private Sub Timer4_Timer()
start:
Dim Color1 As Single
Dim Color2 As Single
Dim Color3 As Single
Color1 = Int(Rnd * 2)
Color2 = Int(Rnd * 2)
Color3 = Int(Rnd * 2)
If Color1 = 0 And Color2 = 0 And Color3 = 0 Then GoTo start
Eyes.SetColor RGBA(Color1, Color2, Color3, 1)
'GraphicEffect.Flash Color1, Color2, Color3, 500
End Sub

Private Sub SlowToFPS(ByVal FrameRate As Long)
Dim lngTicksPerFrame As Long
Static lngOldTickCount As Long
lngTicksPerFrame = 1000 / FrameRate
While GetTickCount() < lngOldTickCount
Call Sleep(5)
Wend
lngOldTickCount = GetTickCount() + lngTicksPerFrame
End Sub

Private Sub Fall()

'This detects if the user is above a hole or something (ready to fall)

If Room.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - 12, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = False And HypnoRoom.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - 12, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = False And HypnoDoor.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - 12, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = False And HypnoRide.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - 12, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = False And RideCar.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - 12, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = False Then IsFalling = True

If IsFalling = False Then Exit Sub

Dim TimeRate As Single
Dim OldPos As Single
Dim NewPos As Single
Dim HeightChange As Single
Gravity = 5

If FallRate = 0 Then
lngOldTick = GetTickCount()
CameraOriginalPos = Camera.GetPosition.Y
End If

'MsgBox ((GetTickCount() / 1000) - (lngOldTick / 1000))

'Basically this is Fallrate=Gravity*SecondsPassed
TimeRate = ((GetTickCount() / 1000) - (lngOldTick / 1000))
FallRate = (Gravity * TimeRate) ^ 2
If FallRate = 0 Then FallRate = 0.1
If TimeRate = 0 Then TimeRate = 0.1

OldPos = Camera.GetPosition.Y
Camera.SetPosition Camera.GetPosition.X, CameraOriginalPos - FallRate, Camera.GetPosition.z
NewPos = Camera.GetPosition.Y
HeightChange = OldPos - NewPos

If Room.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - HeightChange - 10, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = True Or HypnoRoom.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - HeightChange - 10, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = True Or HypnoRide.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - HeightChange - 10, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = True Or RideCar.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - HeightChange - 10, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = True Then
FallRate = 0
IsFalling = False
End If
End Sub

Public Sub Load3D()
If ExceptionHandlers = True Then On Error GoTo ErrorHandler
    isRunning = True
    Set TV = New TVEngine
    Set Scene = New TVScene
    Set Room = New TVMesh
    Set HypnoRoom = New TVMesh
    Set HypnoDoor = New TVMesh
    Set HypnoChair = New TVMesh
    Set HypnoTV = New TVMesh
    Set HypnoRide = New TVMesh
    Set HypnoRide2 = New TVMesh
    Set RideCar = New TVMesh
    Set HypnoSpiral = New TVMesh
    Set HypnoSpiral2 = New TVMesh
    Set HypnoSpiral3 = New TVMesh
    Set HypnoSpiral4 = New TVMesh
    Set HypnoSpiral5 = New TVMesh
    Set HypnoSpiral6 = New TVMesh
    Set HypnoSpiral7 = New TVMesh
    Set HypnoSpiral8 = New TVMesh
    Set HypnoSpiral9 = New TVMesh
    Set HypnoSpiral10 = New TVMesh
    Set HypnoSpiral11 = New TVMesh
    Set Eyes = New TVMesh
    Set BackChair = New TVMesh
    Set Shaft = New TVMesh
    Set Camera = New TVCamera
    Set MatFactory = New TVMaterialFactory
    Set LightEngine = New TVLightEngine
    Set GraphicEffect = New TVGraphicEffect
    Dim FileName As String

    Set TextureFactory = New TVTextureFactory

   'DoEvents
   TV.SetSearchDirectory App.path
   TV.Init3DWindowedMode frmHypno.hwnd
   
   Scene.SetViewFrustum 90, 200000

  'Set Inp = New TVInputEngine
  TV.SetSearchDirectory App.path
  TV.DisplayFPS = True
  TV.SetAngleSystem TV_ANGLE_DEGREE

  'SoundEngine.Init Me.hwnd
  'Set Listener = SoundEngine.Get3DListener

  Set Room = Scene.CreateMeshBuilder
  Set HypnoRoom = Scene.CreateMeshBuilder
  Set HypnoDoor = Scene.CreateMeshBuilder
  Set HypnoChair = Scene.CreateMeshBuilder
  Set BackChair = Scene.CreateMeshBuilder
  Set HypnoTV = Scene.CreateMeshBuilder
  Set HypnoRide = Scene.CreateMeshBuilder
  Set HypnoRide2 = Scene.CreateMeshBuilder
  Set RideCar = Scene.CreateMeshBuilder
  Set RideDoor = Scene.CreateMeshBuilder
  Set HypnoSpiral = Scene.CreateMeshBuilder
  Set HypnoSpiral2 = Scene.CreateMeshBuilder
  Set HypnoSpiral3 = Scene.CreateMeshBuilder
  Set HypnoSpiral4 = Scene.CreateMeshBuilder
  Set HypnoSpiral5 = Scene.CreateMeshBuilder
  Set HypnoSpiral6 = Scene.CreateMeshBuilder
  Set HypnoSpiral7 = Scene.CreateMeshBuilder
  Set HypnoSpiral8 = Scene.CreateMeshBuilder
  Set HypnoSpiral9 = Scene.CreateMeshBuilder
  Set HypnoSpiral10 = Scene.CreateMeshBuilder
  Set HypnoSpiral11 = Scene.CreateMeshBuilder
  Set Eyes = Scene.CreateMeshBuilder
  Set Shaft = Scene.CreateMeshBuilder
  
  'TextureFactory.LoadTexture App.Path + "\data\stone_wall.bmp", "Stone"
  'TextureFactory.LoadTexture App.Path + "\data\rendtexture.bmp", "Floor"
  TextureFactory.LoadTexture App.path + "\data\bg54.jpg", "SpiralWall"
  TextureFactory.LoadTexture App.path + "\data\bg11.jpg", "BlueTileFloor"
  TextureFactory.LoadTexture App.path + "\data\bluefloor.jpg", "BlueFloor"
  TextureFactory.LoadTexture App.path + "\data\elegance05.jpg", "EleganceWall"
  TextureFactory.LoadTexture App.path + "\data\ff21.jpg", "Ceiling1"
  TextureFactory.LoadTexture App.path + "\data\bg14.jpg", "RedTileFloor"
  TextureFactory.LoadTexture App.path + "\data\bg4l.jpg", "Purple"
  TextureFactory.LoadTexture App.path + "\data\bgc1.jpg", "Blue"
  'TextureFactory.LoadTexture App.Path + "\data\ff09.jpg", "DarkCeiling"
  TextureFactory.LoadTexture App.path + "\data\pc8.jpg", "ShaftBlue"
  TextureFactory.LoadTexture App.path + "\data\pc9.jpg", "ShaftYellow"
  'TextureFactory.LoadTexture App.Path + "\data\storeleft.jpg", "StoreLeft"
  'TextureFactory.LoadTexture App.Path + "\data\storeright.jpg", "StoreRight"
  'TextureFactory.LoadTexture App.Path + "\data\storetop.jpg", "StoreTop"
  'TextureFactory.LoadTexture App.Path + "\data\road.jpg", "Road"
  'TextureFactory.LoadTexture App.Path + "\data\bluebackwall.jpg", "BlueBackWall"
  'TextureFactory.LoadTexture App.Path + "\data\buildbackwall.jpg", "BuildBackWall"
  'TextureFactory.LoadTexture App.Path + "\data\windows1side.jpg", "windows"
  'TextureFactory.LoadTexture App.Path + "\data\top.jpg", "SkyTop"
  'TextureFactory.LoadTexture App.Path + "\data\bottom.jpg", "SkyBottom"
  'TextureFactory.LoadTexture App.Path + "\data\left.jpg", "SkyLeft"
  'TextureFactory.LoadTexture App.Path + "\data\right.jpg", "SkyRight"
  'TextureFactory.LoadTexture App.Path + "\data\front.jpg", "SkyFront"
  'TextureFactory.LoadTexture App.Path + "\data\back.jpg", "SkyBack"
  TextureFactory.LoadTexture App.path + "\data\spiral.jpg", "Spiral"
  TextureFactory.LoadTexture App.path + "\data\YellowWhiteSpiral.jpg", "YellowSpiral"
  TextureFactory.LoadTexture App.path + "\data\spiral2.jpg", "Spiral2"
  TextureFactory.LoadTexture App.path + "\data\hypnotic.jpg", "Hypnotic"
  TextureFactory.LoadTexture App.path + "\data\colorspiral.jpg", "ColorSpiral"
  TextureFactory.LoadTexture App.path + "\data\hypno+eyes.jpg", "HypnoEyes"
  
  'HypnoSound.Load App.Path + "\data\hypno.wav"
  'Note : Quietest volume is -10,000 and loudest is 0
  'HypnoSound.Volume = 0
  'HypnoSound.Loop_ = True
       
  'Sky
  'Atmos.SkyBox_SetTexture GetTex("SkyFront"), GetTex("SkyBack"), GetTex("SkyLeft"), GetTex("SkyRight"), GetTex("SkyTop"), GetTex("SkyBottom")
  'Atmos.SkyBox_Enable True
  
  'Outside
  'Room.AddFloor GetTex("Road"), -50, 120, 100, 200, 300, 2, 2
  'Room.AddWall GetTex("StoreRight"), 0, 120.1, 25, 120.1, 20, 300, -1, 1
  'Room.AddWall GetTex("StoreLeft"), 35, 120.1, 60, 120.1, 20, 300, -1, 1
  'Room.AddWall GetTex("StoreTop"), 0, 120.1, 60, 120.1, 15, 320, -1, 1
  'Room.AddWall GetTex("BuildBackWall"), 10, 120, -50, 120, 30, 300, -1, 1
  'Room.AddWall GetTex("BuildBackWall"), -50, 160, -50, 200, 30, 300, -1, 1
  'Room.AddWall GetTex("BlueBackWall"), -50, 120, -50, 160, 30, 300, -1, 1
  'Room.AddWall GetTex("BuildBackWall"), 50, 120, 100, 120, 30, 300, -1, 1
  'Room.AddWall GetTex("BuildBackWall"), 100, 160, 100, 200, 30, 300, -1, 1
  'Room.AddWall GetTex("BlueBackWall"), 100, 120, 100, 160, 30, 300, 1, 1
  'Room.AddWall GetTex("windows"), -50, 200, 100, 200, 120, 300, 2, 1
  
  'Front Room
  'Room.AddFloor GetTex("BlueFloor"), 10, 50, 50, 120, 300, 4, 4
  'Room.AddWall GetTex("EleganceWall"), 10, 50, 10, 120, 20, 300, 4, 1
  'Room.AddWall GetTex("EleganceWall"), 50, 50, 50, 90, 20, 300, 4, 1
  'Room.AddWall GetTex("EleganceWall"), 50, 100, 50, 120, 20, 300, 4, 1
  'Room.AddWall GetTex("EleganceWall"), 10, 120, 25, 120, 20, 300, 1, 1
  'Room.AddWall GetTex("EleganceWall"), 35, 120, 50, 120, 20, 300, 1, 1
  'Room.AddWall GetTex("EleganceWall"), 10, 50.1, 30, 50.1, 20, 300, 1, 1
  'Room.AddWall GetTex("EleganceWall"), 40, 50.1, 50, 50.1, 20, 300, 1, 1
  'Room.AddWall GetTex("EleganceWall"), 30, 50.1, 40, 50.1, 2, 318, 1, 0.1
  'Room.AddFloor GetTex("Ceiling1"), 10, 50, 50, 120, 320, 4, 4
  
  'Left Hall
  'Room.AddFloor GetTex("BlueFloor"), 50, 85, 150, 105, 300, 4, 4
  'Room.AddFloor GetTex("Ceiling1"), 50, 85, 150, 105, 320, 4, 4
  'Room.AddWall GetTex("EleganceWall"), 50, 85, 150, 85, 20, 300, 4, 1
  'Room.AddWall GetTex("EleganceWall"), 50, 105, 150, 105, 20, 300, 4, 1
  
  'Left Hall 2
  Room.AddFloor GetTex("BlueFloor"), 150, 50, 170, 105, 300, 4, 4
  Room.AddFloor GetTex("Ceiling1"), 150, 50, 170, 105, 320, 4, 4
  Room.AddWall GetTex("EleganceWall"), 170, 105, 170, 50, 20, 300, 4, 1
  Room.AddWall GetTex("EleganceWall"), 150, 85, 150, 50, 20, 300, 4, 1
  Room.AddWall GetTex("EleganceWall"), 150, 105, 170, 105, 20, 300, 4, 1
  
  'HypnoRide Room
  Room.AddFloor GetTex("BlueFloor"), 150, -30, 170, 50, 300, 4, 4
  Room.AddFloor GetTex("Ceiling1"), 150, -30, 200, 50, 320, 4, 4
  Room.AddWall GetTex("EleganceWall"), 200, -30, 200, 50, 20, 300, 4, 1
  Room.AddWall GetTex("EleganceWall"), 150, -30, 150, 50, 20, 300, 4, 1
  Room.AddWall GetTex("EleganceWall"), 170, 50, 200, 50, 27, 293, 4, 1
  Room.AddWall GetTex("EleganceWall"), 150, -30, 170, -30, 20, 300, 4, 1
  
  RideDoor.AddWall GetTex("Purple"), 170, -30, 200, -30, 27, 293, 1, 1
  Room.AddFloor GetTex("Blue"), 170, -30, 200, 50, 293, 4, 4
  Room.AddWall GetTex("Purple"), 170, -30, 170, 50, 7, 293, 4, 1
  Room.AddWall GetTex("Purple"), 200, -30, 200, 50, 7, 293, 4, 1
  
  'HypnoRide Tunnel
  HypnoRide.AddFloor GetTex("ColorSpiral"), -20, 0, 20, -10000, -20, 1, 10000 / 40
  HypnoRide.AddFloor GetTex("ColorSpiral"), -20, 0, 20, -10000, 20, 1, 10000 / 40
  HypnoRide.AddWall GetTex("ColorSpiral"), -20, 0, -20, -10000, 40, -20, 10000 / 40, 1
  HypnoRide.AddWall GetTex("ColorSpiral"), 20, 0, 20, -10000, 40, -20, 10000 / 40, 1
  
  'HypnoRide Tunnel 2
  HypnoRide2.AddFloor GetTex("Spiral2"), -20, 0, 20, -10000, -20, 1, 10000 / 40
  HypnoRide2.AddFloor GetTex("Spiral2"), -20, 0, 20, -10000, 20, 1, 10000 / 40
  HypnoRide2.AddWall GetTex("Spiral2"), -20, 0, -20, -10000, 40, -20, 10000 / 40, 1
  HypnoRide2.AddWall GetTex("Spiral2"), 20, 0, 20, -10000, 40, -20, 10000 / 40, 1
  
  HypnoRide.SetPosition 185, 307, -30
  
  HypnoRide2.SetPosition 185, 307, -10030
  
  'HypnoRide coaster car
  RideCar.AddFloor GetTex("ShaftYellow"), -13, -20, 13, 20, 0, 2, 2
  RideCar.SetPosition 185, 300, 20
  
  'Opposite HypnoRide Room
  'Room.AddFloor GetTex("BlueFloor"), 150, -15000, 170, -15080, 300, 4, 4
  'Room.AddFloor GetTex("Ceiling1"), 150, -15000, 200, -15080, 320, 4, 4
  'Room.AddWall GetTex("EleganceWall"), 200, -15000, 200, -15080, 20, 300, 4, 1
  'Room.AddWall GetTex("EleganceWall"), 150, -15000, 150, -15080, 20, 300, 4, 1
  'Room.AddWall GetTex("EleganceWall"), 170, -15080, 200, -15080, 27, 293, 4, 1
  'Room.AddWall GetTex("EleganceWall"), 150, -15000, 170, -15000, 20, 300, 4, 1
 '
 ' RideDoor.AddWall GetTex("Purple"), 170, -15000, 200, -15000, 27, 293, 1, 1
 ' Room.AddFloor GetTex("Blue"), 170, -15000, 200, -15080, 293, 4, 4
 ' Room.AddWall GetTex("Purple"), 170, -15000, 170, -15080, 7, 293, 4, 1
 ' Room.AddWall GetTex("Purple"), 200, -15000, 200, -15080, 7, 293, 4, 1

  'Hall after opposite room
  'Room.AddFloor GetTex("BlueFloor"), -50, -15080, 0, -15090, 300, 3, 1
  'Room.AddFloor GetTex("BlueFloor"), 10, -15080, 170, -15090, 300, 10, 1
  'Room.AddFloor GetTex("Ceiling1"), -50, -15080, 170, -15090, 320, 13, 1
  'Room.AddWall GetTex("EleganceWall"), 170, -15080, 170, -15090, 20, 300, 1, 1
  'Room.AddWall GetTex("EleganceWall"), -50, -15080, -50, -15090, 20, 300, 1, 1
  'Room.AddWall GetTex("EleganceWall"), -50, -15090, 170, -15090, 20, 300, 12, 1
  'Room.AddWall GetTex("EleganceWall"), -50, -15080, 150, -15080, 20, 300, 11, 1

  'haha
  'Room.AddWall GetTex("BlueFloor"), 0, -15080, 0, -15090, 20, 280, 1, 1
  'Room.AddWall GetTex("BlueFloor"), 10, -15080, 10, -15090, 20, 280, 1, 1
  'Room.AddWall GetTex("BlueFloor"), 0, -15080, 10, -15080, 20, 280, 1, 1
  'Room.AddWall GetTex("BlueFloor"), 0, -15090, 10, -15090, 20, 280, 1, 1

  'Shaft.AddWall GetTex("ShaftYellow"), 0, -15080, 0, -15090, 1000, -720, 2, 100
  'Shaft.AddWall GetTex("ShaftYellow"), 10, -15080, 10, -15090, 1000, -720, 2, 100
  'Shaft.AddWall GetTex("ShaftYellow"), 0, -15080, 10, -15080, 1000, -720, 2, 100
  'Shaft.AddWall GetTex("ShaftYellow"), 0, -15090, 10, -15090, 1000, -720, 2, 100
  'Shaft.AddFloor GetTex("ShaftYellow"), 0, -15080, 10, -15090, -720, 2, 2
  
  'Gateway room
  'Room.AddFloor GetTex("Blue"), 10, 20, 20, 50, 300, 2, 2
  'Room.AddFloor GetTex("Blue"), 20, 10, 50, 50, 300, 2, 2
  'Room.AddWall GetTex("Purple"), 10, 10, 10, 50, 20, 300, 2, 2
  'Room.AddWall GetTex("Purple"), 50, 10, 50, 50, 20, 300, 2, 2
  'Room.AddWall GetTex("Purple"), 10, 10, 50, 10, 20, 300, 2, 2
  'Room.AddWall GetTex("Purple"), 10, 50, 30, 50, 20, 300, 2, 2
  'Room.AddWall GetTex("Purple"), 40, 50, 50, 50, 20, 300, 2, 2
  'Room.AddWall GetTex("Purple"), 30, 50, 40, 50, 2, 318, 2, 0.2
  'Room.AddFloor GetTex("DarkCeiling"), 10, 10, 15, 45, 320, 2, 2
  'Room.AddFloor GetTex("DarkCeiling"), 15, 10, 50, 50, 320, 2, 2
  
  'Shaft
  'Shaft.AddWall GetTex("ShaftYellow"), 10, 10, 10, 20, 280, 20, 2, 30
  'Shaft.AddWall GetTex("ShaftYellow"), 20, 10, 20, 20, 280, 20, 2, 30
  'Shaft.AddWall GetTex("ShaftYellow"), 10, 10, 20, 10, 280, 20, 2, 30
  'Shaft.AddWall GetTex("ShaftYellow"), 10, 20, 20, 20, 280, 20, 2, 30
  
  'Shaft2
  'Shaft.AddWall GetTex("ShaftYellow"), 10, 45, 10, 50, 40, 320, 2, 4
  'Shaft.AddWall GetTex("ShaftYellow"), 15, 45, 15, 50, 40, 320, 2, 4
  'Shaft.AddWall GetTex("ShaftYellow"), 10, 45, 15, 45, 40, 320, 2, 4
  'Shaft.AddWall GetTex("ShaftYellow"), 10, 50, 15, 50, 40, 320, 2, 4
  'Shaft.AddFloor GetTex("ShaftYellow"), 10, 45, 15, 50, 360, 2, 2
  
  'Basement room
  'Room.AddFloor GetTex("ShaftBlue"), -20, -20, 20, 20, 0, 0.5, 1
  'Room.AddWall GetTex("ShaftBlue"), -20, -20, 20, -20, 20, 0, 0.5, 1
  'Room.AddWall GetTex("ShaftBlue"), -20, 20, 20, 20, 20, 0, 0.5, 1
  'Room.AddWall GetTex("ShaftBlue"), -20, -10, -20, 20, 20, 0, 0.5, 1
  'Room.AddWall GetTex("ShaftBlue"), -20, -20, -20, -10, 2, 18, 0.2, 1
  'Room.AddWall GetTex("ShaftBlue"), 20, -20, 20, 20, 20, 0, 0.5, 1
  'Room.AddFloor GetTex("ShaftBlue"), -20, -20, 20, 10, 20, 0.5, 1
  'Room.AddFloor GetTex("ShaftBlue"), -20, 10, 10, 20, 20, 0.5, 1
  
  'Hallway part 1
  Room.AddFloor GetTex("ShaftBlue"), -150, -20, -20, -10, 0, 1, 1
  Room.AddWall GetTex("ShaftBlue"), -150, -20, -20, -20, 20, 0, 1, 1
  Room.AddWall GetTex("ShaftBlue"), -150, -10, -20, -10, 20, 0, 1, 1
  Room.AddFloor GetTex("ShaftBlue"), -150, -20, -20, -10, 20, 1, 1
  
  'Hallway part 2
  Room.AddFloor GetTex("ShaftBlue"), -160, -10, -150, -100, 0, 0, 1, 1
  Room.AddWall GetTex("ShaftBlue"), -150, -20, -150, -100, 20, 0, 1, 1
  Room.AddWall GetTex("ShaftBlue"), -160, -10, -160, -100, 20, 0, 1, 1
  Room.AddWall GetTex("ShaftBlue"), -160, -10, -150, -10, 20, 0, 1, 1
  Room.AddFloor GetTex("ShaftBlue"), -160, -10, -150, -100, 20, 0, 1, 1
  
  'Hypno Room
  HypnoRoom.AddFloor GetTex("BlueTileFloor"), -200, -100, -100, -150, 0, 12, 6
  HypnoRoom.AddWall GetTex("SpiralWall"), -200, -100, -160, -100, 30, 0, 6, 6
  HypnoRoom.AddWall GetTex("SpiralWall"), -150, -100, -100, -100, 30, 0, 6, 6
  HypnoRoom.AddWall GetTex("SpiralWall"), -160, -100, -150, -100, 10, 20, 2, 2
  HypnoDoor.AddWall GetTex("SpiralWall"), -160, -100.1, -150, -100.1, 20, 0, 2, 4
  HypnoRoom.AddWall GetTex("SpiralWall"), -200, -150, -100, -150, 30, 0, 12, 6
  HypnoRoom.AddWall GetTex("SpiralWall"), -200, -100, -200, -150, 30, 0, 6, 6
  HypnoRoom.AddWall GetTex("SpiralWall"), -100, -100, -100, -150, 30, 0, 6, 6
  HypnoRoom.AddFloor GetTex("RedTileFloor"), -200, -100, -100, -150, 30, 12, 6
  
  'BackChair.Load3DSMesh App.Path + "\data\chair11.3ds"
  'BackChair.SetPosition 38, 303, 26
  'BackChair.ScaleMesh 0.2, 0.2, 0.2
  ''BackChair.SetRotation 0, 180, 0

  HypnoChair.Load3DSMesh App.path + "\data\chair12.3ds"
  HypnoChair.SetPosition -150, 5, -125
  HypnoChair.ScaleMesh 0.3, 0.3, 0.3
  HypnoChair.SetRotation 0, 90, 0

  'HypnoTV.Load3DSMesh App.Path + "\data\tv.3ds", True, True, True
  'HypnoTV.SetPosition 38, 307, 11
  'HypnoTV.ScaleMesh 0.03, 0.03, 0.03
  'HypnoTV.SetRotation 0, 180, 0
  
  HypnoSpiral11.SetPosition 38, 305.25, 14
  HypnoSpiral11.AddWall GetTex("ColorSpiral"), 0, -3.5, 0, 3.5, 7, -3.5, 1, 1
  HypnoSpiral11.SetRotation 0, 90, 0

  HypnoSpiral.Load3DSMesh App.path + "\data\hypnospiral.3ds"
  HypnoSpiral.SetPosition -199, 13, -125
  HypnoSpiral.ScaleMesh 0.1, 0.1, 0.1
  HypnoSpiral.SetRotation 0, 0, 90
  'HypnoSpiral.SetColor (RGBA(10, 10, 10, 1))
  'HypnoSpiral.SetTexture GetTex("ShaftYellow")
  
  HypnoSpiral2.SetPosition -199.7, 13.5, -138
  HypnoSpiral3.SetPosition -199.7, 13.5, -112
  HypnoSpiral2.AddWall GetTex("Spiral"), 0, -5, 0, 5, 10, -5, 1, 1
  HypnoSpiral3.AddWall GetTex("Spiral"), 0, -5, 0, 5, 10, -5, 1, 1
  
  HypnoSpiral4.SetPosition -199.8, 18, -142
  HypnoSpiral4.AddWall GetTex("YellowSpiral"), 0, -5, 0, 5, 10, -5, 1, 1
  
  HypnoSpiral5.SetPosition -199.8, 18, -108
  HypnoSpiral5.AddWall GetTex("YellowSpiral"), 0, -5, 0, 5, 10, -5, 1, 1
  
  HypnoSpiral6.SetPosition -199.9, 13.5, -125
  HypnoSpiral6.AddWall GetTex("Spiral2"), 0, -30, 0, 30, 60, -30, 1, 1
  
  HypnoSpiral7.SetPosition -185, 15, -100.1
  HypnoSpiral7.AddWall GetTex("ColorSpiral"), -15, 0, 15, 0, 30, -15, 1, 1
  
  HypnoSpiral8.SetPosition -185, 15, -149.9
  HypnoSpiral8.AddWall GetTex("ColorSpiral"), -15, 0, 15, 0, 30, -15, 1, 1
  
  HypnoSpiral9.SetPosition -185, 0.1, -125
  HypnoSpiral9.AddFloor GetTex("Hypnotic"), -15, -15, 15, 15, 0, 1, 1
  
  HypnoSpiral10.SetPosition -185, 29.9, -125
  HypnoSpiral10.AddFloor GetTex("Hypnotic"), -15, -15, 15, 15, 0, 1, 1
  
  Eyes.SetPosition -195, 23, -125.3
  Eyes.AddWall GetTex("HypnoEyes"), 0, -7, 0, 7, 2.5, 0, 1, 1
  
  MatFactory.CreateMaterialQuick 0.2, 0.2, 0.2, 1, "QuickMAT"
  MatFactory.CreateMaterialQuick 1, 1, 1, 1, "QuickMAT2"
  MatFactory.CreateMaterialQuick 0.05, 0, 0.05, 1, "QuickMAT3"
  
  'GoTo skiplights
  Light(1).Type = D3DLIGHT_POINT
  Light(1).Position = Vector3(30, 320, 70)
  Light(1).Ambient = DXColor(1, 1, 1, 1)
  Light(1).diffuse = DXColor(1, 1, 1, 1)
  Light(1).Attenuation0 = 0.5
  Light(1).Range = 60
  LightEngine.CreateLight Light(1), "Light"
  LightEngine.UpdateLight 1, Light(1)

  Light(2).Type = D3DLIGHT_POINT
  Light(2).Position = Vector3(30, 320, 20)
  Light(2).Ambient = DXColor(0, 1, 1, 1)
  Light(2).diffuse = DXColor(1, 1, 1, 1)
  Light(2).Attenuation0 = 0
  Light(2).Range = 30
  LightEngine.CreateLight Light(2), "Light2"
  LightEngine.UpdateLight 2, Light(2)

  Light(3).Type = D3DLIGHT_POINT
  Light(3).Position = Vector3(15, 50, 15)
  Light(3).Ambient = DXColor(1, 1, 0, 1)
  Light(3).diffuse = DXColor(1, 1, 1, 1)
  Light(3).Direction = Vector(0, 30, 0)
  Light(3).Attenuation0 = 0
  Light(3).Range = 170
  LightEngine.CreateLight Light(3), "Light3"
  LightEngine.UpdateLight 3, Light(3)
  
  Light(4).Type = D3DLIGHT_POINT
  Light(4).Position = Vector3(-155, 20, -100)
  Light(4).Ambient = DXColor(0, 1, 1, 1)
  Light(4).diffuse = DXColor(0, 1, 1, 1)
  'Light(4).Direction = Vector(0, 30, 0)
  Light(4).Attenuation0 = 0
  Light(4).Range = 50
  LightEngine.CreateLight Light(4), "Light4"
  LightEngine.UpdateLight 4, Light(4)
  
  Light(5).Type = D3DLIGHT_POINT
  Light(5).Position = Vector3(-150, 30, -125)
  Light(5).Ambient = DXColor(1, 1, 0, 1)
  Light(5).diffuse = DXColor(1, 1, 1, 1)
  Light(5).Direction = Vector(0, 30, 0)
  Light(5).Attenuation0 = 0
  Light(5).Range = 30
  LightEngine.CreateLight Light(5), "Light5"
  LightEngine.UpdateLight 5, Light(5)
  
  Light(6).Type = D3DLIGHT_POINT
  Light(6).Position = Vector3(-200, 0, -150)
  Light(6).Ambient = DXColor(1, 1, 1, 1)
  Light(6).diffuse = DXColor(1, 1, 1, 1)
  Light(6).Direction = Vector(0, 330, 0)
  Light(6).Attenuation0 = 0
  Light(6).Attenuation1 = 0
  Light(6).Attenuation2 = 0
  Light(6).Range = 30
  LightEngine.CreateLight Light(6), "Light6"
  LightEngine.UpdateLight 6, Light(6)

  Light(7).Type = D3DLIGHT_POINT
  Light(7).Position = Vector3(-200, 0, -125)
  Light(7).Ambient = DXColor(1, 1, 0, 1)
  Light(7).diffuse = DXColor(1, 1, 0, 1)
  Light(7).Direction = Vector(0, 330, 0)
  Light(7).Attenuation0 = 0
  Light(7).Attenuation1 = 0
  Light(7).Attenuation2 = 0
  Light(7).Range = 30
  LightEngine.CreateLight Light(7), "Light7"
  LightEngine.UpdateLight 7, Light(7)

  Light(8).Type = D3DLIGHT_POINT
  Light(8).Position = Vector3(-200, 0, -100)
  Light(8).Ambient = DXColor(0, 1, 1, 1)
  Light(8).diffuse = DXColor(0, 1, 1, 1)
  Light(8).Direction = Vector(0, 330, 0)
  Light(8).Attenuation0 = 0
  Light(8).Attenuation1 = 0
  Light(8).Attenuation2 = 0
  Light(8).Range = 30
  LightEngine.CreateLight Light(8), "Light8"
  LightEngine.UpdateLight 8, Light(8)

  Light(9).Type = D3DLIGHT_POINT
  Light(9).Position = Vector3(-200, 30, -100)
  Light(9).Ambient = DXColor(1, 0, 1, 1)
  Light(9).diffuse = DXColor(1, 0, 1, 1)
  Light(9).Direction = Vector(0, 330, 0)
  Light(9).Attenuation0 = 0
  Light(9).Attenuation1 = 0
  Light(9).Attenuation2 = 0
  Light(9).Range = 30
  LightEngine.CreateLight Light(9), "Light9"
  LightEngine.UpdateLight 9, Light(9)

  Light(10).Type = D3DLIGHT_POINT
  Light(10).Position = Vector3(-200, 30, -125)
  Light(10).Ambient = DXColor(1, 0, 1, 1)
  Light(10).diffuse = DXColor(0, 1, 1, 1)
  Light(10).Direction = Vector(0, 330, 0)
  Light(10).Attenuation0 = 0
  Light(10).Attenuation1 = 0
  Light(10).Attenuation2 = 0
  Light(10).Range = 30
  LightEngine.CreateLight Light(10), "Light10"
  LightEngine.UpdateLight 10, Light(10)

  Light(11).Type = D3DLIGHT_POINT
  Light(11).Position = Vector3(-200, 30, -150)
  Light(11).Ambient = DXColor(1, 1, 0, 1)
  Light(11).diffuse = DXColor(1, 1, 1, 1)
  Light(11).Direction = Vector(0, 330, 0)
  Light(11).Attenuation0 = 0
  Light(11).Attenuation1 = 0
  Light(11).Attenuation2 = 0
  Light(11).Range = 30
  LightEngine.CreateLight Light(11), "Light11"
  LightEngine.UpdateLight 11, Light(11)

skiplights:
  'HypnoRide room light
  Light(12).Type = D3DLIGHT_SPOT
  Light(12).Position = Vector3(150, 310, 0)
  Light(12).Ambient = DXColor(0.8, 0.8, 0.8, 0.8)
  Light(12).diffuse = DXColor(1, 5, 5, 5)
  Light(12).Direction = Vector(0, -1, 0)
  Light(12).Attenuation0 = 0
  Light(12).Attenuation1 = 0.007
  Light(12).Attenuation2 = 0
  Light(12).Range = 1000
  'Light(12).Falloff = 1#
  'Light(12).Phi = 0.5
  'Light(12).Theta = Light(12).Phi / 2#
  LightEngine.CreateLight Light(12), "Light12"
  LightEngine.UpdateLight 12, Light(12)
  
  Room.SetMaterial (GetMat("QuickMAT"))
  HypnoRoom.SetMaterial (GetMat("QuickMAT"))
  HypnoDoor.SetMaterial (GetMat("QuickMAT"))
  Shaft.SetMaterial (GetMat("QuickMAT2"))
  HypnoRide.SetMaterial (GetMat("QuickMAT2"))
  RideCar.SetMaterial (GetMat("QuickMAT"))
  HypnoSpiral.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral2.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral3.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral4.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral5.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral6.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral7.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral8.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral9.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral10.SetMaterial (GetMat("QuickMat3"))
  HypnoSpiral11.SetMaterial (GetMat("QuickMat2"))
  Eyes.SetMaterial (GetMat("QuickMat3"))
  
  Room.ComputeNormals
  HypnoRoom.ComputeNormals
  HypnoDoor.ComputeNormals
  Shaft.ComputeNormals
  HypnoRide.ComputeNormals
  RideCar.ComputeNormals
  
  Room.Optimize
  HypnoRoom.Optimize
  Shaft.Optimize
  HypnoRide.Optimize
Exit Sub

ErrorHandler:
err.Source = "3D Subsystem - Load3D"
Call ErrorReport("An error occurred while loading and initializing the TrueVision3D graphics engine.", vbCritical)
Quit = True
isRunning = False
Unload Me
End Sub

Private Sub Cleanup()
'unload allocated Truevision3D resources
Set TV = Nothing
Set Scene = Nothing
Set Room = Nothing
Set HypnoRoom = Nothing
Set HypnoDoor = Nothing
Set HypnoChair = Nothing
Set HypnoTV = Nothing
Set HypnoRide = Nothing
Set HypnoRide2 = Nothing
Set RideCar = Nothing
Set HypnoSpiral = Nothing
Set HypnoSpiral2 = Nothing
Set HypnoSpiral3 = Nothing
Set HypnoSpiral4 = Nothing
Set HypnoSpiral5 = Nothing
Set HypnoSpiral6 = Nothing
Set HypnoSpiral7 = Nothing
Set HypnoSpiral8 = Nothing
Set HypnoSpiral9 = Nothing
Set HypnoSpiral10 = Nothing
Set HypnoSpiral11 = Nothing
Set Eyes = Nothing
Set BackChair = Nothing
Set Shaft = Nothing
Set Camera = Nothing
Set MatFactory = Nothing
Set LightEngine = Nothing
Set GraphicEffect = Nothing
Set TextureFactory = Nothing
Unload Me
End Sub

Private Sub Timer5_Timer()
    'SlowToFPS (25)
    
    'If frmDebug.Check2.Value = 1 Then Call Fall
    Call Fall
    linestart = Camera.GetPosition
    'If frmDebug.Check1.Value = 1 Then
        Room.SetCollisionEnable True
        HypnoRoom.SetCollisionEnable True
        HypnoDoor.SetCollisionEnable True
        HypnoRide.SetCollisionEnable True
    'End If
    
    '3D Sound code
    'Listener.SetPosition Camera.GetPosition.X / 100, Camera.GetPosition.Y / 100, Camera.GetPosition.z / 100
             
    'Dim matCamera As D3DMATRIX
    'matCamera = Scene.GetCamera.GetRotationMatrix
    'Listener.SetOrientation matCamera.m31, matCamera.m32, matCamera.m33, matCamera.m21, matCamera.m22, matCamera.m23
  
    TV.Clear
    
    'If Inp.IsKeyPressed(TV_KEY_UP) = True Then Camera.MoveRelative ScaleValue(0.01), 0, 0
    'If Inp.IsKeyPressed(TV_KEY_DOWN) = True Then Camera.MoveRelative ScaleValue(-0.01), 0, 0
    'If Inp.IsKeyPressed(TV_KEY_LEFT) = True Then Camera.RotateY TV.TimeElapsed * -6 / 100
    'If Inp.IsKeyPressed(TV_KEY_RIGHT) = True Then Camera.RotateY TV.TimeElapsed * 6 / 100
    'If Inp.IsKeyPressed(TV_KEY_PAGEUP) = True Then Camera.RotateX -0.68
    'If Inp.IsKeyPressed(TV_KEY_PAGEDOWN) = True Then Camera.RotateX 0.68
    'If Inp.IsKeyPressed(TV_KEY_HOME) = True Then Camera.MoveRelative 0, 1, 0
    'If Inp.IsKeyPressed(TV_KEY_END) = True Then Camera.MoveRelative 0, -1, 0
    'If Inp.IsKeyPressed(TV_KEY_F1) = True Then TV.ScreenShot (App.Path + "\shot.bmp")
    'If Inp.IsKeyPressed(TV_KEY_A) = True And RideCar.GetPosition.z > 0 Then GoCar = True
    'If Inp.IsKeyPressed(TV_KEY_SPACE) = True Then Camera.SetRotation 0, 180, 0

    'automation code for VH
    
    If frmSession.optHypnoMachine.value = True Then
        If SectionID = 0 And Camera.GetPosition.z > -125 Then Camera.MoveRelative ScaleValue(0.01), 0, 0: GoTo AfterAuto
        If SectionID = 1 And Camera.GetRotationMatrix.m11 < 0 Then Camera.RotateY 1: GoTo AfterAuto
        'user is now in position
        If SectionID = 2 And Camera.GetPosition.X < -148.5 Then Camera.MoveRelative ScaleValue(-0.005), 0, 0: GoTo AfterAuto
        If SectionID = 3 And HypnoMachineOn = False Then
            LightEngine.EnableLight(1) = False
            LightEngine.EnableLight(2) = False
            LightEngine.EnableLight(3) = False
            LightEngine.EnableLight(4) = False
            HypnoMachineOn = True
            GoTo AfterAuto
        End If
        If SectionID = 4 Then GoTo AfterAuto
        SectionID = SectionID + 1
    End If
    If frmSession.optHypnoCoaster.value = True Then
        If SectionID = 0 And Camera.GetPosition.z > 10 Then Camera.MoveRelative ScaleValue(0.01), 0, 0: GoTo AfterAuto
        If SectionID = 1 And Camera.GetPosition.X < RideCar.GetPosition.X Then Camera.MoveRelative 0, 0, ScaleValue(-0.01): GoTo AfterAuto
        If SectionID = 2 And GoCar = False Then GoCar = True: GoTo AfterAuto
        SectionID = SectionID + 1
    End If
AfterAuto:

    lineend = Camera.GetPosition
    
    LineTest = lineend
 
    If lineend.X > linestart.X Then LineTest.X = lineend.X + 2
    If lineend.X < linestart.X Then LineTest.X = lineend.X - 2
    If lineend.z > linestart.z Then LineTest.z = lineend.z + 2
    If lineend.z < linestart.z Then LineTest.z = lineend.z - 2
 
    'If frmDebug.Check1.Value = 1 And (Room.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or HypnoRoom.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or HypnoDoor.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or HypnoRide.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or RideDoor.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or RideCar.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True) Then
    If Room.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or HypnoRoom.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or HypnoDoor.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or HypnoRide.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or RideDoor.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Or RideCar.Collision(linestart, LineTest, TV_TESTTYPE_ACCURATETESTING) = True Then
        Camera.SetPosition linestart.X, linestart.Y, linestart.z
    Else
        Camera.SetPosition lineend.X, lineend.Y, lineend.z
    End If
    
    If HypnoRoom.Collision(Camera.GetPosition, Vector(Camera.GetPosition.X, Camera.GetPosition.Y - 12, Camera.GetPosition.z), TV_TESTTYPE_ACCURATETESTING) = True Then
        'LightEngine.EnableLight(1) = False
        'LightEngine.EnableLight(2) = False
        'LightEngine.EnableLight(3) = False
        'LightEngine.EnableLight(4) = False
    End If
         
    If HypnoMachineOn = True Then
        Started = True
        If HypnoDoor.GetPosition.Y < 10 Then HypnoDoor.SetPosition HypnoDoor.GetPosition.X, 30, HypnoDoor.GetPosition.z
        HypnoDoor.Enable True
        Timer3.Enabled = True
        Timer1.Enabled = True
        HypnoSpiral.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral2.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral3.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral4.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral5.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral6.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral7.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral8.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral9.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral10.SetMaterial (GetMat("QuickMat2"))
        HypnoSpiral.SetColor RGBA(0, 1, 0, 1)
        Eyes.SetMaterial (GetMat("QuickMat2"))
        Timer2.Enabled = True
        Timer4.Enabled = True
        'HypnoSound.Play
    End If
    
    If GoCar = True Then
        If RideCar.GetPosition.z < -15000 Then
            'If CarSpeed > 0 Then
            '    CarSpeed = (CarSpeed / 1.1) - 0.1
            '    RideCar.MoveRelative -CarSpeed, 0, 0
            '    Camera.SetPosition RideCar.GetPosition.X, RideCar.GetPosition.Y + 10, RideCar.GetPosition.z - 10
            'Else
            '    RideDoor.MoveRelative 0, -0.5, 0
            'End If
            'If RideDoor.GetPosition.Y <= 0 Then GoCar = False
            otherway = True
            Camera.SetRotation 0, 0, 0
            RideCar.SetRotation 0, 180, 0
        End If
        
        If otherway = True And RideCar.GetPosition.z < -5000 Then
            RideCar.MoveRelative -CarSpeed, 0, 0
            Camera.SetPosition RideCar.GetPosition.X, RideCar.GetPosition.Y + 10, RideCar.GetPosition.z + 10
            GoTo SkipMain
        End If
        
        If otherway = True And RideCar.GetPosition.z > -5000 Then
            Camera.SetRotation 0, 180, 0
            RideCar.SetRotation 0, 0, 0
            otherway = False
        End If

        If RideDoor.GetPosition.Y < 27 Then
            RideDoor.MoveRelative 0, 0.5, 0
        Else
            CarSpeed = (CarSpeed * 1.1) + 0.1
            If CarSpeed > 10 Then CarSpeed = 10
            RideCar.MoveRelative -CarSpeed, 0, 0
            Camera.SetPosition RideCar.GetPosition.X, RideCar.GetPosition.Y + 10, RideCar.GetPosition.z - 10
        End If
SkipMain:
    End If

    If Camera.GetPosition.Y < -650 Then
        Camera.SetPosition 12.5, 350, 47.5
        FallRate = 0
    End If

    If GoCar = True Then
        If otherway = False Then
            HypnoRide.RotateZ 5
            HypnoRide2.RotateZ -5
        Else
            HypnoRide.RotateZ -5
            HypnoRide2.RotateZ 5
        End If
    End If
    
    Atmos.Atmosphere_Render
    Scene.RenderAllMeshes
    TV.RenderToScreen
    DoEvents
    
If Quit = True Then
    Timer5.Enabled = False
    isRunning = False
    Call Cleanup
    Exit Sub
End If
End Sub
