小编Edd*_*die的帖子

Go if语句中的多个初始值设定项

刚刚发现了Go,到目前为止我非常好奇.我知道我只是懒惰,但我想知道是否可以在if语句中初始化多个变量.我知道以下是可能的:

if x := 5; x == 5 {
    fmt.Printf("Whee!\n")
}
Run Code Online (Sandbox Code Playgroud)

我尝试过以下方法:

if x := 5, y := 38; x == 5 {
    fmt.Printf("Whee! %d\n", y)
}

if x := 5 && y := 38; x == 5 {
    fmt.Printf("Whee! %d\n", y)
}
Run Code Online (Sandbox Code Playgroud)

但都没有奏效.我查看了Go网站上的文档,所以我有什么遗漏或者这根本不可能吗?

initialization go

8
推荐指数
1
解决办法
2158
查看次数

需要有关使用分离轴定理实现碰撞检测的帮助

因此,经过数小时的谷歌搜索和阅读,我发现使用SAT检测碰撞的基本过程是:

for each edge of poly A
    project A and B onto the normal for this edge
    if intervals do not overlap, return false
end for

for each edge of poly B
    project A and B onto the normal for this edge
    if intervals do not overlap, return false
end for
Run Code Online (Sandbox Code Playgroud)

但是,尽管我尝试在代码中实现这一点的方法很多,但我无法让它检测到碰撞.我目前的代码如下:

for (unsigned int i = 0; i < asteroids.size(); i++) {
    if (asteroids.valid(i)) {
        asteroids[i]->Update();

        // Player-Asteroid collision detection
        bool collision = true;
        SDL_Rect asteroidBox = asteroids[i]->boundingBox;

        // …
Run Code Online (Sandbox Code Playgroud)

c++ vector collision-detection

5
推荐指数
1
解决办法
1737
查看次数

标签 统计

c++ ×1

collision-detection ×1

go ×1

initialization ×1

vector ×1