如何在Opengl中使用gluUnProject draw 3D [英] How to use gluUnProject draw 3D with Opengl

查看:70
本文介绍了如何在Opengl中使用gluUnProject draw 3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎没有人理解我的代码.
抱歉,因为我发布了新问题,而之前没有人回答过这个问题
我已经阅读了有关gluUnProject Nehe第13课的内容,但我不明白.
giatuan询问了OpenGL中的鼠标.
Z深度是吗?
我知道Z指向屏幕对着我
如何获得Z值鼠标?
假设我画了三个轴x,y,z
我的目的是在3D中绘制多边形
帮助我

nobody seems to understand my code.
sorry, because I post new questions while no one has answered the question before
I have read about gluUnProject Nehe lession 13 but I do not understand.
giatuan asked about the mouse in OpenGL.
Is Z depth?
I understand Z points out of the screen towards me
How can I get value Z mouse?
suppose I drew three axes x, y, z
My purpose is to draw polygon in 3D
help me

推荐答案

看看是否对您有帮助-Googled
http://www.idevgames.com/forums/thread-6400.html [ ^ ]

检查此代码-

http://nehe.gamedev.net/data/articles/article.asp?article=13 [^ ]

我正在从该链接复制所需的代码,正在转换鼠标(X,Y)
指向空间(X,Y,Z)GL坐标-

CVector3 GetOGLPos(int x,int y)
{
GLint视口[4];
GLdouble modelview [16];
GLdouble投影[16];
GLfloat winX,winY,winZ;
GLdouble posX,posY,posZ;
glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
glGetDoublev(GL_PROJECTION_MATRIX,projection);
glGetIntegerv(GL_VIEWPORT,viewport);
winX =(float)x;
winY =(float)viewport [3]-(float)y;
glReadPixels(x,int(winY),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,& winZ);
gluUnProject(winX,winY,winZ,模型视图,投影,视口,& posX,& posY,&pos;);
返回CVector3(posX,posY,posZ);
}

希望这对您有帮助...
See if this helps you - Googled
http://www.idevgames.com/forums/thread-6400.html[^]

Check this for code -

http://nehe.gamedev.net/data/articles/article.asp?article=13[^]

I am copying the code from that link what you need, you are converting mouse (X,Y)
points to a space(X,Y,Z) GL coordinates -

CVector3 GetOGLPos(int x, int y)
{
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
winX = (float)x;
winY = (float)viewport[3] - (float)y;
glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
return CVector3(posX, posY, posZ);
}

Hope this helps...


这篇关于如何在Opengl中使用gluUnProject draw 3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