c – OpenGL – 使用四元数轨道运行的相机
发布时间:2020-12-16 07:34:29 所属栏目:百科 来源:网络整理
导读:所以我目前使用四元数来存储和修改OpenGL场景中对象的方向,以及相机的方向.当直接旋转这些物体时(即说我想围绕Z轴旋转摄像机Z量,或者我想围绕X轴旋转物体X然后沿着局部Z轴将其旋转T),我有没有问题,所以我只能假设我的基本旋转代码是正确的. 但是,我现在正在
所以我目前使用四元数来存储和修改OpenGL场景中对象的方向,以及相机的方向.当直接旋转这些物体时(即说我想围绕Z轴旋转摄像机Z量,或者我想围绕X轴旋转物体X然后沿着局部Z轴将其旋转T),我有没有问题,所以我只能假设我的基本旋转代码是正确的.
但是,我现在正在尝试实现一个功能,使我的相机轨道在太空中的任意点,并且我很难相处.这是我到目前为止所提出的,它不起作用(这发生在Camera类中). //Get the inverse of the orientation,which should represent the orientation //"from" the focal point to the camera Quaternion InverSEOrient = m_Orientation; InverSEOrient.Invert(); ///Rotation //Create change quaternions for each axis Quaternion xOffset = Quaternion(); xOffset.FromAxisAngle(xChange * m_TurnSpeed,1.0,0.0,0.0); Quaternion yOffset = Quaternion(); yOffset.FromAxisAngle(yChange * m_TurnSpeed,0.0); Quaternion zOffset = Quaternion(); zOffset.FromAxisAngle(zChange * m_TurnSpeed,1.0); //Multiply the change quats into the inversed orientation quat InverSEOrient = yOffset * zOffset * xOffset * InverSEOrient; //Translate according to the focal distance //Start with a vector relative to the position being looked at sf::Vector3<float> RelativePos(0,-m_FocalDistance); //Rotate according to the quaternion RelativePos = InverSEOrient.MultVect(RelativePos); //Add that relative position to the focal point m_Position.x = m_FocalPoint->x + RelativePos.x; m_Position.y = m_FocalPoint->y + RelativePos.y; m_Position.z = m_FocalPoint->z + RelativePos.z; //Now set the orientation to the inverse of the quaternion //used to position the camera m_Orientation = InverSEOrient; m_Orientation.Invert(); 最终发生的事情是相机围绕其他点旋转 – 当然不是物体,但显然也不是自己,就好像它在螺旋路径中穿过空间一样. 所以这显然不是围绕一个点围绕相机轨道运行的方式,但是这是什么? 解决方法
我会首先在球面坐标上对相机进行操作,并根据需要转换为四元数.
鉴于以下假设: >相机没有滚动 以下是如何计算一些重要值: >视图矢量:v = [vx,vy,vz] = [cos(yaw)* cos(pitch),sin(pitch),– sin(yaw)* cos(pitch)] 现在在您的模拟中,您可以在俯仰/偏航上操作,这非常直观.如果要进行插值,将前后俯仰偏航转换为四元数并进行四元数球面线性插值. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |