【发布时间】:2013-09-19 06:09:18
【问题描述】:
我在 Internet 上找到了这个 (http://lodev.org/cgtutor/raycasting.html) 教程,并且很感兴趣并想自己制作。不过我想用 SFML 来做,我想扩展它,制作一个 3D 版本,这样玩家可以在不同的关卡上行走。因此,每个像素都需要 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 行,但显然这不是我所做的......我想如果我能找出导致这不起作用的原因,我可能可以修复主要问题问题。另外,如果您认为有更好的方法来代替,您可以告诉我:)
谢谢!
【问题讨论】:
-
看起来像这样,因为您使用了模运算符。
%
标签: c++ sfml raycasting