OpenGLを学習中なのですが、平行移動について分からないことがあるので質問させて頂きます。
3Dモデルに対して、マウスボタン右をドラッグして視点の回転、マウスボタンの左をドラッグして平行移動する仕様で実装したいのですが
c
1 2double horizontal=0; 3double vertical=0; 4double incidence=0; 5double azimuth=0; 6ディスプレイ関数(..){ 7 glRotated( -incidence, 1.0, 0.0, 0.0 ); 8 glRotated( -azimuth, 0.0, 0.0, 1.0 ); 9 10 11 glTranslated(horizontal,vertical,0.0); 12} 13 14// callback function for handling mouse dragging 15void motion( int x, int y ) 16{ 17 const double ratio = 0.1; 18 const double rating = 0.01; 19 20 // dragging the right mouse button 21 if ( right_mouse ) { 22 azimuth -= ratio * ( double )( x - last_pointer_x ); 23 incidence -= ratio * ( double )( y - last_pointer_y ); 24 } 25 // dragging the left mouse button 26 if ( left_mouse ) { 27 horizontal += (rating)*(double)(x-last_pointer_x); 28 vertical += (rating)*(double)(y-last_pointer_y); 29 } 30 // update the latest mouse coordinates 31 last_pointer_x = x; 32 last_pointer_y = y; 33 // redraw the 3D scene on the screen 34 glutPostRedisplay(); 35
こんな具合になります。関係ないところは省略しています。
ここで問題点なのですが、こうするとx-y平面に対してはマウスを上下左右にドラッグしたときにその方向に物体も移動しますが、z-x,z-y平面に関しては手前や奥に移動したり、x-y平面でも反対側から見た際には移動方向が反転してしまいます。
なので、軸に関係なくどんな角度から見ても上下左右に動かしたときに、今の視点でその方向に物体を移動できるようにしたいのですが、上手いやり方が思いつきません。
知識のある方、回答よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。