Parenting

BlitzMax Modules Forums/MiniB3D/Parenting

Hi there,

could someone experienced with B3D tell me if the following code is

a) plain wrong
b) a bug with miniB3D

Strict

Import "../MiniB3D.bmx"

Type TSun
Field PIVOT:TPivot
Field MESH:TMesh
Field LIGHT:TLight

Function Create:TSun()
	Local tmp:TSun = New TSun
	tmp.PIVOT = CreatePivot()
	tmp.MESH = CreateSphere(8,tmp.PIVOT)
	tmp.LIGHT = CreateLight(1,tmp.PIVOT)
	tmp.LIGHT.LightColor(255,20,20)	
	Return tmp
End Function
End Type

Local width=640,height=480,depth=16,mode=0

Graphics3D width,height,depth,mode

HideMouse()

Local cam:TCamera=CreateCamera()
cam.PositionEntity(0,0,-10)

Local Sun:TSun = TSun.Create()
Sun.MESH.ScaleEntity(3,3,3)
Sun.PIVOT.PositionEntity(0,0,20)

While Not KeyDown(KEY_ESCAPE)	
	
	RenderWorld
	
	Text 0,0,"Light: "+Sun.LIGHT.px+", "+Sun.LIGHT.py+", "+Sun.LIGHT.pz
	Text 0,20,"Mesh : "+Sun.MESH.px+ ", "+Sun.MESH.py+ ", "+Sun.MESH.pz
	Text 0,40,"Pivot: "+Sun.PIVOT.px+", "+Sun.PIVOT.py+", "+Sun.PIVOT.pz	

	Flip	
Wend


This never moves the Children to where the parent(pivot) is.

a) It doesnt Look wrong. Will run it later at home.

hmmm.

this works:

Import "../MiniB3D.bmx"

Strict

Local width=1024,height=768,depth=32,mode=0 ; Graphics3D width,height,depth,mode

Local cam:TCamera=CreateCamera()

PositionEntity cam,0,0,-20

AmbientLight 200,200,200

Local pivot:Tpivot = CreatePivot()
Local Ball:TMesh=CreateSphere(8,pivot)

Local rad#=5
Local ang#
Repeat
	
	ang#:+2
	
		PositionEntity(pivot,Sin(ang)*rad,Cos(ang)*rad,0)
	
	
	RenderWorld
	Flip

Until KeyDown(KEY_ESCAPE)






This never moves the Children to where the parent(pivot) is.

It does. You're printing out the values of px, py, pz, which a) you shouldn't really do, you should use EntityX/Y/Z instead, and b) px, py, pz are the local positional values, meaning the children are positioned 0 units away fromt the parent.

Use EntityX/Y/Z(True) to get global co-ordinate values.

Well that just explained a number of oddities i have been experiencing.
Thanks alot!