MLRShape.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #pragma once
  5. #define MLR_MLRSHAPE_HPP
  6. #if !defined(MLR_MLR_HPP)
  7. #include <MLR\MLR.hpp>
  8. #endif
  9. #if !defined(MLR_MLRPRIMITIVE_HPP)
  10. #include <MLR\MLRPrimitiveBase.hpp>
  11. #endif
  12. #if !defined(MLR_MLRLIGHT_HPP)
  13. #include <MLR\MLRLight.hpp>
  14. #endif
  15. #if !defined(MLR_GOSVERTEXPOOL_HPP)
  16. #include <MLR\GOSVertexPool.hpp>
  17. #endif
  18. namespace MidLevelRenderer {
  19. class MLRPrimitiveBase;
  20. class MLRClipper;
  21. //##########################################################################
  22. //########################## MLRShape ################################
  23. //##########################################################################
  24. // This class is a container for MLRPrimitve's. A shape has a Matrix and is
  25. // attached to the hierarchy
  26. class MLRShape :
  27. public Stuff::Plug
  28. {
  29. friend class MLRClipper;
  30. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  31. // Initialization
  32. //
  33. public:
  34. static void
  35. InitializeClass();
  36. static void
  37. TerminateClass();
  38. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. // Constructors/Destructors
  40. //
  41. protected:
  42. MLRShape(
  43. Stuff::MemoryStream *stream,
  44. int version
  45. );
  46. ~MLRShape();
  47. public:
  48. MLRShape(int);
  49. static MLRShape*
  50. Make(
  51. Stuff::MemoryStream *stream,
  52. int version
  53. );
  54. void
  55. Save(Stuff::MemoryStream *stream);
  56. public:
  57. void Add (MLRPrimitiveBase*);
  58. MLRPrimitiveBase* Find (int);
  59. int Find (MLRPrimitiveBase*);
  60. // use this functions with care --- they are slow
  61. MLRPrimitiveBase *Remove(MLRPrimitiveBase*);
  62. MLRPrimitiveBase *Remove(int);
  63. int Insert(MLRPrimitiveBase*, int);
  64. bool
  65. Replace(MLRPrimitiveBase*, MLRPrimitiveBase*);
  66. // returns the number of primitives in the container
  67. int GetNum ()
  68. { Check_Object(this); return numPrimitives; };
  69. // returns the number of faces overall in the shape
  70. int
  71. GetNumPrimitives();
  72. // returns the number of drawn triangles in the shape
  73. int
  74. GetNumDrawnTriangles();
  75. // is to call at begin of every frame
  76. void InitializePrimitives(unsigned char, const MLRState& master, int=0);
  77. // clips the geometry and fills the data into the vertex pool
  78. // the clipping states defines the planes against the shape might have be culled
  79. // now done only on primitive level - int Clip(MLRClippingState, GOSVertexPool*);
  80. // lights the geometry, uses the worldToShape matrix and an array of lights which
  81. // affect the shape in this frame and the number of lights in this array
  82. void Lighting(const Stuff::LinearMatrix4D&, MLRLight* const*, int nrLights);
  83. // casts an ray against the geometry contained in shape
  84. bool
  85. CastRay(
  86. Stuff::Line3D *line,
  87. Stuff::Normal3D *normal
  88. );
  89. void
  90. HurtMe(const Stuff::LinearMatrix4D&, Stuff::Scalar radius);
  91. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. // Class Data Support
  93. //
  94. public:
  95. static ClassData
  96. *DefaultData;
  97. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. // Reference counting
  99. //
  100. public:
  101. void
  102. AttachReference()
  103. {Check_Object(this); ++referenceCount;}
  104. void
  105. DetachReference()
  106. {
  107. Check_Object(this); Verify(referenceCount > 0);
  108. if ((--referenceCount) == 0)
  109. {
  110. Unregister_Object(this);
  111. delete this;
  112. }
  113. }
  114. int
  115. GetReferenceCount()
  116. {return referenceCount;}
  117. protected:
  118. int
  119. referenceCount;
  120. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. // Testing
  122. //
  123. public:
  124. void
  125. TestInstance() const
  126. {};
  127. virtual int
  128. GetSize()
  129. {
  130. Check_Object(this);
  131. int ret = allPrimitives.GetSize();
  132. return ret;
  133. }
  134. protected:
  135. int
  136. FindBackFace(const Stuff::Point3D&);
  137. // void
  138. // Transform(Stuff::Matrix4D*);
  139. // void
  140. // Transform();
  141. Stuff::DynamicArrayOf<MLRPrimitiveBase*>
  142. allPrimitives;
  143. const Stuff::LinearMatrix4D
  144. *worldToShape;
  145. Stuff::Matrix4D
  146. shapeToClipMatrix;
  147. private:
  148. int numPrimitives;
  149. };
  150. }