Exemplo n.º 1
0
        protected Vector3 IntersectionSearch(Vector3 prevPoint, Vector3 velocity, SchwarzschildBlackHoleEquation equation)
        {
            float   stepLow = 0, stepHigh = equation.StepSize;
            Vector3 newPoint = prevPoint;
            Vector3 tempVelocity;

            while (true)
            {
                float stepMid = (stepLow + stepHigh) / 2;
                newPoint     = prevPoint;
                tempVelocity = velocity;
                equation.Function(ref newPoint, ref tempVelocity, stepMid);

                float distanceSqr = (newPoint - center).LengthSquared();
                if (Math.Abs(stepHigh - stepLow) < 0.00001)
                {
                    break;
                }
                if (distanceSqr < radiusSqr)
                {
                    stepHigh = stepMid;
                }
                else
                {
                    stepLow = stepMid;
                }
            }
            return(newPoint);
        }
Exemplo n.º 2
0
        public Scene(Vector3 CameraPosition, Vector3 CameraLookAt, Vector3 UpVector, float Fov, List <IHitable> hitables, float CurvatureCoeff, float AngularMomentum)
        {
            this.CameraPosition = CameraPosition;
            this.CameraLookAt   = CameraLookAt;
            this.UpVector       = UpVector;
            this.hitables       = hitables;
            this.Fov            = Fov;

            double tempR = 0, tempTheta = 0, tempPhi = 0;

            Util.ToSpherical(CameraPosition.X, CameraPosition.Y, CameraPosition.Z, ref tempR, ref tempTheta, ref tempPhi);
            CameraDistance  = tempR;
            CameraAngleVert = tempTheta;
            CameraAngleHorz = tempPhi - 0.1;

            SchwarzschildEquation = new SchwarzschildBlackHoleEquation(CurvatureCoeff);
            KerrEquation          = new KerrBlackHoleEquation(CameraDistance, CameraAngleHorz, CameraAngleVert, AngularMomentum);
        }
