PickedEntity doesn't work for me

BlitzMax Modules Forums/MiniB3D/PickedEntity doesn't work for me

DebugLog "PickedEntity(): "+String(PICKEDENTITY())


I looked in the MiniB3D.bmx if it was defined, it is, but it doesn't work in any of the examples. Any ideas?

pickedentity returns the entity that was picked via linepick,campick, etc.

you need to set those.

there is a picking example in the minib3d examples folder

?? ... ?? I actually tried it with the samples, but all the entries are marked quoted, and when unquoted they give an error message. Maybe I have to cast them before?

Edit:
Actually...
DebugLog "PickedEntity(): "+ PICKEDENTITY().toString()
seems to do the trick.

try this:


Import "MiniB3D.bmx"

Strict

Local width=1024,height=768,depth=16,mode=1

Graphics3D width,height,depth,mode

Local cam:TCamera=CreateCamera()
PositionEntity cam,0,5,0

Local light:TLight=CreateLight()
RotateEntity light,45,0,0

Local marker:TMesh=CreateSphere()
ScaleEntity marker,0.2,0.2,0.2
EntityColor marker,255,0,0

Local mesh:TMesh=Createcube()
Local MeshArray:Tmesh[10000]
Local size:Int = 16
Local z:Int
For Local mm:Int = 0 To size
	For Local x:Int = 0 To size
	
			mesharray[x] = copymesh(mesh)
			EntityPickMode mesharray[x],2
			EntityColor mesharray[x],Rnd(0,255),Rnd(0,150),100+mm

			PositionEntity mesharray[x] ,(-size/2)*4+x*4,0,(-size/2)*4+z*4
			mesharray[x].MeshCullRadius(0.75)

	Next
	z:+1
Next


' used by camera code
Local mxs#=0
Local mys#=0
Local move#=0.5
MouseXSpeed() ' flush
MouseYSpeed() ' flush

' used by fps code
Local old_ms=MilliSecs()
Local renders
Local fps

While Not KeyDown(KEY_ESCAPE)		

	If KeyHit(KEY_ENTER) Then DebugStop

	'' control camera
	
	' mouse look
	
	mxs#=mxs#+(MouseXSpeed()/5.0)
	mys#=mys#+(MouseYSpeed()/5.0)

	RotateEntity cam,mys#,-mxs#,0

	If KeyDown(KEY_SPACE)=False
		MoveMouse width/2,height/2
		MouseXSpeed() ' flush
		MouseYSpeed() ' flush
	EndIf

	' move camera forwards/backwards/left/right with cursor keys
	
	If KeyDown(KEY_W) Or KeyDown(KEY_UP)=True Then MoveEntity cam,0,0,move# ' move camera forward
	If KeyDown(KEY_S) Or KeyDown(KEY_DOWN)=True Then MoveEntity cam,0,0,-move# ' move camera back

	If KeyDown(KEY_A) Or KeyDown(KEY_LEFT)=True Then MoveEntity cam,-move#,0,0 ' move camera left
	If KeyDown(KEY_D) Or KeyDown(KEY_RIGHT)=True Then MoveEntity cam,move#,0,0 ' move camera right
	
	''
	
	'TurnEntity mesh,0,1,0

	' if mousehit then perform camerapick
	If MouseDown(1)
	
		Local pick:TEntity=CameraPick(cam,MouseX(),MouseY())
		
		
		If pick<>Null
			DebugLog "Picked!"
			DebugLog "PickedX(): "+String(PickedX())
			DebugLog "PickedY(): "+String(PickedY())
			DebugLog "PickedZ(): "+String(PickedZ())
			DebugLog "PickedNX(): "+String(PickedNX())
			DebugLog "PickedNY(): "+String(PickedNY())
			DebugLog "PickedNZ(): "+String(PickedNZ())
			DebugLog "PickedTime(): "+String(PickedTime())
			DebugLog "PickedEntity(): "+PickedEntity().tostring()
			DebugLog "PickedSurface(): "+PickedSurface().tostring()
			DebugLog "PickedTriangle(): "+PickedTriangle()
			EntityColor PickedEntity(),255,255,0
			PositionEntity marker,PickedX(),PickedY(),PickedZ()
		Else
			DebugLog "Not Picked"
		EndIf
		
	EndIf

	RenderWorld
	renders=renders+1

	' calculate fps
	If MilliSecs()-old_ms>=1000
		old_ms=MilliSecs()
		fps=renders
		renders=0
	EndIf
	
	DebugText 0,0,"FPS: "+String(fps)

	Flip

Wend
End


Function CreatePlane:TMesh(parent_ent:TEntity=Null,Segments:Int=1)
	
		Local mesh:TMesh=TMesh.CreateMesh(parent_ent)
	
		Local surf:TSurface=mesh.CreateSurface()
			
		surf.AddVertex(-1.0,-1.0,-1.0)
		surf.AddVertex(-1.0, 1.0,-1.0)
		surf.AddVertex( 1.0, 1.0,-1.0)
		surf.AddVertex( 1.0,-1.0,-1.0)
		
		surf.VertexNormal(0,0.0,0.0,-1.0)
		
		surf.VertexTexCoords(0,0.0,1.0)
		
				
		surf.AddTriangle(0,1,2)
		surf.AddTriangle(0,2,3)
		

		Return mesh
	
	End Function



I know my english isn't the best, because I have the impression we are talking about different things.

The xxxxx.toString() did what I wanted (see my last post), no problems anymore! Your example is surely very kind, but I don't get your point? But thanks anyhow for your kind help!

The communication problem stemmed from you describing your problem as "doesn't work". In the future, please describe specifically what behavior you want to see and then describe what you are currently seeing. That will keep the thread on track.

Well if you have a look at all the MiniB3D examples you will see that once you unquote the above mentioned line you will get an compiler error, thus it doesn't work ;) By using the method toString() instead of String(PickedEntity) it 'works'.

But I will try to be more specific in the future.

it works until you unquote it. you will find alot of examples of commented code that remains in the final versions. it is part of the coding process.


anyway, here is some more detail

Function PickedEntity:TEntity()
		Return picked_ent
	End Function
	
	Function PickedSurface:TSurface()
		Return picked_surface
	End Function
	
	Function PickedTriangle()
		Return picked_triangle
	End Function



PickedEntity() returns a TEntity handle
PickedSurface() returns a TSurface handle
PickedTriangle() returns an int (i think)

Thanks bradford6, I'm new to oop, new to BMax and new to MiniB3D ;) In reality you always think you understood what you have read until you actually use it in practice ;) But I have a small project in mind, so I'm really motivated, but I must always understand, not simply copy&Paste. It would have been nice if simonh would have coded all with superstrict on :)