src/Screens/Experimental/MeshHittestWithBVHScreen.cpp
// assumes vertex array is set. Only sets uModel and draws each frame
assumes vertex array is set. Only sets uModel and draws each frame
assumes vertex array is set . Only sets uModel and draws each frame
static void drawBVHRecursive(BVH const& bvh, SolidColorShader& shader, int pos) {
    BVHNode const& n = bvh.nodes[pos];
    glm::vec3 halfWidths = AABBDims(n.bounds) / 2.0f;
    glm::vec3 center = AABBCenter(n.bounds);
    glm::mat4 scaler = glm::scale(glm::mat4{1.0f}, halfWidths);
    glm::mat4 mover = glm::translate(glm::mat4{1.0f}, center);
    glm::mat4 mmtx = mover * scaler;
    gl::Uniform(shader.uModel, mmtx);
    gl::DrawElements(GL_LINES, 24, GL_UNSIGNED_INT, nullptr);
    if (n.nlhs >= 0) {  
        drawBVHRecursive(bvh, shader, pos+1);
        drawBVHRecursive(bvh, shader, pos+n.nlhs+1);
    }
}
static void drawBVHRecursive ( BVH const & bvh , SolidColorShader & shader , int pos ) { BVHNode const & n = bvh . nodes [ pos ] ; glm :: vec3 halfWidths = AABBDims ( n . bounds ) / 2.0f ; glm :: vec3 center = AABBCenter ( n . bounds ) ; glm :: mat4 scaler = glm :: scale ( glm :: mat4 { 1.0f } , halfWidths ) ; glm :: mat4 mover = glm :: translate ( glm :: mat4 { 1.0f } , center ) ; glm :: mat4 mmtx = mover * scaler ; gl :: Uniform ( shader . uModel , mmtx ) ; gl :: DrawElements ( GL_LINES , 24 , GL_UNSIGNED_INT , nullptr ) ; if ( n . nlhs >= 0 ) { drawBVHRecursive ( bvh , shader , pos + 1 ) ; drawBVHRecursive ( bvh , shader , pos + n . nlhs + 1 ) ; } }
assumes vertex array is set.
assumes vertex array is set .
// if it's an internal node