VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "WorldClass"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Dim LookAt As D3DVECTOR, Loc As D3DVECTOR, Up As D3DVECTOR
Public Sub RotateCamera(X As Single, Y As Single, Z As Single)
    LookAt = RotateVector(LookAt, X, Y, Z)
    D3DXMatrixLookAtLH ViewMatrix, Loc, LookAt, Up
    Device.SetTransform D3DTS_VIEW, ViewMatrix
End Sub

Public Property Let BackgroundColor(ByVal vData As Long)
    Background = vData
End Property
Public Property Get BackgroundColor() As Long
    BackgroundColor = Background
End Property
Public Sub Rotate(RotationVector As D3DVECTOR)
    World_RotX = RotationVector.X: World_RotY = RotationVector.Y: World_RotZ = RotationVector.Z
End Sub

Public Sub RotateXYZ(X As Single, Y As Single, Z As Single)
    World_RotX = Z: World_RotY = Y: World_RotZ = Z
End Sub
Public Sub AddLight(LightType As CONST_D3DLIGHTTYPE, X As Single, Y As Single, Z As Single, Optional Direction_X As Single = 0, Optional Direction_Y As Single = 0, Optional Direction_Z As Single = 0, Optional Attenuation_Constant As Single = 0, Optional Linear As Single = 0, Optional Attenuation_Cubic As Single = 0, Optional Ambient_Red = 0, Optional Ambient_Green = 0, Optional Ambient_Blue = 0, Optional Diffuse_Red = 0, Optional Diffuse_Green = 0, Optional Diffuse_Blue = 0, Optional Specular_Red = 0, Optional Specular_Green = 0, Optional Specular_Blue = 0, Optional Falloff As Single = 0, Optional Phi As Single = 0, Optional Range As Single = 100, Optional Theta As Single = 0)
'All lights require a color - any diffuse, specular, or ambient or cobmination will do

'Directional lights just require a Direction
'Point Lights require:  Position, Range, and any sort or combination of attenuation

'Spot lights require a position, range, direction -
'Theta (area were there is full ilumination in degrees), Phi -
'(area were the light breaks off in degrees also), and attenuation
Static LightNum As Byte
Dim TempLight As D3DLIGHT8
LightNum = LightNum + 1
    If LightType = D3DLIGHT_DIRECTIONAL Then
        With TempLight
            With .Ambient
                .r = Ambient_Red
                .g = Ambient_Green
                .b = Ambient_Blue
            End With
            With .diffuse
                .b = Diffuse_Blue
                .g = Diffuse_Green
                .r = Diffuse_Red
            End With
            With .specular
                .r = Specular_Red
                .g = Specular_Green
                .b = Specular_Blue
            End With
            .Type = D3DLIGHT_DIRECTIONAL
        End With
        TempLight.Direction = MakeVector(Direction_X, Direction_Y, Direction_Z)
        Device.SetLight LightNum, TempLight
        Device.LightEnable LightNum, True
        Exit Sub
    End If
    
    If LightType = D3DLIGHT_POINT Then
            
        With TempLight
            With .Ambient
                .r = Ambient_Red
                .g = Ambient_Green
                .b = Ambient_Blue
            End With
            With .diffuse
                .b = Diffuse_Blue
                .g = Diffuse_Green
                .r = Diffuse_Red
            End With
            With .specular
                .r = Specular_Red
                .g = Specular_Green
                .b = Specular_Blue
            End With
            .position = MakeVector(X, Y, Z)
            .Range = Range
            .Attenuation0 = Attenuation_Constant
            .Attenuation1 = Linear
            .Attenuation2 = Attenuation_Cubic
            .Type = D3DLIGHT_POINT
        End With
        Device.SetLight LightNum, TempLight
        Device.LightEnable LightNum, True
        Exit Sub
    End If
    
    If LightType = D3DLIGHT_SPOT Then
        With TempLight
            With .Ambient
                .r = Ambient_Red
                .g = Ambient_Green
                .b = Ambient_Blue
            End With
            With .diffuse
                .b = Diffuse_Blue
                .g = Diffuse_Green
                .r = Diffuse_Red
            End With
            With .specular
                .r = Specular_Red
                .g = Specular_Green
                .b = Specular_Blue
            End With
            .position = MakeVector(X, Y, Z)
            .Range = Range
            .Direction = MakeVector(Direction_X, Direction_Y, Direction_Z)
            .Theta = Theta * Rad
            .Phi = Phi * Rad
            .Attenuation0 = Attenuation_Constant
            .Attenuation1 = Linear
            .Attenuation2 = Attenuation_Cubic
            .Type = D3DLIGHT_SPOT
        End With
        Device.SetLight LightNum, TempLight
        Device.LightEnable LightNum, True
        Exit Sub
    End If
End Sub
Public Sub SetCamera(Location_X As Single, Location_Y As Single, Location_Z As Single, LookAt_X As Single, LookAt_Y As Single, LookAt_z As Single, Optional Up_X As Single = 0, Optional Up_Y As Single = 1, Optional Up_Z As Single = 0)
    
    With Loc
        .X = Location_X
        .Y = Location_Y
        .Z = Location_Z
    End With
    
    With LookAt
        .X = LookAt_X
        .Y = LookAt_Y
        .Z = LookAt_z
    End With
    
    With Up
        .X = Up_X
        .Y = Up_Y
        .Z = Up_Z
    End With
    
    
    D3DXMatrixLookAtLH ViewMatrix, Loc, LookAt, Up
    Device.SetTransform D3DTS_VIEW, ViewMatrix

End Sub
Public Sub SetTextureFilterMode(State As TexFilterMode, FilteringType As CONST_D3DTEXTURESTAGESTATETYPE, Optional Layer As Long = 0)
    Device.SetTextureStageState Layer, FilteringType, State
    'Device.SetTextureStageState 0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR
End Sub




