World3D.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "Array.h"
  3. #include "Critical.h"
  4. #include "GraphicsApi.h"
  5. #include "Model3DCollection.h"
  6. #include "Vec3.h"
  7. namespace Framework
  8. {
  9. class Zeichnung3D; //! Drawing.h
  10. class Render3D; //! Render3D.h
  11. struct MausEreignis3D; //! MouseEvent.h
  12. class Model3D;
  13. class DXBuffer;
  14. class Welt3D;
  15. //! Stores all 3D drawings of a scene
  16. class Welt3D : public Model3DCollection
  17. {
  18. protected:
  19. DiffuseLight* diffuseLights;
  20. RCArray<Model3DCollection> modelCollections;
  21. int diffuseLightCount;
  22. PointLight* pointLights;
  23. int pointLightCount;
  24. private:
  25. RCArray<Model3D>* members;
  26. bool rend;
  27. Critical cs;
  28. public:
  29. //! Constructor
  30. DLLEXPORT Welt3D();
  31. //! Destructor
  32. DLLEXPORT virtual ~Welt3D();
  33. //! Locks access to the object and waits for access if necessary
  34. DLLEXPORT void lock();
  35. //! Releases the object for other threads
  36. DLLEXPORT void unlock();
  37. //! Adds an object to the world
  38. //! \param obj The object to add
  39. DLLEXPORT void addZeichnung(Model3D* obj);
  40. //! Removes an object from the world
  41. //! \param obj The object to remove (without increased reference counter)
  42. DLLEXPORT void removeZeichnung(Model3D* zObj);
  43. //! Adds a collection of objects to the world
  44. //! \param collection The collection to add
  45. DLLEXPORT void addCollection(Model3DCollection* collection);
  46. //! removes a collection of models from the world
  47. //! \param zCollection The collection to remove
  48. DLLEXPORT void removeCollection(Model3DCollection* zCollection);
  49. //! Processes a mouse event
  50. //! \param me The mouse event to process
  51. DLLEXPORT void doMausEreignis(MausEreignis3D& me);
  52. //! Processes elapsed time
  53. //! \param tickval The time in seconds since the last call of this
  54. //! function \return true if the object changed, false otherwise.
  55. DLLEXPORT virtual bool tick(double tickval);
  56. //! Calculates the color of a view ray from a specific point
  57. //! in a specific direction \param point The origin of the ray
  58. //! \param dir The direction of the ray \return The color of the ray
  59. DLLEXPORT virtual int traceRay(Vec3<float>& point, Vec3<float>& dir);
  60. //! Executes a function on each model
  61. DLLEXPORT virtual void forAll(std::function<void(Model3D*)> f) override;
  62. //! Executes a tick function on each model
  63. DLLEXPORT virtual bool tick(
  64. std::function<void(Model3D*)> f, double time) override;
  65. //! Executes a render function on each model
  66. DLLEXPORT virtual void render(std::function<void(Model3D*)> f) override;
  67. //! Returns the number of point light sources
  68. DLLEXPORT int getPointLightCount() const;
  69. //! Returns the number of diffuse light sources
  70. DLLEXPORT int getDiffuseLightCount() const;
  71. //! Copies all light sources into the buffers
  72. //! \param zDiffuse The buffer for diffuse light sources
  73. //! \param zPoints The buffer for point light sources
  74. DLLEXPORT void copyLight(DXBuffer* zDiffuse, DXBuffer* zPoints) const;
  75. //! Adds a new diffuse light source
  76. //! \param light The new light source
  77. DLLEXPORT void addDiffuseLight(DiffuseLight light);
  78. //! Adds a new point light source
  79. //! \param light The new light source
  80. DLLEXPORT void addPointLight(PointLight light);
  81. //! Returns a reference to a diffuse light source
  82. //! \param index The index of the light source
  83. DLLEXPORT DiffuseLight& getDiffuseLight(int index) const;
  84. //! Returns a reference to a point light source
  85. //! \param index The index of the light source
  86. DLLEXPORT PointLight& getPointLight(int index) const;
  87. //! removes a specific fiffuse light from the world
  88. //! \param index the index of the light
  89. DLLEXPORT void removeDiffuseLight(int index);
  90. //! removes a specific point light from the world
  91. //! \param index the index of the light
  92. DLLEXPORT void removePointLight(int index);
  93. };
  94. } // namespace Framework