Added animation
This commit is contained in:
@@ -47,3 +47,5 @@ set(SOURCE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/timer.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
#add_subdirectory(animation)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
set(HEADERS
|
||||
${HEADERS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/float_track.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/integer_track.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vec3_track.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
set(SOURCE
|
||||
${SOURCE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/float_track.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/integer_track.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vec3_track.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "animation/float_track.h"
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
animated_value float_track::get_value(const animated_value &first, const animated_value &second, float alpha) {
|
||||
animated_value result;
|
||||
result.floatVal = glm::mix(first.floatVal, second.floatVal, alpha);
|
||||
return result;
|
||||
};
|
||||
|
||||
void float_track::control_object(void *controlled_object, const animated_value &value) {
|
||||
*reinterpret_cast<float *>(controlled_object) = value.floatVal;
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "animation_track.h"
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
class float_track : public animation_track {
|
||||
public:
|
||||
animated_value get_value(const animated_value &first, const animated_value &second, float alpha) override;
|
||||
void control_object(void *controlled_object, const animated_value &value) override;
|
||||
};
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "animation/integer_track.h"
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
animated_value integer_track::get_value(const animated_value &first, const animated_value &second, float alpha) {
|
||||
// no interpolation here
|
||||
animated_value result;
|
||||
result.intVal = static_cast<int>(first.intVal + (second.intVal - first.intVal) * alpha);
|
||||
return result;
|
||||
};
|
||||
|
||||
void integer_track::control_object(void *controlled_object, const animated_value &value) {
|
||||
*reinterpret_cast<int *>(controlled_object) = value.intVal;
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "animation_track.h"
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
class integer_track : public animation_track {
|
||||
public:
|
||||
animated_value get_value(const animated_value &first, const animated_value &second, float alpha) override;
|
||||
void control_object(void *controlled_object, const animated_value &value) override;
|
||||
};
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "vec3_track.h"
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
animated_value vec3_track::get_value(const animated_value &first, const animated_value &second, float alpha) {
|
||||
animated_value result;
|
||||
result.vec3_val = glm::mix(first.vec3_val, second.vec3_val, alpha);
|
||||
return result;
|
||||
};
|
||||
|
||||
void vec3_track::control_object(void *controlled_object, const animated_value &value) {
|
||||
*reinterpret_cast<glm::vec3 *>(controlled_object) = value.vec3_val;
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "animation_track.h"
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
class vec3_track : public animation_track {
|
||||
public:
|
||||
|
||||
animated_value get_value(const animated_value &first, const animated_value &second, float alpha) override;
|
||||
void control_object(void *controlled_object, const animated_value &value) override;
|
||||
};
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -18,11 +18,11 @@ enum class animated_value_type {
|
||||
|
||||
// sadly we cannot use union here since we have non-POD types
|
||||
struct animated_value {
|
||||
int intVal;
|
||||
float floatVal;
|
||||
glm::vec3 vec3Val;
|
||||
glm::vec4 vec4Val;
|
||||
glm::quat quatVal;
|
||||
int int_val;
|
||||
float float_val;
|
||||
glm::vec3 vec3_val;
|
||||
glm::vec4 vec4_val;
|
||||
glm::quat quat_val;
|
||||
};
|
||||
|
||||
struct animation_key {
|
||||
@@ -32,14 +32,14 @@ struct animation_key {
|
||||
static animation_key *vec3Key(float t, glm::vec3 val) {
|
||||
auto *result = new animation_key();
|
||||
result->time = t;
|
||||
result->value.vec3Val = val;
|
||||
result->value.vec3_val = val;
|
||||
return result;
|
||||
}
|
||||
|
||||
static animation_key *floatKey(float t, float val) {
|
||||
auto *result = new animation_key();
|
||||
result->time = t;
|
||||
result->value.floatVal = val;
|
||||
result->value.float_val = val;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user