Light positions reported correctly?

BlitzMax Forums/MiniB3D Module/Light positions reported correctly?

LT(Posted 2007) [#1]
While playing with shaders, I noticed that light positions seem to not be working correctly. To test, I create a sphere and parent it to the light so that I can always see its position. The light is parented to a pivot at the origin and I just turn that pivot on every frame. The effect of the light on the cylinder in the middle is on the opposite side. What the...?

If I'm crazy or just doing something stupid, please let me know!

Btw, does anyone know how to hide the pointer? HidePointer is not supported in MiniB3D.


SuperStrict

Framework BRL.FileSystem
Import "../minib3d.bmx"
'Import klepto.minib3d


Local width:Int = 1024, height:Int = 768
Local depth:Int = 32, mode:Int = 2


Graphics3D width, height, depth, mode


' set environment
AmbientLight(0,0,(0.2 * 255))
'HidePointer()


' create camera
Local cam:TCamera = CreateCamera()
PositionEntity cam, 0, 10, -50
CameraRange( cam, .1, 200000 )
SetCameraFOV( cam, 72 )


' create pivot point
Local piv:TPivot = CreatePivot()

' create light
Local light:TLight = CreateLight(0)
EntityParent light, piv
light.LightColor( 255, 55, 55 )

' create mesh for light
Local LDummy:TMesh = CreateSphere( 16, light )
ScaleEntity( LDummy, 10, 10, 10 )

' moving light and mesh should follow
PositionEntity( light, 0, -100, 155 )


' create cylinder
Local ent:TMesh = CreateCylinder( 12 )
ScaleEntity( ent, 20, 100, 20 )

' used by camera code
Local mxs# = 0
Local mys# = 0
Local move# = 5.0
MouseXSpeed() ' flush
MouseYSpeed() ' flush

' used by fps code
Local old_ms:Int = MilliSecs()
Local renders:Int
Local fps:Int = 10
Local anim_time:Float = 0


' main loop
While Not KeyDown( KEY_ESCAPE )		

	' mouse look
	mxs# = mxs# + ( MouseXSpeed() / 5.0 )
	mys# = mys# + ( MouseYSpeed() / 5.0 )
	RotateEntity cam, mys#, -mxs#, 0
	MoveMouse width / 2, height / 2
	MouseXSpeed() ' flush
	MouseYSpeed() ' flush

	' move camera forwards/backwards/left/right with cursor keys
	If KeyDown( KEY_UP ) = True Then MoveEntity cam, 0, 0, move#			' move camera forward
	If KeyDown( KEY_DOWN ) = True Then MoveEntity cam, 0, 0, -move#			' move camera back

	If KeyDown( KEY_LEFT ) = True Then MoveEntity cam, -move#, 0, 0			' move camera left
	If KeyDown( KEY_RIGHT ) = True Then MoveEntity cam , move# , 0 , 0		' move camera right

	TurnEntity piv, 0, -0.5, 0

	UpdateWorld
	RenderWorld
	renders = renders + 1

	' calculate fps
	If MilliSecs() - old_ms >= 1000
		old_ms=MilliSecs()
		fps=renders
		renders=0
	EndIf
	
	
	Text 0, 20, "FPS: " + String( fps )
	Text 0, 40, "Light : " + EntityX( Light, True ) + " : " + EntityY( Light, True ) + " : " + EntityZ( Light, True ) 

	Flip( True )

Wend

Function SetCameraFOV ( cam:TCamera, FOV:Float )
   CameraZoom cam, 1.0 / Tan( FOV# / 2.0 )
End Function



Sveinung(Posted 2007) [#2]
Just add 'PointEntity(light,piv)' after you turn the piv.

HideMouse()

Sveinung


simonh(Posted 2007) [#3]
It's because you've created a directional light which is pointing away from the sphere - creating a spot light (type 2) will produce the effect you're expecting.


LT(Posted 2007) [#4]
Duh! And 0 isn't even an option! I took the code from the klepto shader example and it didn't occur to me that it wasn't a point light. No wonder!

Thanks, Simon and Sveinung.