From 53ad1adc71fe829966a9314d2c95e363d9053c18 Mon Sep 17 00:00:00 2001 From: Nou Date: Fri, 15 May 2015 17:22:43 -0700 Subject: [PATCH] Animations still fucked. --- extensions/common/simulation/object.cpp | 88 ++++++++------------ extensions/common/simulation/object.hpp | 6 +- extensions/tests/AT_01.txt | 3 +- extensions/tests/anim_test/anim_test.p3d | Bin 81551 -> 58105 bytes extensions/tests/anim_test/model.cfg | 45 ++++++++-- extensions/vd/debug/penetration_display.cpp | 10 +-- 6 files changed, 83 insertions(+), 69 deletions(-) diff --git a/extensions/common/simulation/object.cpp b/extensions/common/simulation/object.cpp index bbcaa428ef..b3c4c935ef 100644 --- a/extensions/common/simulation/object.cpp +++ b/extensions/common/simulation/object.cpp @@ -8,6 +8,11 @@ ace::simulation::vertex::vertex(vertex_table & _table, ace::vector3 _vert { this->original_vertex = _vertex; this->animated_vertex = _vertex; + //this->original_vertex.z(this->original_vertex.z()*-1); + //this->animated_vertex.z(this->animated_vertex.z()*-1); + //this->original_vertex.x(this->original_vertex.x()*-1); + //this->animated_vertex.x(this->animated_vertex.x()*-1); + } ace::simulation::vertex::~vertex() @@ -32,20 +37,12 @@ ace::simulation::face::~face() { } -void ace::simulation::vertex::animate(const glm::mat4 &matrix, ace::vector3 rotation_offset, bool offset) +void ace::simulation::vertex::animate(const glm::mat4 &matrix) { ace::vector3 temp_vector = this->original_vertex; - if (offset) { - temp_vector = temp_vector - rotation_offset; - } glm::vec4 temp_gl_vector = glm::vec4(temp_vector.x(), temp_vector.y(), temp_vector.z(), 1.0f); temp_gl_vector = matrix*temp_gl_vector; this->animated_vertex = ace::vector3(temp_gl_vector.x, temp_gl_vector.y, temp_gl_vector.z); - if (offset) { - glm::vec4 temp_gl_rotate_vector = glm::vec4(rotation_offset.x(), rotation_offset.y(), rotation_offset.z(), 1.0f); - temp_gl_vector = matrix*temp_gl_rotate_vector; - this->animated_vertex = this->animated_vertex + ace::vector3(temp_gl_vector.x, temp_gl_vector.y, temp_gl_vector.z); - } } ace::simulation::named_selection::named_selection( @@ -68,11 +65,10 @@ ace::simulation::named_selection::~named_selection() { } -void ace::simulation::named_selection::animate(const glm::mat4 &matrix, ace::vector3 rotation_offset) +void ace::simulation::named_selection::animate(const glm::mat4 &matrix) { - bool offset = !rotation_offset.zero_distance(); for (auto selection_vertex : this->vertices) { - selection_vertex->animate(matrix, rotation_offset, offset); + selection_vertex->animate(matrix); } } @@ -83,10 +79,10 @@ ace::simulation::vertex_table::vertex_table(const ace::p3d::vertex_table_p p3d_v { this->vertices.resize(p3d_vertex_table->points.size); ace::vector3 center_off2 = p3d_lod->min_pos+p3d_lod->max_pos-p3d_lod->autocenter_pos; - ace::vector3 center_off = p3d->info->center_of_gravity + p3d->info->offset_2 + p3d->info->cog_offset; + ace::vector3 center_off = p3d->info->cog_offset;//p3d->info->center_of_gravity + p3d->info->offset_2 + p3d->info->cog_offset; for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) { if (p3d->info->autocenter) { - ace::vector3 new_vertex = p3d_vertex_table->points[i] - center_off; + ace::vector3 new_vertex = p3d_vertex_table->points[i] + center_off; this->vertices[i] = std::make_shared(*this, new_vertex, i); } else { @@ -103,7 +99,7 @@ ace::simulation::lod::lod(const ace::p3d::lod_p p3d_lod, const ace::p3d::model_p { this->id = p3d_lod->id; this->vertices = vertex_table(p3d_lod->vertices, p3d_lod, p3d); - this->autocenter_pos = p3d->info->center_of_gravity + p3d->info->offset_2 + p3d->info->cog_offset; + this->autocenter_pos = p3d->info->cog_offset;//p3d->info->center_of_gravity + p3d->info->offset_2 + p3d->info->cog_offset; for (ace::p3d::face_p p3d_face : p3d_lod->faces) { this->faces.push_back(std::make_shared(p3d_face, p3d_lod, p3d, this)); @@ -128,8 +124,8 @@ ace::simulation::lod_animation_info::lod_animation_info( { this->index = p3d_animate_bone->index; if (p3d->info->autocenter) { - ace::vector3 center_off = p3d->info->center_of_gravity + p3d->info->offset_2 + p3d->info->cog_offset; - this->axis_position = p3d_animate_bone->axis_position - center_off; + 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(); } else { @@ -208,13 +204,13 @@ typedef union { #define RAD2DEG(rad) (rad * 180.0f / 3.1415926f); -typedef std::map>> animation_transform; +typedef std::map animation_transform; + animation_transform ace::simulation::animation::animate(const float phase, const std::vector &lods, animation_transform base_transforms) { animation_transform return_matrices; for (auto lod_id : lods) { - glm::mat4 base_matrix = base_transforms[lod_id].first; - ace::vector3 base_rotation_offset = base_transforms[lod_id].second; + glm::mat4 base_matrix = base_transforms[lod_id]; glm::mat4 animation_matrix, direction_matrix; ace::vector3 rotation_offset = ace::vector3(0, 0, 0); @@ -227,48 +223,44 @@ animation_transform ace::simulation::animation::animate(const float phase, const //rotation case 0: { scale = (scale / (max_value - min_value)) * (angle1 - angle0); - - animation_matrix = glm::rotate(glm::mat4(1.0f), -scale, axis_direction); - - rotation_offset = this->lod_info[lod_id]->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 case 1: { scale = (scale / (max_value - min_value)) * (angle1 - angle0); + glm::vec3 rotation_axis = glm::vec3(1.0f, 0.0f, 0.0f); - animation_matrix = glm::rotate(glm::mat4(1.0f), -scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->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); 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::rotate(glm::mat4(1.0f), -scale, rotation_axis); - - rotation_offset = this->lod_info[lod_id]->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); 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::rotate(direction_matrix, -scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->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); break; } //translation case 4: { scale = (scale / (max_value - min_value)) * (offset1 - offset0); - glm::vec3 direction( - this->lod_info[lod_id]->axis_direction.x(), - this->lod_info[lod_id]->axis_direction.y(), - this->lod_info[lod_id]->axis_direction.z() - ); + glm::vec3 direction(axis_direction); direction = direction * scale; animation_matrix = glm::translate(glm::mat4(1.0f), direction); @@ -310,14 +302,13 @@ animation_transform ace::simulation::animation::animate(const float phase, const } //hide case 9: { - if (phase >= hide_value) + if (scale >= hide_value) animation_matrix = glm::mat4x4(0.0f); break; } default: {} } - return_matrices[lod_id].first = base_matrix * animation_matrix; - return_matrices[lod_id].second = base_rotation_offset + rotation_offset; + return_matrices[lod_id] = base_matrix * animation_matrix; } return return_matrices; } @@ -384,14 +375,10 @@ void ace::simulation::bone::animate(const std::map &animatio for (auto child_bone : children) { child_bone->animate(animation_state, lods, base_transforms); } - if (animations.size() > 0) { - for (auto bone_animation : animations) { - for (auto lod_id : lods) { - auto selection = this->base_object->lods[lod_id]->selections.find(this->name); - if (selection != this->base_object->lods[lod_id]->selections.end()) { - selection->second->animate(base_transforms[lod_id].first, base_transforms[lod_id].second); - } - } + for (auto lod_id : lods) { + auto selection = this->base_object->lods[lod_id]->selections.find(this->name); + if (selection != this->base_object->lods[lod_id]->selections.end()) { + selection->second->animate(base_transforms[lod_id]); } } } @@ -436,8 +423,7 @@ void ace::simulation::object::animate(const std::map &animat { animation_transform identity_transform; for (uint32_t lod_id : selected_lods) { - identity_transform[lod_id].first = glm::mat4(); - identity_transform[lod_id].second = ace::vector3(0, 0, 0); + identity_transform[lod_id] = glm::mat4(1.0); } this->root_bone->animate(animation_state, selected_lods, identity_transform); } diff --git a/extensions/common/simulation/object.hpp b/extensions/common/simulation/object.hpp index a77da9d5cf..77f9b7a37b 100644 --- a/extensions/common/simulation/object.hpp +++ b/extensions/common/simulation/object.hpp @@ -26,7 +26,7 @@ namespace ace { class object; typedef std::shared_ptr object_p; - typedef std::map>> animation_transform; + typedef std::map animation_transform; class vertex_table { public: @@ -59,7 +59,7 @@ namespace ace { std::vector faces; std::vector vertices; - void animate(const glm::mat4 &, ace::vector3); + void animate(const glm::mat4 &); }; typedef std::shared_ptr named_selection_p; @@ -93,7 +93,7 @@ namespace ace { std::vector faces; std::vector selections; - void animate(const glm::mat4 &, ace::vector3, bool); + void animate(const glm::mat4 &); private: ace::vector3 original_vertex; diff --git a/extensions/tests/AT_01.txt b/extensions/tests/AT_01.txt index c90e2a41ff..0563f53750 100644 --- a/extensions/tests/AT_01.txt +++ b/extensions/tests/AT_01.txt @@ -2,4 +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.50, barrel_recoil, 1.00 \ No newline at end of file +#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 diff --git a/extensions/tests/anim_test/anim_test.p3d b/extensions/tests/anim_test/anim_test.p3d index ea741853ebcef98a8c1d22d01bb8ef6cabe80d0e..f35349c21270388881493070f61f8b0a96e8ccf0 100644 GIT binary patch delta 7751 zcmeHMYitzP8Jz(G3tk%&+thUk>|#>_t*Gsl2`}$V+QtZ6a8oE%Do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t0!qW>valjm|&Wxm}4@OpQ80qeN2JZC$jZ1v6(IF%z6d>HIc^f=POV! ziLH;JEo^AWG ztjG<+e^B+tJE6-8q00&$+!yiZu+U`%db4z1M&Q30dUaeZY!&g}3fire_lod, *_Batch, *_active_vehicle->object, Colors::Gray); + DrawObject(_active_vehicle->fire_lod, *_Batch, *_active_vehicle->object, Colors::GhostWhite); } if (_active_hits.size() > 0) { DrawHits(0, *_Batch, Colors::Red); @@ -246,9 +246,9 @@ namespace ace { xdivs = std::max(1, xdivs); ydivs = std::max(1, ydivs); - for (size_t i = 0; i <= xdivs; ++i) { + for (size_t i = 0; i <= xdivs*2; ++i) { float fPercent = float(i) / float(xdivs); - fPercent = (fPercent * 2.0f) - 1.0f; + fPercent = (fPercent * 1.0f) - 1.0f; XMVECTOR vScale = XMVectorScale(xAxis, fPercent); vScale = XMVectorAdd(vScale, origin); @@ -257,9 +257,9 @@ namespace ace { batch.DrawLine(v1, v2); } - for (size_t i = 0; i <= ydivs; i++) { + for (size_t i = 0; i <= ydivs*2; i++) { FLOAT fPercent = float(i) / float(ydivs); - fPercent = (fPercent * 2.0f) - 1.0f; + fPercent = (fPercent * 1.0f) - 1.0f; XMVECTOR vScale = XMVectorScale(yAxis, fPercent); vScale = XMVectorAdd(vScale, origin);