I'm trying to make a program that create a signal base on the position where i'm touching on the screen.That means i can change every point from the horizontally line ,with my finger.
But i can't have you do that , beacuse it will be complicated for you , so i want a circle to follow my finger.
I'm mentioning that i'm not using MyGLSurfaceView class, i'm using only MyGLRenderer class (named GL_Render.java):
public class GL_Render implements Renderer
{
private Context context;
private Polygon myPoly = new Polygon();
private desen myDesen= new desen();
private MainActivity mySignal = new MainActivity();
private MainActivity myAngle = new MainActivity();
private MainActivity myZoom = new MainActivity();
public GL_Render(Context context)
{
this.context = context;
}
public void onDrawFrame(GL10 gl)
{
float ZOOM =myZoom.zoom;
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity(); // reset the matrix to its default state
// When using GL_MODELVIEW, you must set the view point
GLU.gluLookAt(gl, 0f, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
//GLU.gluLookAt(gl, eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
// float ratio = (float)( width / height ) ;
gl.glMatrixMode(GL10.GL_PROJECTION); // set matrix to projection mode
gl.glLoadIdentity(); // reset the matrix to its default state
if(ZOOM==0){
gl.glFrustumf(0f, -1f, -1, 1, 3, 7); // apply the projection matrix
//gl.glFrustumf(left, right, bottom, top, zNear, zFar);
}
else
{
gl.glFrustumf(0f, -1f/(2*ZOOM), -1, 1, 3, 7); // apply the projection matrix
//gl.glFrustumf(left, right, bottom, top, zNear, zFar);
}
myDesen.Desen(gl);
if(ZOOM!=0)
{
float l2[] =
{
(float)0.5/(2*ZOOM), 0.5f, 0.0f,
(float)0.5/(2*ZOOM), -0.5f, 0.0f
};
myPoly.Polygon(l2);
myPoly.draw(gl,1,0,0);
}
else{
float l2[] =
{
0.5f, 0.5f, 0.0f,
0.5f, -0.5f, 0.0f
};
myPoly.Polygon(l2);
myPoly.draw(gl,1,0,0);
}
// Create the moving Circle here if possible:
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
// Adjust the viewport based on geometry changes
// such as screen rotations
gl.glViewport(0, 0, width, height);
// make adjustments for screen ratio
float ratio = (float)( width / height ) ;
gl.glMatrixMode(GL10.GL_PROJECTION); // set matrix to projection mode
gl.glLoadIdentity(); // reset the matrix to its default state
gl.glFrustumf(0f, -1f, -1, 1, 3, 7); // apply the projection matrix
//gl.glFrustumf(left, right, bottom, top, zNear, zFar);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig arg1)
{
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
myPoly=new Polygon();
}
private void GL_Prepare(GL10 gl)
{
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glFrontFace(GL10.GL_CW);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
}
private void GL_Finish(GL10 gl)
{
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
}
No matter what view you use whether it's GlSurfaceView or not you need a Touch Listener. You can then use the Touch Listener in the standard way the only difference is you'll need to convert your touch points from screen coordinates to your opengl scene coordinates.