【问题标题】:Android Rect.intersects not working?Android Rect.intersects 不工作?
【发布时间】:2015-03-23 14:59:45
【问题描述】:

我想检查两个矩形是否相交!我有一个 GLObject 类,它代表在屏幕上呈现的项目。还有我的游戏课,制作其他游戏的东西。使用 OpenGLEs 2.0 进行渲染有效! 2 个项目正确显示,但如果我将一个项目移到另一个项目中,则没有任何反应。矩形和顶点是正确的(证明:屏幕上纹理的正确位置/日志输出)

在游戏类中:

@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);
}

在我的 GLObject 类中:

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]);
}

【问题讨论】:

    标签: java android opengl-es intersection rectangles


    【解决方案1】:

    我想我有解决办法: 我的OpenGL Scene和Android Rect Class的坐标系不同:

    ^
    I
    I
    I        OpenGL
    I
    I
    I===========================>
    
    
    I===========================>
    I
    I
    I     Android Rect Class
    I 
    I
    v
    

    (风景)

    我更换了 Ortho,现在它可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-06
      • 2021-12-07
      • 2015-01-04
      • 2018-03-26
      • 2012-08-14
      • 2014-04-18
      • 2011-11-26
      相关资源
      最近更新 更多