obb旋转计算
obb rotation calculation
我需要一些关于obb旋转的帮助:
首先,我检查三维模型的每个顶点,并获得最小和最大值,以找到obb最小/最大点。
void obb::checkVertex(vector3f& vertex)
{
vLowerLeftFront.x = min(vLowerLeftFront.x, vertex.x);
vLowerLeftFront.y = min(vLowerLeftFront.y, vertex.y);
vLowerLeftFront.z = max(vLowerLeftFront.z, vertex.z);
// Update upper-right-back corner of BB
vUpperRightBack.x = max(vUpperRightBack.x, vertex.x);
vUpperRightBack.y = max(vUpperRightBack.y, vertex.y);
vUpperRightBack.z = min(vUpperRightBack.z, vertex.z);
}
然后,对于每一帧,更新obb(八个角)乘以modelViewProjection矩阵。
void obb::update()
{
//vector3f is a struct whit 3 floats (x,y,z);
vector3f tmpV = vector3f(0.0f,0.0f,0.0f);
float *floatMatrix = glm::value_ptr(matrix::getInstance()->getModelViewProjectionMatrix());
tmpV.x = (floatMatrix[0] * vLowerLeftFront.x) +
(floatMatrix[4] * vLowerLeftFront.y) +
(floatMatrix[8] * vLowerLeftFront.z) +
floatMatrix[12];
tmpV.y = (floatMatrix[1] * vLowerLeftFront.x) +
(floatMatrix[5] * vLowerLeftFront.y) +
(floatMatrix[9] * vLowerLeftFront.z) +
floatMatrix[13];
tmpV.z = (floatMatrix[2] * vLowerLeftFront.x) +
(floatMatrix[6] * vLowerLeftFront.y) +
(floatMatrix[10] * vLowerLeftFront.z) +
floatMatrix[14];
vLowerLeftFront = tmpV;
tmpV.x = (floatMatrix[0] * vUpperRightBack.x) +
(floatMatrix[4] * vUpperRightBack.y) +
(floatMatrix[8] * vUpperRightBack.z) +
floatMatrix[12];
tmpV.y = (floatMatrix[1] * vUpperRightBack.x) +
(floatMatrix[5] * vUpperRightBack.y) +
(floatMatrix[9] * vUpperRightBack.z) +
floatMatrix[13];
tmpV.z = (floatMatrix[2] * vUpperRightBack.x) +
(floatMatrix[6] * vUpperRightBack.y) +
(floatMatrix[10] * vUpperRightBack.z) +
floatMatrix[14];
vUpperRightBack = tmpV;
tmpV.x = (floatMatrix[0] * vLowerRightFront.x) +
(floatMatrix[4] * vLowerRightFront.y) +
(floatMatrix[8] * vLowerRightFront.z) +
floatMatrix[12];
tmpV.y = (floatMatrix[1] * vLowerRightFront.x) +
(floatMatrix[5] * vLowerRightFront.y) +
(floatMatrix[9] * vLowerRightFront.z) +
floatMatrix[13];
tmpV.z = (floatMatrix[2] * vLowerRightFront.x) +
(floatMatrix[6] * vLowerRightFront.y) +
(floatMatrix[10] * vLowerRightFront.z) +
floatMatrix[14];
vLowerRightFront = tmpV;
tmpV.x = (floatMatrix[0] * vLowerRightBack.x) +
(floatMatrix[4] * vLowerRightBack.y) +
(floatMatrix[8] * vLowerRightBack.z) +
floatMatrix[12];
tmpV.y = (floatMatrix[1] * vLowerRightBack.x) +
(floatMatrix[5] * vLowerRightBack.y) +
(floatMatrix[9] * vLowerRightBack.z) +
floatMatrix[13];
tmpV.z = (floatMatrix[2] * vLowerRightBack.x) +
(floatMatrix[6] * vLowerRightBack.y) +
(floatMatrix[10] * vLowerRightBack.z) +
floatMatrix[14];
vLowerRightBack = tmpV;
tmpV.x = (floatMatrix[0] * vLowerLeftBack.x) +
(floatMatrix[4] * vLowerLeftBack.y) +
(floatMatrix[8] * vLowerLeftBack.z) +
floatMatrix[12];
tmpV.y = (floatMatrix[1] * vLowerLeftBack.x) +
(floatMatrix[5] * vLowerLeftBack.y) +
(floatMatrix[9] * vLowerLeftBack.z) +
floatMatrix[13];
tmpV.z = (floatMatrix[2] * vLowerLeftBack.x) +
(floatMatrix[6] * vLowerLeftBack.y) +
(floatMatrix[10] * vLowerLeftBack.z) +
floatMatrix[14];
vLowerLeftBack = tmpV;
tmpV.x = (floatMatrix[0] * vUpperRightFront.x) +
(floatMatrix[4] * vUpperRightFront.y) +
(floatMatrix[8] * vUpperRightFront.z) +
floatMatrix[12];
tmpV.y = (floatMatrix[1] * vUpperRightFront.x) +
(floatMatrix[5] * vUpperRightFront.y) +
(floatMatrix[9] * vUpperRightFront.z) +
floatMatrix[13];
tmpV.z = (floatMatrix[2] * vUpperRightFront.x) +
(floatMatrix[6] * vUpperRightFront.y) +
(floatMatrix[10] * vUpperRightFront.z) +
floatMatrix[14];
vUpperRightFront = tmpV;
tmpV.x = (floatMatrix[0] * vUpperLeftBack.x) +
(floatMatrix[4] * vUpperLeftBack.y) +
(floatMatrix[8] * vUpperLeftBack.z) +
floatMatrix[12];
tmpV.y = (floatMatrix[1] * vUpperLeftBack.x) +
(floatMatrix[5] * vUpperLeftBack.y) +
(floatMatrix[9] * vUpperLeftBack.z) +
floatMatrix[13];
tmpV.z = (floatMatrix[2] * vUpperLeftBack.x) +
(floatMatrix[6] * vUpperLeftBack.y) +
(floatMatrix[10] * vUpperLeftBack.z) +
floatMatrix[14];
vUpperLeftBack = tmpV;
tmpV.x = (floatMatrix[0] * vUpperLeftFront.x) +
(floatMatrix[4] * vUpperLeftFront.y) +
(floatMatrix[8] * vUpperLeftFront.z) +
floatMatrix[12];
tmpV.y = (floatMatrix[1] * vUpperLeftFront.x) +
(floatMatrix[5] * vUpperLeftFront.y) +
(floatMatrix[9] * vUpperLeftFront.z) +
floatMatrix[13];
tmpV.z = (floatMatrix[2] * vUpperLeftFront.x) +
(floatMatrix[6] * vUpperLeftFront.y) +
(floatMatrix[10] * vUpperLeftFront.z) +
floatMatrix[14];
vUpperLeftFront = tmpV;
}
问题是旋转计算不正确。。我不知道为什么。。
我需要帮助来解决这个问题,并正确计算obb旋转。
变量内容示例:
floatMatrix[0] = -7.91465e-008
floatMatrix[1] = -0.847687
floatMatrix[2] = -0.936392
floatMatrix[3] = -0.936329
floatMatrix[4] = 1.81066
floatMatrix[5] = -3.70536e-008
floatMatrix[6] = -4.0931e-008
floatMatrix[7] = -4.09282e-008
floatMatrix[8] = 0
floatMatrix[9] = 2.2605
floatMatrix[10] = -0.351147
floatMatrix[11] = -0.351123
floatMatrix[12] = 1.0864
floatMatrix[13] = -7.68569
floatMatrix[14] = 45.4257
floatMatrix[15] = 45.6226
vLowerLeftFront: (-727.46, 84.64, 273.49)
vUpperRightBack: (-459.98, -19.68, 19.6)
然后,对于每一帧,更新obb(八个角)乘以modelViewProjection矩阵。
这种矩阵组合将顶点从模型空间转换到世界空间(这可能是你想要的),然后转换到相机空间,最后转换到剪辑空间,这一点都不太有用。
乘以模型矩阵仅可将模型坐标转换为世界坐标。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 递归函数计算序列中的平方和(并输出过程)
- 如何有效地计算将单位立方体映射到自身的反射和旋转?
- 如何使用增强::几何计算多边形的旋转固体体积?
- 给定方向和位置如何使用 GLM 计算旋转矩阵
- 快速计算变换/旋转马里克斯4x4
- 在Qt5的OpenGL绘图中通过鼠标移动计算对象旋转角度
- 如何从OpenCV rvecs计算旋转角度
- OpenCV 计算相机位置和旋转
- c++:旋转锁或互斥对象比较(简单计算)
- 对象旋转/平移后重新计算AABB正确
- 从盒子计算 AABB(中心、半大小、旋转)
- 如何使用OpenCV计算两帧之间的旋转平移矩阵
- 如何在三维空间中计算旋转碰撞
- obb旋转计算
- c++OpenGL的旋转和计算
- 我们如何计算旋转和平移两个立体相机在opencv StereoRectify(r,t自变量)中使用
- 如何计算基于方向向量的旋转矩阵
- 计算旋转直线的反弹角度
- 如何在平移/旋转后重新计算轴对齐的边界框