From b1d843becf5b7305f6deca35da7a598d4d848947 Mon Sep 17 00:00:00 2001 From: Nou Date: Fri, 15 May 2015 20:34:36 -0700 Subject: [PATCH] Lots of changes to animations... Mostly working now I hope! --- extensions/common/simulation/object.cpp | 40 ++++++++++++------------- extensions/tests/AT_01.txt | 4 +-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/extensions/common/simulation/object.cpp b/extensions/common/simulation/object.cpp index b3c4c935ef..a5b2c2b125 100644 --- a/extensions/common/simulation/object.cpp +++ b/extensions/common/simulation/object.cpp @@ -126,7 +126,7 @@ ace::simulation::lod_animation_info::lod_animation_info( if (p3d->info->autocenter) { ace::vector3 center_off = p3d->info->cog_offset;//p3d->info->center_of_gravity + p3d->info->offset_2 + p3d->info->cog_offset; this->axis_position = p3d_animate_bone->axis_position + center_off; - this->axis_direction = p3d_animate_bone->axis_direction.normalize(); + this->axis_direction = p3d_animate_bone->axis_direction; } else { this->axis_position = p3d_animate_bone->axis_position; @@ -223,9 +223,9 @@ animation_transform ace::simulation::animation::animate(const float phase, const //rotation case 0: { scale = (scale / (max_value - min_value)) * (angle1 - angle0); - animation_matrix = glm::translate(glm::mat4(1.0f), -axis_position); - animation_matrix *= glm::rotate(glm::mat4(1.0f), -scale, axis_direction); - animation_matrix *= glm::translate(glm::mat4(1.0f), axis_position); + animation_matrix = glm::translate(glm::mat4(1.0f), axis_position); + animation_matrix *= glm::rotate(glm::mat4(1.0f), scale, axis_direction); + animation_matrix *= glm::translate(glm::mat4(1.0f), -axis_position); break; } //rotationX @@ -234,27 +234,28 @@ animation_transform ace::simulation::animation::animate(const float phase, const glm::vec3 rotation_axis = glm::vec3(1.0f, 0.0f, 0.0f); - animation_matrix = glm::translate(glm::mat4(1.0f), -axis_position); + animation_matrix = glm::translate(glm::mat4(1.0f), axis_position); animation_matrix *= glm::rotate(glm::mat4(1.0f), -scale, rotation_axis); - animation_matrix *= glm::translate(glm::mat4(1.0f),axis_position); + animation_matrix *= glm::translate(glm::mat4(1.0f), -axis_position); break; } //rotationY case 2: { scale = (scale / (max_value - min_value)) * (angle1 - angle0); glm::vec3 rotation_axis = glm::vec3(0.0f, 1.0f, 0.0f); - animation_matrix = glm::translate(glm::mat4(1.0f), -axis_position); + + animation_matrix = glm::translate(glm::mat4(1.0f), axis_position); animation_matrix *= glm::rotate(glm::mat4(1.0f), -scale, rotation_axis); - animation_matrix *= glm::translate(glm::mat4(1.0f), axis_position); + animation_matrix *= glm::translate(glm::mat4(1.0f), -axis_position); break; } //rotationZ case 3: { scale = (scale / (max_value - min_value)) * (angle1 - angle0); glm::vec3 rotation_axis = glm::vec3(0.0f, 0.0f, 1.0f); - animation_matrix = glm::translate(glm::mat4(1.0f), -axis_position); + animation_matrix = glm::translate(glm::mat4(1.0f), axis_position); animation_matrix *= glm::rotate(glm::mat4(1.0f), -scale, rotation_axis); - animation_matrix *= glm::translate(glm::mat4(1.0f), axis_position); + animation_matrix *= glm::translate(glm::mat4(1.0f), -axis_position); break; } //translation @@ -268,7 +269,6 @@ animation_transform ace::simulation::animation::animate(const float phase, const } //translationX case 5: { - scale = (scale / (max_value - min_value)) * (offset1 - offset0); animation_matrix = glm::translate(animation_matrix, glm::vec3( scale, 0.0f, @@ -278,7 +278,6 @@ animation_transform ace::simulation::animation::animate(const float phase, const } //translationY case 6: { - scale = (scale / (max_value - min_value)) * (offset1 - offset0); animation_matrix = glm::translate(animation_matrix, glm::vec3( 0.0f, scale, @@ -288,7 +287,6 @@ animation_transform ace::simulation::animation::animate(const float phase, const } //translationZ case 7: { - scale = (scale / (max_value - min_value)) * (offset1 - offset0); animation_matrix = glm::translate(animation_matrix, glm::vec3( 0.0f, 0.0f, @@ -321,16 +319,18 @@ float ace::simulation::animation::get_scale(float phase) switch (source_address) { case 1: - scale = fmod(phase - min_value, (max_value - min_value) * 2) + min_value; - // when over limit, mirror - if (phase > max_value) phase = max_value - (phase - max_value); - + scale = fmod(phase - min_value, max_value - min_value) + min_value; scale = std::min(std::max(scale, min_phase), max_phase); - break; case 2: - scale = fmod(phase - min_value, (max_value - min_value)) + min_value; - if (scale > max_value) scale = max_value - (scale - max_value); + //@TODO: possibly a better way to do this?! + if (min_phase < 0.0f && phase < 0) { + scale = std::fmod((std::fabs(phase) - std::fabs(min_value)), ((max_value - min_value) * 2)) + min_value; + } + else { + scale = std::fmod((phase - min_value), ((max_value - min_value) * 2)) + min_value; + }; + if (scale>max_value) scale = max_value - (scale - max_value); scale = std::min(std::max(scale, min_phase), max_phase); break; default: diff --git a/extensions/tests/AT_01.txt b/extensions/tests/AT_01.txt index 0563f53750..ca209de8bb 100644 --- a/extensions/tests/AT_01.txt +++ b/extensions/tests/AT_01.txt @@ -2,5 +2,5 @@ init: debug_render: register_vehicle:\x\nou\addons\anim_test\anim_test.p3d,0,4050.18;3802.55;5.075 -#set_animation_state:0, turret, 0.500, rotation_drum, 0.0, barrel_recoil, 0, barrel_hide, 0 -set_animation_state:0, turret, 0.500 \ No newline at end of file +set_animation_state:0, turret, 0.0, rotation_drum, 0.0, barrel_recoil, -6, barrel_hide, 0 +#set_animation_state:0, turret, 0.500 \ No newline at end of file