Android : Android Rect.intersects not working?

on Monday, March 23, 2015


I want to check if two rectangles are intersecting each other! I have a GLObject class, which represent Items, which are rendered on the screen. And my Game class, which make other game stuff. The rendering with OpenGLEs 2.0 works! The 2 Items are displayed correctly, but if i move the one Item into the other nothing happens.. The rectangles and vertices are correct (Proof: right positions of textures on screen/Log output)


In Game class:



@Override
public void Process(long elapsed)
{
// TODO: Implement this method
super.Process(elapsed);

Rect r1 = mtest1.getRect(); // get Rectangle
Rect r2 = mtest2.getRect();

if (Rect.intersects(r1, r2)) // always false
System.exit(0);

//Log.e("logpos", "left" + r1.left + " top" + r1.top + " right" + r1.right + " bottom" + r1.bottom);
//this logs the correct position:
//left830 top200 right920 bottom100 for r1
//left810 top200 right900 bottom100 for r2

r1 = r2; // make them equal for testing

if (Rect.intersects(r1, r2)) // always flase
System.exit(0);
}


In my GLObject class:



private float mRect[] =
{
//counterclockwise
10.0f, 200f, 0.0f, // top left
10.0f, 100f, 0.0f, // bottom left
100f, 100f, 0.0f, // bottom right
100f, 200f, 0.0f // top right
};

//...

public Rect getRect()
{
return new Rect((int)mRect[0],
(int)mRect[1],
(int)mRect[6],
(int)mRect[4]);
}

0 comments:

Post a Comment