当前位置: 首页>>代码示例>>C#>>正文


C# Ray.getMax方法代码示例

本文整理汇总了C#中Ray.getMax方法的典型用法代码示例。如果您正苦于以下问题:C# Ray.getMax方法的具体用法?C# Ray.getMax怎么用?C# Ray.getMax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ray的用法示例。


在下文中一共展示了Ray.getMax方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: intersectFlake

        private void intersectFlake(Ray r, IntersectionState state, int level, float qa, float qaInv, float cx, float cy, float cz, float dx, float dy, float dz, float radius)
        {
            if (level <= 0) {
                // we reached the bottom - intersect sphere and bail out
                float vcx = cx - r.ox;
                float vcy = cy - r.oy;
                float vcz = cz - r.oz;
                float b = r.dx * vcx + r.dy * vcy + r.dz * vcz;
                float disc = b * b - qa * ((vcx * vcx + vcy * vcy + vcz * vcz) - radius * radius);
                if (disc > 0) {
                    // intersects - check t values
                    float d = (float) Math.Sqrt(disc);
                    float t1 = (b - d) * qaInv;
                    float t2 = (b + d) * qaInv;
                    if (t1 >= r.getMax() || t2 <= r.getMin())
                        return;
                    if (t1 > r.getMin())
                        r.setMax(t1);
                    else
                        r.setMax(t2);
                    state.setIntersection(0, cx, cy, cz);
                }
            } else {
                float boundRadius = radius * (1 + boundingRadiusOffset[level]);
                float vcx = cx - r.ox;
                float vcy = cy - r.oy;
                float vcz = cz - r.oz;
                float b = r.dx * vcx + r.dy * vcy + r.dz * vcz;
                float vcd = (vcx * vcx + vcy * vcy + vcz * vcz);
                float disc = b * b - qa * (vcd - boundRadius * boundRadius);
                if (disc > 0) {
                    // intersects - check t values
                    float d = (float) Math.Sqrt(disc);
                    float t1 = (b - d) * qaInv;
                    float t2 = (b + d) * qaInv;
                    if (t1 >= r.getMax() || t2 <= r.getMin())
                        return;

                    // we hit the bounds, now compute intersection with the actual
                    // leaf sphere
                    disc = b * b - qa * (vcd - radius * radius);
                    if (disc > 0) {
                        d = (float) Math.Sqrt(disc);
                        t1 = (b - d) * qaInv;
                        t2 = (b + d) * qaInv;
                        if (t1 >= r.getMax() || t2 <= r.getMin()) {
                            // no hit
                        } else {
                            if (t1 > r.getMin())
                                r.setMax(t1);
                            else
                                r.setMax(t2);
                            state.setIntersection(0, cx, cy, cz);
                        }
                    }

                    // recursively intersect 9 other spheres
                    // step1: compute basis around displacement vector
                    float b1x, b1y, b1z;
                    if (dx * dx < dy * dy && dx * dx < dz * dz) {
                        b1x = 0;
                        b1y = dz;
                        b1z = -dy;
                    }
                    else if (dy * dy < dz * dz)
                    {
                        b1x = dz;
                        b1y = 0;
                        b1z = -dx;
                    }
                    else
                    {
                        b1x = dy;
                        b1y = -dx;
                        b1z = 0;
                    }

                    float n = 1 / (float) Math.Sqrt(b1x * b1x + b1y * b1y + b1z * b1z);
                    b1x *= n;
                    b1y *= n;
                    b1z *= n;
                    float b2x = dy * b1z - dz * b1y;
                    float b2y = dz * b1x - dx * b1z;
                    float b2z = dx * b1y - dy * b1x;
                    b1x = dy * b2z - dz * b2y;
                    b1y = dz * b2x - dx * b2z;
                    b1z = dx * b2y - dy * b2x;
                    // step2: generate 9 children recursively
                    float nr = radius * (1 / 3.0f), scale = radius + nr;
                    for (int i = 0; i < 9 * 3; i += 3) {
                        // transform by basis
                        float ndx = recursivePattern[i] * dx + recursivePattern[i + 1] * b1x + recursivePattern[i + 2] * b2x;
                        float ndy = recursivePattern[i] * dy + recursivePattern[i + 1] * b1y + recursivePattern[i + 2] * b2y;
                        float ndz = recursivePattern[i] * dz + recursivePattern[i + 1] * b1z + recursivePattern[i + 2] * b2z;
                        // recurse !
                        intersectFlake(r, state, level - 1, qa, qaInv, cx + scale * ndx, cy + scale * ndy, cz + scale * ndz, ndx, ndy, ndz, nr);
                    }
                }
            }
        }
开发者ID:,项目名称:,代码行数:100,代码来源:


注:本文中的Ray.getMax方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。