Added animation

This commit is contained in:
2022-04-23 23:51:28 +03:00
parent 50d032418e
commit 674191238f
10 changed files with 112 additions and 7 deletions
+2
View File
@@ -10,7 +10,9 @@ find_package(OpenGL REQUIRED)
include_directories("src/") include_directories("src/")
include_directories("gl/include") include_directories("gl/include")
add_subdirectory(lib/glm EXCLUDE_FROM_ALL) add_subdirectory(lib/glm EXCLUDE_FROM_ALL)
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(src/animation)
add_executable(demo main.cpp gl/src/glad.c ${SOURCE}) add_executable(demo main.cpp gl/src/glad.c ${SOURCE})
target_link_libraries(demo glfw OpenGL::GL) target_link_libraries(demo glfw OpenGL::GL)
+2
View File
@@ -47,3 +47,5 @@ set(SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/timer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/timer.cpp
PARENT_SCOPE PARENT_SCOPE
) )
#add_subdirectory(animation)
+15
View File
@@ -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
)
+15
View File
@@ -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
+13
View File
@@ -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
+16
View File
@@ -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
+13
View File
@@ -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
+15
View File
@@ -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
+14
View File
@@ -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
+7 -7
View File
@@ -18,11 +18,11 @@ enum class animated_value_type {
// sadly we cannot use union here since we have non-POD types // sadly we cannot use union here since we have non-POD types
struct animated_value { struct animated_value {
int intVal; int int_val;
float floatVal; float float_val;
glm::vec3 vec3Val; glm::vec3 vec3_val;
glm::vec4 vec4Val; glm::vec4 vec4_val;
glm::quat quatVal; glm::quat quat_val;
}; };
struct animation_key { struct animation_key {
@@ -32,14 +32,14 @@ struct animation_key {
static animation_key *vec3Key(float t, glm::vec3 val) { static animation_key *vec3Key(float t, glm::vec3 val) {
auto *result = new animation_key(); auto *result = new animation_key();
result->time = t; result->time = t;
result->value.vec3Val = val; result->value.vec3_val = val;
return result; return result;
} }
static animation_key *floatKey(float t, float val) { static animation_key *floatKey(float t, float val) {
auto *result = new animation_key(); auto *result = new animation_key();
result->time = t; result->time = t;
result->value.floatVal = val; result->value.float_val = val;
return result; return result;
} }
}; };