opengl에서 물체를 picking 하려고 합니다
글쓴이: qkrtntjd / 작성시간: 수, 2014/07/23 - 2:30오후
위젯의 크기는 500x400이구요
위젯에 큐브가 그려집니다
그런데 그 큐브를 클릭해서 이동시키려고 하는 작업에 있습니다
하지만 ortho를 써서 좌표계를 -3000~3000으로 만들었는데 picking이 되지 않습니다
ortho를 안쓰면 잘 되는데 말이죠..
아마 위젯크기와 실제 그려지는 좌표계의 차이때문에 그런것 같은데 도움좀 주십시오.
resizeGL()에서 다음처럼 좌표계를 설정했습니다..
glOrtho(-3000.0*scale, 3000.0*scale, -3000.0*scale, 3000.0*scale, -30000.0, 30000.0);
다음은 피킹 코드입니다.
void GLWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
int face = faceAtPosition(event->pos());
qDebug() << "mouse pos :" << event->pos();
qDebug() << "face :" << face;
if (face != -1) {
QColor color = QColorDialog::getColor(faceColors, this);
if (color.isValid()) {
faceColors = color;
colours[selectedObj] = faceColors;
updateGL();
}
}
int GLWidget::faceAtPosition(const QPoint &pos)
{
qDebug() << "faceatpostion" ;
const int MaxSize = 512;
GLuint buffer[512];
GLint viewport[4];
makeCurrent();
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(MaxSize, buffer);
glRenderMode(GL_SELECT);
glInitNames();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()),
5.0, 5.0, viewport);
if(isloaded){
drawMarkers(); //그려지는 부분
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
if (!glRenderMode(GL_RENDER)){
qDebug() <<"return";
return -1;
}
ProcessSelect(buffer);
return buffer[3];
}
}Forums:


댓글 달기