Team Fortress 2 Source Code as on 22/4/2020
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.

127 lines
3.3 KiB

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