c++ - “Release”中的方法无法正常工作
问题描述
我是 C++ 新手,所以我遇到了问题。在“调试”模式下,我得到了这张照片,这是正确的:所有的墙壁都是透明的
但是在“发布”模式下,我得到了这个:
我确定我搞砸了我的墙类并创建了对象:
std::vector<Wall> glassWalls = {
Wall(Vec2(2.0f, 1.0f), Vec2(2.0f, 2.0f),true,255, 0, 0, 0.5f),
Wall(Vec2(2.0f, 2.0f), Vec2(3.0f, 1.0f),true, 255, 0, 0, 0.5f),
Wall(Vec2(3.0f, 1.0f), Vec2(2.0f, 1.0f), true, 255, 0, 0, 0.5f),
Wall(Vec2(1.0f, 3.0f), Vec2(3.0f, 7.0f), true, 0, 255, 0, 0.5f),
Wall(Vec2(3.0f, 7.0f), Vec2(3.0f, 4.0f), true, 0, 255, 0, 0.5f),
Wall(Vec2(3.0f, 4.0f), Vec2(1.0f, 3.0f), true, 0, 255, 0, 0.5f),
Wall(Vec2(5.0f, 7.0f), Vec2(6.0f, 7.0f), true, 255, 255, 0, 0.5f),
Wall(Vec2(6.0f, 7.0f), Vec2(6.0f, 6.0f), true, 255, 255, 0, 0.5f),
Wall(Vec2(6.0f, 6.0f), Vec2(5.0f, 7.0f), true, 255, 255, 0, 0.5f),
Wall(Vec2(5.0f, 1.0f), Vec2(5.0f, 4.0f), true, 255, 0, 255, 0.5f),
Wall(Vec2(5.0f, 4.0f), Vec2(7.0f, 5.0f), true, 255, 0, 255, 0.5f),
Wall(Vec2(7.0f, 5.0f), Vec2(5.0f, 1.0f), true, 255, 0, 255, 0.5f)
};
这是我的方法,应该通过 dist 返回颜色
int red = std::min((int)(std::max((-colorR / WALL_VISIBILITY * dist + colorR + emmision * 255.0f), 0.0f)), colorR);
int green = std::min((int)(std::max((-colorG / WALL_VISIBILITY * dist + colorG + emmision * 255.0f), 0.0f)), colorG);
int blue = std::min((int)(std::max((-colorB / WALL_VISIBILITY * dist + colorB + emmision * 255.0f), 0.0f)), colorB);
if (isGlass) {
sf::Color newCol(red, green, blue, std::max(std::min((int)(transparency * 255), 255), 0));
return newCol;
}
else {
float k = std::max(std::min(transparency, 1.0f), 0.0f);
return sf::Color((int)(red * k), (int)(green * k), (int)(blue * k));
}
解决方案
molbdnilo是对的,我搞砸了我的构造函数。类有字段“isGlass”,构造函数也有“isGlass”。
推荐阅读
- python - ImportError:通过 GUI 运行时没有名为 face_recognition 的模块
- discord.py - 我可以用wavelink python播放本地音频文件吗?
- xml - 在自定义操作栏中制作居中徽标
- javascript - 使用 JS 调用时,Bootstrap 5 折叠显示/隐藏不起作用
- c++ - C++ 乘法表
- python - Pyodbc 错误“TVP 的行必须是序列对象。”,'HY000'
- flutter - 颤振项目的 Android Studio 中缺少“图像资产”选项
- angular - Angular 10 中的 Chart.js:指定颜色未显示在多系列条形图中(而不是随机颜色)
- google-chrome-extension - 检测 Chrome 扩展程序是否提供后退/前进按钮
- ios - UIViewControllerRepresentable 未正确占用空间