2
\$\begingroup\$

I have 2 objects on the screen:

static:

enter image description here

non-static:

enter image description here

non-static object moves randomly over the screen.

How do I know that non-static Object cross the "+" (static).

Both objects I draw by using followed code:

private void updateScreenData(float screenWidth, float screenHeight){
    // takes screen Height and Width
    this.mScreenWidth = (screenWidth > 0) ? screenWidth : 1f;
    this.mScreenHeight = screenHeight;
    wRatio = 10f/mScreenWidth;
    hRatio = mScreenHeight/10f;     
}

protected void drawTarget(GL10 gl){
    gl.glPushMatrix();
    try {           
        float transx =  shiftX + (wRatio * (x)); 
        float transy =  shiftY +(mScreenHeight*wRatio) - (wRatio * (y)) - 1/hRatio; 

        gl.glTranslatef(transx, transy, 0.0f);

        //###########  draw ##############

        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, floatBufferArray[mFrame]);

        //update();

        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

        //###############################

    } catch (NullPointerException e) {
    }
    gl.glPopMatrix();   
}

public void loadTextures(GL10 gl) {
    Log.e(LOG_TAG, "loadTextures");  

    InputStream is;

    is = mContext.getResources().openRawResource(_SRC);

    Bitmap bitmap = BitmapFactory.decodeStream(is);

    try {
        is.close();
        is = null;
    } catch (IOException e) {
    }

    gl.glGenTextures(TEXTURE_COUNT, textures, 0);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

    bitmap.recycle(); 


}

Any ideas?

What do I need to compare in both Objects?

[EDIT]

I see my question is not so clear, so i'll try once more.

Since my cross image stays at the middle of screen (screenWidth/2 and screenWidth/2) I know the coordinates, it do not change. But second Object changes.

How can I fetch out coordinates (aka x,y) from dynamic object?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You need to compare their positions. \$\endgroup\$
    – House
    Jul 27, 2013 at 14:00
  • \$\begingroup\$ What @Byte56 said, this has nothing to do with OpenGL ES, that's only there for drawing. Things like collision or intersection detection has nothing to do with it, so I don't see any relation from the code you posted to the problem you're trying to solve. \$\endgroup\$
    – PeterT
    Jul 27, 2013 at 14:02

1 Answer 1

1
\$\begingroup\$

One of the simplest and fastest ways is to compare the bounding boxes of the two, and see if they intersect/overlap. This is usually fairly trivial.

In your case, it seems like you have a "hit zone" in the middle of your crosshairs. I would alternatively check if the bounding box of that inner area overlaps the skulls, and if it does, that's a valid hit.

You can see this question's answers for some ways to calculate overlap/intersection..

\$\endgroup\$
2
  • \$\begingroup\$ Well, i know how to do that in canvas/bitmap. This logic worked for me, but when i moved to OpenGL ES, all stuff changed. My question is how can I extract current position from Object? \$\endgroup\$ Jul 27, 2013 at 15:01
  • 1
    \$\begingroup\$ @MaximShoustin you yourself passed the position to OpenGL, so you should know where the Object is. You may have some differences like (0,0) being in the center for OpenGL and in the top-left corner for most software-based solutions. But it's not that difficult to subtract (width/2.0,height/2.0) \$\endgroup\$
    – PeterT
    Jul 27, 2013 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .