EntityInView.bb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ; EntityInView Example
  2. ; --------------------
  3. Graphics3D 640,480
  4. SetBuffer BackBuffer()
  5. camera=CreateCamera()
  6. PositionEntity camera,0,2,-10
  7. light=CreateLight()
  8. RotateEntity light,90,0,0
  9. plane=CreatePlane()
  10. ground_tex=LoadTexture("media/Chorme-2.bmp")
  11. EntityTexture plane,ground_tex
  12. cube=CreateCube()
  13. cube_tex=LoadTexture("media/b3dlogo.jpg")
  14. EntityTexture cube,cube_tex
  15. PositionEntity cube,0,1,0
  16. While Not KeyDown( 1 )
  17. If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0
  18. If KeyDown( 203 )=True Then TurnEntity camera,0,1,0
  19. If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05
  20. If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05
  21. ; Use camera project to get 2D coordinates from 3D coordinates of cube
  22. CameraProject(camera,EntityX(cube),EntityY(cube),EntityZ(cube))
  23. RenderWorld
  24. ; If cube is in view then draw text, if not then draw nothing otherwise text will be drawn at 0,0
  25. If EntityInView(cube,camera)=True
  26. ; Use ProjectedX() and ProjectedY() to get 2D coordinates from when CameraProject was used.
  27. ; Use these coordinates to draw text at a 2D position, on top of a 3D scene.
  28. Text ProjectedX#(),ProjectedY#(),"Cube"
  29. EndIf
  30. Text 0,0,"Use cursor keys to move about"
  31. Text 0,20,"ProjectedX: "+ProjectedX#()
  32. Text 0,40,"ProjectedY: "+ProjectedY#()
  33. Text 0,60,"ProjectedZ: "+ProjectedZ#()
  34. Text 0,80,"EntityInView: "+EntityInView(cube,camera)
  35. Flip
  36. Wend
  37. End