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.

130 lines
3.3 KiB

  1. #include "raytrace.h"
  2. #include <bspfile.h>
  3. #include "bsplib.h"
  4. // NOTE: This has to be the last file included!
  5. #include "tier0/memdbgon.h"
  6. static Vector VertCoord(dface_t const &f, int vnum)
  7. {
  8. int eIndex = dsurfedges[f.firstedge+vnum];
  9. int point;
  10. if( eIndex < 0 )
  11. {
  12. point = dedges[-eIndex].v[1];
  13. }
  14. else
  15. {
  16. point = dedges[eIndex].v[0];
  17. }
  18. dvertex_t *v=dvertexes+point;
  19. return Vector(v->point[0],v->point[1],v->point[2]);
  20. }
  21. Vector colors[]={
  22. Vector(0.5,0.5,1),
  23. Vector(0.5,1,0.5),
  24. Vector(0.5,1,1),
  25. Vector(1,0.5,0.5),
  26. Vector(1,0.5,1),
  27. Vector(1,1,1)};
  28. void RayTracingEnvironment::AddBSPFace(int id,dface_t const &face)
  29. {
  30. if (face.dispinfo!=-1) // displacements must be dealt with elsewhere
  31. return;
  32. texinfo_t *tx =(face.texinfo>=0)?&(texinfo[face.texinfo]):0;
  33. // if (tx && (tx->flags & (SURF_SKY|SURF_NODRAW)))
  34. // return;
  35. if (tx)
  36. {
  37. printf("id %d flags=%x\n",id,tx->flags);
  38. }
  39. printf("side: ");
  40. for(int v=0;v<face.numedges;v++)
  41. {
  42. printf("(%f %f %f) ",XYZ(VertCoord(face,v)));
  43. }
  44. printf("\n");
  45. int ntris=face.numedges-2;
  46. for(int tri=0;tri<ntris;tri++)
  47. {
  48. AddTriangle(id,VertCoord(face,0),VertCoord(face,(tri+1)%face.numedges),
  49. VertCoord(face,(tri+2)%face.numedges),Vector(1,1,1)); //colors[id % NELEMS(colors)]);
  50. }
  51. }
  52. void RayTracingEnvironment::InitializeFromLoadedBSP(void)
  53. {
  54. // CUtlVector<uint8> PlanesToSkip;
  55. // SidesToSkip.EnsureCapacity(numplanes);
  56. // for(int s=0;s<numplanes;s++)
  57. // SidesToSkip.AddToTail(0);
  58. // for(int b=0;b<numbrushes;b++)
  59. // if ((dbrushes[b].contents & MASK_OPAQUE)==0)
  60. // {
  61. // // transparent brush - mark all its sides as "do not process"
  62. // for(int s=0;s<dbrushes[b].numsides;s++)
  63. // {
  64. // PlanesToSkip[s+dbrushes[b].firstside]=1;
  65. // }
  66. // }
  67. // // now, add all origfaces, omitting those whose sides are the ones we marked previously
  68. // for(int c=0;c<numorigfaces;c++)
  69. // {
  70. // dface_t const &f=dorigfaces[c];
  71. // if (SidesToSkip[f.AddBSPFace(c,dorigfaces[c]);
  72. // }
  73. // // ugly - I want to traverse all the faces. but there is no way to get from a face back to it's
  74. // // original brush, and I need to get back to the face to the contents field of the brush. So I
  75. // // will create a temporary mapping from a "side" to its brush. I can get from the face to it
  76. // // side, which can get me back to its brush.
  77. // CUtlVector<uint8> OrigFaceVisited;
  78. // OrigFaceVisited.EnsureCapacity(numorigfaces);
  79. // int n_added=0;
  80. // for(int i=0;i<numorigfaces;i++)
  81. // OrigFaceVisited.AddToTail(0);
  82. // for(int l=0;l<numleafs;l++)
  83. // {
  84. // dleaf_t const &lf=dleafs[l];
  85. // // if (lf.contents & MASK_OPAQUE)
  86. // {
  87. // for(int f=0;f<lf.numleaffaces;f++);
  88. // {
  89. // dface_t const &face=dfaces[f+lf.firstleafface];
  90. // if (OrigFaceVisited[face.origFace]==0)
  91. // {
  92. // dface_t const &oface=dorigfaces[face.origFace];
  93. // OrigFaceVisited[face.origFace]=1;
  94. // n_added++;
  95. // AddBSPFace(face.origFace,oface);
  96. // }
  97. // }
  98. // }
  99. // }
  100. // printf("added %d of %d\n",n_added,numorigfaces);
  101. // for(int c=0;c<numorigfaces;c++)
  102. // {
  103. // dface_t const &f=dorigfaces[c];
  104. // AddBSPFace(c,dorigfaces[c]);
  105. // }
  106. for(int c=0;c<numfaces;c++)
  107. {
  108. // dface_t const &f=dfaces[c];
  109. AddBSPFace(c,dorigfaces[c]);
  110. }
  111. // AddTriangle(1234,Vector(51,145,-700),Vector(71,165,-700),Vector(51,165,-700),colors[5]);
  112. }