Selecting entities with mouse
Blitz3D Forums/Blitz3D Programming/Selecting entities with mouse
| ||
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 |
| ||
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. |
| ||
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 |
| ||
Thanks :) I guess I could have figured a reverse cameraproject would be camerapick. |
| ||
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. |
| ||
uh... bump? |
| ||
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 |
| ||
Hmm it's still not working. Does it matter that I'm manually creating surfaces from vertices? |