Math 平移摄影机,使对象位于屏幕边缘

Math 平移摄影机,使对象位于屏幕边缘,math,3d,Math,3d,我试图写一个公式来平移相机,使物体的中心点在屏幕边缘可见。 换句话说,如果物体向右看不见,我会改变相机的x和y位置,使物体正好位于屏幕的右边缘(不改变相机角度或z坐标)。 有人能给我一些提示吗?我想出了一个符合我目的的解决方案,但唯一的办法是修改相机高度(这不是我想要的): //注意:pos是显示在屏幕边缘的对象的中心 //m_位置是相机的3d位置 //m_平面[]是相机fustrum的左、右等平面的阵列 无效摄影机::PanTo(常量矢量3D和pos) { int n; 矢量3D矢量最近; 对

我试图写一个公式来平移相机,使物体的中心点在屏幕边缘可见。 换句话说,如果物体向右看不见,我会改变相机的x和y位置,使物体正好位于屏幕的右边缘(不改变相机角度或z坐标)。
有人能给我一些提示吗?

我想出了一个符合我目的的解决方案,但唯一的办法是修改相机高度(这不是我想要的):

//注意:pos是显示在屏幕边缘的对象的中心
//m_位置是相机的3d位置
//m_平面[]是相机fustrum的左、右等平面的阵列
无效摄影机::PanTo(常量矢量3D和pos)
{
int n;
矢量3D矢量最近;
对于(n=0;n
// note: pos is the center of the object that is to appear at edge of screen
// m_position is the 3d position of the camera
// m_plane[] is array of left, right, etc. planes of camera fustrum

void Camera::PanTo(const Vector3D& pos) 
{
    int n;
    Vector3D vectorNearest;
    for (n = 0; n < NUM_PLANES; n++)
    {
        if (m_plane[n].GetDistance(pos) < 0)
        {
            m_plane[n].Normalize();
            vectorNearest += m_plane[n].GetVectorNearest(pos);
        }
    }
    m_posDesire.m[IX_X] = m_position.m[IX_X] + vectorNearest.m[IX_X];
    m_posDesire.m[IX_Y] = m_position.m[IX_Y] + vectorNearest.m[IX_Y];
    m_posDesire.m[IX_Z] = m_position.m[IX_Z] + vectorNearest.m[IX_Z];
}



// This is the definition of the Plane class:
class Plane  
{
public:
    void Normalize()
    {
        float lenInv = 1.0f/sqrtf(m_a*m_a + m_b*m_b + m_c*m_c);
        m_a *= lenInv;
        m_b *= lenInv;
        m_c *= lenInv;
        m_d *= lenInv;
    }
    float GetDistance(const Vector3D& pos) const
    {
        return m_a*pos.m[IX_X] + m_b*pos.m[IX_Y] + 
            m_c*pos.m[IX_Z] + m_d;
    }
    Vector3D GetVectorNearest(const Vector3D& pos) const
    {
        Vector3D normal(m_a, m_b, m_c);
        float posDotNormal = pos.dotProduct(normal);
        Vector3D nearest = normal*(m_d+posDotNormal);
        return nearest;
    }
    float m_a, m_b, m_c, m_d;
};