我在互联网上发现了这个教程(http://lodev.org/cgtutor/raycasting.html),很感兴趣想要自己尝试。虽然我想使用SFML来实现,并且想要扩展它,制作一个三维版本,这样玩家就可以在不同的层面上行走。因此,每个像素都需要1条光线,因此每个像素都必须独立绘制。我找到了这个教程(http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php),看起来很容易将数组设置为单独的顶点。首先,我觉得最好的方法是创建一个类,它可以读取由光线返回的像素,并将它们绘制到屏幕上。我使用了VertexArray,但奇怪的是事情并没有按预期工作。我试图分离出问题,但一直没有成功。我编写了一个简单的顶点数组,只有绿色像素可以填满部分屏幕,但仍然存在问题。像素只显示了我的代码和我想表达的图片。
#include "SFML/Graphics.hpp"
int main() {
sf::RenderWindow window(sf::VideoMode(400, 240), "Test Window");
window.setFramerateLimit(30);
sf::VertexArray pointmap(sf::Points, 400 * 10);
for(register int a = 0;a < 400 * 10;a++) {
pointmap[a].position = sf::Vector2f(a % 400,a / 400);
pointmap[a].color = sf::Color::Green;
}
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(pointmap);
//</debug>
window.display();
}
return 0;
}
我的意思是只用绿色填充前10行,但显然我没有做到...如果我能弄清楚是什么原因导致这个问题,我可能就能解决主要问题。如果你认为有更好的方法,请告诉我 :)
谢谢!