PolyCamera.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolySceneEntity.h"
  22. namespace Polycode {
  23. class Scene;
  24. class Material;
  25. class ShaderBinding;
  26. class Texture;
  27. /**
  28. * Camera in a 3D scene. Cameras can be added to a scene and changed between dynamically. You can also set a shader to a camera that will run as a screen shader for post-processing effects.
  29. */
  30. class _PolyExport Camera : public SceneEntity {
  31. public:
  32. /**
  33. * Constructor.
  34. * @param parentScene Scene to add the camera to.
  35. */
  36. Camera(Scene *parentScene);
  37. ~Camera();
  38. void buildFrustrumPlanes();
  39. /**
  40. * Checks if the camera can see a sphere.
  41. * @param pos Position of the sphere to check.
  42. * @param fRadius Radius of the sphere.
  43. * @return Returns true if the sphere is within the camera's frustrum, or false if it isn't.
  44. * @see canSee()
  45. */
  46. bool isSphereInFrustrum(Vector3 pos, Number fRadius);
  47. /**
  48. * Checks if the camera can see an entity based on its bounding radius.
  49. * @param entity Entity to check.
  50. * @return Returns true if the entity's bounding radius is within the camera's frustrum, or false if it isn't.
  51. * @see isSphereInFrustrum()
  52. */
  53. bool canSee(SceneEntity *entity);
  54. void setOrthoMode(bool mode);
  55. bool getOrthoMode();
  56. /**
  57. * Sets the field of view (FOV) for the camera. The larger the field of view, the more the camera can see, the smaller it is, the more zoomed in it is.
  58. * @param fov The new FOV value.
  59. */
  60. void setFOV(Number fov);
  61. /**
  62. * Returns the current FOV value for the camera.
  63. * @return Current FOV value for the camera.
  64. */
  65. Number getFOV();
  66. void setParentScene(Scene *parentScene);
  67. void doCameraTransform();
  68. void setLightDepthTexture(Texture *texture);
  69. bool hasFilterShader();
  70. void drawFilter();
  71. /**
  72. * Sets the exposure for the camera. The exposure value can be passed to a shader for HDR rendering.
  73. * @param level The new exposure value.
  74. */
  75. void setExposureLevel(Number level);
  76. /**
  77. * Returns the camera's exposure value.
  78. * @return Current exposure value.
  79. */
  80. Number getExposureLevel();
  81. void createPostFilter(Material *shaderMaterial);
  82. /**
  83. * Sets the post-processing shader for the camera.
  84. * @param shaderName The shader name of the post-processing filter.
  85. */
  86. void setPostFilter(const String& shaderName);
  87. /**
  88. * Removes the currently assigned post filter.
  89. */
  90. void removePostFilter();
  91. /**
  92. * Returns the local shader options for the camera post processing material.
  93. */
  94. std::vector<ShaderBinding*> getLocalShaderOptions() { return localShaderOptions; }
  95. /**
  96. * Returns the shader material applied to the camera.
  97. */
  98. Material *getScreenShaderMaterial() { return filterShaderMaterial; }
  99. protected:
  100. Number exposureLevel;
  101. bool orthoMode;
  102. Number fov;
  103. Number frustumPlanes[6][4];
  104. Scene *parentScene;
  105. bool fovSet;
  106. Material *filterShaderMaterial;
  107. Texture *originalSceneTexture;
  108. Texture *zBufferSceneTexture;
  109. std::vector<ShaderBinding*> localShaderOptions;
  110. bool _hasFilterShader;
  111. };
  112. }