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 :)
EntityPick example please
Blitz3D Forums/Blitz3D Beginners Area/EntityPick example please 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).
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?
Graphics3D 640,480,32,2 SetBuffer BackBuffer() camera=CreateCamera() light=CreateLight() sphere=CreateSphere() MoveEntity sphere,0,0,10 While Not KeyHit(1) Cls If MouseHit(1) e=CameraPick(camera,MouseX(),MouseY()) ; If the selected entity is the sphere, display a message. If e=sphere Then message=1 EndIf EndIf UpdateWorld RenderWorld If message=1 Then Text 0,0,"Ow! That hurt!" EndIf Flip Wend End
Am I missing something?
Yes, you need to set the entitypickmode of the sphere to 1 or 2.
Stevie
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 :
Works just fine here.
Stevie
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.
Graphics3D 640,480,32,2 SetBuffer BackBuffer() camera=CreateCamera() MoveEntity camera,0,1,-10 TurnEntity camera,0,0,0 CameraClsColor camera,127,234,255 ground=CreateCube() ScaleEntity ground,100,.1,100 EntityColor ground,85,160,79 cube1=CreateCube() MoveEntity cube1,-1,1,0 EntityPickMode cube1,1,0 cube2=CreateCube() MoveEntity cube2,0,1,-2 EntityPickMode cube2,2,1 ghostcube=CreateCube() MoveEntity ghostcube,1,1,-4 EntityPickMode ghostcube,2,0 EntityAlpha ghostcube,.5 While Not KeyHit(1) Cls If MouseHit(1) entitylastclicked=CameraPick(camera,MouseX(),MouseY()) If entitylastclicked=cube1 message=1 If entitylastclicked=cube2 message=2 If entitylastclicked=ghostcube message=3 If entitylastclicked=0 message=0 EndIf UpdateWorld RenderWorld Color 0,0,0 Text 0,0,"Click the cubes in left to right succession." If message=1 Text 0,15,"This cube is set as a sphere, so you can't touch it's corners." If message=2 Text 0,15,"This one's set as a mesh, so you can. Setting it as a box would work too." If message=3 Text 0,15,"This one is supposed to be partly obscured, so you can click any part of cube2." If message=0 Text 0,15,"" Flip Wend End