예제 #1
0
        public static AxisAlignedBoundingBox SurroundingBox(AxisAlignedBoundingBox box0, AxisAlignedBoundingBox box1)
        {
            var small = new Vec3(Math.Min(box0.Min().X(), box1.Min().X()),
                                 Math.Min(box0.Min().Y(), box1.Min().Y()),
                                 Math.Min(box0.Min().Z(), box1.Min().Z()));
            var big = new Vec3(Math.Max(box0.Max().X(), box1.Max().X()),
                               Math.Max(box0.Max().Y(), box1.Max().Y()),
                               Math.Max(box0.Max().Z(), box1.Max().Z()));

            return(new AxisAlignedBoundingBox(small, big));
        }
예제 #2
0
        public RotateY(Hitable hitable, double angle)
        {
            _hitable = hitable;

            double radians = (Math.PI / 180.0) * angle;

            _sinTheta = Math.Sin(radians);
            _cosTheta = Math.Cos(radians);
            _hasbox   = _hitable.BoundingBox(0, 1, out _bbox);

            Vec3 min = new Vec3(double.MaxValue, double.MaxValue, double.MaxValue);
            Vec3 max = new Vec3(-double.MaxValue, -double.MaxValue, -double.MaxValue);

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        double x = i * _bbox.Max().X() + (1 - i) * _bbox.Min().X();
                        double y = j * _bbox.Max().Y() + (1 - j) * _bbox.Min().Y();
                        double z = k * _bbox.Max().Z() + (1 - k) * _bbox.Min().Z();

                        double newX   = _cosTheta * x + _sinTheta * z;
                        double newZ   = -_sinTheta * x + _cosTheta * z;
                        Vec3   tester = new Vec3(newX, y, newZ);
                        for (int c = 0; c < 3; c++)
                        {
                            if (tester[c] > max[c])
                            {
                                max[c] = tester[c];
                            }

                            if (tester[c] < min[c])
                            {
                                min[c] = tester[c];
                            }
                        }
                    }
                }
            }

            _bbox = new AxisAlignedBoundingBox(min, max);
        }