clouds.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "irrlichttypes_extrabloated.h"
  18. #include <iostream>
  19. #include "constants.h"
  20. #include "cloudparams.h"
  21. // Menu clouds
  22. class Clouds;
  23. extern Clouds *g_menuclouds;
  24. // Scene manager used for menu clouds
  25. namespace irr{namespace scene{class ISceneManager;}}
  26. extern irr::scene::ISceneManager *g_menucloudsmgr;
  27. class Clouds : public scene::ISceneNode
  28. {
  29. public:
  30. Clouds(scene::ISceneManager* mgr,
  31. s32 id,
  32. u32 seed
  33. );
  34. ~Clouds();
  35. /*
  36. ISceneNode methods
  37. */
  38. virtual void OnRegisterSceneNode();
  39. virtual void render();
  40. virtual const aabb3f &getBoundingBox() const
  41. {
  42. return m_box;
  43. }
  44. virtual u32 getMaterialCount() const
  45. {
  46. return 1;
  47. }
  48. virtual video::SMaterial& getMaterial(u32 i)
  49. {
  50. return m_material;
  51. }
  52. /*
  53. Other stuff
  54. */
  55. void step(float dtime);
  56. void update(const v3f &camera_p, const video::SColorf &color);
  57. void updateCameraOffset(const v3s16 &camera_offset)
  58. {
  59. m_camera_offset = camera_offset;
  60. updateBox();
  61. }
  62. void readSettings();
  63. void setDensity(float density)
  64. {
  65. m_params.density = density;
  66. // currently does not need bounding
  67. }
  68. void setColorBright(const video::SColor &color_bright)
  69. {
  70. m_params.color_bright = color_bright;
  71. }
  72. void setColorAmbient(const video::SColor &color_ambient)
  73. {
  74. m_params.color_ambient = color_ambient;
  75. }
  76. void setHeight(float height)
  77. {
  78. m_params.height = height; // add bounding when necessary
  79. updateBox();
  80. }
  81. void setSpeed(v2f speed)
  82. {
  83. m_params.speed = speed;
  84. }
  85. void setThickness(float thickness)
  86. {
  87. m_params.thickness = thickness;
  88. updateBox();
  89. }
  90. bool isCameraInsideCloud() const { return m_camera_inside_cloud; }
  91. const video::SColor getColor() const { return m_color.toSColor(); }
  92. private:
  93. void updateBox()
  94. {
  95. float height_bs = m_params.height * BS;
  96. float thickness_bs = m_params.thickness * BS;
  97. m_box = aabb3f(-BS * 1000000.0f, height_bs - BS * m_camera_offset.Y, -BS * 1000000.0f,
  98. BS * 1000000.0f, height_bs + thickness_bs - BS * m_camera_offset.Y, BS * 1000000.0f);
  99. }
  100. bool gridFilled(int x, int y) const;
  101. video::SMaterial m_material;
  102. aabb3f m_box;
  103. u16 m_cloud_radius_i;
  104. bool m_enable_3d;
  105. u32 m_seed;
  106. v3f m_camera_pos;
  107. v2f m_origin;
  108. v3s16 m_camera_offset;
  109. video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
  110. CloudParams m_params;
  111. bool m_camera_inside_cloud = false;
  112. };