I need help with the lights, in particular with point and spot lights in TV6.5.
I am working with VB2008 and I got some strange behaviour like the following:
-To see the light I must have a “radius” very big, for example 50 even if the light is only few units from the land
-The light attenuation looks like working the other way round than expected, in other words when you get closer to the land the light attenuates more.
Also more strange behaviour if you try with VB6 or with TV6.3
Is it a bug?
Try this:
Public Class Form1
Private TV As TVEngine
Private Scene As TVScene
Private TF As TVTextureFactory
Private Materialfactory As TVMaterialFactory
Private Lights As TVLightEngine
Private LightMark As TVMesh
Private IDLight As Long
Private Cam As TVCamera
Private GL As TVGlobals
Private bLoop As Boolean
Private land As TVLandscape
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
bLoop = False
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TV = New TVEngine
Scene = New TVScene
TF = New TVTextureFactory
Cam = New TVCamera
Materialfactory = New TVMaterialFactory
Lights = New TVLightEngine
GL = New TVGlobals
land = New TVLandscape
TV.SetDebugFile(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\debugfile.txt") ' Set the debug file to the same folder as the program itself. This is very useful, Sylvain is good at catching common mistakes and informing you that you've made them in this files log.
' Instanciate the form
TV.Init3DWindowed(Me.Handle, True) ' We want to initialize on our windows handle and we have hardware transform and lighting.
' material for the land , to be simple: only diffuse
Dim matLand As Long
matLand = Materialfactory.CreateMaterial("matLand")
Materialfactory.SetEmissive(matLand, 0.0#, 0.0#, 0.0#, 1)
Materialfactory.SetDiffuse(matLand, 1, 1.0#, 1.0#, 1)
Materialfactory.SetAmbient(matLand, 0, 0, 0, 1)
' landscape, something to receive the light
land = Scene.CreateLandscape
land.CreateEmptyTerrain(CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 100, 100, -50, 0, -50)
land.SetMaterial(matLand)
land.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED)
Dim phi, theta, radius As Single
phi = 20
theta = 20
radius = 50 ' try to put something smaller, like 10 and see...
' Create a point light
IDLight = Lights.CreateSpotLight(GL.Vector(0, 1, 0), GL.Vector(0, -1, 0), 1, 1, 1, radius, phi, theta, "Lamp", 1)
' IDLight = Lights.CreatePointLight(GL.Vector(0, 6, 0), 1, 1, 1, 200, "Lamp", 0)
Lights.EnableLight(IDLight, True)
Lights.SetLightAttenuation(IDLight, 1, 0.005, 0) ' try to comment this out
LightMark = Scene.CreateMeshBuilder()
LightMark.CreateSphere(0.25)
LightMark.SetPosition(0, 5, 0)
Cam.SetCamera(60, 20, 0, 0, 0, 0)
Cam.SetViewFrustum(45, 2500, 1)
bLoop = True
Me.Show()
Dim y As Single
Dim fTime As Single
While bLoop
fTime = TV.AccurateTimeElapsed()
' rendering
TV.Clear()
land.Render()
Scene.RenderAllMeshes()
TV.RenderToScreen()
' UpdateScene changing the light height
y = 20 * Math.Sin(TV.TickCount / 1000) + 20
Me.Text = y.ToString ' window caption
LightMark.SetPosition(0, y, 0)
Lights.SetLightPosition(IDLight, 0, y, 0)
Application.DoEvents()
End While
TV.ReleaseAll()
TV = Nothing
End
End Sub
End Class
Thanks
Fabio