Source code of Windows XP (NT5)
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.

83 lines
2.5 KiB

  1. /*============================================================================
  2. *
  3. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: npatch.hpp
  6. * Content: Declarations for n-Patch scheme
  7. *
  8. ****************************************************************************/
  9. #ifndef _NPATCH_HPP
  10. #define _NPATCH_HPP
  11. class RDCubicBezierTriangle
  12. {
  13. public:
  14. void SamplePosition(double u, double v, FLOAT *Q) const;
  15. void Sample(DWORD dwDataType, double u, double v, const BYTE* const B[], BYTE *Q) const;
  16. protected:
  17. double m_B[4][4][3];
  18. private:
  19. unsigned factorial(unsigned k) const
  20. {
  21. _ASSERT(k < 13, "Factorial out of range");
  22. for(unsigned i = 1, t = 1; i <= k; t *= i++);
  23. return t;
  24. }
  25. double Basis(unsigned i, unsigned j, double u, double v) const
  26. {
  27. unsigned k = 3 - i - j;
  28. double w = 1.0 - u - v;
  29. _ASSERT(i + j + k == 3, "Barycentric coordinates need to add to 3");
  30. return (6.0 * pow(u, double(i)) * pow(v, double(j)) * pow(w, double(k))) / double(factorial(i) * factorial(j) * factorial(k));
  31. }
  32. };
  33. class RDNPatch : public RDCubicBezierTriangle
  34. {
  35. public:
  36. RDNPatch(const FLOAT* const pV[], const FLOAT* const pN[],
  37. const DWORD PositionOrder, const DWORD NormalOrder);
  38. void SamplePosition(double u, double v, FLOAT *Q) const;
  39. void SampleNormal(double u, double v, const BYTE* const B[], FLOAT *Q) const;
  40. private:
  41. void ComputeEdgeControlPoint(unsigned a, unsigned b, const FLOAT* const pV[], const FLOAT* const pN[], unsigned u, unsigned v);
  42. void ComputeNormalControlPoint(RDVECTOR3* cp, unsigned i, unsigned j,
  43. const FLOAT* const pV[],
  44. const FLOAT* const pN[]);
  45. DWORD m_PositionOrder;
  46. DWORD m_NormalOrder;
  47. // Normal coefficients
  48. RDVECTOR3 m_N200;
  49. RDVECTOR3 m_N020;
  50. RDVECTOR3 m_N002;
  51. RDVECTOR3 m_N110;
  52. RDVECTOR3 m_N011;
  53. RDVECTOR3 m_N101;
  54. };
  55. class RRIndexAccessor
  56. {
  57. public:
  58. RRIndexAccessor(BYTE *pBuf, DWORD dwStride, DWORD dwStart)
  59. {
  60. _ASSERT(dwStride == 2 || dwStride == 4, "Unsupported indexbuffer stride");
  61. m_pBuf = pBuf + dwStart * dwStride;
  62. m_32 = (dwStride == 4);
  63. }
  64. unsigned operator[](unsigned i) const
  65. {
  66. return m_32 ? ((DWORD*)m_pBuf)[i] : ((WORD*)m_pBuf)[i];
  67. }
  68. private:
  69. VOID *m_pBuf;
  70. bool m_32;
  71. };
  72. #endif // _NPATCH_HPP