XYZ两个GLM :: MAT4矩阵的距离点对点
XYZ Distance point-to-point of two glm::mat4 matrices
我有两个glm :: mat4 modelView矩阵,我需要比较两个XYZ点之间的距离,我尝试了此代码,但似乎并不准确。
inline GLfloat Dist3D(GLfloat X1, GLfloat Y1, GLfloat Z1,
GLfloat X2, GLfloat Y2, GLfloat Z2) {
return sqrt(pow((X2 - X1), 2) + pow((Y2 - Y1), 2) + pow((Z2 - Z1), 2));
}
void PlayerScore::CompareMatrixes(
glm::mat4 Target,
glm::mat4 Source) {
GLfloat dist = Dist3D(
Target[3][0], Target[3][1], Target[3][2],
Source[3][0], Source[3][1], Source[3][2]);
printf("Dist to target %fn", dist);
}
您只需使用glm::length
来确定两个分之间的距离。
glm::vec3 v1 = {2.0, 0.0, 0.0};
glm::vec3 v2 = {6.0, 0.0, 0.0};
auto distance = glm::length(v2 - v1);
std::cout << distance << std::endl; // expected output is 4
glm::mat4 identity(1.0);
glm::mat4 m1 = glm::translate(identity, v1);
glm::mat4 m2 = glm::translate(identity, v2);
// note that the operator[] returns an entire column as vec4
distance = glm::length(m2[3] - m1[3]);
std::cout << distance << std::endl; // expected output is 4
相关文章:
- 如何对点云数据进行排序
- 测试与浮点对齐
- 使用哪个 pcl 滤波器对点云进行下采样
- 找到所有可能的点对之间的力总和?
- 将对向量与int和点对向量
- XYZ两个GLM :: MAT4矩阵的距离点对点
- 如何正确地铺面浮点对
- MPI 点对点通信到集体通信
- 最近点对O(nlogn)算法——c++实现中的一些数据问题
- 根据点的坐标对点进行排序
- 根据其标记点对齐2个面部图像
- 使用较少STL运算符对点进行排序
- 根据另一个向量对点向量进行排序
- 在安卓和PC之间创建Wifi点对点连接
- OpenGL:如何根据相机距离对点进行排序
- 根据点之间的距离对点进行排序
- Windows XP到Ubuntu Linux点对点通信使用Python或C/ c++
- 使用ZeroMQ构建点对点工作负载调度器是否有帮助?
- 使用gSoap的异步、确认、点对点连接
- 全局路由 结合无线网络和点对点连接时出错