C ++ If语句被跳过

我正在使用两个AABB实现冲突解决,但是编译器似乎完全跳过了“ if(* yDepth> 0)”。当我在Visual Studio中将断点应用于该语句时,它回答“此断点当前不会被命中。指针是否有问题?我试图移动该语句的内容,更改条件,但似乎总是跳过if有问题的陈述。

Vector2* normal = new Vector2();
Vector2* vFrom1to2 = new Vector2();
*vFrom1to2 = Vector2(b->getX() - a->getX(), b->getY() - a->getY());
float* xDepth = new float();
*xDepth = (a->getWidth()) + (b->getWidth()) - abs(vFrom1to2->x);
float* yDepth = new float();


if (*xDepth > 0) {

    *yDepth = (a->getHeight()) + (b->getHeight()) - abs(vFrom1to2->y);
    std::cout << "break";
    if (*yDepth > 0) { //this statement is skipped completely. yDepth is greater than 0 on testing.

        if (xDepth < yDepth) {
            if (vFrom1to2->x < 0) {
                normal->x == -1;
                normal->y == 0;
            }
            else {
                normal->x == 1;
                normal->y == 0;
            }

        }
        else {
            if (vFrom1to2->y < 0) {
                normal->x == 0;
                normal->y == -1;
            }
            else {
                normal->x == 0;
                normal->y == 1;
            }

        }

    }


}
评论