开发者

OPENGL ES MatrixGrabber and GLU.gluUnproject() mayhem

开发者 https://www.devze.com 2023-03-14 15:15 出处:网络
[EDIT] Ignore this post, it was a noob\'s mistake [/EDIT] I started Android last week (= I\'m pretty new to it :) ) and I\'m banging my head on a problem:

[EDIT] Ignore this post, it was a noob's mistake [/EDIT]

I started Android last week (= I'm pretty new to it :) ) and I'm banging my head on a problem: I try to perfom a raycasting to get the objects under a point of the screen. I found out that the GLU.gluUnproject method was what I needed, after a decent amount of failures, I found a solution

I've copied the MatrixGrabber, MatrixStack and MatrixTrackingGL classes in my project, they seem fine.

the method I use goes as follow:

static public Vertex unProject( float x, float y, World world )
{

world.mg = new MatrixGrabber();  
world.mg.getCurrentState(world.gl);

float[] pos = new float[4]; 

GLU.gluUnProject(   x, y, 0f, 
                    world.mg.mModelView, 0, 
                    world.mg.mProjecti开发者_运维技巧on, 0, 
                    world.view().get_size(), 0, 
                    pos, 0);

return new Vertex(pos[0], pos[1], pos[2]);

}

Vertex is a dataHolder with x,y,z floats

World extends GLSurfaceView, I do the GLWrapper replacement in the constructor: world.mg is a MatrixGrabber()

public World( Context context )
{
super(context);
[...]
//allows matrix manipulation
setGLWrapper( new GLWrapper()  
{  
    public GL wrap(GL gl)  
    {  
        return new MatrixTrackingGL(gl);  
    }  
});
}

and I make sure that all the variables are instanciated when I do my call

but still I can't get this to work: the app crashes badly on the

world.mg.getCurrentState(world.gl);

call. it also crashes it on getCurrentModelView(gl); and getCurrentProjection(gl);

I'm using Android 1.5, but tried with other versions up to 3. same thing. I don't really know which version of OpenGLI'm using ; the GL10 is used everywhere, I don't know if it is important, all I've read concerned the GL10 "Type".

if anyone has a clue, an advice, a workaround or a solution, I'd be happy happy happy

and anyway, thanks for reading :)


private void getMatrix(GL10 gl, int mode, float[] mat) {
        MatrixTrackingGL gl2 = new MatrixTrackingGL(gl);
        gl2.glMatrixMode(mode);
        gl2.getMatrix(mat, 0);
    }

replace the casting on the first line of the MatrixGrabber.java


my World class extended GLSurfaceView and was using the MatrixTrackingGL as a wrapper.

the problem was that the Viewport also extended GLSurfaceView and was NOT using the MatrixTrackingGL... stupid.

now the world doesn't extend anything and the Viewport ( extending GLSurfaceView ) implements the Wrapper's change and everything's fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消