Пример #1
0
 public static Vertex Fract(Vertex vert)
 {
     return(new Vertex(
                vert.x - XMath.Floor(vert.x),
                vert.y - XMath.Floor(vert.y),
                vert.z - XMath.Floor(vert.z)));
 }
Пример #2
0
 public void Fract_IP()
 {
     this.x -= XMath.Floor(x);
     this.y -= XMath.Floor(y);
     this.z -= XMath.Floor(z);
     return;
 }
Пример #3
0
        static void TransposeKernel(Index1 index, ArrayView <float> Output, ArrayView <float> Input, int columns)
        {
            // (int)Math.Floor(Input.Length / columns) => The Row
            // (int)(Input.Length % columns) => The Column
            float invcol = 1f / columns;

            Output[(index % columns) * ((int)(Input.Length * invcol)) + ((int)XMath.Floor(index * invcol))] = Input[index];
        }
Пример #4
0
        public HitRecord hit(Ray ray, float tmin, float tmax)
        {
            if (aabb.hit(ray, tmin, tmax))
            {
                float t = tmin;

                Vec3 pos = ray.a;

                Vec3i iPos = new Vec3i(XMath.Floor(pos.x), XMath.Floor(pos.y), XMath.Floor(pos.z));

                Vec3 step = new Vec3(ray.b.x > 0 ? 1f : -1f, ray.b.y > 0 ? 1f : -1f, ray.b.z > 0 ? 1f : -1f);

                Vec3 tDelta = new Vec3(
                    XMath.Abs(1f / ray.b.x),
                    XMath.Abs(1f / ray.b.y),
                    XMath.Abs(1f / ray.b.z));

                Vec3 dist = new Vec3(
                    step.x > 0 ? (iPos.x + 1 - pos.x) : (pos.x - iPos.x),
                    step.y > 0 ? (iPos.y + 1 - pos.y) : (pos.y - iPos.y),
                    step.z > 0 ? (iPos.z + 1 - pos.z) : (pos.z - iPos.z));

                Vec3 tMax = new Vec3(
                    float.IsInfinity(tDelta.x) ? float.MaxValue : tDelta.x * dist.x,
                    float.IsInfinity(tDelta.y) ? float.MaxValue : tDelta.y * dist.y,
                    float.IsInfinity(tDelta.z) ? float.MaxValue : tDelta.z * dist.z);

                int stepIndex = -1;
                int i         = -1;

                while (i < maxViewDist)
                {
                    int tile = tileAt(pos);
                    i++;

                    if (tile > 0)
                    {
                        Vec3 hitPos  = ray.pointAtParameter(t);
                        Vec3 hitNorm = new Vec3();

                        if (stepIndex == 0)
                        {
                            hitNorm = new Vec3(-step.x, 0, 0);
                        }
                        else if (stepIndex == 1)
                        {
                            hitNorm = new Vec3(0, -step.y, 0);
                        }
                        else if (stepIndex == 2)
                        {
                            hitNorm = new Vec3(0, 0, -step.z);
                        }

                        return(new HitRecord(t, hitPos, hitNorm, false, tileMaterialIDs[tile], tile));
                    }

                    if (tMax.x < tMax.y)
                    {
                        if (tMax.x < tMax.z)
                        {
                            pos.x    += step.x;
                            t         = tMax.x;
                            tMax.x   += tDelta.x;
                            stepIndex = 0;
                        }
                        else
                        {
                            pos.z    += step.z;
                            t         = tMax.z;
                            tMax.z   += tDelta.z;
                            stepIndex = 2;
                        }
                    }
                    else
                    {
                        if (tMax.y < tMax.z)
                        {
                            pos.y    += step.y;
                            t         = tMax.y;
                            tMax.y   += tDelta.y;
                            stepIndex = 1;
                        }
                        else
                        {
                            pos.z    += step.z;
                            t         = tMax.z;
                            tMax.z   += tDelta.z;
                            stepIndex = 2;
                        }
                    }
                }

                return(new HitRecord(float.MaxValue, new Vec3(), new Vec3(), false, -1, -1));
            }
            else
            {
                return(new HitRecord(float.MaxValue, new Vec3(), new Vec3(), false, -1, -1));
            }
        }