Algorithm.h dnacalib/TypeDefs.h RotateCommand.cpp dnac //CopyrightEpicGames,Inc.AllRightsReserved. #pragmaonce #include"dnacalib/TypeDefs.h" namespacednac{ inlinefmat4getTransformationMatrix(constfvec3&translation,constfvec3&rotation,constfvec3&scale={1.0f,1.0f,1.0f}){ returntdm::scale(scale)*tdm::rotate(rotation)*tdm::translate(translation); } inlinefmat4extractTranslationMatrix(constfmat4&transformationMatrix){ autot=fmat4::identity(); t(3,0)=transformationMatrix(3,0); t(3,1)=transformationMatrix(3,1); t(3,2)=transformationMatrix(3,2); returnt; } inlinefvec3extractScaleVector(constfmat4&transformationMatrix){ constauto&m=transformationMatrix; constfloatsx=fvec3{m(0,0),m(0,1),m(0,2)}.length(); constfloatsy=fvec3{m(1,0),m(1,1),m(1,2)}.length(); constfloatsz=fvec3{m(2,0),m(2,1),m(2,2)}.length(); return{sx,sy,sz}; } inlinefmat4extractRotationMatrix(constfmat4&transformationMatrix){ autor=transformationMatrix; r(3,0)=0.0f; r(3,1)=0.0f; r(3,2)=0.0f; constautoscale=tdm::scale(extractScaleVector(transformationMatrix)); constautoinverseScale=tdm::inverse(scale); returninverseScale*r; } inlinefvec3extractTranslationVector(constfmat4&transformationMatrix){ return{transformationMatrix(3,0),transformationMatrix(3,1),transformationMatrix(3,2)}; } inlinefvec3extractRotationVector(constfmat4&transformationMatrix){ fvec3angle{}; constautor=extractRotationMatrix(transformationMatrix); constautor02=r(0,2); if(r02<1.0f){ if(r02>-1.0f){ angle[0]=std::atan2(r(1,2),r(2,2)); angle[1]=std::asin(-r02); angle[2]=std::atan2(r(0,1),r(0,0)); }else{ angle[0]=std::atan2(-r(2,1),r(1,1)); angle[1]=static_cast<float>(tdm::pi()/2.0f); angle[2]=0; } }else{ angle[0]=-std::atan2(-r(2,1),r(1,1)); angle[1]=static_cast<float>(-tdm::pi()/2.0f); angle[2]=0; } returnangle; } }//namespacednac