【发布时间】:2020-11-08 06:35:43
【问题描述】:
我正在尝试使用 SFML 中的凸形类将 Pac-man 绘制为作业的一部分,但我总是从点 0,0 绘制一个额外的部分
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
using namespace std;
#define PI 3.14f
#define Deg2Rad PI/180
ConvexShape Pac(float radius, Vector2f center)
{
int pointsCount = 315;
float theta = 0;
ConvexShape circle;
circle.setPointCount(pointsCount);
for (int i = 45, index = 0; i < 315; i++, index++)
{
Vector2f point;
theta = i * Deg2Rad;
point.x = center.x + radius * cos(theta);
point.y = center.y + radius * sin(theta);
cout << point.x << "," << point.y << endl;
circle.setPoint(index, point);
}
return circle;
}
int main()
{
RenderWindow window(VideoMode(500, 500), "Pac_man");
ConvexShape pacman;
pacman = Pac(100.0f, Vector2f(100, 100));
pacman.setFillColor(sf::Color::Yellow);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case Event::Closed:
window.close();
break;
}
}
window.clear();
window.draw(pacman);
window.display();
}
return 0;
}
总是这样
【问题讨论】:
-
你能用这个方法正确渲染一个三角形吗?不要计算角位置,而是将它们硬编码到您的源代码中。如果这有效,那么你的错误一定是介于两者之间。如果没有,你有一个minimal reproducible example。作为这里的新用户,也请带上tour并阅读How to Ask。