superstrict oop example

BlitzMax Modules Forums/MiniB3D/superstrict oop example

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

FINALLY found the problem! And it's a devious little bug within MiniB3D itself.

What's happening is that when you pick the first sphere, you are in fact picking something else - the hidden sp entity that is created at the start.

Because it is hidden, it really shouldn't be pickable - but this has been overlooked in MiniB3D. So then all further new spheres are hidden too!

The ScaleEntity thing really threw me off the scent - the reason that removing ScaleEntity works is because with it, the first sphere is always smaller than the sp sphere, so you always pick sp.

Apologies for the hair-pulling this may have caused you! At least I've rooted a bug out from it.

Here's the fully working version, with the entity types moved around so that sp isn't pickable.

'**************************************************************************************************
' This program was written with BLIde
' Application:
' Author:
' License:
'**************************************************************************************************

Import "../MiniB3D.bmx"

SuperStrict

Const WIDTH:Int = 800, HEIGHT:Int = 600, DEPTH:Int = 32, MODE:Int = 2

Graphics3D WIDTH, HEIGHT, DEPTH, MODE

Type TBlob
	
	Global Anzahl:Int
	Global blobs:TList = CreateList()
	Field ent:TEntity
	Field x:Float, y:Float, z:Float

	Method New()
		Anzahl :+ 1
	End Method

	Method addBlob(sp:TEntity,par:TEntity, x:Float, y:Float, z:Float)
		Local blob:TBlob = New TBlob
		Local ent:TEntity = CopyEntity(sp,par)
		ENTITYPICKMODE ent,2
		DebugLog"x: " + String(Self.x)
		DebugLog"par: " + par.toString()
		PositionEntity ent,x,y,z,True
		EntityColor ent,Rand(100,255),Rand(100,255),Rand(100,255)
		Local s:Float = Rnd(0.8,1)
		ScaleEntity ent,s,s,s
		Self.x = Rnd(-1,1)
		DebugLog"x2: " + String(Self.x)
		Self.y = Rnd(-1,1)
		Self.z = 0
		blobs.AddLast(ent) 
	End Method
	Method updateBlob()
		Local content:TEntity
		For content = EachIn blobs
			TurnEntity content, Self.x, Self.y, Self.z
		Next		
	End Method
	
End Type

Global cam:TCamera = CreateCamera()
PositionEntity cam,0,0,-6

Local lit:TLight = CreateLight()
TurnEntity lit,45,45,0


Global sp:TMesh = CreateSphere(5)
HideEntity sp	
Global stage:TPivot = CreatePivot()

Local blob:TBlob = New TBlob
blob.addBlob(sp,stage,0,0,0)

While Not KeyDown(KEY_ESCAPE)
	Cls
	Local xm:Float = MouseX()
	Local ym:Float = MouseY()
	'Left Click to add a blob
	If MouseHit(1)
		Local sel:TEntity = CAMERAPICK(cam,xm,ym)
		If sel <> Null
			sel = PICKEDENTITY()
			DebugLog "Picked"
			DebugLog "PickedX(): "+String(PICKEDX())
			DebugLog "PickedY(): "+String(PickedY())
			DebugLog "PickedZ(): "+String(PickedZ())
			DebugLog "PickedEntity(): "+ PICKEDENTITY().toString()
			DebugLog "SelectedEntity(): "+ sel.toString()
			DebugLog "Anzahl: " + TBlob.Anzahl
			blob.addBlob(sp,sel,PICKEDX(),PICKEDY(),PICKEDZ())
		Else 
			DebugLog "Nada"
		End If
	End If

	If MouseDown(2)
		TurnEntity stage, Float(MouseXSpeed()/10), Float(MouseYSpeed()/10),0
	End If
	Local f:Int
	If KeyHit(57) Then f = 1-f
	If f = 0 Then blob.updateBlob()
	
	UpdateWorld
	RenderWorld

	Flip
Wend