我想用用户定义的参数绘制2D线。但是x和y轴的范围是[-1,1]。
如何绘制可以完全显示在窗口中的线?我使用了 .Mappings(m => m
.Map<SearchTopic>(mm => mm
.Properties(p => p
.Text(t => t
.Name(n => n.Posts)
.Analyzer("pfstop")
)
.Text(t => t
.Name(n => n.FirstPost)
.Analyzer("pfstop")
)
.Text(t => t
.Name(n => n.Title)
.Analyzer("pfstop")
)
)
)
)
,但这似乎不是一个好选择,因为该范围根据参数是动态的。
例如,该行是gluOrtho2D(-10.0, 10.0, -10.0, 10.0)
。 x的范围是[1,100]。
我的代码是:
y=ax^3+bx^2+cx+d
答案 0 :(得分:1)
设置投影矩阵不是一次性的操作。您可以随时更改它。事实上,强烈建议您不要使用init
的方式。只需在绘图功能中设置投影参数即可。也要使用标准库函数,不要自己动手。无需自己实现power
。只需使用pow
标准库函数即可。最后但并非最不重要的一点是,使用双重缓冲。因为它具有更好的性能,并且具有更好的兼容性。
#include "pch.h"
#include <windows.h>
#include <gl/glut.h>
#include <iostream>
#include <cmath>
using namespace std;
double a, b, c, d;
double x_min, x_max, y_min, y_max; // <<<<---- fill these per your needs
void linesegment(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(x_min, x_max, y_min, y_max, -1, 1);
glColor3f(1, 0, 0);
glPointSize(1);
glBegin(GL_POINTS);
for (int i = 1; i <= 10; ++i) {
double y = a * pow(i, 3) + b * pow(i, 2) + c * i + d;
glVertex2f(i, y);
}
glEnd();
glFlush();
}