おまけ:RICOH THETAのJPG画像を平面-球変換してOpenGLで表示する(その4)
zenithの補正と、ofEasyCamだとRollの回転が入ってしまいちょっと見づらい状況が出来てしまうのを直します。
・zenith角から天頂方向を計算して、その分逆に回転します。カメラの向きを直すのは面倒そうなので、モデルの方を回します。
・カメラの上方向ベクトルと、視線方向ベクトルの外積ベクトルを計算して、z成分をなくすような回転を与えることで水平を維持します。
//--------------------------------------------------------------
void testApp::draw() {
ofBackgroundGradient(ofColor::gray, ofColor::black, OF_GRADIENT_CIRCULAR);
ofQuaternion qzx, qzy;
qzx.set(sin(zenith_x/2*M_PI/180.0),0,0,cos(zenith_x/2*M_PI/180.0));
qzy.set(0,sin(-zenith_y/2*M_PI/180.0),0,cos(-zenith_y/2*M_PI/180.0));
ofMatrix4x4 m44(qzx*qzy);
ofVec3f updir = cam.getUpDir();
ofVec3f lookdir = cam.getLookAtDir();
ofVec3f hordir = updir.getCrossed(lookdir);
ofQuaternion quat;
quat.makeRotate(ofVec3f(hordir.x,hordir.y,0).normalized(),hordir.normalized());
ofMatrix4x4 upmat(quat);
ofVec3f new_updir = upmat*updir;
cam.lookAt(lookdir, new_updir);
// even points can overlap with each other, let's avoid that
cam.begin();
ofPushMatrix();
ofMultMatrix(m44.getInverse());
mesh.draw();
ofPopMatrix();
cam.end();
}
*1:なんか面倒くさい計算になってるので、もっといい方法がありそう・・・