代码之家  ›  专栏  ›  技术社区  ›  Brock Woolf

帮助构建OBB,尝试用3个向量表示矩阵

  •  2
  • Brock Woolf  · 技术社区  · 16 年前

    东方快车 (Oriented Bounding Box) 使用《实时碰撞检测》一书中包含的源代码和数学。

    本书中包含的代码的一个问题是,它很少解释参数对方法的意义。

    我试图弄清楚我需要什么来为我的setOBB()方法提供数据(我写了这个)。它是这样的:

    void PhysicalObject::setOBB( Ogre::Vector3 centrePoint, Ogre::Vector3 localAxes[3], Ogre::Vector3 positiveHalfwidthExtents )
    {
        // Ogre::Vector3    c;      // OBB center point
        // Ogre::Vector3    u[3];   // Local x-, y-, and z-axes (rotation matrix)
        // Ogre::Vector3    e;  // Positive halfwidth extents of OBB along each axis
    
        m_obb.c         = centrePoint;
        m_obb.u[0]      = localAxes[0];
        m_obb.u[1]      = localAxes[1];
        m_obb.u[2]      = localAxes[2];
        m_obb.e         = positiveHalfwidthExtents;
    }
    

    看看上面想要的参数,我相信我理解第一个和第三个参数。

    1. 这是我的问题。 我认为它想要一个用3个向量数组表示的矩阵? 但是怎么做?

    以下是我目前正在做的事情:

    // Build the OBB
    Ogre::Vector3 rotation[3];
    Ogre::Vector3 centrePoint       = sphere->getPosition();
    rotation[0]         = ?
    rotation[1]         = ?
    rotation[2]         = ?
    Ogre::Vector3 halfEdgeLengths   = Ogre::Vector3( 1,1,1 );
    
    myObject->setOBB( centrepoint, rotation, halfEdgeLengths );
    

    2 回复  |  直到 16 年前
        1
  •  2
  •   haffax    16 年前

    (Ogre使用列主矩阵)

    所以, localAxes[3] 简单来说就是旋转。你可以从四元数中得到它。

    Ogre::Vector3 rotation[3];
    Ogre::Quaternion orientation = sphere->getOrientation();
    orientation.ToAxes(rotation);
    // Now rotation has the three axes representing the orientation of the sphere.
    
        2
  •  1
  •   Kyle Walsh    16 年前

    也就是说,如果你以统一的方式将这些向量填充到一个矩阵中,那么你要么将它们作为矩阵的行,要么将其作为矩阵的列,并且或多或少有50%的机会得到正确的结果,这取决于接受矩阵的函数期望矩阵如何格式化。因此,我建议将二维数组设置为矩阵,并谨慎行事。例如:

    int matrix[3][3] = {     { x1, x2, x3 },
                             { y1, y2, y3 },
                             { z1, z2, z3 }
                       };
    

    推荐文章