From 77614ca015611b19f7f595efc13b5b8a2722513d Mon Sep 17 00:00:00 2001 From: jaynus Date: Mon, 11 May 2015 22:33:39 -0700 Subject: [PATCH] Animations nearly aligning correctly. --- .../functions/fnc_getAnimationStates.sqf | 2 +- addons/vehicledamage/script_component.hpp | 2 +- extensions/common/arguments.hpp | 3 + extensions/common/shared.cpp | 5 + extensions/common/shared.hpp | 17 + extensions/common/simulation/object.cpp | 609 +++++++++--------- extensions/tests/longrod_dxtk_test.cpp | 8 +- extensions/tests/longrod_dxtk_test.txt | 8 +- extensions/tests/longrod_dxtk_test.txt.backup | 3 +- extensions/tests/test.p3d | Bin 7190 -> 0 bytes extensions/tests/test.pbo.txt | 4 +- extensions/tests/test_model/config.cpp | 2 +- extensions/vd/base_vehicle.cpp | 7 +- extensions/vd/controller.cpp | 2 +- 14 files changed, 362 insertions(+), 310 deletions(-) delete mode 100644 extensions/tests/test.p3d diff --git a/addons/vehicledamage/functions/fnc_getAnimationStates.sqf b/addons/vehicledamage/functions/fnc_getAnimationStates.sqf index 9a6b2ca45e..8c64fcca4e 100644 --- a/addons/vehicledamage/functions/fnc_getAnimationStates.sqf +++ b/addons/vehicledamage/functions/fnc_getAnimationStates.sqf @@ -35,7 +35,7 @@ if(_sendToExtension) then { _cmd = "set_animation_state:"; { - _cmd = _cmd + format["%1,%2,", (_x select 0), (_x select 1)]; + _cmd = _cmd + format["%1,%2,", (_x select 0), ([(_x select 1)] call CBA_fnc_formatNumber)]; } forEach _animationResults; _cmd call FUNC(callExtension); diff --git a/addons/vehicledamage/script_component.hpp b/addons/vehicledamage/script_component.hpp index 44d6dd6ad7..1f81f8bd09 100644 --- a/addons/vehicledamage/script_component.hpp +++ b/addons/vehicledamage/script_component.hpp @@ -18,4 +18,4 @@ #define DEBUG_EXTENSION_DYNLOAD #define DEBUG_LOG_EXTENSION //#define DEBUG_EXTENSION_DYNLOAD_RELOAD -#define DEBUG_VEHICLEDAMAGE_RENDER \ No newline at end of file +//#define DEBUG_VEHICLEDAMAGE_RENDER \ No newline at end of file diff --git a/extensions/common/arguments.hpp b/extensions/common/arguments.hpp index 72e15da497..70e942a241 100644 --- a/extensions/common/arguments.hpp +++ b/extensions/common/arguments.hpp @@ -40,6 +40,9 @@ namespace ace { public: arguments(const std::string & str) : _original(str) { _args = ace::split(str, ','); + for (int i = 0; i < _args.size(); i++) { + _args[i] = trim(_args[i]); + } } size_t size() const { return _args.size(); } diff --git a/extensions/common/shared.cpp b/extensions/common/shared.cpp index bfbcfd2ae7..ca0c65f409 100644 --- a/extensions/common/shared.cpp +++ b/extensions/common/shared.cpp @@ -1,5 +1,10 @@ #include "shared.hpp" +#include +#include +#include +#include + int test(int var) { return var; } diff --git a/extensions/common/shared.hpp b/extensions/common/shared.hpp index 0c1b42d3cf..c84624132a 100644 --- a/extensions/common/shared.hpp +++ b/extensions/common/shared.hpp @@ -40,6 +40,23 @@ namespace ace { std::vector &split(const std::string &s, char delim, std::vector &elems); std::vector split(const std::string &s, char delim); + // trim from start + static inline std::string <rim(std::string &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); + return s; + } + + // trim from end + static inline std::string &rtrim(std::string &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); + return s; + } + + // trim from both ends + static inline std::string &trim(std::string &s) { + return ltrim(rtrim(s)); + } + inline void runtime_assert(bool result); struct exception { diff --git a/extensions/common/simulation/object.cpp b/extensions/common/simulation/object.cpp index be43fd20e3..092eb2d518 100644 --- a/extensions/common/simulation/object.cpp +++ b/extensions/common/simulation/object.cpp @@ -6,8 +6,8 @@ ace::simulation::vertex::vertex(vertex_table & _table, ace::vector3 _vertex, uint32_t _id) : table(_table), vertex_id(_id) { - this->original_vertex = _vertex; - this->animated_vertex = _vertex; + this->original_vertex = _vertex; + this->animated_vertex = _vertex; } ace::simulation::vertex::~vertex() @@ -16,50 +16,50 @@ ace::simulation::vertex::~vertex() ace::simulation::face::face( - const ace::p3d::face_p p3d_face, - const ace::p3d::lod_p p3d_lod, - const ace::p3d::model_p p3d, - ace::simulation::lod *object_lod) + const ace::p3d::face_p p3d_face, + const ace::p3d::lod_p p3d_lod, + const ace::p3d::model_p p3d, + ace::simulation::lod *object_lod) { - this->type = p3d_face->type; - for (uint16_t vertex_id : p3d_face->vertex_table) { - this->vertices.push_back(object_lod->vertices[vertex_id]); - object_lod->vertices[vertex_id]->faces.push_back(this); - } + this->type = p3d_face->type; + for (uint16_t vertex_id : p3d_face->vertex_table) { + this->vertices.push_back(object_lod->vertices[vertex_id]); + object_lod->vertices[vertex_id]->faces.push_back(this); + } } 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 rotation_offset, bool offset) { - 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) { - // this->animated_vertex = this->animated_vertex + rotation_offset; - } + 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) { + // this->animated_vertex = this->animated_vertex + rotation_offset; + } } ace::simulation::named_selection::named_selection( - const ace::p3d::named_selection_p p3d_selection, - const ace::p3d::lod_p p3d_lod, - const ace::p3d::model_p p3d, - ace::simulation::lod *object_lod) + const ace::p3d::named_selection_p p3d_selection, + const ace::p3d::lod_p p3d_lod, + const ace::p3d::model_p p3d, + ace::simulation::lod *object_lod) { - this->name = p3d_selection->name; - for (uint16_t vertex_id : p3d_selection->vertex_table.data) { - this->vertices.push_back(object_lod->vertices[vertex_id]); - object_lod->vertices[vertex_id]->selections.push_back(this); - } - for (uint16_t face_id : p3d_selection->faces.data) { - this->faces.push_back(object_lod->faces[face_id]); - } + this->name = p3d_selection->name; + for (uint16_t vertex_id : p3d_selection->vertex_table.data) { + this->vertices.push_back(object_lod->vertices[vertex_id]); + object_lod->vertices[vertex_id]->selections.push_back(this); + } + for (uint16_t face_id : p3d_selection->faces.data) { + this->faces.push_back(object_lod->faces[face_id]); + } } ace::simulation::named_selection::~named_selection() @@ -68,10 +68,10 @@ ace::simulation::named_selection::~named_selection() void ace::simulation::named_selection::animate(const glm::mat4 &matrix, ace::vector3 rotation_offset) { - bool offset = !rotation_offset.zero_distance(); - for (auto selection_vertex : this->vertices) { - selection_vertex->animate(matrix, rotation_offset, offset); - } + bool offset = !rotation_offset.zero_distance(); + for (auto selection_vertex : this->vertices) { + selection_vertex->animate(matrix, rotation_offset, offset); + } } @@ -79,21 +79,21 @@ void ace::simulation::named_selection::animate(const glm::mat4 &matrix, ace::vec ace::simulation::vertex_table::vertex_table(const ace::p3d::vertex_table_p p3d_vertex_table, const ace::p3d::lod_p p3d_lod, const ace::p3d::model_p p3d) : animated(false) { - this->vertices.resize(p3d_vertex_table->points.size); - for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) { - if(p3d->info->autocenter) { - ace::vector3 new_vertex = ace::vector3( - p3d_vertex_table->points[i].x() + (p3d_lod->autocenter_pos.x()*-1), - p3d_vertex_table->points[i].y() + (p3d_lod->autocenter_pos.y()*-1), - p3d_vertex_table->points[i].z() + (p3d_lod->autocenter_pos.z()*-1) - ); - this->vertices[i] = std::make_shared(*this, new_vertex, i); - - } - else { - this->vertices[i] = std::make_shared(*this, p3d_vertex_table->points[i], i); - } - } + this->vertices.resize(p3d_vertex_table->points.size); + for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) { + if (p3d->info->autocenter) { + ace::vector3 new_vertex = ace::vector3( + p3d_vertex_table->points[i].x() + (p3d_lod->autocenter_pos.x()*-1), + p3d_vertex_table->points[i].y() + (p3d_lod->autocenter_pos.y()*-1), + p3d_vertex_table->points[i].z() + (p3d_lod->autocenter_pos.z()*-1) + ); + this->vertices[i] = std::make_shared(*this, new_vertex, i); + + } + else { + this->vertices[i] = std::make_shared(*this, p3d_vertex_table->points[i], i); + } + } } ace::simulation::vertex_table::~vertex_table() @@ -102,17 +102,17 @@ ace::simulation::vertex_table::~vertex_table() ace::simulation::lod::lod(const ace::p3d::lod_p p3d_lod, const ace::p3d::model_p p3d) { - this->id = p3d_lod->id; - this->vertices = vertex_table(p3d_lod->vertices, p3d_lod, p3d); - this->autocenter_pos = p3d_lod->autocenter_pos; + this->id = p3d_lod->id; + this->vertices = vertex_table(p3d_lod->vertices, p3d_lod, p3d); + this->autocenter_pos = p3d_lod->autocenter_pos; - for (ace::p3d::face_p p3d_face : p3d_lod->faces) { - this->faces.push_back(std::make_shared(p3d_face, p3d_lod, p3d, this)); - } + for (ace::p3d::face_p p3d_face : p3d_lod->faces) { + this->faces.push_back(std::make_shared(p3d_face, p3d_lod, p3d, this)); + } - for (ace::p3d::named_selection_p p3d_selection : p3d_lod->selections) { - this->selections[p3d_selection->name] = std::make_shared(p3d_selection, p3d_lod, p3d, this); - } + for (ace::p3d::named_selection_p p3d_selection : p3d_lod->selections) { + this->selections[p3d_selection->name] = std::make_shared(p3d_selection, p3d_lod, p3d, this); + } } @@ -121,21 +121,21 @@ ace::simulation::lod::~lod() } ace::simulation::lod_animation_info::lod_animation_info( - animation *_animation, - lod_p _lod, - const ace::p3d::animate_bone_p p3d_animate_bone, - const ace::p3d::animation_p p3d_animation, - const ace::p3d::model_p p3d) : animation_definition(_animation), lod(_lod) + animation *_animation, + lod_p _lod, + const ace::p3d::animate_bone_p p3d_animate_bone, + const ace::p3d::animation_p p3d_animation, + const ace::p3d::model_p p3d) : animation_definition(_animation), lod(_lod) { - this->index = p3d_animate_bone->index; - if (p3d->info->autocenter) { - this->axis_position = p3d_animate_bone->axis_position + (lod->autocenter_pos*-1); - this->axis_direction = p3d_animate_bone->axis_direction.normalize(); - } - else { - this->axis_position = p3d_animate_bone->axis_position; - this->axis_direction = p3d_animate_bone->axis_direction.normalize(); - } + this->index = p3d_animate_bone->index; + if (p3d->info->autocenter) { + this->axis_position = p3d_animate_bone->axis_position + (lod->autocenter_pos*-1); + this->axis_direction = p3d_animate_bone->axis_direction.normalize(); + } + else { + this->axis_position = p3d_animate_bone->axis_position; + this->axis_direction = p3d_animate_bone->axis_direction.normalize(); + } } ace::simulation::lod_animation_info::~lod_animation_info() @@ -144,54 +144,54 @@ ace::simulation::lod_animation_info::~lod_animation_info() ace::simulation::animation::animation(object *parent_object, const ace::p3d::animation_p p3d_animation, const ace::p3d::model_p p3d) { - this->type = p3d_animation->type; - this->name = p3d_animation->name; - this->source = p3d_animation->source; + this->type = p3d_animation->type; + this->name = p3d_animation->name; + this->source = p3d_animation->source; - this->source_address = p3d_animation->source_address; + this->source_address = p3d_animation->source_address; - this->min_value = p3d_animation->min_value; - this->max_value = p3d_animation->max_value; + this->min_value = p3d_animation->min_value; + this->max_value = p3d_animation->max_value; - this->min_phase = p3d_animation->min_phase; - this->max_phase = p3d_animation->max_phase; + this->min_phase = p3d_animation->min_phase; + this->max_phase = p3d_animation->max_phase; - switch (type) { - // rotations - case 0: - case 1: - case 2: - case 3: - angle0 = p3d_animation->angle0; - angle1 = p3d_animation->angle1; - break; - // translations - case 4: - case 5: - case 6: - case 7: - offset0 = p3d_animation->offset0; - offset1 = p3d_animation->offset1; - break; - case 8: - direct_axis_pos = p3d_animation->direct_axis_pos; - direct_axis_dir = p3d_animation->direct_axis_dir; - direct_angle = p3d_animation->direct_angle; - direct_axis_offset = p3d_animation->direct_axis_offset; - break; - case 9: - hide_value = p3d_animation->hide_value; - default: - offset0 = 0.0f; - offset1 = 0.0f; - } + switch (type) { + // rotations + case 0: + case 1: + case 2: + case 3: + angle0 = p3d_animation->angle0; + angle1 = p3d_animation->angle1; + break; + // translations + case 4: + case 5: + case 6: + case 7: + offset0 = p3d_animation->offset0; + offset1 = p3d_animation->offset1; + break; + case 8: + direct_axis_pos = p3d_animation->direct_axis_pos; + direct_axis_dir = p3d_animation->direct_axis_dir; + direct_angle = p3d_animation->direct_angle; + direct_axis_offset = p3d_animation->direct_axis_offset; + break; + case 9: + hide_value = p3d_animation->hide_value; + default: + offset0 = 0.0f; + offset1 = 0.0f; + } - for (ace::p3d::animate_bone_p animation_bone : p3d_animation->bones) { - this->lod_info[animation_bone->lod] = std::make_shared(this, parent_object->lods[animation_bone->lod], animation_bone, p3d_animation, p3d); - } + for (ace::p3d::animate_bone_p animation_bone : p3d_animation->bones) { + this->lod_info[animation_bone->lod] = std::make_shared(this, parent_object->lods[animation_bone->lod], animation_bone, p3d_animation, p3d); + } } @@ -200,10 +200,10 @@ ace::simulation::animation::~animation() } typedef union { - float f; - struct { - uint32_t sh1 : 32; - } parts; + float f; + struct { + uint32_t sh1 : 32; + } parts; } double_cast; #define RAD2DEG(rad) (rad * 180.0f / 3.1415926f); @@ -211,176 +211,197 @@ typedef union { 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 animation_matrix, direction_matrix; - ace::vector3 rotation_offset = ace::vector3(0, 0, 0); + 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 animation_matrix, direction_matrix; + ace::vector3 rotation_offset = ace::vector3(0, 0, 0); - float scale = get_scale(phase); + float scale = get_scale(phase); - switch (this->type) { - //rotation - case 0: { - scale = (scale / (max_value - min_value)) * (angle1 - angle0); - glm::vec3 rotation_axis = glm::vec3(this->lod_info[lod_id]->axis_position.x(), this->lod_info[lod_id]->axis_position.y(), this->lod_info[lod_id]->axis_position.z()); - glm::vec3 rotation_direction = glm::vec3(this->lod_info[lod_id]->axis_direction.x(), this->lod_info[lod_id]->axis_direction.y(), this->lod_info[lod_id]->axis_direction.z()); - - animation_matrix = glm::rotate(glm::mat4(1.0f), scale, rotation_direction); - direction_matrix = glm::translate(glm::mat4(1.0f), rotation_axis); - animation_matrix = animation_matrix * direction_matrix; + glm::vec3 axis_position = glm::vec3(this->lod_info[lod_id]->axis_position.x(), this->lod_info[lod_id]->axis_position.y(), this->lod_info[lod_id]->axis_position.z()); + glm::vec3 axis_direction = glm::vec3(this->lod_info[lod_id]->axis_direction.x(), this->lod_info[lod_id]->axis_direction.y(), this->lod_info[lod_id]->axis_direction.z()); - rotation_offset = this->lod_info[lod_id]->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(animation_matrix, scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->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(animation_matrix, scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->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(animation_matrix, scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->axis_position; - break; - } - //translation - case 4: { - scale = (scale / (max_value - min_value)) * (offset1 - offset0); - animation_matrix = glm::translate(animation_matrix, glm::vec3( - this->lod_info[lod_id]->axis_direction.x()*scale, - this->lod_info[lod_id]->axis_direction.y()*scale, - this->lod_info[lod_id]->axis_direction.z()*scale - )); - - break; - } - //translationX - case 5: { - animation_matrix = glm::translate(animation_matrix, glm::vec3( - scale, - 0.0f, - 0.0f - )); - break; - } - //translationY - case 6: { - animation_matrix = glm::translate(animation_matrix, glm::vec3( - 0.0f, - scale, - 0.0f - )); - break; - } - //translationZ - case 7: { - animation_matrix = glm::translate(animation_matrix, glm::vec3( - 0.0f, - 0.0f, - scale - )); - break; - } - case 8: { - // fuck direct for now - } - //hide - case 9: { - if(phase >= hide_value) - animation_matrix = glm::mat4x4(0.0f); - break; - } - default: {} - } - return_matrices[lod_id].first = animation_matrix * base_matrix; - return_matrices[lod_id].second = base_rotation_offset + rotation_offset; - } - return return_matrices; + if (true) { + switch (this->type) { + //rotation + case 0: { + scale = (scale / (max_value - min_value)) * (angle1 - angle0); + + animation_matrix = glm::rotate(glm::mat4(1.0f), scale, axis_direction); + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + + animation_matrix = animation_matrix * direction_matrix; + + rotation_offset = this->lod_info[lod_id]->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); + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + + animation_matrix = animation_matrix * direction_matrix; + + rotation_offset = this->lod_info[lod_id]->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); + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + + animation_matrix = animation_matrix * direction_matrix; + + rotation_offset = this->lod_info[lod_id]->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(glm::mat4(1.0f), scale, rotation_axis); + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + + animation_matrix = animation_matrix * direction_matrix; + + rotation_offset = this->lod_info[lod_id]->axis_position; + break; + } + //translation + case 4: { + scale = (scale / (max_value - min_value)) * (offset1 - offset0); + animation_matrix = glm::translate(glm::mat4(1.0f), glm::vec3( + this->lod_info[lod_id]->axis_direction.x()*scale, + this->lod_info[lod_id]->axis_direction.y()*scale, + this->lod_info[lod_id]->axis_direction.z()*scale + )); + break; + } + //translationX + case 5: { + scale = (scale / (max_value - min_value)) * (offset1 - offset0); + animation_matrix = glm::translate(animation_matrix, glm::vec3( + scale, + 0.0f, + 0.0f + )); + break; + } + //translationY + case 6: { + scale = (scale / (max_value - min_value)) * (offset1 - offset0); + animation_matrix = glm::translate(animation_matrix, glm::vec3( + 0.0f, + scale, + 0.0f + )); + break; + } + //translationZ + case 7: { + scale = (scale / (max_value - min_value)) * (offset1 - offset0); + animation_matrix = glm::translate(animation_matrix, glm::vec3( + 0.0f, + 0.0f, + scale + )); + break; + } + case 8: { + // fuck direct for now + } + //hide + case 9: { + if (phase >= hide_value) + animation_matrix = glm::mat4x4(0.0f); + break; + } + default: {} + } + return_matrices[lod_id].first = animation_matrix * base_matrix; + return_matrices[lod_id].second = base_rotation_offset + rotation_offset; + } + } + return return_matrices; } float ace::simulation::animation::get_scale(float phase) { - float scale = 0; + float scale = 0; - switch (source_address) - { - case 1: - 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) * 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: - scale = std::min(std::max(phase, min_phase), max_phase); - } + switch (source_address) + { + case 1: + 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) * 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: + scale = std::min(std::max(phase, min_phase), max_phase); + } - return scale; + return scale; } ace::simulation::bone::bone( - const std::string _name, - const std::vector &children, - const std::map &p3d_bones, - bone *_parent, - const ace::p3d::model_p p3d, - object * sim_object - ) : parent(_parent), name(_name), base_object(sim_object) + const std::string _name, + const std::vector &children, + const std::map &p3d_bones, + bone *_parent, + const ace::p3d::model_p p3d, + object * sim_object + ) : parent(_parent), name(_name), base_object(sim_object) { - for (auto const child_bone : children) { - if (sim_object->all_bones.find(child_bone) == sim_object->all_bones.end()) { - ace::p3d::bone_p p3d_bone = p3d_bones.find(child_bone)->second; - sim_object->all_bones[child_bone] = std::make_shared(p3d_bone->name, p3d_bone->children, p3d_bones, this, p3d, sim_object); - } - this->children.push_back(sim_object->all_bones[child_bone]); - } - if (parent) { - for (auto p3d_animation : p3d_bones.find(name)->second->animations) { - this->animations.push_back(sim_object->animations[p3d_animation]); - } - } + for (auto const child_bone : children) { + if (sim_object->all_bones.find(child_bone) == sim_object->all_bones.end()) { + ace::p3d::bone_p p3d_bone = p3d_bones.find(child_bone)->second; + sim_object->all_bones[child_bone] = std::make_shared(p3d_bone->name, p3d_bone->children, p3d_bones, this, p3d, sim_object); + } + this->children.push_back(sim_object->all_bones[child_bone]); + } + if (parent) { + for (auto p3d_animation : p3d_bones.find(name)->second->animations) { + this->animations.push_back(sim_object->animations[p3d_animation]); + } + } } void ace::simulation::bone::animate(const std::map &animation_state, const std::vector &lods, animation_transform base_transforms) { - if (animations.size() > 0) { - for (auto bone_animation : animations) { - if(animation_state.find(bone_animation->name) != animation_state.end()) { - base_transforms = bone_animation->animate(animation_state.find(bone_animation->name)->second, lods, base_transforms); - } - } - } - 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); - } - } - } - } + if (animations.size() > 0) { + for (auto bone_animation : animations) { + if (animation_state.find(bone_animation->name) != animation_state.end()) { + base_transforms = bone_animation->animate(animation_state.find(bone_animation->name)->second, lods, base_transforms); + } + } + } + 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); + } + } + } + } } ace::simulation::object::object() @@ -389,27 +410,27 @@ ace::simulation::object::object() ace::simulation::object::object(const ace::p3d::model_p model) { - for (ace::p3d::lod_p p3d_lod : model->lods) { - lod_p new_lod = std::make_shared(p3d_lod, model); - this->lods.push_back(new_lod); + for (ace::p3d::lod_p p3d_lod : model->lods) { + lod_p new_lod = std::make_shared(p3d_lod, model); + this->lods.push_back(new_lod); this->lods[p3d_lod->id]->type = model->info->resolutions[p3d_lod->id]; - } + } - for (ace::p3d::animation_p p3d_animation : model->animations) { - this->animations.push_back(std::make_shared(this, p3d_animation, model)); - } + for (ace::p3d::animation_p p3d_animation : model->animations) { + this->animations.push_back(std::make_shared(this, p3d_animation, model)); + } - std::map p3d_bones; - for (auto const skeleton_bone : model->skeleton->all_bones) { - p3d_bones[skeleton_bone->name] = skeleton_bone; - } + std::map p3d_bones; + for (auto const skeleton_bone : model->skeleton->all_bones) { + p3d_bones[skeleton_bone->name] = skeleton_bone; + } - std::vector root_bones; - for (auto const root_bone : model->skeleton->root_bones) { - root_bones.push_back(root_bone.first); - } + std::vector root_bones; + for (auto const root_bone : model->skeleton->root_bones) { + root_bones.push_back(root_bone.first); + } - this->root_bone = std::make_shared("", root_bones, p3d_bones, nullptr, model, this); + this->root_bone = std::make_shared("", root_bones, p3d_bones, nullptr, model, this); } @@ -421,12 +442,12 @@ ace::simulation::object::~object() void ace::simulation::object::animate(const std::map &animation_state, const std::vector &selected_lods) { - 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); - } - this->root_bone->animate(animation_state, selected_lods, identity_transform); + 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); + } + this->root_bone->animate(animation_state, selected_lods, identity_transform); } diff --git a/extensions/tests/longrod_dxtk_test.cpp b/extensions/tests/longrod_dxtk_test.cpp index d7dc7736c8..201b276938 100644 --- a/extensions/tests/longrod_dxtk_test.cpp +++ b/extensions/tests/longrod_dxtk_test.cpp @@ -69,5 +69,11 @@ int main(int argc, char **argv) { } } - getchar(); + while (true) { + scanf_s("%s", buffer, sizeof(buffer) - 1); + memset(output, 0x00, sizeof(output)); + LOG(INFO) << "Executing: '" << buffer << "'"; + RVExtension(output, sizeof(output), buffer); + LOG(INFO) << "Result: '" << output << "'"; + } } \ No newline at end of file diff --git a/extensions/tests/longrod_dxtk_test.txt b/extensions/tests/longrod_dxtk_test.txt index 6a49ce9bcb..342ed0337d 100644 --- a/extensions/tests/longrod_dxtk_test.txt +++ b/extensions/tests/longrod_dxtk_test.txt @@ -1,9 +1,5 @@ +#c:\arma\arma3\addons\armor_f_epb.pbo C:\dev\ace3\extensions\tests\longrod_dxtk_test.txt init: debug_render: register_vehicle:\A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, 1, 4046.21;3902.56;5.075 -#set_animation_state:damageHide, 0, Wheel_kolL1, 4.45242e-005, Wheel_koloL1, 4.45242e-005, Wheel_podkoloL1, 0.520781, Wheel_kolP1, 4.45066e-005, Wheel_koloP1, 4.45066e-005, Wheel_podkoloP1, 0.521964, Wheel_kolL2, 4.45242e-005, Wheel_kolP2, 4.45066e-005, Wheel_koloL2, 4.45242e-005, Wheel_koloL3, 4.45242e-005, Wheel_koloL4, 4.45242e-005, Wheel_koloL5, 4.45242e-005, Wheel_koloL6, 4.45242e-005, Wheel_koloL7, 4.45242e-005, Wheel_koloP2, 4.45066e-005, Wheel_koloP3, 4.45066e-005, Wheel_koloP4, 4.45066e-005, Wheel_koloP5, 4.45066e-005, Wheel_koloP6, 4.45066e-005, Wheel_koloP7, 4.45066e-005, Wheel_podkoloL2, 0.507025, Wheel_podkoloL3, 0.500526, Wheel_podkoloL4, 0.509195, Wheel_podkoloL5, 0.49289, Wheel_podkoloL6, 0.48161, Wheel_podkoloP2, 0.513542, Wheel_podkoloP3, 0.507042, Wheel_podkoloP4, 0.500768, Wheel_podkoloP5, 0.496353, Wheel_podkoloP6, 0.503705, podkoloL1_hide_damage, 0, podkoloL2_hide_damage, 0, podkoloL3_hide_damage, 0, podkoloL4_hide_damage, 0, podkoloL5_hide_damage, 0, podkoloL6_hide_damage, 0, podkoloL7_hide_damage, 0, podkoloL8_hide_damage, 0, podkoloP1_hide_damage, 0, podkoloP2_hide_damage, 0, podkoloP3_hide_damage, 0, podkoloP4_hide_damage, 0, podkoloP5_hide_damage, 0, podkoloP6_hide_damage, 0, podkoloP7_hide_damage, 0, podkoloP8_hide_damage, 0, damageVez, 0, MainTurret, 2.37036, MainGun, 0.347653, Recoil, 0, ObsTurret, 0, ObsGun, 0, MainGunOptics, 0.347653, Wheel_podkoloP7, 0.493503, Wheel_podkoloL7, 0.479849, HatchDriver, 0, HatchCommander, 0, HatchGunner, 0, damageVezVelitele, 0, poklop_commander_damage, 0, poklop_gunner_damage, 0, poklop_driver_damage, 0, zaslehROT_HMG, 0, zaslehROT_coax, 14.094, cannon_muzzle_flash, 0, zaslehROT_cannon, 18, HideHull, 0.303806, HideTurret, 0.0209581, LockMuzzle, 0, -#hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, ["damagehide"], 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -108.073;1739.99;-17.7792, -18.9268;0.0336914;-1.73933, -0.0619889;0.998028;-0.00989257, 0.173648;-0.984808;-0.000745866 -hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, [], 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -107.792;1724.28;-18.3618, -18.9268;0.0336914;-1.73933, -0.0619889;0.998028;-0.00989257, 0.173648;-0.984808;-0.000746796 -#hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, [], 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -106.921;1703.28;-19.728, -18.9268;0.0336914;-1.73933, -0.0619889;0.998028;-0.00989257, 0.173648;-0.984808;-0.000745866 -#hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, [], 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -92.8136;1569.56;-19.7856, -18.9268;0.0336914;-1.73933, -0.0619889;0.998028;-0.00989257, 0.173648;-0.984808;-0.000746472 -#hit:1, \A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, ["damagehide"], 0.984803;0.173649;-0.00285841, 0.0029445;-0.000238176;0.999996, 2, Sh_120mm_APFSDS_Tracer_Yellow, 65, 27, 0, 0, 0, -76.7551;1435.97;-17.8176, -18.9268;0.0336914;-1.73933, -0.0619889;0.998028;-0.00989257, 0.173648;-0.984808;-0.000745866 \ No newline at end of file +set_animation_state:1,damageHide, 0, Wheel_kolL1, 0, Wheel_koloL1, 0, Wheel_podkoloL1, 1, Wheel_kolP1, 0, Wheel_koloP1, 0, Wheel_podkoloP1, 1, Wheel_kolL2, 0, Wheel_kolP2, 0, Wheel_koloL2, 0, Wheel_koloL3, 0, Wheel_koloL4, 0, Wheel_koloL5, 0, Wheel_koloL6, 0, Wheel_koloL7, 0, Wheel_koloP2, 0, Wheel_koloP3, 0, Wheel_koloP4, 0, Wheel_koloP5, 0, Wheel_koloP6, 0, Wheel_koloP7, 0, Wheel_podkoloL2, 1, Wheel_podkoloL3, 1, Wheel_podkoloL4, 1, Wheel_podkoloL5, 0, Wheel_podkoloL6, 0, Wheel_podkoloP2, 1, Wheel_podkoloP3, 1, Wheel_podkoloP4, 1, Wheel_podkoloP5, 0, Wheel_podkoloP6, 1, podkoloL1_hide_damage, 0, podkoloL2_hide_damage, 0, podkoloL3_hide_damage, 0, podkoloL4_hide_damage, 0, podkoloL5_hide_damage, 0, podkoloL6_hide_damage, 0, podkoloL7_hide_damage, 0, podkoloL8_hide_damage, 0, podkoloP1_hide_damage, 0, podkoloP2_hide_damage, 0, podkoloP3_hide_damage, 0, podkoloP4_hide_damage, 0, podkoloP5_hide_damage, 0, podkoloP6_hide_damage, 0, podkoloP7_hide_damage, 0, podkoloP8_hide_damage, 0, damageVez, 0, MainTurret, -3, MainGun, 0, Recoil, 0, ObsTurret, -0, ObsGun, 0, MainGunOptics, 0, Wheel_podkoloP7, 0, Wheel_podkoloL7, 0, HatchDriver, 0, HatchCommander, 0, HatchGunner, 0, damageVezVelitele, 0, poklop_commander_damage, 0, poklop_gunner_damage, 0, poklop_driver_damage, 0, zaslehROT_HMG, 101, zaslehROT_coax, 16, cannon_muzzle_flash, 0, zaslehROT_cannon, 956, HideHull, 1, HideTurret, 1, LockMuzzle, 0 \ No newline at end of file diff --git a/extensions/tests/longrod_dxtk_test.txt.backup b/extensions/tests/longrod_dxtk_test.txt.backup index de0de31ee5..ab2eeb6a0e 100644 --- a/extensions/tests/longrod_dxtk_test.txt.backup +++ b/extensions/tests/longrod_dxtk_test.txt.backup @@ -1,5 +1,6 @@ +#c:\arma\arma3\addons\structures_f_ind.pbo C:\dev\ace3\extensions\tests\longrod_dxtk_test.txt.backup init: debug_render: register_vehicle:\A3\Structures_F\Ind\Cargo\Cargo40_blue_F.p3d,0,4050.18;3802.55;5.075 -set_animation_state:Door_1_rot,1,Door_Locked_1_rot,0,Door_2_rot,0,Door_Locked_2_rot,0, +set_animation_state:0,Door_1_rot,0,Door_Locked_1_rot,0,Door_2_rot,0,Door_Locked_2_rot,0, fetch_result:1 \ No newline at end of file diff --git a/extensions/tests/test.p3d b/extensions/tests/test.p3d deleted file mode 100644 index c0dea83658a3303724276f67c4ad27b9bed41625..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7190 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 T15;l$m>ONMn5yr@#W3}MG{f5x diff --git a/extensions/tests/test.pbo.txt b/extensions/tests/test.pbo.txt index 0efa05ee5c..bcf512e9e6 100644 --- a/extensions/tests/test.pbo.txt +++ b/extensions/tests/test.pbo.txt @@ -1,3 +1,5 @@ +# C:\dev\ace3\extensions\tests\test.pbo C:\dev\ace3\extensions\tests\test.pbo.txt init: debug_render: -register_vehicle:\test\test.p3d,2,4050.18;3802.55;5.075 +register_vehicle:\test\test.p3d,0,4050.18;3802.55;5.075 +set_animation_state:0,box3_rotate,0.5,box3_translate,0, \ No newline at end of file diff --git a/extensions/tests/test_model/config.cpp b/extensions/tests/test_model/config.cpp index 5818df7f4f..2a7deaa41e 100644 --- a/extensions/tests/test_model/config.cpp +++ b/extensions/tests/test_model/config.cpp @@ -18,7 +18,7 @@ class CfgVehicles { author = "Nou"; _generalMacro = "nou_snow_2x2"; scope = 2; - model = "\x\nou\addons\test_model\test.p3d"; + model = "test_model\test.p3d"; vehicleClass = "Structures"; cost = 50000; replaceDamagedLimit = 0.99999; diff --git a/extensions/vd/base_vehicle.cpp b/extensions/vd/base_vehicle.cpp index 292e5a321c..2e3caaec36 100644 --- a/extensions/vd/base_vehicle.cpp +++ b/extensions/vd/base_vehicle.cpp @@ -20,9 +20,10 @@ namespace ace { } } if (fire_lod == -1) // @TODO: fallback on geo LOD - fire_lod = 11; + fire_lod = 0; + //fire_lod = 0; assert(fire_lod != -1); - + // Build the mesh from object faces // TODO: LOD!? // P3d store in x,z,y format @@ -58,7 +59,7 @@ namespace ace { std::vector lods; lods.push_back(fire_lod); - object->animate(animation_state, lods); + object->animate(animation_state, lods); return true; } diff --git a/extensions/vd/controller.cpp b/extensions/vd/controller.cpp index cf6706c7d1..479dac3fc7 100644 --- a/extensions/vd/controller.cpp +++ b/extensions/vd/controller.cpp @@ -153,7 +153,7 @@ namespace ace { if (vehicles.find(id) == vehicles.end()) return false; - for (int x = 0, y = 0; x < vehicles[id]->animation_state.size() && x < _args.size() / 2; x++, y +=2) { + for (int x = 1, y = 1; x < vehicles[id]->animation_state.size() && x < _args.size() / 2; x++, y +=2) { std::string animation_name = _args[y]; float state = _args[y + 1]; vehicles[id]->animation_state[animation_name] = state;