EntityBox and ScaleEntity

Blitz3D Forums/Blitz3D Beginners Area/EntityBox and ScaleEntity

I think the reason for that is that collisions are allways sphere to something. So, the 'emitting' entity is still represented by a sphere, and the 'receiving' entities are boxes. I changed the code a bit to make the EntityRadius visible:
Graphics3D 1024,768,32,2
SetBuffer BackBuffer()
Color 255,255,255
SeedRnd MilliSecs()

Local trainsel=-1
Local last_chkpt=MilliSecs()
Local framecount
Local fps
Local newtrain=0
Local newtype=0
;Local mouseimage=LoadImage("mouse.bmp")
Local type_camera=1
Local type_ground=2
Local type_train=3

Dim train(2)

;MaskImage mouseimage,192,192,255
Collisions type_camera,type_ground,1,2
Collisions type_train,type_train,1,2

; setup entities
light=CreateLight()
camera=CreateCamera()
PositionEntity camera, 0,6,-16
RotateEntity camera,15.0,0,0
EntityType camera,type_camera
ground=CreatePlane()
EntityColor ground, 34,53,123
EntityType ground,type_ground

For k=0 To 2
	train(k)=CreateCube()
	ScaleEntity train(k),1,4,1
	EntityBox train(k), -1,-4,-1,2,8,2
	PreviewEntityRadius train(k),2,8
	PositionEntity train(k),k*5,1,Rand(30)
	EntityPickMode train(k),3
	EntityType train(k),type_train
Next

While Not KeyDown( 1 )
	; check for selection
	If MouseHit(1) Then
		For k=0 To 2
			EntityColor train(k),255,255,255
		Next
		trainsel=-1
		newtype=0
		newtrain=CameraPick(camera,MouseX(),MouseY())
		If newtrain<>0 Then
			newtype=GetEntityType(newtrain)
			If newtype=type_train Then
				For k=0 To 2
					If train(k)=newtrain Then
						trainsel=k
						Exit
					EndIf
				Next
				EntityColor PickedEntity(),255,255,0
			EndIf
		EndIf
	EndIf
	; check for move/rotate
	If KeyDown(42) Then ; LEFTSHIFT
		If KeyDown(200) Then
			MoveEntity camera,0,0,0.1
		ElseIf KeyDown(208) Then
			MoveEntity camera,0,0,-0.1
		EndIf
	ElseIf KeyDown(29) Then ; LEFT CTRL
		If KeyDown(200) Then
			MoveEntity camera,0,0.1,0
		ElseIf KeyDown(208) Then
			MoveEntity camera,0,-0.1,0
		EndIf
	ElseIf trainsel>-1 Then
		If KeyDown(200) Then
			If KeyDown(203) Then
				TurnEntity train(trainsel),0,1.0,0
			EndIf
			If KeyDown(205) Then
				TurnEntity train(trainsel),0,-1.0,0
			EndIf
			MoveEntity train(trainsel),0,0,-0.1
		EndIf
	EndIf
	; update screen
	UpdateWorld
	RenderWorld
	framecount=framecount+1
	If MilliSecs()-last_chkpt>=1000
		last_chkpt=MilliSecs()
		fps=framecount
		framecount=0
	EndIf
	Text 0,0,"FPS: "+fps
;	DrawImage mouseimage,MouseX(),MouseY()
	Flip
Wend

For k=0 To 2
	FreeEntity train(k)
Next
FreeImage mouseimage
End


Function PreviewEntityRadius(mesh, xz_radius#, y_radius#)
	EntityRadius mesh, xz_radius#, y_radius#
	ok = FindChild(mesh, "COLLISION_SPHERE")
	If ok <> 0 Then FreeEntity ok
	sphere = CreateSphere()
	ScaleEntity sphere, xz_radius#, y_radius#, xz_radius#
	EntityAlpha sphere, 0.1
	EntityParent sphere, mesh
	RotateEntity sphere, 0, 0, 0, 1
End Function