World3D.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. private:
  25. RCArray<Model3D>* members;
  26. bool rend;
  27. ReadWriteLock lock;
  28. public:
  29. //! Constructor
  30. DLLEXPORT World3D();
  31. //! Destructor
  32. DLLEXPORT virtual ~World3D();
  33. //! returns a lock for reading the object
  34. DLLEXPORT Lock& readLock();
  35. //! returns a lock for writing the object
  36. DLLEXPORT Lock& writeLock();
  37. //! Adds an object to the world
  38. //! \param obj The object to add
  39. DLLEXPORT void addDrawable(Model3D* obj);
  40. //! Removes an object from the world
  41. //! \param obj The object to remove (without increased reference
  42. //! counter)
  43. DLLEXPORT void removeDrawable(Model3D* zObj);
  44. //! Adds a collection of objects to the world
  45. //! \param collection The collection to add
  46. DLLEXPORT void addCollection(Model3DCollection* collection);
  47. //! removes a collection of models from the world
  48. //! \param zCollection The collection to remove
  49. DLLEXPORT void removeCollection(Model3DCollection* zCollection);
  50. //! Processes a mouse event
  51. //! \param me The mouse event to process
  52. DLLEXPORT void doMouseEvent(MouseEvent3D& me);
  53. //! Processes elapsed time
  54. //! \param tickval The time in seconds since the last call of this
  55. //! function \return true if the object changed, false otherwise.
  56. DLLEXPORT virtual bool tick(double tickval);
  57. //! Calculates the color of a view ray from a specific point
  58. //! in a specific direction \param point The origin of the ray
  59. //! \param dir The direction of the ray \return The color of the ray
  60. DLLEXPORT virtual int traceRay(Vec3<float>& point, Vec3<float>& dir);
  61. //! Executes a function on each model
  62. DLLEXPORT virtual void forAll(std::function<void(Model3D*)> f) override;
  63. //! Executes a tick function on each model
  64. DLLEXPORT virtual bool tick(
  65. std::function<void(Model3D*)> f, double time) override;
  66. //! Executes a render function on each model
  67. DLLEXPORT virtual void render(std::function<void(Model3D*)> f) override;
  68. //! Returns the number of point light sources
  69. DLLEXPORT int getPointLightCount() const;
  70. //! Returns the number of diffuse light sources
  71. DLLEXPORT int getDiffuseLightCount() const;
  72. //! Copies all light sources into the buffers
  73. //! \param zDiffuse The buffer for diffuse light sources
  74. //! \param zPoints The buffer for point light sources
  75. DLLEXPORT void copyLight(DXBuffer* zDiffuse, DXBuffer* zPoints) const;
  76. //! Adds a new diffuse light source
  77. //! \param light The new light source
  78. DLLEXPORT void addDiffuseLight(DiffuseLight light);
  79. //! Adds a new point light source
  80. //! \param light The new light source
  81. DLLEXPORT void addPointLight(PointLight light);
  82. //! Returns a reference to a diffuse light source
  83. //! \param index The index of the light source
  84. DLLEXPORT DiffuseLight& getDiffuseLight(int index) const;
  85. //! Returns a reference to a point light source
  86. //! \param index The index of the light source
  87. DLLEXPORT PointLight& getPointLight(int index) const;
  88. //! removes a specific fiffuse light from the world
  89. //! \param index the index of the light
  90. DLLEXPORT void removeDiffuseLight(int index);
  91. //! removes a specific point light from the world
  92. //! \param index the index of the light
  93. DLLEXPORT void removePointLight(int index);
  94. };
  95. } // namespace Framework