Added GetRotateMatrix() in Matrix.h

This commit is contained in:
hyzboy 2024-08-01 01:27:23 +08:00
parent 7165984d22
commit 6a688a2991
2 changed files with 19 additions and 0 deletions

View File

@ -215,6 +215,8 @@ namespace hgl
return root*child;
}
const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction);
/**
*
* @param m1 1

View File

@ -178,4 +178,21 @@ namespace hgl
return result;
}
/**
*
*/
const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction)
{
Vector3f axis=glm::cross(cur_direction,new_direction);
if(glm::length2(axis)<0.0001)
return Matrix4f(1.0f);
axis=glm::normalize(axis);
float angle=acos(glm::dot(cur_direction,new_direction));
return glm::rotate(Matrix4f(1.0f),angle,axis);
}
}//namespace hgl