Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
9.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef MAPATOM_H
  8. #define MAPATOM_H
  9. #pragma once
  10. #include "hammer_mathlib.h"
  11. #include "tier1/utlvector.h"
  12. class Box3D;
  13. class CRender2D;
  14. class CRender3D;
  15. enum SelectionState_t
  16. {
  17. SELECT_NONE = 0, // unselected
  18. SELECT_NORMAL, // selected
  19. SELECT_MORPH, // selected for vertex manipulation
  20. SELECT_MULTI_PARTIAL, // partial selection in a multiselect
  21. SELECT_MODIFY, // being modified by a tool
  22. };
  23. //
  24. // Notification codes for NotifyDependents.
  25. //
  26. enum Notify_Dependent_t
  27. {
  28. Notify_Changed = 0, // The notifying object has changed.
  29. Notify_Removed, // The notifying object is being removed from the world.
  30. Notify_Undo,
  31. Notify_Transform,
  32. Notify_Rebuild,
  33. Notify_Rebuild_Full,
  34. Notify_Clipped_Intermediate,
  35. Notify_Clipped
  36. };
  37. class CMapAtom
  38. {
  39. public:
  40. int m_nObjectID;
  41. //-----------------------------------------------------------------------------
  42. // Purpose: Debugging hook.
  43. //-----------------------------------------------------------------------------
  44. virtual void Debug(void) {}
  45. //-----------------------------------------------------------------------------
  46. // Purpose: Returns whether this object is selected.
  47. //-----------------------------------------------------------------------------
  48. virtual bool IsSelected(void) const
  49. {
  50. return(m_eSelectionState != SELECT_NONE);
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose: Returns the current selection state of this object.
  54. //-----------------------------------------------------------------------------
  55. virtual SelectionState_t GetSelectionState(void) const
  56. {
  57. return(m_eSelectionState);
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose: Sets the current selection state of this object.
  61. //-----------------------------------------------------------------------------
  62. virtual SelectionState_t SetSelectionState(SelectionState_t eSelectionState)
  63. {
  64. SelectionState_t ePrevState = m_eSelectionState;
  65. m_eSelectionState = eSelectionState;
  66. return ePrevState;
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose: Sets the render color of this object.
  70. //-----------------------------------------------------------------------------
  71. virtual void SetRenderColor(unsigned char red, unsigned char green, unsigned char blue)
  72. {
  73. r = red;
  74. g = green;
  75. b = blue;
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Sets the render color of this object.
  79. //-----------------------------------------------------------------------------
  80. virtual void SetRenderColor(color32 rgbColor)
  81. {
  82. r = rgbColor.r;
  83. g = rgbColor.g;
  84. b = rgbColor.b;
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose: Returns the render color of this object.
  88. //-----------------------------------------------------------------------------
  89. virtual void GetRenderColor(unsigned char &red, unsigned char &green, unsigned char &blue)
  90. {
  91. red = r;
  92. green = g;
  93. blue = b;
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Returns the render color of this object.
  97. //-----------------------------------------------------------------------------
  98. virtual color32 GetRenderColor(void)
  99. {
  100. color32 rgbColor;
  101. rgbColor.r = r;
  102. rgbColor.g = g;
  103. rgbColor.b = b;
  104. rgbColor.a = 0;
  105. return rgbColor;
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose: Sets this object's parent.
  109. // Input : pParent -
  110. //-----------------------------------------------------------------------------
  111. virtual void SetParent(CMapAtom *pParent)
  112. {
  113. m_pParent = pParent;
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Purpose: Returns the parent of this CMapAtom.
  117. // Output : Parent pointer, NULL if this object has no parent.
  118. //-----------------------------------------------------------------------------
  119. virtual CMapAtom *GetParent(void) const
  120. {
  121. return(m_pParent);
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose: Preloads any rendering info (textures, etc.). Called once per object
  125. // from the renderer's Initialize function.
  126. // Input : pRender - Pointer to the 3D rendering interface.
  127. // bNewContext - True if the renderer pointed to by pRender is a new
  128. // rendering context, false if not.
  129. //-----------------------------------------------------------------------------
  130. virtual bool RenderPreload(CRender3D *pRender, bool bNewContext)
  131. {
  132. return(true);
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Purpose: Renders this object into the 3D view.
  136. // Input : pRender - Pointer to the 3D rendering interface.
  137. //-----------------------------------------------------------------------------
  138. virtual void Render3D(CRender3D *pRender)
  139. {
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Purpose: Renders this object into the 3D view.
  143. // Input : pRender - Pointer to the 3D rendering interface.
  144. //-----------------------------------------------------------------------------
  145. virtual void Render2D(CRender2D *pRender)
  146. {
  147. }
  148. virtual void AddShadowingTriangles( CUtlVector<Vector> &tri_list )
  149. {
  150. // should add triangles representing the shadows this object would cast
  151. // in lighting preview mode by adding 3 vector positions per triangle
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose: Returns a coordinate frame to render in
  155. // Input : matrix -
  156. // Output : returns true if a new matrix is returned, false if the new matrix is bad
  157. //-----------------------------------------------------------------------------
  158. virtual bool GetTransformMatrix( VMatrix& matrix )
  159. {
  160. // try and get our parents transform matrix
  161. CMapAtom *p = GetParent();
  162. if ( p )
  163. {
  164. return p->GetTransformMatrix( matrix );
  165. }
  166. return false;
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Transformation functions.
  170. //-----------------------------------------------------------------------------
  171. void Transform(const VMatrix &matrix)
  172. {
  173. DoTransform(matrix);
  174. PostUpdate(Notify_Transform);
  175. }
  176. void TransMove(const Vector &Delta)
  177. {
  178. VMatrix matrix;
  179. matrix.Identity();
  180. matrix.SetTranslation(Delta);
  181. DoTransform(matrix);
  182. PostUpdate(Notify_Transform);
  183. }
  184. void TransRotate(const Vector &RefPoint, const QAngle &Angles)
  185. {
  186. VMatrix matrix;
  187. QAngle hammerAngle( -Angles.y, Angles.z, Angles.x );
  188. matrix.SetupMatrixOrgAngles( vec3_origin, hammerAngle );
  189. Vector vOffset;
  190. matrix.V3Mul( RefPoint, vOffset );
  191. vOffset = RefPoint - vOffset;
  192. matrix.SetTranslation( vOffset );
  193. DoTransform(matrix);
  194. PostUpdate(Notify_Transform);
  195. }
  196. void TransScale(const Vector &RefPoint, const Vector &Scale)
  197. {
  198. VMatrix matrix;
  199. matrix.Identity();
  200. matrix = matrix.Scale( Scale );
  201. Vector vOffset;
  202. matrix.V3Mul( RefPoint, vOffset );
  203. vOffset = RefPoint - vOffset;
  204. matrix.SetTranslation( vOffset );
  205. DoTransform(matrix);
  206. PostUpdate(Notify_Transform);
  207. }
  208. //-----------------------------------------------------------------------------
  209. // Must be called after modifying the object for bounds recalculation and
  210. // dependency updates.
  211. //-----------------------------------------------------------------------------
  212. virtual void PostUpdate(Notify_Dependent_t eNotifyType) {}
  213. //-----------------------------------------------------------------------------
  214. // Override this for helpers. This indicates whether a helper provides a visual
  215. // representation for the entity that it belongs to. Entities with no
  216. // visual elements are given a default box so they can be seen.
  217. //-----------------------------------------------------------------------------
  218. virtual bool IsVisualElement(void) { return(false); }
  219. //-----------------------------------------------------------------------------
  220. // Override this to tell the renderer to render you last. This is useful for
  221. // alpha blended elements such as sprites.
  222. //-----------------------------------------------------------------------------
  223. virtual bool ShouldRenderLast(void)
  224. {
  225. return(false);
  226. }
  227. virtual void SignalChanged(void ) // object has changed
  228. {
  229. }
  230. protected:
  231. static int s_nObjectIDCtr;
  232. CMapAtom(void)
  233. {
  234. m_eSelectionState = SELECT_NONE;
  235. m_pParent = NULL;
  236. m_nObjectID = s_nObjectIDCtr++;
  237. }
  238. //-----------------------------------------------------------------------------
  239. // DoTransform functions. Virtual, called by base Transfom functions.
  240. //-----------------------------------------------------------------------------
  241. virtual void DoTransform(const VMatrix &matrix) {}
  242. CMapAtom *m_pParent; // This object's parent.
  243. SelectionState_t m_eSelectionState; // The current selection state of this object.
  244. unsigned char r; // Red color component.
  245. unsigned char g; // Green color component.
  246. unsigned char b; // Blue color component.
  247. };
  248. #endif // MAPATOM_H