本文整理汇总了Java中javax.media.opengl.glu.GLU.gluUnProject方法的典型用法代码示例。如果您正苦于以下问题:Java GLU.gluUnProject方法的具体用法?Java GLU.gluUnProject怎么用?Java GLU.gluUnProject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.media.opengl.glu.GLU
的用法示例。
在下文中一共展示了GLU.gluUnProject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getModelCoordinates
import javax.media.opengl.glu.GLU; //导入方法依赖的package包/类
public static Vector3d getModelCoordinates(GL2 gl, ScreenCoordinates screenCoordinates) {
double modelView[] = new double[16];
double projection[] = new double[16];
int viewport[] = new int[4];
double wcoord[] = new double[4];
gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, modelView, 0);
gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projection, 0 );
gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0 );
GLU glu = new GLU();
glu.gluUnProject(screenCoordinates.getPoint().getX(), screenCoordinates.getPoint().getY(), screenCoordinates.getDepth(),
modelView, 0,
projection, 0,
viewport, 0,
wcoord, 0);
return new Vector3d(wcoord[0], wcoord[1], wcoord[2]);
}
示例2: getWorldCoordinates
import javax.media.opengl.glu.GLU; //导入方法依赖的package包/类
public static Location getWorldCoordinates(GL gl, GLU glu, Location screen, Location store) {
if (store == null) {
store = new Location(0,0,0);
}
// Modelview matrix
DoubleBuffer mvBuffer = DoubleBuffer.allocate(16);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvBuffer);
// Projection_matrix
DoubleBuffer prBuffer = DoubleBuffer.allocate(16);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, prBuffer);
// Viewport matrix
IntBuffer vpBuffer = IntBuffer.allocate(16); // 4 is necessary
gl.glGetIntegerv(GL.GL_VIEWPORT, vpBuffer);
// 3d coordinates
DoubleBuffer result = DoubleBuffer.allocate(3);
glu.gluUnProject(screen.x,
screen.y,
screen.z,
mvBuffer,
prBuffer,
vpBuffer,
result);
store = new Location(result.get(0), result.get(1), result.get(2));
return store;
}
示例3: screenToWorld
import javax.media.opengl.glu.GLU; //导入方法依赖的package包/类
public Point2D screenToWorld(Point2D mouse) {
double[] wcoord = new double[4];
double x = mouse.getX();
double y = viewport.get(3) - mouse.getY();
GLU glu = new GLU();
glu.gluUnProject(x, y, 0, modelview.array(), 0, projection.array(), 0,
viewport.array(), 0, wcoord, 0);
Point2D p = new Point2D.Float();
p.setLocation(wcoord[0], wcoord[1]);
return p;
}
示例4: getOGLPos
import javax.media.opengl.glu.GLU; //导入方法依赖的package包/类
public static double[] getOGLPos(GL2 gl, GLU glu, int x, int y) {
int[] viewport = new int[4];
double[] modelview = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
double[] projection = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
double winX, winY;
float[] winZ = new float[1];
Buffer winZBuf = FloatBuffer.wrap(winZ);
gl.glGetDoublev( GL2.GL_MODELVIEW_MATRIX, modelview, 0 ); // Kevin Watts stackoverflow said use identity. Not likely.
gl.glGetDoublev( GL2.GL_PROJECTION_MATRIX, projection, 0 );
gl.glGetIntegerv( GL2.GL_VIEWPORT, viewport, 0 );
winX = (double)x;
winY = (double)viewport[3] - (double)y;
gl.glReadPixels( x, (int)winY, 1, 1, GL2.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, winZBuf );
double[] objPos = new double[3];
glu.gluUnProject(winX, winY, winZ[0], modelview, 0, projection, 0, viewport, 0, objPos, 0);
// Draw sphere at objPos
// gl.glPushMatrix();
// gl.glTranslated(objPos[0], objPos[1], objPos[2]);
// gl.glColor3f(1,0,0);
// GLUquadric quadric = glu.gluNewQuadric();
// glu.gluQuadricDrawStyle(quadric, GLU.GLU_LINE);
// glu.gluQuadricNormals (quadric, GLU.GLU_NONE);
// glu.gluSphere(quadric, 1.0, 10, 10);
// gl.glPopMatrix();
return objPos;
}