游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1537|回复: 1

视点变化了,对象选中不了

[复制链接]

1

主题

2

帖子

8

积分

新手上路

Rank: 1

积分
8
发表于 2010-7-21 15:16:00 | 显示全部楼层 |阅读模式
我想实现opengl场景中对象拾取功能,视点不变即初始场景时可以选取物体,但视点变化之后选中不了,各位高手帮我看看
void CScene:rocessSelection (CPoint point)
{
    GLuint selectBuf[BUFSIZE];//create the selection buffer
    GLint hits;
    GLint viewport[4];//create a viewport
    int x=0;
    int y=0;
    x=point.x;
    y=point.y;
    glGetIntegerv (GL_VIEWPORT, viewport);
    glSelectBuffer (BUFSIZE, selectBuf);
    (void) glRenderMode (GL_SELECT);
    glInitNames();
    glPushName(0);
    glPopName();   
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    //setup a pick matrix
    gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
        5, 5, viewport);
    GLdouble aspect(0);
    aspect=(GLdouble)viewport[2]/(GLdouble)viewport[3];
    //gluPerspective(45.0f, aspect, .01f, 200.0f);
    gluPerspective(45.0f, aspect, 0.1,10);
    Render(GL_SELECT);// Draw to the pick matrix instead of our normal one
    glMatrixMode (GL_PROJECTION);
    glPopMatrix ();
    glFlush ();
    hits = glRenderMode (GL_RENDER);
    ProcessObject (selectBuf);
}

1

主题

2

帖子

8

积分

新手上路

Rank: 1

积分
8
 楼主| 发表于 2010-7-21 15:17:00 | 显示全部楼层

Re:视点变化了,对象选中不了

我怀疑是gluPerspective(45.0f, aspect, 0.1,10); 的问题,最后这个参数改大了的话也选中不了物体,不知为什么
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-8 08:37

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表