Exemplo n.º 3
0
        public bool Hit(ref Vector3 point, double sqrNorm, Vector3 prevPoint, double prevSqrNorm, ref Vector3 velocity, SchwarzschildBlackHoleEquation equation, double r, double theta, double phi, ref Color color, ref bool stop, bool debug)
        {
            float distanceSqr = (point.X - center.X) * (point.X - center.X)
                                + (point.Y - center.Y) * (point.Y - center.Y)
                                + (point.Z - center.Z) * (point.Z - center.Z);

            if (distanceSqr < radiusSqr)
            {
                var colpoint         = IntersectionSearch(prevPoint, velocity, equation);
                var impactFromCenter = Vector3.Normalize(center - colpoint);

                // and now transform to spherical coordinates relative to center of sphere.
                double tempR = 0, tempTheta = 0, tempPhi = 0;
                // hack: rejigger axes to make textures appear right side up.
                Util.ToSpherical(impactFromCenter.X, impactFromCenter.Z, -impactFromCenter.Y, ref tempR, ref tempTheta, ref tempPhi);

                color = Util.AddColor(GetColor(tempR, tempTheta, tempPhi), color);
                stop  = true;
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public bool Hit(ref Vector3 point, double sqrNorm, Vector3 prevPoint, double prevSqrNorm, ref Vector3 velocity, SchwarzschildBlackHoleEquation equation, double r, double theta, double phi, ref Color color, ref bool stop, bool debug)
        {
            float distanceSqr = (point.X - center.X) * (point.X - center.X)
                                + (point.Y - center.Y) * (point.Y - center.Y)
                                + (point.Z - center.Z) * (point.Z - center.Z);

            if (distanceSqr < radiusSqr)
            {
                point    = IntersectionSearch(prevPoint, velocity, equation);
                velocity = Vector3.Reflect(velocity, Vector3.Normalize(point - center));

                color = Util.AddColor(Color.FromArgb(8, 8, 8), color);
                stop  = false;
                return(true);
            }
            return(false);
        }
Exemplo n.º 5
0
        public bool Hit(ref Vector3 point, double sqrNorm, Vector3 prevPoint, double prevSqrNorm, ref Vector3 velocity, SchwarzschildBlackHoleEquation equation, double r, double theta, double phi, ref Color color, ref bool stop, bool debug)
        {
            // Has the ray fallen past the horizon?
            if (prevSqrNorm > 1 && sqrNorm < 1)
            {
                var colpoint = IntersectionSearch(prevPoint, velocity, equation);

                double tempR = 0, tempTheta = 0, tempPhi = 0;
                Util.ToSpherical(colpoint.X, colpoint.Z, colpoint.Y, ref tempR, ref tempTheta, ref tempPhi);

                Color col = Color.Black;
                if (checkered)
                {
                    var m1 = Util.DoubleMod(tempTheta, 1.04719); // Pi / 3
                    var m2 = Util.DoubleMod(tempPhi, 1.04719);   // Pi / 3
                    if ((m1 < 0.52359) ^ (m2 < 0.52359))         // Pi / 6
                    {
                        col = Color.Green;
                    }
                }
                else if (textureBitmap != null)
                {
                    int xPos, yPos;
                    textureMap.Map(r, theta, -phi, out xPos, out yPos);

                    col = Color.FromArgb(textureBitmap[yPos * textureWidth + xPos]);
                }
                color = Util.AddColor(col, color);
                stop  = true;
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        public bool Hit(ref Vector3 point, double sqrNorm, Vector3 prevPoint, double prevSqrNorm, ref Vector3 velocity, SchwarzschildBlackHoleEquation equation, double r, double theta, double phi, ref Color color, ref bool stop, bool debug)
        {
            // Has the ray escaped to infinity?
            if (sqrNorm > radiusSqr)
            {
                int xPos, yPos;
                textureMap.Map(r, theta, phi, out xPos, out yPos);

                color = Util.AddColor(Color.FromArgb(textureBitmap[yPos * textureWidth + xPos]), color);
                stop  = true;
                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
        public bool Hit(ref Vector3 point, double sqrNorm, Vector3 prevPoint, double prevSqrNorm, ref Vector3 velocity, SchwarzschildBlackHoleEquation equation, double r, double theta, double phi, ref Color color, ref bool stop, bool debug)
        {
            // Remember what side of the plane we're currently on, so that we can detect
            // whether we've crossed the plane after stepping.
            int side = prevPoint.Y > 0 ? -1 : prevPoint.Y < 0 ? 1 : 0;

            // Did we cross the horizontal plane?
            bool success = false;

            if (point.Y * side >= 0)
            {
                var colpoint    = IntersectionSearch(side, prevPoint, velocity, equation);
                var colpointsqr = colpoint.LengthSquared();

                if ((colpointsqr >= radiusInnerSqr) && (colpointsqr <= radiusOuterSqr))
                {
                    double tempR = 0, tempTheta = 0, tempPhi = 0;
                    Util.ToSpherical(colpoint.X, colpoint.Y, colpoint.Z, ref tempR, ref tempTheta, ref tempPhi);

                    color   = Util.AddColor(GetColor(side, tempR, tempPhi, tempTheta + Math.PI / 12), color);
                    stop    = false;
                    success = true;
                }
            }
            return(success);
        }
Exemplo n.º 8
0
        protected Vector3 IntersectionSearch(int side, Vector3 prevPoint, Vector3 velocity, SchwarzschildBlackHoleEquation equation)
        {
            float   stepLow = 0, stepHigh = equation.StepSize;
            Vector3 newPoint = prevPoint;
            Vector3 tempVelocity;

            while (true)
            {
                float stepMid = (stepLow + stepHigh) / 2;
                newPoint     = prevPoint;
                tempVelocity = velocity;
                equation.Function(ref newPoint, ref tempVelocity, stepMid);

                if (Math.Abs(stepHigh - stepLow) < 0.00001)
                {
                    break;
                }
                if (side * newPoint.Y > 0)
                {
                    stepHigh = stepMid;
                }
                else
                {
                    stepLow = stepMid;
                }
            }
            return(newPoint);
        }