Added GetRotateMatrix() in Matrix.h
This commit is contained in:
parent
7165984d22
commit
6a688a2991
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user