MLRIndexedPolyMesh.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #pragma once
  5. #define MLR_MLRINDEXEDPOLYMESH_HPP
  6. #if !defined(MLR_MLR_HPP)
  7. #include <MLR\MLR.hpp>
  8. #endif
  9. #if !defined(MLR_MLRINDEXEDPRIMITIVE_HPP)
  10. #include <MLR\MLRIndexedPrimitive.hpp>
  11. #endif
  12. namespace MidLevelRenderer {
  13. //##########################################################################
  14. //#################### MLRIndexedPolyMesh ############################
  15. //##########################################################################
  16. class MLRIndexedPolyMesh:
  17. public MLRIndexedPrimitive
  18. {
  19. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. // Initialization
  21. //
  22. public:
  23. static void
  24. InitializeClass();
  25. static void
  26. TerminateClass();
  27. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. // Constructors/Destructors
  29. //
  30. protected:
  31. MLRIndexedPolyMesh(
  32. Stuff::MemoryStream *stream,
  33. int version
  34. );
  35. ~MLRIndexedPolyMesh();
  36. public:
  37. MLRIndexedPolyMesh();
  38. static MLRIndexedPolyMesh*
  39. Make(
  40. Stuff::MemoryStream *stream,
  41. int version
  42. );
  43. void
  44. Save(Stuff::MemoryStream *stream);
  45. void*
  46. operator new(size_t size)
  47. {
  48. Verify(size == sizeof(MLRIndexedPolyMesh));
  49. return AllocatedMemory->New();
  50. }
  51. void
  52. operator delete(void *where)
  53. {AllocatedMemory->Delete(where);}
  54. private:
  55. static Stuff::MemoryBlock
  56. *AllocatedMemory;
  57. public:
  58. virtual void InitializeDrawPrimitive(int, int=0);
  59. virtual void SetPrimitiveLength(unsigned char *, int);
  60. virtual void GetPrimitiveLength(unsigned char **, int*);
  61. void FindFacePlanes();
  62. virtual int FindBackFace(const Stuff::Point3D&);
  63. const Stuff::Plane *GetPolygonPlane(int i)
  64. {
  65. Check_Object(this);
  66. Verify(i<facePlanes.GetLength());
  67. return &facePlanes[i];
  68. }
  69. virtual void Lighting(MLRLight**, int nrLights);
  70. MLRPrimitive *LightMapLighting(MLRLight*);
  71. virtual int Clip(MLRClippingState, GOSVertexPool*);
  72. bool
  73. CastRay(
  74. Stuff::Line3D *line,
  75. Stuff::Normal3D *normal
  76. );
  77. void
  78. Transform(Stuff::Matrix4D*);
  79. virtual void
  80. TransformNoClip(Stuff::Matrix4D*, GOSVertexPool*);
  81. // Initializes the visibility test list
  82. void
  83. ResetTestList();
  84. // find which vertices are visible which not - returns nr of visible vertices
  85. // the result is stored in the visibleIndexedVertices array
  86. int
  87. FindVisibleVertices();
  88. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  89. // Class Data Support
  90. //
  91. public:
  92. static ClassData
  93. *DefaultData;
  94. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. // Testing
  96. //
  97. public:
  98. void
  99. TestInstance() const;
  100. virtual int
  101. GetSize()
  102. {
  103. Check_Object(this);
  104. int ret = MLRIndexedPrimitive::GetSize();
  105. ret += testList.GetSize();
  106. ret += facePlanes.GetSize();
  107. return ret;
  108. }
  109. protected:
  110. Stuff::DynamicArrayOf<unsigned char> testList;
  111. Stuff::DynamicArrayOf<Stuff::Plane> facePlanes;
  112. };
  113. MLRIndexedPolyMesh*
  114. CreateIndexedCube(Stuff::Scalar, Stuff::RGBAColor*, Stuff::Vector3D*, MLRState*);
  115. }