Advertisement
masx1996

Untitled

May 20th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. double angle = 0;
  2.  
  3. void AnimateBone(Mesh& mesh, char* boneName, float phiX, float phiY, float phiZ){
  4.     matrix33 mx = { { 1,0,0 },{ 1,cosf(phiX),-sinf(phiX) },{ 1,sinf(phiX),cosf(phiX) } };
  5.     matrix33 my = { { cosf(phiY),0,sinf(phiY) },{ 0,1,0 },{ -sinf(phiY),0,cosf(phiY) } };
  6.     matrix33 mz = { { cosf(phiZ),-sinf(phiZ),0 },{ cosf(phiZ), sinf(phiX),0 },{ 0,0,1 } };
  7.     int id = mesh.animation.GetBoneIndexOf(boneName);
  8.     matrix44 m4 = mesh.animation.bones[id].matrix;
  9.     mx = mx * my*mz;
  10.     mesh.animation.bones[id].matrix.x_component().x = mx.x_component().x;
  11.     mesh.animation.bones[id].matrix.y_component().y = mx.y_component().y;
  12.     mesh.animation.bones[id].matrix.z_component().z = mx.z_component().z;
  13.     updateChilds(mesh, 1);
  14.     updateChilds(mesh, 5);
  15. }
  16.  
  17. float step = 0.001;
  18. void AnimateArms(Mesh& mesh){
  19.     float t = cos(angle);
  20.     if (angle > 3)
  21.     {
  22.         angle = 3;
  23.         step = -0.001;
  24.     }
  25.     if (angle < 0)
  26.     {
  27.         angle = 0;
  28.         step = 0.001;
  29.     }
  30.     angle += step;
  31.     AnimateBone(mesh, "joint2", 0, -20.0, angle);
  32.     AnimateBone(mesh, "joint5", 0, 20.0, angle);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement