Hi, I am trying to translate one of the B3D examples (birdie\blobs\main.bb) into a full fledged oop example. I have noticed that all the MiniB3D examples are more or less exactly like the B3D examples.
But I must admit that I have failed ;/ so if someone could please be so kind and tell me what is wrong with my code and why?
I can't seem to add new blobs on the picked surface of a blob. This version now does really weird things. I guess that I fundamentally misunderstand some important thing about oop here ;)
Here's the original example:
and here is my miserable attempt :
Edit: I replaced my code with a former working one, where I had to take the 'par' Parameter from CopyEntity out. This code now matches my last description.
Unfortunately I will be gone for the weekend, so I won't be able to investigate further. Maybe... hopefully... some BMax/MiniB3D Guru will be able to give me some helpful hints :) I WANT this thing going the oo way ;)
But I must admit that I have failed ;/ so if someone could please be so kind and tell me what is wrong with my code and why?
I can't seem to add new blobs on the picked surface of a blob. This version now does really weird things. I guess that I fundamentally misunderstand some important thing about oop here ;)
Here's the original example:
; ; Camera Pick and parenting entities ; dave@... ; David Bird(Birdie) ; Graphics3D 1024,768,32,2 SetBuffer BackBuffer() cam=CreateCamera() PositionEntity cam,0,0,-6 light=CreateLight() TurnEntity light,45,45,0 Type blob Field ent ;entity eg blob Field x#,y#,z# ;rotation End Type Global sp=CreateSphere(5) EntityPickMode sp,2 HideEntity sp ;Stage pivot stage=CreatePivot() ;Add the First Blob the the scene Add_Blob(stage,0,0,0) While Not KeyDown(1) xm=MouseX() ym=MouseY() ; Left Click the add a blob If MouseHit(1) Then ent=CameraPick(cam,xm,ym) If ent<>0 Then PickedEntity Add_Blob(ent,PickedX(),PickedY(),PickedZ()) End If End If ;Spin the stage around If MouseDown(2) Then TurnEntity stage,Float(MouseXSpeed()/10),0,Float(MouseYSpeed()/10) MoveMouse 320,200 End If If KeyHit(57) Then f=1-f ;Update all the blobs If Not frozen If f=0 Then Update_Blobs() ;Update the world and render UpdateWorld RenderWorld ;Draw the cursor Color Rand(100,255),0,0 Line xm-3,ym,xm+3,ym Line xm,ym-3,xm,ym+3 Color 255,255,255 Text 0,0,"Left Click the add a blob. Right Click n Hold to Spin the stage." Text 0,15,"Last entity Picked:"+ent+" PX:"+PickedX()+" PY:"+PickedY()+" PZ:"+PickedZ() If f=0 Then a$="Running." Else a$="Frozen" Text 0,30,"Press Space the Freeze rotation:"+a$ Text 0,45,"dave@..." Flip Wend EndGraphics End Function Update_Blobs() For a.blob=Each blob TurnEntity a\ent,a\x,a\y,a\z Next End Function Function Add_Blob(par,x#,y#,z#) a.blob=New blob a\ent=CopyEntity(sp,par) PositionEntity a\ent,x,y,z,True EntityColor a\ent,Rand(100,255),Rand(100,255),Rand(100,255) s#=Rnd(.8,1) ScaleEntity a\ent,s,s,s a\x=Rnd(-1,1) a\y=Rnd(-1,1) a\z=0 End Function
and here is my miserable attempt :
'************************************************************************************************** ' 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) DebugLog"x: " + String(Self.x) DebugLog"par: " + par.toString() PositionEntity ent,Self.x,Self.y,Self.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) ENTITYPICKMODE sp,2 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
Edit: I replaced my code with a former working one, where I had to take the 'par' Parameter from CopyEntity out. This code now matches my last description.
Unfortunately I will be gone for the weekend, so I won't be able to investigate further. Maybe... hopefully... some BMax/MiniB3D Guru will be able to give me some helpful hints :) I WANT this thing going the oo way ;)