• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OpenGL getcoords/translate issue

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, I am producing an OpenGL application on netbeans and am having an issue rendering a graphic at the appropriate coordinates when triggered by a MotionEvent.ACTION_DOWN
The first bit of code is from my main project that would gather the coordinates when someone touches the screen:

public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
//renderer.move(event.getX() - touchStart.x, touchStart.y - event.getY());
//touchStart.set(event.getX(), event.getY());
glSurfaceView.requestRender();
return true;

case MotionEvent.ACTION_DOWN:
//touchStart.set(event.getX(), event.getY());
//renderer.move(event.getX() - touchStart.x, touchStart.y - event.getY());
//renderer.move(touchStart.x, touchStart.y);
renderer.move(event.getX(), event.getY());
glSurfaceView.requestRender();
Log.d("ActionDown", "offset=[" + event.getX() + ", " + event.getY() + "]");
//new AlertDialog.Builder(this).setTitle("Alert").setMessage("x=" + event.getX() + " y=" + event.getY() + " .").setNeutralButton("Close", null).show();
//touchStart.set(event.getX(), event.getY());
return true;

default:
return super.onTouchEvent(event);
}
}






renderer.move is called with parameters x and y, and after testing I find that these values remain constant while passing through functions. The move command is as follows:

public void move(float xDelta, float yDelta) {
offset.x = xDelta;
offset.y = yDelta;
Log.d("TriangleRenderer", "offset=[" + offset.x + ", " + offset.y + "]");
}
}




and the translation happens when the scene is drawn:

public void onDrawFrame(GL10 gl) {
gl.glPushMatrix();

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glTranslatef(offset.x, offset.y, 0);
gl.glColor4f(1.0f, 0.3f, 0.0f, .5f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_SHORT, 0, triangleBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 3);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glPopMatrix();
}





Am I missing something fundamental here? If there is anything else you need to help diagnose the issue please do not hesitate to ask! Thanks!
 
Jihad Boustany
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yea, also the triangle moves, it just moves to incorrect coordinates.
 
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic