MLRPointCloud.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. //#############################################################################
  6. //######################### MLRPointCloud ###############################
  7. //#############################################################################
  8. MLRPointCloud::ClassData*
  9. MLRPointCloud::DefaultData = NULL;
  10. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. //
  12. void
  13. MLRPointCloud::InitializeClass()
  14. {
  15. Verify(!DefaultData);
  16. Verify(gos_GetCurrentHeap() == StaticHeap);
  17. DefaultData =
  18. new ClassData(
  19. MLRPointCloudClassID,
  20. "MidLevelRenderer::MLRPointCloud",
  21. MLREffect::DefaultData
  22. );
  23. Register_Object(DefaultData);
  24. }
  25. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. //
  27. void
  28. MLRPointCloud::TerminateClass()
  29. {
  30. Unregister_Object(DefaultData);
  31. delete DefaultData;
  32. DefaultData = NULL;
  33. }
  34. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. //
  36. MLRPointCloud::MLRPointCloud(int nr, int _type) :
  37. MLREffect(nr, DefaultData), type(_type)
  38. {
  39. Verify(gos_GetCurrentHeap() == Heap);
  40. usedNrOfVertices = 0;
  41. Check_Pointer(this);
  42. drawMode = SortData::PointCloud;
  43. }
  44. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. //
  46. MLRPointCloud::~MLRPointCloud()
  47. {
  48. Check_Object(this);
  49. }
  50. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51. //
  52. void
  53. MLRPointCloud::SetData(
  54. const int *count,
  55. const Stuff::Point3D *point_data,
  56. const Stuff::RGBAColor *color_data
  57. )
  58. {
  59. Check_Pointer(this);
  60. usedNrOfVertices = count;
  61. Verify(*usedNrOfVertices <= maxNrOf);
  62. points = point_data;
  63. colors = color_data;
  64. }
  65. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66. //
  67. void
  68. MLRPointCloud::Draw (DrawEffectInformation *dInfo, GOSVertexPool *allVerticesToDraw, MLRSorter *sorter)
  69. {
  70. Check_Object(this);
  71. worldToEffect.Invert(*dInfo->effectToWorld);
  72. Transform(*usedNrOfVertices, 1);
  73. #if 0
  74. Lighting(*shape->worldToShape, dInfo->activeLights, dInfo->nrOfActiveLights);
  75. #endif
  76. if( Clip(dInfo->clippingFlags, allVerticesToDraw) )
  77. {
  78. sorter->AddEffect(this, dInfo->state);
  79. }
  80. }
  81. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. //
  83. void
  84. MLRPointCloud::Transform(int, int)
  85. {
  86. Check_Object(this);
  87. Start_Timer(Transform_Time);
  88. int i;
  89. for(i=0;i<*usedNrOfVertices;i++)
  90. {
  91. if(IsOn(i) == false)
  92. {
  93. continue;
  94. }
  95. (*transformedCoords)[i].Multiply(points[i], effectToClipMatrix);
  96. }
  97. Stop_Timer(Transform_Time);
  98. }
  99. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100. //
  101. int
  102. MLRPointCloud::Clip(MLRClippingState clippingFlags, GOSVertexPool *vt)
  103. {
  104. //--------------------------------------
  105. // See if we don't have to draw anything
  106. //--------------------------------------
  107. //
  108. int i;
  109. numGOSVertices = 0;
  110. if(clippingFlags.GetClippingState() == 0 || usedNrOfVertices <= 0)
  111. {
  112. if(usedNrOfVertices <= 0)
  113. {
  114. visible = 0;
  115. }
  116. else
  117. {
  118. Check_Object(vt);
  119. gos_vertices = vt->GetActualVertexPool();
  120. for(i=0;i<*usedNrOfVertices;i++)
  121. {
  122. // if(IsOn(i) == false)
  123. // {
  124. // continue;
  125. // }
  126. GOSCopyData(
  127. &gos_vertices[numGOSVertices],
  128. transformedCoords->GetData(),
  129. colors,
  130. i
  131. );
  132. numGOSVertices++;
  133. }
  134. Check_Object(vt);
  135. vt->Increase(numGOSVertices);
  136. visible = numGOSVertices ? 1 : 0;
  137. }
  138. return visible;
  139. }
  140. Check_Object(vt);
  141. gos_vertices = vt->GetActualVertexPool();
  142. Stuff::Vector4D *v4d = transformedCoords->GetData();
  143. for(i=0;i<*usedNrOfVertices;i++,v4d++)
  144. {
  145. // if(IsOn(i) == false)
  146. // {
  147. // continue;
  148. // }
  149. // if( clippingFlags.IsFarClipped() && v4d->w < v4d->z)
  150. // {
  151. // continue;
  152. // }
  153. // if( clippingFlags.IsNearClipped() && v4d->z < 0.0f)
  154. // {
  155. // continue;
  156. // }
  157. // if( clippingFlags.IsRightClipped() && v4d->x < 0.0f)
  158. // {
  159. // continue;
  160. // }
  161. // if( clippingFlags.IsLeftClipped() && v4d->w < v4d->x)
  162. // {
  163. // continue;
  164. // }
  165. // if( clippingFlags.IsBottomClipped() && v4d->y < 0.0f)
  166. // {
  167. // continue;
  168. // }
  169. // if(clippingFlags.IsTopClipped() && v4d->w < v4d->y)
  170. // {
  171. // continue;
  172. // }
  173. GOSCopyData(
  174. &gos_vertices[numGOSVertices],
  175. transformedCoords->GetData(),
  176. colors,
  177. i
  178. );
  179. // if(
  180. // //clippingFlags.IsLeftClipped() &&
  181. // (gos_vertices[numGOSVertices].x + ((type)?type*4.f : 4.f)) > Environment.screenWidth
  182. // )
  183. // {
  184. // continue;
  185. // }
  186. //
  187. // if(
  188. // //clippingFlags.IsTopClipped() &&
  189. // (gos_vertices[numGOSVertices].y + ((type)?type*4.f : 4.f)) > Environment.screenHeight
  190. // )
  191. // {
  192. // continue;
  193. // }
  194. //
  195. numGOSVertices++;
  196. }
  197. vt->Increase(numGOSVertices);
  198. visible = numGOSVertices ? 1 : 0;
  199. if(visible)
  200. {
  201. }
  202. else
  203. {
  204. }
  205. return visible;
  206. }
  207. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  208. //
  209. void
  210. MLRPointCloud::TestInstance() const
  211. {
  212. if (usedNrOfVertices)
  213. {
  214. Verify(*usedNrOfVertices >= 0);
  215. Verify(*usedNrOfVertices <= maxNrOf);
  216. }
  217. }