我想知道究竟如何,我可以转换的位置(XYZ)在屏幕上的一个点(XY)。
I am wondering how exactly I can convert a location (X Y Z) to a point on screen (X Y).
我有一个播放器(可以控制播放器),是谁在(XYZ)坐标和另一名球员是谁也(XYZ)坐标。
I have a player (the player you control) who is in (X Y Z) co-ordinates and another player who is also in (X Y Z) co-ordinates.
我究竟如何可以将其他玩家的XYZ到屏幕上的xy,这样我可以/它使用X Y上面画了他的名字。
How exactly can I convert the other player's X Y Z to X Y on screen so that I can draw a name above him/it using the X Y.
希望是有道理的......
Hope that makes sense...
编辑:
下面是我的gluProject code:
Here is my gluProject code:
IntBuffer viewport = GLAllocation.createDirectIntBuffer(16);
FloatBuffer modelview = GLAllocation.createDirectFloatBuffer(16);
FloatBuffer projection = GLAllocation.createDirectFloatBuffer(16);
FloatBuffer objectCoords = GLAllocation.createDirectFloatBuffer(3);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
GLU.gluProject(x, y, z, modelview, projection, viewport, objectCoords);
eturn objectCoords;
感谢。
您应该能够对付的是:
public get2DFrom3D(float x, float y, float z)
{
/*
FloatBuffer screen_coords = GLAllocation.createDirectFloatBuffer(4);
IntBuffer viewport = GLAllocation.createDirectIntBuffer(16);
FloatBuffer modelview = GLAllocation.createDirectFloatBuffer(16);
FloatBuffer projection = GLAllocation.createDirectFloatBuffer(16);
*/
double[] screen_coords = new double[4];
int[] viewport = new int[4];
double[] modelview = new double[16];
double[] projection = new double[16];
GL11.glGetFloat(2982 /*GL_MODELVIEW_MATRIX*/, modelview);
GL11.glGetFloat(2983 /*GL_PROJECTION_MATRIX*/, projection);
GL11.glGetInteger(2978 /*GL_VIEWPORT*/, viewport);
boolean result = GLU.gluProject(x, y, z, modelview, projection, viewport, screen_coords);
if (result)
{
//System.out.printf("Convert [ %6.2f %6.2f %6.2f ] -> Screen [ %4d %4d ]\n", x, y, z, (int)screen_coords[0], (int)(screen_coords[3] - screen_coords[1]));
System.out.printf("Convert [ %6.2f %6.2f %6.2f ] -> Screen [ %4d %4d ]\n", x, y, z, (int)screen_coords.get(0), (int)(screen_coords.get(3) - screen_coords.get(1)));
return new Vector2(screen_coords[0], screen_coords[3] - screen_coords[1]);
}
else
{
System.out.printf("Failed to convert 3D coords to 2D screen coords");
return null;
}
}
上一篇:错误"检索COM类工厂具有CLSID&QUOT组成部分;启动Excel的时候组成部分、工厂、错误、时候
下一篇:在Ubuntu的i386 12.04,64位:无法安装liblapi台面-GLX台面、Ubuntu、GLX、liblapi