모델을 그려 마우스를 사용하여 회전하는 데 문제가 있습니다. 수학에 문제가 있는지는 확실하지만 확실하지 않습니다. 개체가 이상한 방식으로 회전합니다. 때문에 개체가 현재 위치에서 각 클릭을 회전하기 시작하고 재설정되지 않도록하려면 벡터가 변경되고 계산이 다시 시작됩니다. opengl - 벡터를 사용하여 구 주위를 회전하고 글 루크 컷을 사용하지 않습니다.
void DrawHandler::drawModel(Model * model){
unsigned int l_index;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glLoadIdentity();
Point tempCross;
crossProduct(tempCross,model->getBeginRotate(),model->getCurrRotate());
float tempInner= innerProduct(model->getBeginRotate(),model->getCurrRotate());
float tempNormA =normProduct(model->getBeginRotate());
float tempNormB=normProduct(model->getCurrRotate());
glTranslatef(0.0,0.0,-250.0);
glRotatef(acos (tempInner/(tempNormA*tempNormB)) * 180.0/M_PI,tempCross.getX(),tempCross.getY(),tempCross.getZ());
glColor3d(1,1,1);
glBegin(GL_TRIANGLES);
for (l_index=0;l_index < model->getTrianglesDequeSize() ;l_index++)
{
Triangle t = model->getTriangleByPosition(l_index);
Vertex a1 = model->getVertexByPosition(t.getA());
Vertex a2 = model->getVertexByPosition(t.getB());
Vertex a3 = model->getVertexByPosition(t.getC());
glVertex3f(a1.getX(),a1.getY(),a1.getZ());
glVertex3f(a2.getX(),a2.getY(),a2.getZ());
glVertex3f(a3.getX(),a3.getY(),a3.getZ());
}
glEnd();
}
이
는 회전 화학식void Controller::mouse(int btn, int state, int x, int y)
{
x=x-WINSIZEX/2;
y=y-WINSIZEY/2;
if (btn==GLUT_LEFT_BUTTON){
switch(state){
case(GLUT_DOWN):
if(!_rotating){
_model->setBeginRotate(Point(float(x),float(y),
(-float(x)*x - y*y + SPHERERADIUS*SPHERERADIUS < 0)? 0:float(sqrt(-float(x)*x - y*y + SPHERERADIUS*SPHERERADIUS))));
_rotating=true;
}
break;
case(GLUT_UP):
_rotating=false;
break;
}
}
}
및 전류 벡터를 보유 마지막 다음 함수의 초기 벡터를 저장 마우스 함수이다. 는 sphereradius가
void Controller::getMousePosition(int x,int y){
x=x-WINSIZEX/2;
y=y-WINSIZEY/2;
if(_rotating){
_model->setCurrRotate(Point(float(x),float(y),
(-float(x)*x - y*y + SPHERERADIUS*SPHERERADIUS < 0)? 0:float(sqrt(-float(x)*x - y*y + SPHERERADIUS*SPHERERADIUS))));
}
}
70의 degress
의 구체 반경 O_O 모든 계산은 (초기 벡터 순간 마우스 위치는 어디에 마우스 로 클릭하고 CURR 벡터이고이다) 잘못된 ? 위선자가 문제를 찾은 것 같습니다 ... 감사합니다