Viewport.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/RHI.Reflect/Viewport.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. namespace AZ::RHI
  11. {
  12. void Viewport::Reflect(AZ::ReflectContext* context)
  13. {
  14. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  15. {
  16. serializeContext->Class<Viewport>()
  17. ->Version(1)
  18. ->Field("m_minX", &Viewport::m_minX)
  19. ->Field("m_maxX", &Viewport::m_maxX)
  20. ->Field("m_minY", &Viewport::m_minY)
  21. ->Field("m_maxY", &Viewport::m_maxY)
  22. ->Field("m_minZ", &Viewport::m_minZ)
  23. ->Field("m_maxZ", &Viewport::m_maxZ);
  24. }
  25. }
  26. Viewport::Viewport(
  27. float minX,
  28. float maxX,
  29. float minY,
  30. float maxY,
  31. float minZ,
  32. float maxZ)
  33. : m_minX(minX)
  34. , m_maxX(maxX)
  35. , m_minY(minY)
  36. , m_maxY(maxY)
  37. , m_minZ(minZ)
  38. , m_maxZ(maxZ)
  39. {}
  40. Viewport Viewport::GetScaled(
  41. float normalizedMinX,
  42. float normalizedMaxX,
  43. float normalizedMinY,
  44. float normalizedMaxY,
  45. float normalizedMinZ,
  46. float normalizedMaxZ) const
  47. {
  48. Viewport viewport;
  49. viewport.m_minX = Lerp(m_minX, m_maxX, normalizedMinX);
  50. viewport.m_maxX = Lerp(m_minX, m_maxX, normalizedMaxX);
  51. viewport.m_minY = Lerp(m_minY, m_maxY, normalizedMinY);
  52. viewport.m_maxY = Lerp(m_minY, m_maxY, normalizedMaxY);
  53. viewport.m_minZ = Lerp(m_minZ, m_maxZ, normalizedMinZ);
  54. viewport.m_maxZ = Lerp(m_minZ, m_maxZ, normalizedMaxZ);
  55. return viewport;
  56. }
  57. Viewport Viewport::CreateNull()
  58. {
  59. return Viewport{0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
  60. }
  61. bool Viewport::IsNull() const
  62. {
  63. return ((m_minX >= m_maxX) ||
  64. (m_minY >= m_maxY) ||
  65. (m_minZ >= m_maxZ));
  66. }
  67. }