treegen.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2018 celeron55, Perttu Ahola <celeron55@gmail.com>,
  4. Copyright (C) 2012-2018 RealBadAngel, Maciej Kasatkin
  5. Copyright (C) 2015-2018 paramat
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published by
  8. the Free Software Foundation; either version 2.1 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License along
  15. with this program; if not, write to the Free Software Foundation, Inc.,
  16. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #pragma once
  19. #include <matrix4.h>
  20. #include "noise.h"
  21. class MMVManip;
  22. class NodeDefManager;
  23. class ServerMap;
  24. namespace treegen {
  25. enum error {
  26. SUCCESS,
  27. UNBALANCED_BRACKETS
  28. };
  29. struct TreeDef {
  30. std::string initial_axiom;
  31. std::string rules_a;
  32. std::string rules_b;
  33. std::string rules_c;
  34. std::string rules_d;
  35. MapNode trunknode;
  36. MapNode leavesnode;
  37. MapNode leaves2node;
  38. int leaves2_chance;
  39. int angle;
  40. int iterations;
  41. int iterations_random_level;
  42. std::string trunk_type;
  43. bool thin_branches;
  44. MapNode fruitnode;
  45. int fruit_chance;
  46. s32 seed;
  47. bool explicit_seed;
  48. };
  49. // Add default tree
  50. void make_tree(MMVManip &vmanip, v3s16 p0,
  51. bool is_apple_tree, const NodeDefManager *ndef, s32 seed);
  52. // Add jungle tree
  53. void make_jungletree(MMVManip &vmanip, v3s16 p0,
  54. const NodeDefManager *ndef, s32 seed);
  55. // Add pine tree
  56. void make_pine_tree(MMVManip &vmanip, v3s16 p0,
  57. const NodeDefManager *ndef, s32 seed);
  58. // Add L-Systems tree (used by engine)
  59. treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
  60. const NodeDefManager *ndef, TreeDef tree_definition);
  61. // Spawn L-systems tree from LUA
  62. treegen::error spawn_ltree (ServerMap *map, v3s16 p0,
  63. const NodeDefManager *ndef, const TreeDef &tree_definition);
  64. // L-System tree gen helper functions
  65. void tree_trunk_placement(MMVManip &vmanip, v3f p0,
  66. TreeDef &tree_definition);
  67. void tree_leaves_placement(MMVManip &vmanip, v3f p0,
  68. PseudoRandom ps, TreeDef &tree_definition);
  69. void tree_single_leaves_placement(MMVManip &vmanip, v3f p0,
  70. PseudoRandom ps, TreeDef &tree_definition);
  71. void tree_fruit_placement(MMVManip &vmanip, v3f p0,
  72. TreeDef &tree_definition);
  73. irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis);
  74. v3f transposeMatrix(irr::core::matrix4 M ,v3f v);
  75. }; // namespace treegen