#include "dk_shared.h"
#include "ref.h"
#include "client.h"

#include "dk_cl_curve.h"

#include "dk_gce_spline.h"

int MakeCurve(int num_positions, const vec3_t *positions, const vec3_t *velocities,
    entity_t *reference_entity, float max_angle, float max_length)
{
    if (num_positions < 2) return 0;
    if (positions == NULL) return 0;
    if (velocities == NULL) return 0;
    if (reference_entity == NULL) return 0;

    //make a spline
    CSplineSequence *spline = new CSplineSequence();

    //initialize the spline with the given points.
    spline->InitPositions(num_positions, positions, velocities);

    //spit out entities.
    int num_entities = spline->MakeCurveEntities(reference_entity, V_GetEntity, max_angle, max_length);

    //delete the spline.
    delete spline;

    return num_entities;
}





/*

vec3_t test_points[5] = {
    0, 0, 30,
    100, 100, 30,
    200, 100, 60,
    0, 200, 60,
    0, 0, 90,
};

#define LENGTH 1

vec3_t test_dirs[5] = {
    0, LENGTH, 0,
    0, -LENGTH, 0,
    0, 0, LENGTH,
    0, -LENGTH, 0,
    -LENGTH, 0, 0,
};

void TestFunc() {
    entity_t reference;
    vec3_t random_dirs[5];
    vec3_t random_pts[5];
    float time;

    //set up the reference entity.
    //set the width of the laser.
    reference.frame = 3;
    //flags.
    reference.flags = RF_TRANSLUCENT;
    //alpha
    reference.alpha = 0.1f;

    time = (GetTickCount() % 300) / 300.0f;

    //randomize the directions.
    for (i = 0; i < 5; i++) {
        //make a random vector we will add to our base direction.
        vec3_t added;
        added[0] = 0.4f * sin(i +  6.28318530718 * time);
        added[1] = 0.4f * sin(i +  6.28318530718 * time + 0.2f);
        added[2] = 0.4f * sin(i +  6.28318530718 * time + 0.4f);

        random_dirs[i][0] = test_dirs[i][0] + added[0];
        random_dirs[i][1] = test_dirs[i][1] + added[1];
        random_dirs[i][2] = test_dirs[i][2] + added[2];

        random_pts[i][0] = test_points[i][0] + 30 * added[0];
        random_pts[i][1] = test_points[i][1] + 30 * added[1];
        random_pts[i][2] = test_points[i][2] + 30 * added[2];
    }

    //make our test laser curve.
//    i = 4 * MakeCurve(5, random_pts, random_dirs, &reference, 15, 20);

//    Com_Printf("Num curve polys: %d\n", i);
}

*/