Viewport.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "Camera.h"
  25. #include "PostProcess.h"
  26. #include "Scene.h"
  27. #include "Viewport.h"
  28. Viewport::Viewport() :
  29. rect_(IntRect::ZERO)
  30. {
  31. }
  32. Viewport::Viewport(Scene* scene, Camera* camera) :
  33. scene_(scene),
  34. camera_(camera),
  35. rect_(IntRect::ZERO)
  36. {
  37. }
  38. Viewport::Viewport(Scene* scene, Camera* camera, const IntRect& rect) :
  39. scene_(scene),
  40. camera_(camera),
  41. rect_(rect)
  42. {
  43. }
  44. Viewport::Viewport(Scene* scene, Camera* camera, const Vector<SharedPtr<PostProcess> >& postProcesses) :
  45. scene_(scene),
  46. camera_(camera),
  47. rect_(IntRect::ZERO),
  48. postProcesses_(postProcesses)
  49. {
  50. }
  51. Viewport::Viewport(Scene* scene, Camera* camera, const IntRect& rect, const Vector<SharedPtr<PostProcess> >& postProcesses) :
  52. scene_(scene),
  53. camera_(camera),
  54. rect_(rect),
  55. postProcesses_(postProcesses)
  56. {
  57. }
  58. Viewport::~Viewport()
  59. {
  60. }
  61. void Viewport::SetScene(Scene* scene)
  62. {
  63. scene_ = scene;
  64. }
  65. void Viewport::SetCamera(Camera* camera)
  66. {
  67. camera_ = camera;
  68. }
  69. void Viewport::SetRect(const IntRect& rect)
  70. {
  71. rect_ = rect;
  72. }
  73. void Viewport::AddPostProcess(PostProcess* effect)
  74. {
  75. if (!effect)
  76. return;
  77. SharedPtr<PostProcess> effectPtr(effect);
  78. if (!postProcesses_.Contains(effectPtr))
  79. postProcesses_.Push(effectPtr);
  80. }
  81. void Viewport::InsertPostProcess(unsigned int index, PostProcess* effect)
  82. {
  83. if (!effect)
  84. return;
  85. SharedPtr<PostProcess> effectPtr(effect);
  86. if (postProcesses_.Contains(effectPtr))
  87. return;
  88. if (index >= postProcesses_.Size())
  89. postProcesses_.Push(effectPtr);
  90. else
  91. postProcesses_.Insert(postProcesses_.Begin() + index, effectPtr);
  92. }
  93. void Viewport::RemovePostProcess(PostProcess* effect)
  94. {
  95. for (Vector<SharedPtr<PostProcess> >::Iterator i = postProcesses_.Begin(); i != postProcesses_.End(); ++i)
  96. {
  97. if (i->Get() == effect)
  98. {
  99. postProcesses_.Erase(i);
  100. return;
  101. }
  102. }
  103. }
  104. void Viewport::RemovePostProcess(unsigned index)
  105. {
  106. postProcesses_.Erase(index);
  107. }
  108. void Viewport::RemoveAllPostProcesses()
  109. {
  110. postProcesses_.Clear();
  111. }
  112. Scene* Viewport::GetScene() const
  113. {
  114. return scene_;
  115. }
  116. Camera* Viewport::GetCamera() const
  117. {
  118. return camera_;
  119. }
  120. PostProcess* Viewport::GetPostProcess(unsigned index) const
  121. {
  122. return index < postProcesses_.Size() ? postProcesses_[index] : (PostProcess*)0;
  123. }