Merge branch 'vehicledamage' of github.com:acemod/ACE3 into vehicledamage

This commit is contained in:
jaynus 2015-05-15 17:26:07 -07:00
commit b4aead6bf7
6 changed files with 83 additions and 69 deletions

View File

@ -8,6 +8,11 @@ ace::simulation::vertex::vertex(vertex_table & _table, ace::vector3<float> _vert
{ {
this->original_vertex = _vertex; this->original_vertex = _vertex;
this->animated_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() ace::simulation::vertex::~vertex()
@ -32,20 +37,12 @@ ace::simulation::face::~face()
{ {
} }
void ace::simulation::vertex::animate(const glm::mat4 &matrix, ace::vector3<float> rotation_offset, bool offset) void ace::simulation::vertex::animate(const glm::mat4 &matrix)
{ {
ace::vector3<float> temp_vector = this->original_vertex; ace::vector3<float> 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); 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; temp_gl_vector = matrix*temp_gl_vector;
this->animated_vertex = ace::vector3<float>(temp_gl_vector.x, temp_gl_vector.y, temp_gl_vector.z); this->animated_vertex = ace::vector3<float>(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<float>(temp_gl_vector.x, temp_gl_vector.y, temp_gl_vector.z);
}
} }
ace::simulation::named_selection::named_selection( 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<float> rotation_offset) void ace::simulation::named_selection::animate(const glm::mat4 &matrix)
{ {
bool offset = !rotation_offset.zero_distance();
for (auto selection_vertex : this->vertices) { 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); this->vertices.resize(p3d_vertex_table->points.size);
ace::vector3<float> center_off2 = p3d_lod->min_pos+p3d_lod->max_pos-p3d_lod->autocenter_pos; ace::vector3<float> center_off2 = p3d_lod->min_pos+p3d_lod->max_pos-p3d_lod->autocenter_pos;
ace::vector3<float> center_off = p3d->info->center_of_gravity + p3d->info->offset_2 + p3d->info->cog_offset; ace::vector3<float> 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) { for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) {
if (p3d->info->autocenter) { if (p3d->info->autocenter) {
ace::vector3<float> new_vertex = p3d_vertex_table->points[i] - center_off; ace::vector3<float> new_vertex = p3d_vertex_table->points[i] + center_off;
this->vertices[i] = std::make_shared<vertex>(*this, new_vertex, i); this->vertices[i] = std::make_shared<vertex>(*this, new_vertex, i);
} }
else { 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->id = p3d_lod->id;
this->vertices = vertex_table(p3d_lod->vertices, p3d_lod, p3d); 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) { for (ace::p3d::face_p p3d_face : p3d_lod->faces) {
this->faces.push_back(std::make_shared<face>(p3d_face, p3d_lod, p3d, this)); this->faces.push_back(std::make_shared<face>(p3d_face, p3d_lod, p3d, this));
@ -128,8 +124,8 @@ ace::simulation::lod_animation_info::lod_animation_info(
{ {
this->index = p3d_animate_bone->index; this->index = p3d_animate_bone->index;
if (p3d->info->autocenter) { if (p3d->info->autocenter) {
ace::vector3<float> center_off = p3d->info->center_of_gravity + p3d->info->offset_2 + p3d->info->cog_offset; ace::vector3<float> 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_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.normalize();
} }
else { else {
@ -208,13 +204,13 @@ typedef union {
#define RAD2DEG(rad) (rad * 180.0f / 3.1415926f); #define RAD2DEG(rad) (rad * 180.0f / 3.1415926f);
typedef std::map<uint32_t, std::pair<glm::mat4, ace::vector3<float>>> animation_transform; typedef std::map<uint32_t, glm::mat4> animation_transform;
animation_transform ace::simulation::animation::animate(const float phase, const std::vector<uint32_t> &lods, animation_transform base_transforms) animation_transform ace::simulation::animation::animate(const float phase, const std::vector<uint32_t> &lods, animation_transform base_transforms)
{ {
animation_transform return_matrices; animation_transform return_matrices;
for (auto lod_id : lods) { for (auto lod_id : lods) {
glm::mat4 base_matrix = base_transforms[lod_id].first; glm::mat4 base_matrix = base_transforms[lod_id];
ace::vector3<float> base_rotation_offset = base_transforms[lod_id].second;
glm::mat4 animation_matrix, direction_matrix; glm::mat4 animation_matrix, direction_matrix;
ace::vector3<float> rotation_offset = ace::vector3<float>(0, 0, 0); ace::vector3<float> rotation_offset = ace::vector3<float>(0, 0, 0);
@ -227,48 +223,44 @@ animation_transform ace::simulation::animation::animate(const float phase, const
//rotation //rotation
case 0: { case 0: {
scale = (scale / (max_value - min_value)) * (angle1 - angle0); 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::rotate(glm::mat4(1.0f), -scale, axis_direction);
animation_matrix *= glm::translate(glm::mat4(1.0f), axis_position);
rotation_offset = this->lod_info[lod_id]->axis_position;
break; break;
} }
//rotationX //rotationX
case 1: { case 1: {
scale = (scale / (max_value - min_value)) * (angle1 - angle0); scale = (scale / (max_value - min_value)) * (angle1 - angle0);
glm::vec3 rotation_axis = glm::vec3(1.0f, 0.0f, 0.0f); glm::vec3 rotation_axis = glm::vec3(1.0f, 0.0f, 0.0f);
animation_matrix = glm::rotate(glm::mat4(1.0f), -scale, rotation_axis); animation_matrix = glm::translate(glm::mat4(1.0f), -axis_position);
rotation_offset = this->lod_info[lod_id]->axis_position; animation_matrix *= glm::rotate(glm::mat4(1.0f), -scale, rotation_axis);
animation_matrix *= glm::translate(glm::mat4(1.0f),axis_position);
break; break;
} }
//rotationY //rotationY
case 2: { case 2: {
scale = (scale / (max_value - min_value)) * (angle1 - angle0); scale = (scale / (max_value - min_value)) * (angle1 - angle0);
glm::vec3 rotation_axis = glm::vec3(0.0f, 1.0f, 0.0f); 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::rotate(glm::mat4(1.0f), -scale, rotation_axis); animation_matrix *= glm::rotate(glm::mat4(1.0f), -scale, rotation_axis);
animation_matrix *= glm::translate(glm::mat4(1.0f), axis_position);
rotation_offset = this->lod_info[lod_id]->axis_position;
break; break;
} }
//rotationZ //rotationZ
case 3: { case 3: {
scale = (scale / (max_value - min_value)) * (angle1 - angle0); scale = (scale / (max_value - min_value)) * (angle1 - angle0);
glm::vec3 rotation_axis = glm::vec3(0.0f, 0.0f, 1.0f); 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::rotate(direction_matrix, -scale, rotation_axis); 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);
break; break;
} }
//translation //translation
case 4: { case 4: {
scale = (scale / (max_value - min_value)) * (offset1 - offset0); scale = (scale / (max_value - min_value)) * (offset1 - offset0);
glm::vec3 direction( glm::vec3 direction(axis_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()
);
direction = direction * scale; direction = direction * scale;
animation_matrix = glm::translate(glm::mat4(1.0f), direction); animation_matrix = glm::translate(glm::mat4(1.0f), direction);
@ -310,14 +302,13 @@ animation_transform ace::simulation::animation::animate(const float phase, const
} }
//hide //hide
case 9: { case 9: {
if (phase >= hide_value) if (scale >= hide_value)
animation_matrix = glm::mat4x4(0.0f); animation_matrix = glm::mat4x4(0.0f);
break; break;
} }
default: {} default: {}
} }
return_matrices[lod_id].first = base_matrix * animation_matrix; return_matrices[lod_id] = base_matrix * animation_matrix;
return_matrices[lod_id].second = base_rotation_offset + rotation_offset;
} }
return return_matrices; return return_matrices;
} }
@ -384,14 +375,10 @@ void ace::simulation::bone::animate(const std::map<std::string, float> &animatio
for (auto child_bone : children) { for (auto child_bone : children) {
child_bone->animate(animation_state, lods, base_transforms); child_bone->animate(animation_state, lods, base_transforms);
} }
if (animations.size() > 0) { for (auto lod_id : lods) {
for (auto bone_animation : animations) { auto selection = this->base_object->lods[lod_id]->selections.find(this->name);
for (auto lod_id : lods) { if (selection != this->base_object->lods[lod_id]->selections.end()) {
auto selection = this->base_object->lods[lod_id]->selections.find(this->name); selection->second->animate(base_transforms[lod_id]);
if (selection != this->base_object->lods[lod_id]->selections.end()) {
selection->second->animate(base_transforms[lod_id].first, base_transforms[lod_id].second);
}
}
} }
} }
} }
@ -436,8 +423,7 @@ void ace::simulation::object::animate(const std::map<std::string, float> &animat
{ {
animation_transform identity_transform; animation_transform identity_transform;
for (uint32_t lod_id : selected_lods) { for (uint32_t lod_id : selected_lods) {
identity_transform[lod_id].first = glm::mat4(); identity_transform[lod_id] = glm::mat4(1.0);
identity_transform[lod_id].second = ace::vector3<float>(0, 0, 0);
} }
this->root_bone->animate(animation_state, selected_lods, identity_transform); this->root_bone->animate(animation_state, selected_lods, identity_transform);
} }

View File

@ -26,7 +26,7 @@ namespace ace {
class object; class object;
typedef std::shared_ptr<object> object_p; typedef std::shared_ptr<object> object_p;
typedef std::map<uint32_t, std::pair<glm::mat4, ace::vector3<float>>> animation_transform; typedef std::map<uint32_t, glm::mat4> animation_transform;
class vertex_table { class vertex_table {
public: public:
@ -59,7 +59,7 @@ namespace ace {
std::vector<face_p> faces; std::vector<face_p> faces;
std::vector<vertex_p> vertices; std::vector<vertex_p> vertices;
void animate(const glm::mat4 &, ace::vector3<float>); void animate(const glm::mat4 &);
}; };
typedef std::shared_ptr<named_selection> named_selection_p; typedef std::shared_ptr<named_selection> named_selection_p;
@ -93,7 +93,7 @@ namespace ace {
std::vector<face *> faces; std::vector<face *> faces;
std::vector<named_selection *> selections; std::vector<named_selection *> selections;
void animate(const glm::mat4 &, ace::vector3<float>, bool); void animate(const glm::mat4 &);
private: private:
ace::vector3<float> original_vertex; ace::vector3<float> original_vertex;

View File

@ -2,4 +2,5 @@
init: init:
debug_render: debug_render:
register_vehicle:\x\nou\addons\anim_test\anim_test.p3d,0,4050.18;3802.55;5.075 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 #set_animation_state:0, turret, 0.500, rotation_drum, 0.0, barrel_recoil, 0, barrel_hide, 0
set_animation_state:0, turret, 0.500

View File

@ -12,6 +12,7 @@ class CfgSkeletons
class test_anim_skeleton : Default { class test_anim_skeleton : Default {
skeletonBones[] = skeletonBones[] =
{ {
"a_pos","",
"pedestal","", "pedestal","",
"turret","pedestal", "turret","pedestal",
"rotation_drum","turret", "rotation_drum","turret",
@ -45,9 +46,23 @@ class CfgModels
source = "turret"; source = "turret";
selection = "turret"; selection = "turret";
animPeriod = 0.0001; animPeriod = 0.0001;
minValue = "rad -360"; minValue = "0";
maxValue = "rad 360"; maxValue = "4";
angle0 = "rad -360"; angle0 = "0";
angle1 = "rad 360";
sourceAddress = "loop";
};
/*
class a_pos
{
type = "rotationY";
axis = "turret_rotation_axis";
source = "a_pos";
selection = "a_pos";
animPeriod = 0.0001;
minValue = "0";
maxValue = "4";
angle0 = "0";
angle1 = "rad 360"; angle1 = "rad 360";
sourceAddress = "loop"; sourceAddress = "loop";
}; };
@ -58,26 +73,38 @@ class CfgModels
selection = "rotation_drum"; selection = "rotation_drum";
axis = "barrel_elevation_axis"; axis = "barrel_elevation_axis";
animPeriod = 0.0001; animPeriod = 0.0001;
minValue = "rad -360"; minValue = "0";
maxValue = "rad 360"; maxValue = "4";
angle0 = "rad -360"; angle0 = "0";
angle1 = "rad 360"; angle1 = "rad 360";
sourceAddress = "loop"; sourceAddress = "loop";
}; };
class barrel_recoil class barrel_recoil
{ {
type = "translation"; type = "translationZ";
source = "barrel_recoil"; source = "barrel_recoil";
selection = "barrel"; selection = "barrel";
axis = "barrel_recoil_axis"; axis = "barrel_recoil_axis";
offset0 = 0; offset0 = 0;
offset1 = -2; offset1 = -2;
animPeriod = 0.0001; animPeriod = 0.0001;
minValue = -1; minValue = 0;
maxValue = 1; maxValue = 0.5;
sourceAddress = "mirror"; sourceAddress = "mirror";
}; };
class barrel_hide
{
type = "hide";
source = "barrel_hide";
selection = "barrel";
axis = "barrel_recoil_axis";
hideValue = 0.5;
minValue = "0";
maxValue = "1";
sourceAddress = "mirror";
};
*/
}; };
}; };
}; };

View File

@ -121,7 +121,7 @@ namespace ace {
if (_active_vehicle) { if (_active_vehicle) {
DrawObject(_active_vehicle->fire_lod, *_Batch, *_active_vehicle->object, Colors::Gray); DrawObject(_active_vehicle->fire_lod, *_Batch, *_active_vehicle->object, Colors::GhostWhite);
} }
if (_active_hits.size() > 0) { if (_active_hits.size() > 0) {
DrawHits(0, *_Batch, Colors::Yellow); DrawHits(0, *_Batch, Colors::Yellow);
@ -255,9 +255,9 @@ namespace ace {
xdivs = std::max<size_t>(1, xdivs); xdivs = std::max<size_t>(1, xdivs);
ydivs = std::max<size_t>(1, ydivs); ydivs = std::max<size_t>(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); float fPercent = float(i) / float(xdivs);
fPercent = (fPercent * 2.0f) - 1.0f; fPercent = (fPercent * 1.0f) - 1.0f;
XMVECTOR vScale = XMVectorScale(xAxis, fPercent); XMVECTOR vScale = XMVectorScale(xAxis, fPercent);
vScale = XMVectorAdd(vScale, origin); vScale = XMVectorAdd(vScale, origin);
@ -266,9 +266,9 @@ namespace ace {
batch.DrawLine(v1, v2); 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); FLOAT fPercent = float(i) / float(ydivs);
fPercent = (fPercent * 2.0f) - 1.0f; fPercent = (fPercent * 1.0f) - 1.0f;
XMVECTOR vScale = XMVectorScale(yAxis, fPercent); XMVECTOR vScale = XMVectorScale(yAxis, fPercent);
vScale = XMVectorAdd(vScale, origin); vScale = XMVectorAdd(vScale, origin);