<commit_before>#include <glowutils/CameraPathPlayer.h>

#include <cassert>
#include <string>
#include <algorithm>
#include <functional>
#include <limits>
#include <vector>

#include <glm/gtc/type_ptr.hpp>

#include <glowbase/StaticStringSource.h>

#include <glow/Buffer.h>
#include <glow/Program.h>
#include <glow/VertexArrayObject.h>
#include <glow/VertexAttributeBinding.h>
#include <glow/logging.h>

#include <glowutils/Camera.h>
#include <glowutils/StringTemplate.h>
#include <glowutils/math/BezierCurve.h>

using namespace glm;

namespace glowutils
{

CameraPathPlayer::CameraPathPlayer(Camera & camera)
: m_camera(camera)
, m_bufferSize(0)
{
}

void CameraPathPlayer::setPath(const CameraPath & path)
{
   m_path = path;
   prepare();
}

void CameraPathPlayer::prepare()
{
    const std::vector<CameraPathPoint>& points = m_path.points();

    if (points.size()<=1)
        return;

    float totalLength = 0.0;
    const CameraPathPoint* previous = &points[0];

    for (unsigned int i = 1; i<points.size(); ++i)
    {
        const CameraPathPoint* current = &points[i];
        float distance = glm::length(current->eye - previous->eye);

        float startT = totalLength;
        float endT = startT + distance;

        PathSection section{ previous, current, startT, endT, glm::vec3(), glm::vec3() };
        m_sections.push_back(section);

        totalLength = endT;
        previous = current;
    }

    /*{
        const CameraPathPoint* current = &points[0];
        float distance = glm::length(current->eye - previous->eye);

        float startT = totalLength;
        float endT = startT + distance;

        PathSection section{ previous, current, startT, endT };
        m_sections.push_back(section);

        totalLength = endT;
    }*/

    // normalize
    for (PathSection& section : m_sections)
    {
        section.startT /= totalLength;
        section.endT /= totalLength;
    }

    prepareControlPoints();
}

namespace {
vec3 intersection(const vec3& a, const vec3& r, const vec3& p, const vec3& n)
{
    float rDotN = dot(r, n);

    assert(std::abs(rDotN) < std::numeric_limits<float>::epsilon());

    float t = dot(p - a, n) / rDotN;
    return a + r * t;
}

const char* vertexSource = R"(
#version 140
#extension GL_ARB_explicit_attrib_location : require

uniform mat4 transform;

layout(location = 0) in vec4 vertex;

out float t;

void main()
{
    gl_Position = transform * vec4(vertex.xyz, 1.0);
    t = vertex.w;

}
)";

const char* fragmentSource = R"(
#version 140
#extension GL_ARB_explicit_attrib_location : require

layout(location=0) out vec4 fragColor;

in float t;

void main()
{
    fragColor = vec4(vec3(1.0, 0.2+t*0.8, t/2.0), 1.0);
}
)";

}

void CameraPathPlayer::prepareControlPoints()
{
    const std::vector<CameraPathPoint>& points = m_path.points();

    const CameraPathPoint* previous = &points[0];
    const CameraPathPoint* current = &points[1];

    //const CameraPathPoint* first = &points[0];
    const CameraPathPoint* last = &points[points.size()-1];

    std::vector<glm::vec3> dirs;
    vec3 dir0 = current->eye - previous->eye;
    dir0 = (dir0 + (previous->eye - (&points[points.size()-2])->eye))/2.f;
    dirs.push_back(dir0);

    for (unsigned int i = 1; i<points.size()-1; ++i)
    {
        const CameraPathPoint* current = &points[i];
        const CameraPathPoint* next = &points[i+1];
<commit_msg>Remove unused function (closes #223)<commit_after>#include <glowutils/CameraPathPlayer.h>

#include <cassert>
#include <string>
#include <algorithm>
#include <functional>
#include <limits>
#include <vector>

#include <glm/gtc/type_ptr.hpp>

#include <glowbase/StaticStringSource.h>

#include <glow/Buffer.h>
#include <glow/Program.h>
#include <glow/VertexArrayObject.h>
#include <glow/VertexAttributeBinding.h>
#include <glow/logging.h>

#include <glowutils/Camera.h>
#include <glowutils/StringTemplate.h>
#include <glowutils/math/BezierCurve.h>

using namespace glm;

namespace {

    const char* vertexSource = R"(
#version 140
#extension GL_ARB_explicit_attrib_location : require

uniform mat4 transform;

layout(location = 0) in vec4 vertex;

out float t;

void main()
{
    gl_Position = transform * vec4(vertex.xyz, 1.0);
    t = vertex.w;

}
)";

    const char* fragmentSource = R"(
#version 140
#extension GL_ARB_explicit_attrib_location : require

layout(location=0) out vec4 fragColor;

in float t;

void main()
{
    fragColor = vec4(vec3(1.0, 0.2+t*0.8, t/2.0), 1.0);
}
)";

}

namespace glowutils
{

CameraPathPlayer::CameraPathPlayer(Camera & camera)
: m_camera(camera)
, m_bufferSize(0)
{
}

void CameraPathPlayer::setPath(const CameraPath & path)
{
   m_path = path;
   prepare();
}

void CameraPathPlayer::prepare()
{
    const std::vector<CameraPathPoint>& points = m_path.points();

    if (points.size()<=1)
        return;

    float totalLength = 0.0;
    const CameraPathPoint* previous = &points[0];

    for (unsigned int i = 1; i<points.size(); ++i)
    {
        const CameraPathPoint* current = &points[i];
        float distance = glm::length(current->eye - previous->eye);

        float startT = totalLength;
        float endT = startT + distance;

        PathSection section{ previous, current, startT, endT, glm::vec3(), glm::vec3() };
        m_sections.push_back(section);

        totalLength = endT;
        previous = current;
    }

    /*{
        const CameraPathPoint* current = &points[0];
        float distance = glm::length(current->eye - previous->eye);

        float startT = totalLength;
        float endT = startT + distance;

        PathSection section{ previous, current, startT, endT };
        m_sections.push_back(section);

        totalLength = endT;
    }*/

    // normalize
    for (PathSection& section : m_sections)
    {
        section.startT /= totalLength;
        section.endT /= totalLength;
    }

    prepareControlPoints();
}

void CameraPathPlayer::prepareControlPoints()
{
    const std::vector<CameraPathPoint>& points = m_path.points();

    const CameraPathPoint* previous = &points[0];
    const CameraPathPoint* current = &points[1];

    //const CameraPathPoint* first = &points[0];
    const CameraPathPoint* last = &points[points.size()-1];

    std::vector<glm::vec3> dirs;
    vec3 dir0 = current->eye - previous->eye;
    dir0 = (dir0 + (previous->eye - (&points[points.size()-2])->eye))/2.f;
    dirs.push_back(dir0);

    for (unsigned int i = 1; i<points.size()-1; ++i)
    {
        const CameraPathPoint* current = &points[i];
        const CameraPathPoint* next = &points[i+1];

{'fraction_non_alphanumeric': 0.14013418725221105, 'fraction_numerical': 0.01646843549862763, 'mean_word_length': 3.471029311520109, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5516763', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2203, 'n_words': 503}