Added GetRotateQuat()
This commit is contained in:
parent
6a688a2991
commit
7589d62732
@ -216,6 +216,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction);
|
const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction);
|
||||||
|
const Quatf GetRotateQuat(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 带误差的比较两个浮点矩阵是否相等
|
* 带误差的比较两个浮点矩阵是否相等
|
||||||
|
@ -195,4 +195,21 @@ namespace hgl
|
|||||||
|
|
||||||
return glm::rotate(Matrix4f(1.0f),angle,axis);
|
return glm::rotate(Matrix4f(1.0f),angle,axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算一个方向旋转成另一个方向的四元数
|
||||||
|
*/
|
||||||
|
const Quatf GetRotateQuat(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 Quatf(1.0f,0.0f,0.0f,0.0f);
|
||||||
|
|
||||||
|
axis=glm::normalize(axis);
|
||||||
|
|
||||||
|
float angle=acos(glm::dot(cur_direction,new_direction));
|
||||||
|
|
||||||
|
return glm::angleAxis(angle,axis);
|
||||||
|
}
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user