Java LWJGL OpenGL将3d点转换为2d点 [英] Java LWJGL OpenGL convert 3d point to 2d point
问题描述
我正在尝试将OpenGL中的3d点转换为屏幕上的2d点,以渲染我正在编写的一款小游戏的健康栏.但是,在检索在何处绘制运行状况栏的x坐标时遇到了一些麻烦.基本上,健康栏必须看起来在播放器上方,但相对于屏幕必须始终具有相同的宽度/高度.
I'm trying to convert a 3d point in OpenGL to a 2d point on screen to render a healthbar for a little game I'm writing. However, I'm having some trouble retrieving the x coordinate of where to draw the healthbar. Basically, the healthbar must appear to be above a player, but must always have the same width/height relative to the screen.
我在似乎 可以很好地与y坐标配合使用,但是,无论角度如何,x始终返回0.
It seems to work fine with the y coordinate, however, x always returns 0 no matter what the angle is.
非常感谢!
推荐答案
screenCoords.get(3)
应该为screenCoords.get(0)
,因为x位置存储在索引0中.实际上,您实际上只需要screenCoords
的容量为3个浮点数,而不是4.
screenCoords.get(3)
should be screenCoords.get(0)
because the x position is stored at index 0. You also only actually need the capacity of screenCoords
to be 3 floats, not 4.
这篇关于Java LWJGL OpenGL将3d点转换为2d点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!