All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
LabelView.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "LabelViewTypes.h"
7 #include "IAnchoredLabel.h"
8 #include "LabelStyle.h"
9 #include "Camera.h"
10 #include "AxisAlignedBox2.h"
11 #include "ShapedGlyph.h"
12 
13 #include <vector>
14 
15 namespace Eegeo
16 {
17  namespace Labels
18  {
20  {
21  public:
22  typedef IAnchoredLabel::IdType IdType;
23  const static int LOD_ARRAY_SIZE = 2;
24 
25  LabelView(const IAnchoredLabel& anchoredLabel,
26  const LabelStyle& labelStyle,
27  bool hasTextComponent,
28  bool hasIconComponent,
29  const v2& textScale,
30  const v2& textAlignmentOffset,
31  const v2& iconScale,
32  const v2& iconAlignmentOffset,
33  bool isHidden,
34  bool horizonCullAlwaysRequired,
35  int pickingGroup,
36  int tieBreakPriority,
37  int lodCount,
38  u32 componentMaskPerLod[LOD_ARRAY_SIZE]);
39 
40  IdType GetId() const;
41 
42  void NotifyAnchorChanged();
43 
44  bool HasCachedAnchorBasisEcef() const { return m_hasCachedAnchorBasisEcef; }
45 
46  void UpdateCached(const LabelViewUpdateParams& labelViewUpdateParams);
47 
48  static void UpdateTransformsPrefetch(const LabelView* pLabelView);
49  LabelViewVisibility::Type CalcTransformsAndVisibility(const LabelViewUpdateParams& labelViewUpdateParams, LabelViewTransforms& out_result) const;
50 
51  void SetTransforms(const LabelViewTransforms& transforms);
52 
53  static void UpdateFadeStatePrefetch(const LabelView* pLabelView);
54  void UpdateFadeState(float dt);
55 
56  const std::vector<Text::ShapedGlyph>& GetShapedGlyphs() const { return m_shapedGlyphs; }
57  const Icons::IconDefinition* GetIcon() const { return m_pIconDefinition; }
58 
59  const LabelStyle& GetStyle() const { return *m_pLabelStyle; }
60  int GetStyleIndex() const { return m_styleIndex; }
61 
62  v2 GetTextTranslate() const { return m_textTranslate; }
63  v2 GetIconTranslate() const { return m_iconTranslate; }
64  v2 GetRotate() const { return m_rotateCosSin; }
65  v2 GetTextScale() const { return m_textScale; } // Note: Why aren't these const ref?
66  const v2& GetIconScale() const { return m_iconScale; }
67  float GetGlyphSizeScale() const { return m_glyphSizeScale; } // TODO: This isn't used - always set to 1.f???
68  LabelDisplay::Type GetDisplayType() const { return m_displayType; }
69  bool WillIgnoreOcclusion() const { return m_willIgnoreOcclusion; }
70 
71  const Geometry::AxisAlignedBox2& GetLabelAxisAlignedBounds() const { return m_labelAxisAlignedBounds; }
72  const Geometry::OrientedBox2& GetComponentOrientedBounds(const LabelComponent::Type labelComponent) const;
73  const Geometry::AxisAlignedBox2& GetComponentAxisAlignedBounds(const LabelComponent::Type labelComponent) const;
74 
75  m44 GetCameraRelativeWorldTransform() const;
76 
77  int GetPriority() const { return m_priority; }
78  int GetSubPriority() const { return m_subPriority; }
79  float GetFadeParam() const { return m_fadeParam; }
80  float GetTextFadeParam() const { return m_textFadeParam; }
81  bool ShouldDisplayComponent(const LabelComponent::Type labelComponent) const;
82 
83  bool IsAxisAligned() const { return m_orientationType == LabelOrientation::Screen; }
84  int GetTiebreakPriority() const { return m_tieBreakPriority; }
85 
86  bool HasComponent(const LabelComponent::Type labelComponent) const { return ((m_componentMask & (1 << labelComponent)) > 0) ? true : false; }
87  u32 GetComponentMask() const { return m_componentMask; }
88 
89  int GetOccludableComponentCount() const { return m_occludableComponentCount; }
90 
91 
92  LabelFadeState::Type GetFadeState() const { return m_fadeState; }
93 
94  void CalcProjectedConstraintPoints(const Camera::RenderCamera& renderCamera, v2& out_start, v2& out_end) const;
95 
96  v2 CalcProjectedAnchorPoint(const Camera::RenderCamera& renderCamera) const;
97 
98  void BeginFadeIn();
99 
100  bool ShouldDisplayForLevel(int zLevel) const;
101 
102  bool IsHidden() const { return m_isHidden; }
103  void SetHidden(bool hidden) { m_isHidden = hidden; }
104  const IAnchoredLabel& GetAnchoredLabel() const { return *m_pAnchoredLabel; }
105 
106  int GetPickingGroup() const { return m_pickingGroup; }
107 
108  int GetLod() const { return m_lod; }
109  void SetLod(int lod) { Eegeo_ASSERT_SLOW(lod < m_lodCount); m_lod = lod; }
110  bool IsInvisibleLod() const { return m_lod < 0; }
111  int GetLodCount() const { return m_lodCount; }
112  u32 GetComponentMaskForLod(int lod) const { Eegeo_ASSERT_SLOW(lod >= 0 && lod < m_lodCount); return m_componentMaskPerLod[lod]; }
113  const Geometry::AxisAlignedBox2& GetAxisAlignedBoundsForLod(int lod) const;
114 
115  float GetViewDepth() const { return m_viewDepth; }
116  private:
117  void UpdateAnchorBasisEcef(const m44& inverseViewMatrix, float environmentFlatteningScale);
118  bool CalcHasExceededConstraintRadius(const MvpMatrix& mvp, const LabelViewUpdateParams& labelViewUpdateParams) const;
119  v2 CalcTranslate(const v2& anchorScreenPos, const v2& rotateCosSin, const v2& alignmentOffset, const v2& layoutScale) const;
120  v3 CalcAnchorBasisEcefTranslate(const LabelViewUpdateParams& labelViewUpdateParams) const;
121  m44 CalcAnchorBasisEcef(const m44& inverseViewMatrix, float environmentFlatteningScale) const;
122  void CacheValueFromAnchoredLabel();
123 
124  // TODO: Fix Lot of duplication of stuff for icons (3 types of bounds, 'layoutScale' and 'alignmentOffset' which is dif for text and icons, along with the final calculated 'translate' vector
125 
126  // read from during common hot execution path (UpdateTransformsAndVisibility):
127  Geometry::AxisAlignedBox2 m_localTextBounds;
128  Geometry::AxisAlignedBox2 m_localIconBounds;
129  dv3 m_anchorUnflattenedEcef;
130  v3 m_anchorOffset;
131  v3 m_anchorBasisEcefRight;
132  v2 m_textScale;
133  v2 m_textAlignmentOffset;
134  v2 m_iconScale;
135  v2 m_iconAlignmentOffset;
136  float m_anchorConstraintRadiusEcef;
137  float m_precalcConstraintRadiusSq;
138  const int m_occludableComponentCount;
139  u32 m_componentMask;
140  const float m_screenMargin;
141  const ScreenMarginHiding::Type m_screenMarginHiding;
142  LabelPlacement::Type m_anchorLabelPlacementType;
143  LabelOrientation::Type m_orientationType;
144  LabelFadeState::Type m_fadeState;
145  LabelDisplay::Type m_displayType;
146  bool m_hasCachedAnchorBasisEcef;
147  bool m_canCacheAnchorOffset;
148  bool m_anchorChanged;
149  bool m_horizonCullAlwaysRequired;
150 
151  inline static int HotWriteFieldsOffset() { return offsetof(LabelView, m_textOrientedBounds); }
152 
153  // written to during common hot execution path:
154  Geometry::AxisAlignedBox2 m_labelAxisAlignedBounds;
155  Geometry::OrientedBox2 m_textOrientedBounds;
156  Geometry::AxisAlignedBox2 m_textAxisAlignedBounds;
157  Geometry::OrientedBox2 m_iconOrientedBounds;
158  Geometry::AxisAlignedBox2 m_iconAxisAlignedBounds;
159  v3 m_anchorBasisEcefTranslate;
160  v3 m_anchorBasisEcefUp;
161  v3 m_anchorBasisEcefForward;
162  v2 m_textTranslate;
163  v2 m_iconTranslate;
164  v2 m_rotateCosSin;
165  float m_viewDepth;
166  bool m_exceedsConstraintRadius;
167 
168  // cold
169  bool m_isEcefBackFacing;
170  bool m_isHidden;
171  bool m_isOutsideScreenMargin;
172  const bool m_willIgnoreOcclusion;
173  u8 m_minZLevel;
174  u8 m_maxZLevel;
175  float m_anchorAltitude;
176  float m_anchorAltitudeOffset;
177  float m_fadeParam;
178  float m_textFadeParam;
179  float m_glyphSizeScale;
180  int m_priority;
181  int m_subPriority;
182  int m_tieBreakPriority;
183  int m_lod;
184  int m_lodCount;
185  u32 m_componentMaskPerLod[LOD_ARRAY_SIZE];
186  const IAnchoredLabel* m_pAnchoredLabel;
187  const LabelStyle* m_pLabelStyle;
188  const int m_styleIndex;
189  std::vector<Text::ShapedGlyph> m_shapedGlyphs;
190  const Icons::IconDefinition* m_pIconDefinition;
191  int m_pickingGroup;
192  };
193  }
194 }