【问题标题】:Ray tracing cylinder degenerates when rotated光线追踪圆柱体在旋转时退化
【发布时间】:2016-06-13 23:10:22
【问题描述】:

我正在尝试开发一个简单的光线追踪器并获得正确的球体、平面和圆锥体,但我面临一个无法解决的问题。 我为无限圆柱尝试了几种不同的公式,当使用不是 0 或 1 且仅在一个轴上的旋转时,所有应该考虑旋转的人都会使其“退化”......例如:

0,0,1 有效,但 0,0,0.5 给了我一个椭球体,而 0,1,1 给了我一个双曲面......

这是我用来将光线与圆柱体相交的代码。

enum e_bool test_intersect(double t[2], double *current_z)
{
    enum e_bool retvalue;

    retvalue = false;
    if ((t[0] > DOUBLE_ZERO)
    && (t[0] < *(current_z) || double_equal(*(current_z), t[0])))
    {
        *(current_z) = t[0];
        retvalue = true;
    }
    if (!double_equal(t[0], t[1])
    && (t[1] > DOUBLE_ZERO) 
    && (t[1] < *(current_z) || double_equal(*(current_z), t[1])))
    {
        *(current_z) = t[1];
        retvalue = true;
    }
    return (retvalue);
}

enum e_bool intersect_cylinder(t_primitive cp, t_ray r, double *current_z)
{
    t_vec3 eye = vec3_substract(r.origin, cp.position);
    double a = vec3_dot(r.direction, r.direction) - pow(vec3_dot(r.direction, cp.direction), 2);
    double b = 2 * (vec3_dot(r.direction, eye) - vec3_dot(r.direction, cp.direction) * vec3_dot(eye, cp.direction));
    double c = vec3_dot(eye, eye) - pow(vec3_dot(eye, cp.direction), 2) - cp.radius * cp.radius;
    double  t[2];
    double delta;
    delta = sqrt((b * b) - (4.0 * a * c));
    if (delta < 0)
        return (false);
    t[0] = (-b - (delta)) / (2.0 * a);
    t[1] = (-b + (delta)) / (2.0 * a);
    return (test_intersect(t, current_z));
}

Here is the cylinder with a rotation of 1, 0, 0

Here it is with a rotation of 1, 1, 0

我错过了什么,问题与透视或等距射线投射相同,所以它与相交算法有关,但我找不到问题所在......

【问题讨论】:

    标签: 3d intersection raytracing


    【解决方案1】:

    阅读这些页面后,我找到了解决问题的方法(gamedev 帮了我很多):

    http://mrl.nyu.edu/~dzorin/cg05/lecture12.pdf

    http://www.gamedev.net/topic/467789-raycylinder-intersection/

    我像这样重新做了我的交集方程,它工作正常:

    enum e_bool intersect_cylinder(t_primitive cp, t_ray r, double *current_z)
    {
        t_vec3  pdp = vec3_substract(cp.direction, cp.position);
        t_vec3  eyexpdp = vec3_cross(vec3_substract(r.origin, cp.position), pdp);
        t_vec3  rdxpdp = vec3_cross(r.direction, pdp);
        float   a = vec3_dot(rdxpdp, rdxpdp);
        float   b = 2 * vec3_dot(rdxpdp, eyexpdp);
        float   c = vec3_dot(eyexpdp, eyexpdp) - (cp.radius * cp.radius * vec3_dot(pdp, pdp));
        double  t[2];
        double delta;
        delta = sqrt((b * b) - (4.0 * a * c));
        if (delta < 0)
            return (false);
        t[0] = (-b - (delta)) / (2.0 * a);
        t[1] = (-b + (delta)) / (2.0 * a);
        return (test_intersect(t, current_z));
    }
    

    现在我的法线是错误的,但这不是什么大问题要解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      • 2016-08-23
      • 2015-02-05
      • 1970-01-01
      相关资源
      最近更新 更多