Boop, animations should be working (direct is still not implemented).

This commit is contained in:
Nou 2015-05-14 00:21:48 -07:00
parent 4a41f8b9e2
commit e5af159cdc
5 changed files with 110 additions and 129 deletions

View File

@ -42,7 +42,9 @@ void ace::simulation::vertex::animate(const glm::mat4 &matrix, ace::vector3<floa
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);
if (offset) {
// this->animated_vertex = this->animated_vertex + rotation_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);
}
}
@ -80,15 +82,12 @@ 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);
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;
for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) {
if (p3d->info->autocenter) {
ace::vector3<float> new_vertex = ace::vector3<float>(
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)
);
ace::vector3<float> new_vertex = p3d_vertex_table->points[i] - center_off;
this->vertices[i] = std::make_shared<vertex>(*this, new_vertex, i);
}
else {
this->vertices[i] = std::make_shared<vertex>(*this, p3d_vertex_table->points[i], i);
@ -104,7 +103,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_lod->autocenter_pos;
this->autocenter_pos = 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<face>(p3d_face, p3d_lod, p3d, this));
@ -129,7 +128,8 @@ ace::simulation::lod_animation_info::lod_animation_info(
{
this->index = p3d_animate_bone->index;
if (p3d->info->autocenter) {
this->axis_position = p3d_animate_bone->axis_position + (lod->autocenter_pos*-1);
ace::vector3<float> 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;
this->axis_direction = p3d_animate_bone->axis_direction.normalize();
}
else {
@ -223,16 +223,12 @@ animation_transform ace::simulation::animation::animate(const float phase, const
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());
if (this->type < 4) {
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;
animation_matrix = glm::rotate(glm::mat4(1.0f), -scale, axis_direction);
rotation_offset = this->lod_info[lod_id]->axis_position;
break;
@ -243,10 +239,6 @@ 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::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;
}
@ -255,10 +247,7 @@ animation_transform ace::simulation::animation::animate(const float phase, const
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;
animation_matrix = glm::rotate(glm::mat4(1.0f), -scale, rotation_axis);
rotation_offset = this->lod_info[lod_id]->axis_position;
break;
@ -268,12 +257,7 @@ animation_transform ace::simulation::animation::animate(const float phase, const
scale = (scale / (max_value - min_value)) * (angle1 - angle0);
glm::vec3 rotation_axis = glm::vec3(0.0f, 0.0f, 1.0f);
direction_matrix = glm::translate(glm::mat4(1.0f), axis_position);
animation_matrix = glm::rotate(direction_matrix, -scale, rotation_axis);
animation_matrix = animation_matrix * direction_matrix;
rotation_offset = this->lod_info[lod_id]->axis_position;
break;
}
@ -286,9 +270,7 @@ animation_transform ace::simulation::animation::animate(const float phase, const
this->lod_info[lod_id]->axis_direction.z()
);
direction = direction * scale;
direction_matrix = glm::translate(glm::mat4(1.0f), axis_position);
animation_matrix = glm::translate(glm::mat4(1.0f), direction);
animation_matrix = animation_matrix * direction_matrix;
break;
}
@ -334,10 +316,9 @@ animation_transform ace::simulation::animation::animate(const float phase, const
}
default: {}
}
return_matrices[lod_id].first = animation_matrix * base_matrix;
return_matrices[lod_id].first = base_matrix * animation_matrix;
return_matrices[lod_id].second = base_rotation_offset + rotation_offset;
}
}
return return_matrices;
}

View File

@ -1,5 +1,5 @@
#c:\arma\arma3\addons\static_f_gamma.pbo C:\dev\ace3\extensions\tests\AT_01.txt
init:
debug_render:
register_vehicle:\z\ace\test\anim_test.p3d,0,4050.18;3802.55;5.075
set_animation_state:0, turret, 2.00, rotation_drum, 2, barrel_recoil, 2
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

View File

@ -21,7 +21,7 @@ namespace ace {
}
if (fire_lod == -1) // @TODO: fallback on geo LOD
fire_lod = 0;
fire_lod = 0;
//fire_lod = 0;
assert(fire_lod != -1);
// Build the mesh from object faces

View File

@ -153,7 +153,7 @@ namespace ace {
if (vehicles.find(id) == vehicles.end())
return false;
for (int x = 1, y = 1; 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++, y +=2) {
std::string animation_name = _args[y];
float state = _args[y + 1];
vehicles[id]->animation_state[animation_name] = state;

View File

@ -87,11 +87,11 @@ namespace ace {
const XMVECTORF32 v3 = { 100.f, 0.f, 0.f };
const XMVECTORF32 v4 = { -100.f, 0.f, 0.f };
_Batch->DrawLine(VertexPositionColor(v3, Colors::Red), VertexPositionColor(v4, Colors::Red));
_Batch->DrawLine(VertexPositionColor(v3, Colors::Green), VertexPositionColor(v4, Colors::Green));
const XMVECTORF32 v5 = { 0.f, 0.f, 100.f };
const XMVECTORF32 v6 = { 0.f, -0.f, -100.f };
_Batch->DrawLine(VertexPositionColor(v5, Colors::Red), VertexPositionColor(v6, Colors::Red));
_Batch->DrawLine(VertexPositionColor(v5, Colors::Blue), VertexPositionColor(v6, Colors::Blue));
_Batch->End();