HFpick.dpr 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. {: A crude but effective way of "picking" in an height field.
  2. This demo implements a simple way to "pick" a clicked sector in an
  3. heightfield, using it for a basic "3D paint". In "paint" mode,
  4. the left button will paint in blue and the right one in red.
  5. The "rotate" mode allows you to move around the height field
  6. to continue your painting from a different angle.
  7. No you can't save your art ;)
  8. The picking is performed by getting the 3D coordinates from the
  9. 2D mouse coordinates via PixelRayToWorld (which reads the depth
  10. buffer), and converting those absolute 3D coordinates to local
  11. coordinates of the HeightField, the last steps are then obvious.
  12. This method is approximate in that its precision highly depends on
  13. that of the ZBuffer. It will also fail if some objects "obstructs"
  14. picking (prevent the read of a proper ZBuffer value).
  15. Some simple improvements left as an exercice to the reader:<ul>
  16. <li>add a "terraform" mode allowing to raise and lower height values
  17. <li>add more colors to the paint mode
  18. <li>allow painting the top and bottom of the heightfield with different colors
  19. <li>painting to a texture instead of a grid
  20. </ul>
  21. }
  22. program HFpick;
  23. uses
  24. Forms,
  25. fHFPick in 'fHFPick.pas' {FormHFPick};
  26. {$R *.res}
  27. begin
  28. Application.Initialize;
  29. Application.CreateForm(TFormHFPick, FormHFPick);
  30. Application.Run;
  31. end.