Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
*/
/*!
/file Path.cpp
/author Team42, Jiawei Gu
/e-mail jiawei.gu@digipen.edu
/date 10/24/2015
/Brief Copyright (C) 2015 DigiPen Institute of Technology. Reproduction or
disclosure of this file or its contents without the prior written consent of
DigiPen Institute of Technology is prohibited.
*/
/* End Header ******************************************************************
*/
#include "Path.h"
#define CURVE_TABLE_ERROR 1e-4
namespace Anime
{
Path::Path() :
spline(),
accS(0.0f),
direction(0, 0, 0),
controlPointsCount(0),
interPolatedPointsCount(0),
drawControlPoints(true),
drawPath(true)
{
VAO[0] = 0; VAO[1] = 0;
VBO[0] = 0; VBO[1] = 0;
spline.SetAutoCalculate(false);
}
void Path::AddControlPoint(const Vector3 & point)
{
controlPoints.push_back(point);
}
void Path::UpdateControlPoint(unsigned int index, const Vector3 & point)
{
controlPoints[index] = point;
}
void Path::CalculatePath()
{
spline.SetControlPoints(controlPoints);
spline.RecalculateTangents();
wholePath.clear();
curveTable.Clear();
wholePath.push_back(controlPoints[0]);
curveTable.AddIncreaseLength(0.0f, 0.0f);
if (controlPoints.size() > 1)
{
float deltaU = 1.0f / (controlPoints.size() - 1);
for (unsigned int i = 0; i < controlPoints.size() - 1; +
+i)
MakeCurveTable(controlPoints[i], controlPoints[i
void Path::DrawPath()
{
if (drawPath)
{
glBindVertexArray(VAO[1]);
glDrawArrays(GL_LINES, 0, wholePath.size());
glBindVertexArray(0);
}
}
void Path::SetupEditor(EditorUnit * editor)
{
editor->AddVariableRO("Control Pts", "Path", &controlPointsCount
);
editor->AddVariableRO("Inter Pts", "Path", &interPolatedPointsCo
unt);
editor->AddVariableRW("Draw Ctrl Pts", "Path", &drawControlPoint
s);
editor->AddVariableRW("Draw Path", "Path", &drawPath);
}
void Path::SwitchDrawControlPoints()
{
drawControlPoints = !drawControlPoints;
}
void Path::SwitchDrawPath()
{
drawPath = !drawPath;
}
}