gpt4 book ai didi

c++ - 试图画吃 bean 人

转载 作者:行者123 更新时间:2023-12-03 06:58:40 25 4
gpt4 key购买 nike

我正在尝试使用SFML中的凸形类将吃 bean 人作为作业的一部分来绘制,而且我总是从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;
}
它总是这样出来的

最佳答案

您的for循环仅迭代270次(315-45),因此仅在315个顶点中设置270。其他45个顶点位于默认位置(0,0)。
下一个问题是您不会在中心创建顶点。因此,您需要一个额外的顶点作为中心。
对这两个问题进行排序后,结果为:pacman
编辑:我现在也意识到吃 bean 不是凸形的,所以“它可能无法正确绘制”。为了正确绘制它,您需要将其拆分为多个凸形或使用其他原始类型(sf::TriangleFan?)

关于c++ - 试图画吃 bean 人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64735444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com