圆圈的顶点
VertexArray of circles
本文关键字:顶点 更新时间:2023-10-16
我想知道是否可以在sfml中创建一个圆的顶点。我已经寻找答案,但没有找到任何可以帮助的东西。此外,我不了解SFML文档上的部分,我可以在其中创建自己的实体,我认为这也许是我想做的。
编辑:我想这样做,因为我必须画很多圆圈。
感谢您帮助我
而@nvoigt的答案是正确的,我发现对与矢量合作的实现有用(请参阅http://en.cppreference.com/w/cpp/container/vector详细信息,查找" C 容器",有几种类型的容器可以优化读/写入时间)。
您可能不需要上述用例,但是在以后的实施中可能需要它,并考虑这是良好的编码实践。
#include <SFML/Graphics.hpp>
#include <vector>
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
// clear the window with black color
window.clear(sf::Color::Black);
// initialize myvector
std::vector<sf::CircleShape> myvector;
// add 10 circles
for (int i = 0; i < 10; i++)
{
sf::CircleShape shape(50);
// draw a circle every 100 pixels
shape.setPosition(i * 100, 25);
shape.setFillColor(sf::Color(100, 250, 50));
// copy shape to vector
myvector.push_back(shape);
}
// iterate through vector
for (std::vector<sf::CircleShape>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
{
// draw all circles
window.draw(*it);
}
window.display();
}
return 0;
}
sf::CircleShape
是已经使用顶点阵列的已经(感谢从sf::Shape
继承)。您无需做任何额外的事情。
如果您有很多圆圈,请首先使用sf::CircleShape
,并且仅在具有实际用例时进行优化,可以测量解决方案。
此外,我将尝试解释为什么没有cirdles的默认顶点。
通过计算机图形学意识形态(在我们的情况下为SFML)顶点是最小的原始图形原始功能,其功能最少。顶点的经典示例是点,线,三角形,瓜德和多边形。对于您的视频卡来说,前四个非常简单,可以存储和绘制。多边形可以是任何几何图形,但处理更重,这就是为什么在3D grapichs中多边形是三角形的原因。
圆圈更复杂。例如,录像带不知道她需要多少要点才能使您的圆圈足够平滑。因此,正如@nvoigt回答的那样,存在一个由更原始的verticies构建的sf ::圆形。
相关文章:
- 如何循环打印顶点结构
- D3D11-将混合权重和索引传递到顶点着色器
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 如何将一半传递给顶点着色器?
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- QT QOpenGLWidget:如何在不使用数据块复制的情况下修改VBO中的单个顶点值?
- 使用 OpenGL 4.5 更改所选顶点的颜色
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 创建异构顶点数据数组的可移植方法
- 使用 glvertex4i 传递网格面索引时的顶点着色器错误
- 无法从 cso 文件创建顶点着色器(从 fx 文件创建)
- OpenGL 相机移动程序顶点着色器问题
- 使用 std::list 存储顶点并使用 SFML 绘制它们
- 为什么顶点数组对象会导致错误?
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- 将顶点位置从顶点传递到片段着色器 - 仅在使用 Nsight 进行调试时有效
- FBX SDK 在预期 3 个顶点时返回 4 个顶点
- 我对 MyGraph 属性顶点名称和边权重有问题