Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
1  
You need to compare their positions. –  Byte56 Jul 27 '13 at 14:00
    
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. –  PeterT Jul 27 '13 at 14:02

1 Answer 1

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..

share|improve this answer
    
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? –  Maxim Shoustin Jul 27 '13 at 15:01
1  
@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) –  PeterT Jul 27 '13 at 15:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.