- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 C++ 在 Windows 控制台上构建一个简单的 2D 应用程序来显示各种图元,因此我从最基本的一个开始:三角形。我可以正确显示三角形的轮廓和顶点,但在填充它时遇到问题。我遇到过一些此处介绍的光栅化算法:http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html并决定我会采用第一种方法。我复制了平底三角形案例的代码,但这似乎在我的应用程序上无法正常工作,而且我不知道问题的原因是什么。
我的结果:
main()
screen.fillFlatBottomTriangle(30,10, 10, 140/4, 256/2, 140/4, block_char, FG_CYAN);
screen.drawTriangle(30,10, 10, 140/4, 256/2, 140/4, block_char, BG_DARK_GREY);
screen.drawPixel(30,10,block_char,FG_RED);
screen.drawPixel(10,140/4,block_char,FG_GREEN);
screen.drawPixel(256/2,140/4,block_char,FG_MAGENTA);
填充FlatBottomTriangle
//http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html
void Screen::fillFlatBottomTriangle(int x1, int y1, int x2, int y2, int x3, int y3, short character, short color)
{
float invslope1 = (x2 - x1) / (y2 - y1);
float invslope2 = (x3 - x1) / (y3 - y1);
float curx1 = x1;
float curx2 = x1;
for (int scanlineY = y1; scanlineY <= y2; scanlineY++)
{
this->drawLine((int)curx1, scanlineY, (int)curx2, scanlineY, character, color);
curx1 += invslope1;
curx2 += invslope2;
}
}
画线
// https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
void Screen::drawLine(int x1, int y1, int x2, int y2, short character, short color)
{
float delta_x = x2 - x1;
float delta_y = y2 - y1;
float step;
if (abs(delta_x) >= abs(delta_y))
step = abs(delta_x);
else
step = abs(delta_y);
delta_x = delta_x / step;
delta_y = delta_y / step;
float x = x1;
float y = y1;
for (int i = 1; i <= step; i++)
{
this->drawPixel((int)x, (int)y, character, color);
x += delta_x;
y += delta_y;
}
}
绘制三角形
void Screen::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, short character, short color)
{
this->drawLine(x1,y1, x2, y2, character, color);
this->drawLine(x1,y1, x3, y3, character, color);
this->drawLine(x2,y2, x3, y3, character, color);
}
最佳答案
请参阅这部分:(x2 - x1)/(y2 - y1)
由于这里的所有变量都是整数,所以这是整数除法。也就是说,除法的结果向 0 舍入。将结果分配给 float 不会改变这一点。
要进行浮点除法,您应该将至少一个操作数转换为浮点:(x2 - x1)/(float) (y2 - y1)
您当前的代码将其中一个反斜率舍入为 0,从而在左侧产生垂直线。另一侧的 x 值也增加得不够快,因为该部分也在下方进行了舍入。
关于C++ 2D 图形 : Flat Bottom Triangle Rasterization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65524726/
当从谷歌浏览器访问我的网站时,一切正常(也在移动设备上)。但是当尝试从边缘\移动普通浏览器(不是谷歌浏览器)访问时我明白 TypeError: Object doesn't support prope
我正在将许可版本的 flat-ui-pro 与我的 Rails 应用程序集成。 为此,我正在使用“designmodo-flatuipro-rails”gem 我的环境是:- 操作系统 - Windo
当有人在表单上的单个字段中输入街道地址时,我想将街道地址转换为标题大小写之类的内容。它不完全是标题大小写,因为直接跟在数字字符串后面的字母应该是大写的。 举个例子,我想要“Flat 3 245A Hi
apollo-server-Getting started 我正在使用上面的链接在我的系统中进行 apollo-server 设置。当我尝试使用 node index.js 运行节点文件时。我遇到以下
这更像是一个面向业务的编程问题,我似乎无法弄清楚如何解决。我与一个使用 BASIC 超过 20 年的程序员团队一起工作。我被请来帮助在 .NET 中编写相同的软件,只有更新和现代实践。问题是我似乎无法
在我的映射中,我使用平面文件作为源和目标。我必须使用未连接的查找。当我们使用平面文件作为源和目标时,有人能告诉我如何从未连接的查找中返回多个值吗? 我知道在使用关系表时如何返回多个值。在那种情况下,我
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我目前尝试使用 Elasticsearch Significant Terms 聚合来制作产品推荐系统的原型(prototype)。到目前为止,我还没有找到一个很好的例子来处理来自关系数据库的 sal
如何在不使用 flat() 的情况下展平数组。 1级? 到目前为止我有这个 function flatten(array) { let flattened = []; for (let i =
问题:如果用户在其可见边框之外单击,我希望用户无法点击该按钮。 我创建了两个FlatButton,里面没有任何填充,问题是即使我在两个按钮之间点击,我的按钮仍然可以单击。 请向我解释为什么会这样? 如
这个问题已经有答案了: How to extend an existing JavaScript array with another array, without creating a new ar
当我四处拖动我的“表格”单元格时,大多数时候连接是平坦的/水平的(比如链接的垂直部分或来自 ORDERLINE 表格的小部分),但有时它们最终会在一个小 Angular (链接的左侧位)。有没有办法防
为什么 array.flat 上的链接函数没有按预期工作 const input = [[[{"type":"banana"},{"type":"orange"}]]]; console.log(in
我正在发出 API 请求并获取我不确定如何处理的数据。我希望将 pandas 数据框中的所有数据以“channel_id”作为行(或我认为的索引),将所有其他信息作为列。 这是我调用的电话: with
我正在尝试创建一个没有阴影的平面操作栏 附上图片: 我的风格 xml @style/MyActionBar @null true @draw
下面的代码 function steamrollArray(arr) { // I'm a steamroller, baby return arr.flat(); } steamrollAr
我正在使用 Flat-UI ( http://designmodo.github.io/Flat-UI/) 来帮助我构建的小型 MeteorJS 应用程序的前端元素。 我遇到的问题是“选择下拉列表”不
据说,在 Material 主题中,有两种按钮:凸起的和扁平的: 当我创建 ,它看起来像“凸起”按钮。如何使用标记制作“平面按钮”。有什么风格或属性可以做到吗?我在主题编辑器中找到了这张图片。 最佳
在过去的几年中,已经将许多有用的功能添加到Javascript Array全局对象中,这些功能为开发人员在编写可用于数组的代码时提供了多种选择。这些功能提供了许多优点,其中最值得注意的是,虽然在过去
如前所述 here ,谁能解释一下“平面”32 位空间是什么意思? 懒人的文字: Another interesting feature of the architecture is a virtua
我是一名优秀的程序员,十分优秀!