EntityPick example please
Blitz3D Forums/Blitz3D Beginners Area/EntityPick example please
| ||
Would someone mind making an example using EntityPick, LinePick, CameraPick, and EntityPickMode? None of the docs have examples for them, though they all refer to each other for reference!? CameraPick has an example, but it doesn't use the other 3 in it, so I don't understand how it relates. Hope someone here can help :) |
| ||
I don't have examples, but EntityPick, LinePick and CameraPick all fundamentally do the same thing. EntityPick does a line pick from the position of the entity (0,0,0) to infinity in front of the entity (0,0,infinity). LinePick is the same but picks from the x,y,z position to an offset position dx,dy,dz relative to the start point. EntityPickMode chooses whether an entity is picked as an imaginary sphere, imaginary cube, or using the triangles of the mesh. Hope this helps (a little). |
| ||
They're all basically raycasting. It casts a ray from any given point in 3D space to any given point in 3D space, and tells you if it hit anything along the way. If it did, it tells you what it hit and where. |
| ||
Wait wait, I thought entitypick used a sphere, as you can specify the range# of the picking to do. The way you described it's nothing but another linepick in the Z Axis. Is that so? |
| ||
This is a simple example. Basically, if the user clicks the sphere with his\her mouse, a message will be displayed.graphics3d 800,600,0,2 cam=createcamera() s=createsphere() ;main loop while not keyhit(1) setbuffer backbuffer() cls if mousehit(1) then e=camerapick(cam,mousex(),mousey()) if e=s then ;if the selected entity is the sphere... msg=true ;display a message end if end if updateworld renderworld if msg=true then text 0,0,"Ow! That hurt!" end if flip wend |
| ||
Wait wait, I thought entitypick used a sphere, as you can specify the range# of the picking to do. The way you described it's nothing but another linepick in the Z Axis. Is that so? It's up to EntityPickMode. If you set the picking mode to sphere for that specific entity, then it shall use sphere. |
| ||
Wait wait, I thought entitypick used a sphere, as you can specify the range# of the picking to do. The way you described it's nothing but another linepick in the Z Axis. Is that so? It is just another linepick along the local Z axis of the source entity. http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPick&ref=3d_a-z |
| ||
My mistake. You are right: EntityPick does have a range. I've never actually used it, cos I use LinePick for most things (more flexible). Your picking can also have a radius which helps prevent lines 'missing' the target with gaps (and math errors) and the like. |
| ||
Note that increasing the raduis also increases the time taken to do the pick. |
| ||
Hmm, this didn't seem to work: Am I missing something? |
| ||
Yes, you need to set the entitypickmode of the sphere to 1 or 2. Stevie |
| ||
e=CameraPick(camera,MouseX(),MouseY()) Won't work. You need to do the pick: CameraPick(camera,MouseX(),MouseY()) e = PickedEntity() CameraPick simple executes the linepick. Using Pickedx(), pickedy() etc etc (read the manual) you can get data from the pick. If pickedentity() returns 0, nothing has been picked. |
| ||
@ Ross, you're wrong. If you run the example above and apply an entitypickmode to the sphere it works just fine. I guess it makes PickedEntity() somewhat redundant. |
| ||
I tried both and neither work. Is there some assumptive thing I'm supposed to already know about? I thought clicking on the sphere was supposed to make the message appear. |
| ||
As I mentioned in post 11, you need to set the entitypickmode of the sphere. Add this line after the "moveentity sphere ..." line :EntityPickMode sphere, 1 Works just fine here. Stevie |
| ||
Oh okay, thanks for explaining that. I was just putting in the code snippets. |
| ||
The only thing I don't understand now is how to make the last parameter of EntityPickMode work in conjunction with EntityVisible, so cube2 will obscure the ghost cube even though it's behind it. I've got cube2 setup as transparent, but I don't know how to do the rest. |