Selecting entities with mouse

Blitz3D Forums/Blitz3D Programming/Selecting entities with mouse

syfax(Posted 2003) [#1]
Me again :)

How would I select an entity when the mouse is over it? I assume I do a linepick but the mousex/mousey isn't the same as the 3d x/y. A sort of reverse cameraproject, that converted 2d coordinates into 3d ones, would be nice if it exists.

Thanks is advance


gameproducer(Posted 2003) [#2]
quite simple: you use camerapick and it returns the mesh/whatever id you needed.

then you could loop through your entities and check whether that pickedId matches with one of your entities. after that: you can use other entity information (like name) to display stuff you need.


BlitzSupport(Posted 2003) [#3]
Here ya go...

Graphics3D 640, 480, 0, 2

cam = CreateCamera ()

cube = CreateCube ()
ball = CreateSphere ()

MoveEntity cube, -5, 0, 10
MoveEntity ball, 5, 0, 10

EntityPickMode cube, 3
EntityPickMode ball, 1

Repeat

	entity = CameraPick (cam, MouseX (), MouseY ())
	
	Select entity
		Case cube
			picked$ = "Cube!"
		Case ball
			picked$ = "Ball!"
		Default
			picked$ = "Nothing picked!"
	End Select
	
	UpdateWorld
	RenderWorld
		
	Text 20, 20, picked$
	
	Flip

Until KeyHit (1)

End



syfax(Posted 2003) [#4]
Thanks :)

I guess I could have figured a reverse cameraproject would be camerapick.


syfax(Posted 2003) [#5]
Sighs...

How do I select a surface? There was no help file for Pickedsurface() so I tried:

newentity =CameraPick (camera,MouseX(),MouseY())
surface = PickedSurface()

But that always returns 0.

Sorry for being so slow, God knows what I'd do without this forum.


syfax(Posted 2003) [#6]
uh... bump?


fredborg(Posted 2003) [#7]
You need to set the EntityPickMode to 2, otherwise you won't get any PickedSurface. Be aware that if you pick an entity that does not have any surfaces, ie. a pivot or terrain, the old PickedSurface will not be cleared...

Hope this helps,
Fredborg


syfax(Posted 2003) [#8]
Hmm it's still not working. Does it matter that I'm manually creating surfaces from vertices?