如何将参数提供给期望所有常量值的方法

How togive parameters to a method which expects all const values?

本文关键字:常量 方法 期望 参数      更新时间:2023-10-16

http://www.chai3d.org/doc/classc_camera.html#6b5bbcc535b601c19e10be288dfc65f7

bool cCamera::set   (   const cVector3d &   a_localPosition,
                        const cVector3d &   a_localLookAt,
                        const cVector3d &   a_localUp    
)   

此调用返回 true 即为成功

camera->set( cVector3d (1, 0.0, 3),    // camera position (eye)
        cVector3d (0.0, 0.0, 0.0),    // lookat position (target)
        cVector3d (-1.0, 0.0, 0.0));   // direction of the "up" vector);
    }

我没有收到任何错误,但是此调用返回false,这是无法设置相机新位置,为什么?

 camera->set( cVector3d(toolPos.x,toolPos.y,toolPos.z),
              cVector3d(toolPos.x,toolPos.y,toolPos.z),
              cVector3d (1.0, 0.0, 0.0)); 

工具是一个 cVector3d 变量,当我使用断点检查时具有有效值....也cVector3d 的定义是

cVector3d (const double a_x, const double a_y, const double a_z)

构造函数通过传递双精度来初始化向量。

你的第一个向量(相机位置)和第二个向量(观察位置)具有相同的值。设置新位置的算法无法确定相机朝哪个方向,因为没有从eyelookAt的方向。只需将lookat positioneye移动到您想要查看的方向即可。