Lights and Parents

BlitzMax Forums/MiniB3D Module/Lights and Parents

WildStorm(Posted 2007) [#1]
Run this code:

SuperStrict

Import klepto.minib3d
Graphics3D 800,600,32,2


Local lCam:TEntity = CreateCamera()
Local lSky:TMesh = CreateSphere(70)
EntityColor lsky,9,175,255
'ScaleEntity lSky,40,40,40
ScaleEntity lSky,10,10,10
'FlipMesh lSky

Local lSunPivot:TEntity = CreatePivot()
Local lSunLight:TLight = CreateLight(1,lSunPivot)
CreateCube(lsunlight)
'LightRange(lSunLight,50)
'LightColor(lSunLight,255,255,255)
Local lSun:TEntity = CreateSphere(10,lSunPivot)
MoveEntity lSunLight,0,0,38
MoveEntity lSun,0,0,50
'MoveEntity lSunLight,0,0,-50   'This works...but why?!

MoveEntity lCam,0,0,-80


Local wf:Byte
Repeat
	If KeyHit(KEY_W) Then
		wf = not wf
		Wireframe wf
	EndIf
	
	TurnEntity lSunPivot,1,0,0
	'PositionEntity lSunLight,EntityX(lSun,1),EntityY(lSun,1),EntityZ(lSun,1),1
	'PointEntity lSunLight,lSunPivot
	'TurnEntity lSunLight,0,-180,0
	'PointEntity lSunLight,lSun

	UpdateWorld
	RenderWorld
	Flip
Until KeyDown(KEY_ESCAPE)


The cube represents the light. Isn't it strange, that the sphere is lighted from the other side?
If you use CreateLight(2) that works. But, if you scale the sphere to 40,40,40 and flip it and use now the CreateLight(2) inside the Sphere, you won't see anything. Why?!

SuperStrict

Import klepto.minib3d
Graphics3D 800,600,32,2


Local lCam:TEntity = CreateCamera()
Local lSky:TMesh = CreateSphere(70)
EntityColor lsky,9,175,255
ScaleEntity lSky,40,40,40
'ScaleEntity lSky,10,10,10
FlipMesh lSky

Local lSunPivot:TEntity = CreatePivot()
Local lSunLight:TLight = CreateLight(2,lSunPivot)
CreateCube(lsunlight)
'LightRange(lSunLight,50)
'LightColor(lSunLight,255,255,255)
Local lSun:TEntity = CreateSphere(10,lSunPivot)
MoveEntity lSunLight,0,0,38
MoveEntity lSun,0,0,38
'MoveEntity lSunLight,0,0,-50   'This works...but why?!

MoveEntity lCam,0,0,-80


Local wf:Byte
Repeat
	If KeyHit(KEY_W) Then
		wf = not wf
		Wireframe wf
	EndIf
	
	TurnEntity lSunPivot,1,0,0
	'PositionEntity lSunLight,EntityX(lSun,1),EntityY(lSun,1),EntityZ(lSun,1),1
	'PointEntity lSunLight,lSunPivot
	'TurnEntity lSunLight,0,-180,0
	'PointEntity lSunLight,lSun

	UpdateWorld
	RenderWorld
	Flip
Until KeyDown(KEY_ESCAPE)


In Blitz3D that works fine:

Graphics3D 800,600,32,2
SetBuffer(BackBuffer())

cam = CreateCamera()

sky = CreateSphere(60)
ScaleEntity sky,40,40,40
FlipMesh sky
EntityColor sky,9,175,255

MoveEntity cam,0,0,-60

sunpiv=createpivot()
sun=createlight(2,sunpiv)
MoveEntity sun,0,0,38
CreateCube(sun)

Repeat

	TurnEntity sunpiv,1,0,0

	UpdateWorld
	RenderWorld
	Flip
Until KeyDown(1)


Please help!


simonh(Posted 2007) [#2]
The top code listing works the same in MiniB3D and B3D - it's a directional light pointing away from the planet towards the cube. A directional light doesn't have a position, just a direction.

The bottom code listing appears to be due to FlipMesh not correctly flipping the mesh normals. Using UpdateNormals after FlipMesh in the MiniB3D version will make it work correctly.


(tu) sinu(Posted 2007) [#3]
just a quick question, can/should we list coomands we have found in minib3d that don't work as they do in b3d?


WildStorm(Posted 2007) [#4]
Ah okay, thanks for the information!
And to sinu's answer: That would be a great idea!