[英]Rotating the camera around the Y axis of the world (at O(0,0,0))
我正在嘗試使相機繞世界的Y
軸旋轉,在我的項目中以3D十字標記。
我已經完成的工作是繞其自身的軸旋轉,這很酷,但這不是我想要的。
如何通過使用四元數和一些數學而不是 osg::PositionAttitudeTransforms
或任何易於使用但難以理解的基礎結構來實現這一目標。
我想了解它背后的數學原理。
相關的代碼是
osg::Matrixd camM;
std::stringstream oss;
osg::Quat x_rot_q(osg::DegreesToRadians(-DEG), osg::Vec3d(1.0, 0.0, 0.0));
osg::Quat y_rot_q(osg::DegreesToRadians(DEG), osg::Vec3d(0.0, 1.0, 0.0));
camM = cameraManipulator->getMatrix();
camM.makeRotate(x_rot_q * y_rot_q);
camM.setTrans(250.0, 300.0, 250.0);
cameraManipulator->setByMatrix(camM);
osg::Quat y_delta_trans(osg::DegreesToRadians(DEG_DELTA), osg::Vec3d(0.0, 1.0, 0.0));
while(!viewer.done()) {
oss.str(std::string());
oss.clear();
camM = cameraManipulator->getMatrix();
camM.makeRotate(camM.getRotate() * y_delta_trans);
camM.setTrans(250.0, 300.0, 250.0);
cameraManipulator->setByMatrix(camM);
oss << getMatrixRepresentation(camM);
hudGeode->setStatus(oss.str());
viewer.frame();
}
您可以在文件Simple.cpp
的底部找到該文件。 整個項目可以在此修訂本中找到。
在GNU / Linux機器上,只需鍵入make
,它應該在安裝了適當工具的情況下即可使用。
繞着另一個軸旋轉相機是非常簡單的,只需按順序執行以下步驟:
或數學上作為矩陣乘積:
[ 1 0 0 -Xc ] [ 1 0 0 Xc ]
Transformation Matrix = [ 0 1 0 -Yc ] Rotation Matrix [ 0 1 0 Yc ]
[ 0 0 1 -Zc ] [ 0 0 1 Zc ]
[ 0 0 0 1 ] [ 0 0 0 1 ]
編輯:
請注意,這是繞對象而非原點旋轉對象的一般方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.