# Lab5

CatmullRom Animation 도형을 그려본다.
(n-key를 누를 시, “사”-도형이 아지랑이 피어오르듯이 올라간다)

Sa::Sa(glm::vec3 p_) : GeometryPositionColor()
{
p = p_;
for (int i=0; i<4; i++) pipe[i] = Parallelpiped();

std::vector<KeyFrame> keyframes;
keyframes.push_back(KeyFrame(glm::vec3(0, 0, 0), 0)); // Posotion & Time
keyframes.push_back(KeyFrame(glm::vec3(1, 1, 0), 2000));
// Posotion & Time
keyframes.push_back(KeyFrame(glm::vec3(-1, 2, 0),
4000
));
// Posotion & Time
keyframes.push_back(KeyFrame(glm::vec3(2, 3, 0), 6000)); // Posotion & Time
curve = new CatmullRomCurveAnimation(keyframes, false);
// loop을 원하면 true

init();
}

void Sa::init() // “사”
{
glm::vec3 p0 = p;
pipe[0].set(p0, glm::vec3(0.3f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.7f, 1.0f, 0.0f));
glm::vec3 p1 = p + glm::vec3(1.4f, 0.0f, 0.0f);
pipe[1].set(p1, glm::vec3(0.3f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(-0.7f, 1.0f, 0.0f));
glm::vec3 p2 = p + glm::vec3(2.0f, 0.0f, 0.0f);
pipe[2].set(p2, glm::vec3(0.3f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.0f, 1.0f,
0.0f));
glm::vec3 p3 = p + glm::vec3(2.3f, 0.35f, 0.0f);
pipe[3].set(p3, glm::vec3(0.5f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.0f, 0.3f, 0.0f));
}

void Sa::draw(bool wireframe)
{
for (int i=0; i<4; i++) pipe[i].draw();
}

// GeometryPositionColor 의 update을 override
bool Sa::update(float elapsedTime)
{
if (active)
{
if (curve)
{
curve->updatePosition(elapsedTime);
p = curve->getPosition();

// if time is greater than duration, then set time to duration and set active to false
if (!curve->getLoop() && elapsedTime >=  curve->getDuration())
{
done = true;
active = false;
}
}
init();
}
return true;
}