Skip to content

Commit

Permalink
fix: Fix Type4 IK
Browse files Browse the repository at this point in the history
Apparently the cause was flipping over the rotation and target
in the struct definitions. Flipping them back causes the bug to
dissappear. This allows for future refactors to `BoneAnim` making all IK
animations use the same enum variant
  • Loading branch information
Waelwindows committed Jul 20, 2020
1 parent ea4f4ef commit 9c97507
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 419 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
Cargo.lock
tags
*.bvh
*.mot
*.mot
bone
405 changes: 0 additions & 405 deletions bone

This file was deleted.

5 changes: 5 additions & 0 deletions examples/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ fn main() -> Result<()> {
};
let get3 = |x: &BoneAnim| match x {
BoneAnim::Rotation(rot) => (get(&rot.x), get(&rot.y), get(&rot.z)),
BoneAnim::RotationIK {rotation, target} => (get(&rotation.x), get(&rotation.y), get(&rotation.z)),
BoneAnim::ArmIK {rotation, target} => (get(&rotation.x), get(&rotation.y), get(&rotation.z)),
_ => unreachable!(),
};
println!("kl_hara_xz: {:?}", get3(qual.anims[2].1.as_ref().unwrap()));
println!("kl_hara_etc: {:?}", get3(qual.anims[3].1.as_ref().unwrap()));
println!("n_hara: {:?}", get3(qual.anims[4].1.as_ref().unwrap()));
println!("n_hara: {:?}", get3(qual.anims[6].1.as_ref().unwrap()));
println!("c_kata_l: {:?}", get3(qual.anims[104].1.as_ref().unwrap()));
println!("c_kata_r: {:?}", get3(qual.anims[137].1.as_ref().unwrap()));
// for (id, anim) in qual.anims.iter_mut() {
// match anim {
// // Some(BoneAnim::Rotation(p)) => {
Expand Down
9 changes: 3 additions & 6 deletions examples/mot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() -> Result<()> {
match anims.iter_mut().find(|(i, _)| *i == bone_id) {
Some((_, anim)) => match anim {
Some(BoneAnim::RotationIK { rotation, target }) => {
debug!("setting {}'s target", name);
debug!("ROIK: setting {}'s target", name);
*target = new_target
}
Some(BoneAnim::ArmIK { rotation, target }) => {
Expand Down Expand Up @@ -174,17 +174,14 @@ fn main() -> Result<()> {
let halfpi = std::f32::consts::PI;
let rotation = Vec3 {
x: FrameData::Pose(0.),
y: FrameData::Pose(halfpi),
z: FrameData::Pose(0.),
y: FrameData::Pose(0.),
z: FrameData::Pose(-halfpi),
};
let target = Vec3 {
x: FrameData::Pose(0.),
y: FrameData::Pose(0.),
z: FrameData::Pose(0.),
};
if name == "cl_mune" {
dbg!(2);
}
anims.push((bone_id, Some(BoneAnim::RotationIK { rotation, target })));
}
BoneType::Type5 => {
Expand Down
6 changes: 3 additions & 3 deletions src/qualified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ pub enum BoneAnim {
rotation: Vec3,
},
RotationIK {
//Type4
rotation: Vec3, // guess
//Type4; target is first
target: Vec3,
rotation: Vec3, // guess
},
ArmIK {
//Type 5
Expand Down Expand Up @@ -127,8 +127,8 @@ impl Motion {
rotation: vec3(),
},
BoneType::Type4 => BoneAnim::RotationIK {
rotation: vec3(),
target: vec3(),
rotation: vec3(),
},
BoneType::Type5 => BoneAnim::ArmIK {
target: vec3(),
Expand Down
8 changes: 4 additions & 4 deletions src/qualified/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl BoneAnim {
rotation, // guess
target,
} => {
rotation.write(&mut writer)?;
target.write(&mut writer)?;
rotation.write(&mut writer)?;
}
ArmIK {
//Type 5
Expand Down Expand Up @@ -136,8 +136,8 @@ impl BoneAnim {
vec
}
RotationIK { rotation, target } => {
let mut vec = rotation.get_bits();
vec.append(&mut target.get_bits());
let mut vec = target.get_bits();
vec.append(&mut rotation.get_bits());
vec
}
ArmIK { rotation, target } => {
Expand Down Expand Up @@ -175,7 +175,7 @@ impl BoneAnim {
position.x, position.y, position.z, rotation.x, rotation.y, rotation.z,
],
RotationIK { rotation, target } => vec![
rotation.x, rotation.y, rotation.z, target.x, target.y, target.z,
target.x, target.y, target.z, rotation.x, rotation.y, rotation.z,
], //rotationnown
ArmIK { rotation, target } => vec![
target.x, target.y, target.z, rotation.x, rotation.y, rotation.z,
Expand Down

0 comments on commit 9c97507

Please sign in to comment.