CameraProject.htm 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>CameraProject camera,x#,y#,z#</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. camera - camera handle <br />
  13. x# - world coordinate x <br />
  14. y# - world coordinate y <br />
  15. z# - world coordinate z
  16. </td>
  17. </tr>
  18. </table>
  19. <h1>Description</h1>
  20. <table>
  21. <tr>
  22. <td>
  23. Projects the world coordinates x,y,z on to the 2D screen.
  24. </td>
  25. </tr>
  26. </table>
  27. <h1><a href=../3d_examples/CameraProject.bb>Example</a></h1>
  28. <table>
  29. <tr>
  30. <td>
  31. ; CameraProject Example <br />
  32. ; --------------------- <br />
  33. <br />
  34. Graphics3D 640,480 <br />
  35. SetBuffer BackBuffer() <br />
  36. <br />
  37. camera=CreateCamera() <br />
  38. PositionEntity camera,0,2,-10 <br />
  39. <br />
  40. light=CreateLight() <br />
  41. RotateEntity light,90,0,0 <br />
  42. <br />
  43. plane=CreatePlane() <br />
  44. ground_tex=LoadTexture("media/Chorme-2.bmp") <br />
  45. EntityTexture plane,ground_tex <br />
  46. <br />
  47. cube=CreateCube() <br />
  48. cube_tex=LoadTexture("media/b3dlogo.jpg") <br />
  49. EntityTexture cube,cube_tex <br />
  50. PositionEntity cube,0,1,0 <br />
  51. <br />
  52. While Not KeyDown( 1 ) <br />
  53. <br />
  54. If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 <br />
  55. If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 <br />
  56. If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05 <br />
  57. If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05 <br />
  58. <br />
  59. ; Use camera project to get 2D coordinates from 3D coordinates of cube <br />
  60. CameraProject(camera,EntityX(cube),EntityY(cube),EntityZ(cube)) <br />
  61. <br />
  62. RenderWorld <br />
  63. <br />
  64. ; If cube is in view then draw text, if not then draw nothing otherwise text will be drawn at 0,0 <br />
  65. If EntityInView(cube,camera)=True <br />
  66. <br />
  67. ; Use ProjectedX() and ProjectedY() to get 2D coordinates from when CameraProject was used. <br />
  68. ; Use these coordinates to draw text at a 2D position, on top of a 3D scene. <br />
  69. Text ProjectedX#(),ProjectedY#(),"Cube" <br />
  70. <br />
  71. EndIf <br />
  72. <br />
  73. Text 0,0,"Use cursor keys to move about" <br />
  74. Text 0,20,"ProjectedX: "+ProjectedX#() <br />
  75. Text 0,40,"ProjectedY: "+ProjectedY#() <br />
  76. Text 0,60,"ProjectedZ: "+ProjectedZ#() <br />
  77. Text 0,80,"EntityInView: "+EntityInView(cube,camera) <br />
  78. <br />
  79. Flip <br />
  80. <br />
  81. Wend <br />
  82. <br />
  83. End
  84. </td>
  85. </tr>
  86. </table>
  87. <br>
  88. <a target=_top href=../index.htm>Index</a><br>
  89. <br>
  90. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=CameraProject&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  91. </html>