1

アークボール インターフェースを実装しようとしていますが、90 度回転した後、モデルがその特定の方向に回転しなくなったようです。画面上のクリックをアークボールにマッピングすることに問題があると思われますが、計算が間違っている可能性があります。 /または間違った変換の蓄積、助けをいただければ幸いです。ベクトルを操作する場合、問題に関連するコードは次のとおりです。^演算子は外積を表し、*演算子は内積を表します

    void mouseButton(int button,int state,int x,int y){
          if(state==GLUT_DOWN){
            GLdouble xx,yy,zz;
            GLdouble modelMatrix[16];
            glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
            GLdouble projMatrix[16];
            glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
            int viewport[4];
            glGetIntegerv(GL_VIEWPORT,viewport);
            gluUnProject(x,height-y-1,0.755
                 ,modelMatrix,projMatrix,viewport,&xx,&yy,&zz);
            arcBall_begin(xx,yy);
          }

        }

        void mouseMotion(int x,int y){
          GLdouble xx,yy,zz;
          GLdouble modelMatrix[16];
          glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
          GLdouble projMatrix[16];
          glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
          int viewport[4];
          glGetIntegerv(GL_VIEWPORT,viewport);
          gluUnProject(x,height-y-1,0.755
                   ,modelMatrix,projMatrix,viewport,&xx,&yy,&zz);

          arcBall_drag(xx,yy);  

    }

void arcBall_begin(GLdouble x,GLdouble y){
  if(sqrt((x*x)+(y*y))>radius)
    begin = vec(x,y,0);
  else
    begin = vec(x,y,sqrt((radius*radius)-(x*x)-(y*y)));
  begin = begin.unit(); 
 glGetDoublev(GL_MODELVIEW_MATRIX,mm);    
}


void arcBall_drag(GLdouble x,GLdouble y){
   if(sqrt((x*x)+(y*y))>radius)
    end = vec(x,y,0);
  else
    end = vec(x,y,sqrt((radius*radius)-(x*x)-(y*y)));
  end = end.unit(); 

  rotationAxis = begin^end;
  rotationAxis = rotationAxis.unit();

  angle =  -2*acos(begin*end);
  angle = angle * (float(180)/float(PI));
}

float arcBall_rotate(){

  if(angle!=0.0){
    glLoadMatrixd(mm);
    glRotatef(angle,rotationAxis.x,rotationAxis.y,rotationAxis.z);
    angle = 0.0;
  }
  return angle;      
}
4

1 に答える 1

0

Remember that in OpenGL pixel coordinates are (0,0) in the upper left corner of the screen, so when you want to map you have to reverse the y axis to map the coordinates to a sphere.

于 2012-03-06T08:31:15.047 に答える