World3D.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 Drawable3D; //! Drawing.h
  10. class Render3D; //! Render3D.h
  11. struct MouseEvent3D; //! MouseEvent.h
  12. class Model3D;
  13. class DXBuffer;
  14. class World3D;
  15. //! Stores all 3D drawings of a scene
  16. class World3D : public Model3DCollection
  17. {
  18. protected:
  19. DiffuseLight* diffuseLights;
  20. RCArray<Model3DCollection> modelCollections;
  21. int diffuseLightCount;
  22. PointLight* pointLights;
  23. int pointLightCount;
  24. int id;
  25. private:
  26. RCArray<Model3D>* members;
  27. bool rend;
  28. ReadWriteLock lock;
  29. public:
  30. //! Constructor
  31. DLLEXPORT World3D();
  32. //! Destructor
  33. DLLEXPORT virtual ~World3D();
  34. //! returns a lock for reading the object
  35. DLLEXPORT Lock& readLock();
  36. //! returns a lock for writing the object
  37. DLLEXPORT Lock& writeLock();
  38. //! Adds an object to the world
  39. //! \param obj The object to add
  40. DLLEXPORT void addDrawable(Model3D* obj);
  41. //! Removes an object from the world
  42. //! \param obj The object to remove (without increased reference
  43. //! counter)
  44. DLLEXPORT void removeDrawable(Model3D* zObj);
  45. //! Adds a collection of objects to the world
  46. //! \param collection The collection to add
  47. DLLEXPORT void addCollection(Model3DCollection* collection);
  48. //! removes a collection of models from the world
  49. //! \param zCollection The collection to remove
  50. DLLEXPORT void removeCollection(Model3DCollection* zCollection);
  51. //! Processes a mouse event
  52. //! \param me The mouse event to process
  53. DLLEXPORT void doMouseEvent(MouseEvent3D& me);
  54. //! Processes elapsed time
  55. //! \param tickval The time in seconds since the last call of this
  56. //! function \return true if the object changed, false otherwise.
  57. DLLEXPORT virtual bool tick(double tickval);
  58. //! Calculates the color of a view ray from a specific point
  59. //! in a specific direction \param point The origin of the ray
  60. //! \param dir The direction of the ray \return The color of the ray
  61. DLLEXPORT virtual int traceRay(Vec3<float>& point, Vec3<float>& dir);
  62. //! Executes a function on each model
  63. DLLEXPORT virtual void forAll(std::function<void(Model3D*)> f) override;
  64. //! Executes a tick function on each model
  65. DLLEXPORT virtual bool tick(
  66. std::function<void(Model3D*)> f, double time) override;
  67. //! Executes a render function on each model
  68. DLLEXPORT virtual void render(std::function<void(Model3D*)> f) override;
  69. //! Returns the number of point light sources
  70. DLLEXPORT int getPointLightCount() const;
  71. //! Returns the number of diffuse light sources
  72. DLLEXPORT int getDiffuseLightCount() const;
  73. //! Copies all light sources into the buffers
  74. //! \param zDiffuse The buffer for diffuse light sources
  75. //! \param zPoints The buffer for point light sources
  76. DLLEXPORT void copyLight(DXBuffer* zDiffuse, DXBuffer* zPoints) const;
  77. //! Adds a new diffuse light source
  78. //! \param light The new light source
  79. DLLEXPORT void addDiffuseLight(DiffuseLight light);
  80. //! Adds a new point light source
  81. //! \param light The new light source
  82. DLLEXPORT void addPointLight(PointLight light);
  83. //! Returns a reference to a diffuse light source
  84. //! \param index The index of the light source
  85. DLLEXPORT DiffuseLight& getDiffuseLight(int index) const;
  86. //! Returns a reference to a point light source
  87. //! \param index The index of the light source
  88. DLLEXPORT PointLight& getPointLight(int index) const;
  89. //! removes a specific fiffuse light from the world
  90. //! \param index the index of the light
  91. DLLEXPORT void removeDiffuseLight(int index);
  92. //! removes a specific point light from the world
  93. //! \param index the index of the light
  94. DLLEXPORT void removePointLight(int index);
  95. //! Sets the id of the world
  96. //! this wil be called by the used graphics api when the world is
  97. //! rendered to asociate specific gpu resources with this world instance
  98. DLLEXPORT void setId(int id);
  99. //! Returns the id of the world
  100. DLLEXPORT int getId() const;
  101. };
  102. } // namespace Framework