0
votes

I am new to opengl. I am drawing a map in android using opengl ES2.0. When i touch on screen i am getting screen coordinates. i want these coordinates to be converted into world coordinates. The code i found through research is as follows:

vec3 UnProjectPoint( const vec3& Point, const max4& Projection, const mat4& ModelView )
{
    vec4 R( Point, 1.0f );

    R.x = 2.0f * R.x - 1.0f;
    R.y = 2.0f * R.y - 1.0f;
    R.y = -R.y;

    R.z = 1.0f;

    R = Projection.GetInversed() * R;
    R = ModelView.GetInversed() * R;

    return R.ToVec3();
}

but android is not allowing me to use vec3 and vec4? I also use built in gluunproject function but this function is also not giving me correct results.

1

1 Answers

0
votes

I suggest you just use an ortographic projection. This worked for me in this 2d example project of mine:

And then: Matrix.multiplyMM(... Take a look in that aforementioned source. In the vertex shader, you then simply use:

gl_Position = uMVPMatrix * vPosition;

Graphics The whole application logic works with the screen coordinates and these are projected onto OpenGL coordinates within that vertex shader.

I'm just an OpenGL noob, so I don't know whether this is an optimal solution.

BTW: On Page 111 in this book: Graphics Gems V. one can find a general approach to such transformations.

HTH