HitContext.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. // Description : Hit testing for editor viewport operations
  9. #ifndef CRYINCLUDE_EDITOR_INCLUDE_HITCONTEXT_H
  10. #define CRYINCLUDE_EDITOR_INCLUDE_HITCONTEXT_H
  11. #pragma once
  12. class CBaseObject;
  13. struct IDisplayViewport;
  14. struct AABB;
  15. #include <QRect>
  16. #include <platform.h>
  17. //! Flags used in HitContext for nSubObjFlags member.
  18. enum ESubObjHitFlags
  19. {
  20. //! When set all hit elements will be selected.
  21. SO_HIT_SELECT = BIT(1),
  22. //! Only test selected elements for hit.
  23. SO_HIT_TEST_SELECTED = BIT(2),
  24. //! Only hit test point2d, not rectangle
  25. //! Will only test/select 1 closest element
  26. SO_HIT_POINT = BIT(3),
  27. //! Adds hit elements to previously selected ones.
  28. SO_HIT_SELECT_ADD = BIT(4),
  29. //! Remove hit elements from previously selected ones.
  30. SO_HIT_SELECT_REMOVE = BIT(5),
  31. //! Output flag, set if selection was changed.
  32. SO_HIT_SELECTION_CHANGED = BIT(6),
  33. //! Hit testing to highlight sub object-element.
  34. SO_HIT_HIGHLIGHT_ONLY = BIT(7),
  35. //! This hit test is not for editing sub-objects.
  36. //! (ex. for moving an object by its face-normal)
  37. SO_HIT_NO_EDIT = BIT(8),
  38. // Check hit with vertices.
  39. SO_HIT_ELEM_VERTEX = BIT(10),
  40. // Check hit with edges.
  41. SO_HIT_ELEM_EDGE = BIT(11),
  42. // Check hit with faces.
  43. SO_HIT_ELEM_FACE = BIT(12),
  44. // Check hit with polygons.
  45. SO_HIT_ELEM_POLYGON = BIT(13)
  46. };
  47. #define SO_HIT_ELEM_ALL (SO_HIT_ELEM_VERTEX | SO_HIT_ELEM_EDGE | SO_HIT_ELEM_FACE | SO_HIT_ELEM_POLYGON)
  48. //! Collision structure passed to HitTest function.
  49. struct HitContext
  50. {
  51. //! Viewport that originates hit testing.
  52. IDisplayViewport* view;
  53. //! 2D point on view that is used for hit testing.
  54. QPoint point2d;
  55. //! 2D Selection rectangle (Only when HitTestRect)
  56. QRect rect;
  57. //! Optional limiting bounding box for hit testing.
  58. AABB* bounds;
  59. //! Testing performed in 2D viewport.
  60. bool b2DViewport;
  61. //! True if axis collision must be ignored.
  62. bool bIgnoreAxis;
  63. //! Hit test only gizmo objects
  64. bool bOnlyGizmo;
  65. //! Test objects using advanced selection helpers.
  66. bool bUseSelectionHelpers;
  67. //! an object excluded in hittest.
  68. CBaseObject* pExcludedObject;
  69. // Input parameters.
  70. //! Ray origin.
  71. Vec3 raySrc;
  72. //! Ray direction.
  73. Vec3 rayDir;
  74. //! Relaxation parameter for hit testing.
  75. float distanceTolerance;
  76. //! Sub object hit testing flags, @see ESubObjHitFlags
  77. int nSubObjFlags;
  78. // Output parameters.
  79. //! true if this hit should have less priority then non weak hits.
  80. //! (exp: Ray hit entity bounding box but not entity geometry.)
  81. bool weakHit;
  82. //! constrain axis if hit AxisGizmo.
  83. int axis;
  84. //! if hit axis gizmo, 1 - move mode, 2 - rotate mode, 3 - scale mode, 4 - rotate circle mode
  85. int manipulatorMode;
  86. //! distance to the object from src.
  87. float dist;
  88. //! object that have been hit.
  89. CBaseObject* object;
  90. //! For linking tool
  91. const char* name;
  92. //! true if this hit was from the object icon
  93. bool iconHit;
  94. HitContext()
  95. {
  96. rect = QRect();
  97. b2DViewport = false;
  98. view = 0;
  99. point2d = QPoint();
  100. axis = 0;
  101. distanceTolerance = 0;
  102. raySrc(0, 0, 0);
  103. rayDir(0, 0, 0);
  104. dist = 0;
  105. object = 0;
  106. weakHit = false;
  107. manipulatorMode = 0;
  108. nSubObjFlags = 0;
  109. bounds = 0;
  110. bIgnoreAxis = false;
  111. bOnlyGizmo = false;
  112. bUseSelectionHelpers = false;
  113. name = nullptr;
  114. iconHit = false;
  115. }
  116. };
  117. #endif // CRYINCLUDE_EDITOR_INCLUDE_HITCONTEXT_H