fork download
  1.  
  2. bool Player::IsSweptColliding(float timeStep)
  3. {
  4. glm::vec3 vel = m_velocity*timeStep;
  5.  
  6. if(IsNullVec(vel))
  7. return false;
  8.  
  9. AABB g = m_aabb;
  10. g.SetCenter(this->m_position);
  11.  
  12. auto vec = m_octree->CheckCollisionSwept(g, vel);
  13.  
  14. if(vec.size()==0)
  15. {
  16. m_position += vel;
  17. return false;
  18. }
  19.  
  20. glm::vec3 sweepDir = glm::normalize(vel);
  21. float minHitDist = vec[0].time;
  22. bool axisBlocked[3] = {false,false,false};
  23. float minDistAxis[3] = {99999999,99999999,99999999};
  24. uint32_t axisVoxel[3] = {0,0,0};
  25.  
  26. ///for decoding voxel coordinates
  27. uint32_t x1,y1,z1;
  28. uint32_t x2,y2,z2;
  29.  
  30. ///check which axis to clamp motion on
  31. for(unsigned int i = 0; i < vec.size(); i++)
  32. {
  33. auto voxel = vec[i];
  34. float t = voxel.time;
  35.  
  36. if(t==1||IsNullVec(voxel.normal))
  37. continue;
  38.  
  39. int axis = GetBlockAxis(voxel.normal);
  40.  
  41. // get nearest distance
  42. if( t < minHitDist)
  43. minHitDist = t;
  44.  
  45. ///this loop lets player slide against walls just fine, but can't make it work on y axis
  46. ///and this probably also will have more issues when player size changes and voxel count increases
  47. loop(j, vec.size())
  48. {
  49. if(i==j)
  50. continue;
  51.  
  52. decodeMK(vec[i].voxelMK,x1,y1,z1);
  53. decodeMK(vec[j].voxelMK,x2,y2,z2);
  54. if(axis==0&&z1==z2)
  55. goto noblock;
  56. if(axis==2&&x1==x2)
  57. goto noblock;
  58. if(axis==1 && vel.y<0 && ((x1==x2||z1==z2) && y1 < y2))
  59. goto noblock;
  60. }
  61. axisBlocked[axis] = true;
  62.  
  63. noblock:;
  64. }
  65.  
  66. printf("Blck axisd[%.2f,%.2f,%.2f]\n", minDistAxis[0], minDistAxis[1], minDistAxis[2]);
  67. printf("Blck axis [%i, %i, %i]\n", axisBlocked[0], axisBlocked[1], axisBlocked[2]);
  68.  
  69. glm::vec3 clampedMotion = vel;
  70. for(int i = 0; i < 3; i++)
  71. {
  72. if(axisBlocked[i])
  73. clampedMotion[i] *= minHitDist;
  74. }
  75.  
  76. m_position = m_position + clampedMotion;
  77. return true;
  78. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:6: error: ‘Player’ has not been declared
 bool Player::IsSweptColliding(float timeStep)
      ^
prog.cpp: In function ‘bool IsSweptColliding(float)’:
prog.cpp:4:3: error: ‘glm’ has not been declared
   glm::vec3 vel = m_velocity*timeStep;
   ^
prog.cpp:4:13: error: expected ‘;’ before ‘vel’
   glm::vec3 vel = m_velocity*timeStep;
             ^
prog.cpp:6:16: error: ‘vel’ was not declared in this scope
   if(IsNullVec(vel))
                ^
prog.cpp:6:19: error: ‘IsNullVec’ was not declared in this scope
   if(IsNullVec(vel))
                   ^
prog.cpp:9:3: error: ‘AABB’ was not declared in this scope
   AABB g = m_aabb;
   ^
prog.cpp:9:8: error: expected ‘;’ before ‘g’
   AABB g = m_aabb;
        ^
prog.cpp:10:3: error: ‘g’ was not declared in this scope
   g.SetCenter(this->m_position);
   ^
prog.cpp:10:15: error: invalid use of ‘this’ in non-member function
   g.SetCenter(this->m_position);
               ^
prog.cpp:12:14: error: ‘m_octree’ was not declared in this scope
   auto vec = m_octree->CheckCollisionSwept(g, vel);
              ^
prog.cpp:12:47: error: ‘vel’ was not declared in this scope
   auto vec = m_octree->CheckCollisionSwept(g, vel);
                                               ^
prog.cpp:16:7: error: ‘m_position’ was not declared in this scope
       m_position += vel;
       ^
prog.cpp:20:3: error: ‘glm’ has not been declared
   glm::vec3 sweepDir = glm::normalize(vel);
   ^
prog.cpp:20:13: error: expected ‘;’ before ‘sweepDir’
   glm::vec3 sweepDir = glm::normalize(vel);
             ^
prog.cpp:23:53: warning: narrowing conversion of ‘99999999’ from ‘int’ to ‘float’ inside { } [-Wnarrowing]
   float minDistAxis[3] = {99999999,99999999,99999999};
                                                     ^
prog.cpp:23:53: warning: narrowing conversion of ‘99999999’ from ‘int’ to ‘float’ inside { } [-Wnarrowing]
prog.cpp:23:53: warning: narrowing conversion of ‘99999999’ from ‘int’ to ‘float’ inside { } [-Wnarrowing]
prog.cpp:24:3: error: ‘uint32_t’ was not declared in this scope
   uint32_t axisVoxel[3] = {0,0,0};  
   ^
prog.cpp:24:12: error: expected ‘;’ before ‘axisVoxel’
   uint32_t axisVoxel[3] = {0,0,0};  
            ^
prog.cpp:27:12: error: expected ‘;’ before ‘x1’
   uint32_t x1,y1,z1;
            ^
prog.cpp:28:12: error: expected ‘;’ before ‘x2’
   uint32_t x2,y2,z2;
            ^
prog.cpp:36:36: error: ‘IsNullVec’ was not declared in this scope
     if(t==1||IsNullVec(voxel.normal))
                                    ^
prog.cpp:39:41: error: ‘GetBlockAxis’ was not declared in this scope
     int axis = GetBlockAxis(voxel.normal);
                                         ^
prog.cpp:47:10: error: ‘j’ was not declared in this scope
     loop(j, vec.size())
          ^
prog.cpp:47:23: error: ‘loop’ was not declared in this scope
     loop(j, vec.size())
                       ^
prog.cpp:48:7: error: expected ‘;’ before ‘{’ token
       {
       ^
prog.cpp:66:88: error: ‘printf’ was not declared in this scope
   printf("Blck axisd[%.2f,%.2f,%.2f]\n", minDistAxis[0], minDistAxis[1], minDistAxis[2]);
                                                                                        ^
prog.cpp:69:3: error: ‘glm’ has not been declared
   glm::vec3 clampedMotion = vel;
   ^
prog.cpp:69:13: error: expected ‘;’ before ‘clampedMotion’
   glm::vec3 clampedMotion = vel;
             ^
prog.cpp:73:7: error: ‘clampedMotion’ was not declared in this scope
       clampedMotion[i] *= minHitDist;      
       ^
prog.cpp:76:3: error: ‘m_position’ was not declared in this scope
   m_position = m_position + clampedMotion;
   ^
prog.cpp:76:29: error: ‘clampedMotion’ was not declared in this scope
   m_position = m_position + clampedMotion;
                             ^
prog.cpp:63:3: warning: label ‘noblock’ defined but not used [-Wunused-label]
   noblock:;
   ^
stdout
Standard output is empty