解决求导问题

dev-VirtualTexture
wuyize 2022-10-07 16:16:28 +08:00
parent f4900b8df2
commit 6dc7119923
4 changed files with 10 additions and 10 deletions

View File

@ -20,9 +20,9 @@ Point CubicBezier::calculateControlPoint(Point a, Point b) {
} }
void CubicBezier::findPointsOfDivison(vector<double> &p, vector<double>& res) { void CubicBezier::findPointsOfDivison(vector<double> &p, vector<double>& res) {
double a = -3 * p[0] + 9 * p[1] - 9 * p[2] + 3 * p[3]; double a = -3 * p[0] + 3 * p[1] - 3 * p[2] + 3 * p[3];
double b = 6 * p[0] - 12 * p[1] + 6 * p[2]; double b = 6 * p[0] - 4 * p[1] + 2 * p[2];
double c = -3 * p[0] + 3 * p[1]; double c = -3 * p[0] + p[1];
double deta = b * b - 4 * a * c, t = 0; double deta = b * b - 4 * a * c, t = 0;
if (fabs(a) > eps) { if (fabs(a) > eps) {
if (deta < eps) return; if (deta < eps) return;
@ -112,7 +112,7 @@ int CubicBezier::judgeBoundIntersection(double xy, double l, double r, bool isY)
be = *vY.begin(); be = *vY.begin();
en = *vY.rbegin(); en = *vY.rbegin();
} }
if ((be - xy) * (en - xy) > eps) return 0; if ((be - xy) * (en - xy) >= eps) return 0;
double t = findTByValue(xy, isY); double t = findTByValue(xy, isY);
double value = getLineValueByT(t, !isY); double value = getLineValueByT(t, !isY);
if (l <= value && value <= r && fabs(t) > eps && fabs(1 - t) > eps) { if (l <= value && value <= r && fabs(t) > eps && fabs(1 - t) > eps) {

View File

@ -309,10 +309,10 @@ void RendererWidget::paintGL()
depthMipmapProgramPtr->bind(); depthMipmapProgramPtr->bind();
for (int i = 0; i <= 3; i++) for (int i = 0; i <= 3; i++)
glBindImageTexture(i, gbuffers[7], i, GL_FALSE, 0, GL_READ_WRITE, GL_R32F); glBindImageTexture(i, gbuffers[7], i, GL_FALSE, 0, GL_READ_WRITE, GL_R32F);
glDispatchCompute(ceil(depthWidth / 2 / 8.), ceil(depthHeight / 2 / 8.), 1); glDispatchCompute(ceil(depthWidth / 2. / 8.), ceil(depthHeight / 2. / 8.), 1);
for (int i = 0; i <= 3; i++) for (int i = 0; i <= 3; i++)
glBindImageTexture(i, gbuffers[7], i + 3, GL_FALSE, 0, GL_READ_WRITE, GL_R32F); glBindImageTexture(i, gbuffers[7], i + 3, GL_FALSE, 0, GL_READ_WRITE, GL_R32F);
glDispatchCompute(ceil(depthWidth / 2 / 8 / 8.), ceil(depthHeight / 2 / 8 / 8.), 1); glDispatchCompute(ceil(depthWidth / 2. / 8. / 8.), ceil(depthHeight / 2. / 8. / 8.), 1);
depthMipmapProgramPtr->release(); depthMipmapProgramPtr->release();
shadowMappingProgramPtr->bind(); shadowMappingProgramPtr->bind();

View File

@ -31,7 +31,7 @@ int StraightLine::judgeBoundIntersection(double xy, double l, double r, bool isY
swap(be.x, be.y); swap(be.x, be.y);
swap(en.x, en.y); swap(en.x, en.y);
} }
if ((be.x - xy) * (en.x - xy) > eps) return 0; if ((be.x - xy) * (en.x - xy) >= eps) return 0;
if (direction(isY)) { if (direction(isY)) {
float t = findTByValue(xy, isY); float t = findTByValue(xy, isY);
float value = getLineValueByT(t, !isY); float value = getLineValueByT(t, !isY);

View File

@ -4,7 +4,7 @@
vector<vector<Point>> SvgParser::parse(const std::string path, float width, float height) vector<vector<Point>> SvgParser::parse(const std::string path, float width, float height)
{ {
std::string tmp; std::string tmp;
vector<float> point; vector<double> point;
vector<Point> line; vector<Point> line;
vector<vector<Point>> lines; vector<vector<Point>> lines;
for (char c : path.substr(1)) for (char c : path.substr(1))
@ -18,11 +18,11 @@ vector<vector<Point>> SvgParser::parse(const std::string path, float width, floa
{ {
if (tmp != "") if (tmp != "")
{ {
point.push_back(std::stof(tmp)); point.push_back(std::stod(tmp));
tmp = ""; tmp = "";
if (point.size() == 2) if (point.size() == 2)
{ {
line.push_back(Point{ std::clamp(point[0] / width * 2 - 1, -1.f, 1.f) , std::clamp(1 - point[1] / height * 2 , -1.f, 1.f)}); line.push_back(Point{ std::clamp(point[0] / width * 2 - 1, -1., 1.) , std::clamp(1 - point[1] / height * 2 , -1., 1.)});
point.clear(); point.clear();
} }
} }