コード例 #1
0
ファイル: RayTracer.cs プロジェクト: TheCoffeeTime/Opensim
        /// <summary>
        /// Draw a given path (A given path may contains many rays). This method just get all the ray in the 
        /// given path and draw them sequentially.
        /// </summary>
        /// <param name="path"></param>
        public void drawRayPath(PathFromTxToRy path)
        {
            foreach(KeyValuePair<string, RayAsPathSection> ray in path.rayList)
            {
                //Note: Team KeyValuePair and Value are c# syntax for accessing dictionary element value and its key.
                // To get the key, we do section.Key. To get the value we do section.Value;

                string name = "ray_" + path.getNoOfReflection() + "_" + path.id + "_" + ray.Value.id;
                drawRay(ray.Value.startPoint, ray.Value.endPoint, name);
            }
        }
コード例 #2
0
ファイル: RayTracer.cs プロジェクト: TheCoffeeTime/Opensim
        /// <summary>
        /// From the transmitter, we create a ray in all direction (with angle between ray = ANGLE_BETWEEN_RAY). For each
        /// of those ray, we 'trace/follow' them and find where they are heading. If they reaches the reciever, then 
        /// we store them in a list. 
        /// </summary>
        public void startRayTracerBrutefoce()
        {
            m_log.DebugFormat("[BARE BONES NON SHARED] Started Raytracing!");

            float lat, lon;
            float toPercent = 100.0f/360.0f;

            //For every lon and lat increase by ANGLE_BETWEEN_RAY
            for (lon = 0; lon < 360; lon += ANGLE_BETWEEN_RAY)
            {
                for (lat = 0; lat < 360; lat += ANGLE_BETWEEN_RAY)
                {
                    double lonr = lon * DEG_TO_RAD;
                    double latr = lat * DEG_TO_RAD;
                    
                    //Note: Lat = angle of elevation. Lon = angle around the z-axis
                    //To get a point on a sphere using 2 angle 
                    //Assuming Radius = 1 so we can get rid of multiplying radius. 
                    //http://stackoverflow.com/questions/969798/plotting-a-point-on-the-edge-of-a-sphere

                    float x = (float)(Math.Sin(latr) * Math.Cos(lonr));
                    float y = (float)(Math.Sin(latr) * Math.Sin(lonr));
                    float z = (float)(Math.Cos(latr));

                    Vector3 pointOnSphere = new Vector3(x, y, z);
                    pointOnSphere.Normalize();

                    Vector3 direction = pointOnSphere;
                    Ray ray = new Ray(transmitter.RootPart.AbsolutePosition, direction);

                    //Trace this ray
                    string pathID = getPathID();
                    PathFromTxToRy thisRayPath = new PathFromTxToRy(this, transmitter.RootPart.AbsolutePosition, pathID);
                    thisRayPath = traceRay(thisRayPath, ray, transmitter.RootPart);

                    //If it reaches the receiver, then add it to the hit list. 
                    if (thisRayPath.reachesReceiver && !checkPathIsDrawn(thisRayPath))
                    {
                        pathHits[thisRayPath.getNoOfReflection()].Add(pathID, thisRayPath);
                    }
                }
                //If lon < 359 then calculate the progress 
                if (lon < 359)
                {
                    updateProgressBar(lon * toPercent);
                }
                else //else it is completed so return 100%
                {
                    updateProgressBar(100.0f);
                }
           }//for
        }
コード例 #3
0
ファイル: RayTracer.cs プロジェクト: TheCoffeeTime/Opensim
        /// <summary>
        /// A recursive method which trace a ray until its power is less than ray-minimum power thershold
        /// </summary>
        /// <param name="path">New PathFromTxToRy object.</param>
        /// <param name="ray">A starting ray (first ray)</param>
        /// <param name="lastIntersectPart">A world object which this ray last intersect, or start</param>
        /// <returns>PathFromTxToRy with True if it reaches receiver and False if it did not reach the receiver.</returns>
        public PathFromTxToRy traceRay(PathFromTxToRy path, Ray ray, SceneObjectPart lastIntersectPart)
        {
            EntityIntersectionWithPart nextHit = findNextHit(ray, transmitter.RootPart);

            if (nextHit.intersection.HitTF)
            {
                //Check for limit number of reflection allowed.
                if(path.getNoOfReflection() >= MAX_REFLECTIONS)
                {
                    path.reachesReceiver = false;
                    return path;
                }
                //drawRay(ray.Origin, nextHit.intersection.ipoint);
                else if (nextHit.intersectPart.Equals(receiver.RootPart)) //If it reaches the receiver
                {
                    path.reachesReceiver = true;
                    path.addNextPoint(nextHit.intersection.ipoint, receiver.RootPart.Material);
                    return path;
                }//if

                //recursive case, keep tracing this ray.
                else
                {
                    path.addNextPoint(nextHit.intersection.ipoint, nextHit.intersectPart.Material);
                    Vector3 reflectedVector = getReflectedVector(ray.Direction, nextHit.intersection.normal);
                    Ray newRay = new Ray(nextHit.intersection.ipoint, reflectedVector);
                    return traceRay(path, newRay, nextHit.intersectPart);
                }//else if
            }
            else //It didn't hit anything
            {
                path.reachesReceiver = false;
                return path;
            }//else
        }
コード例 #4
0
ファイル: RayTracer.cs プロジェクト: TheCoffeeTime/Opensim
        /// <summary>
        /// Start a ray tracer from a given model. The model has 3 sections seperate by '//'
        /// First section: Just says 'RTModel' to indicate that this is a ray tracer model
        /// Second section: Variables section. This contians the variables which were set by the user
        /// Third section: Set of paths from transmitter to the receiver.
        /// </summary>
        public void RayTraceFromModel(string givenModel, Scene _scene, UUID _scriptID)
        {
            string[] tokens = Regex.Split(givenModel, "//");
            string section1 = tokens[0];
            string section2 = tokens[1];
            string section3 = tokens[2];

            //Do a small check on the file. To make this better, we can do a checksum and keep it in here
            //instead of 'RTModel'

            if (section1 != "RTModel")
            {
                throw new Exception("The given ray trace model is not compatible");
            }


            Initialise(_scene, section2, _scriptID);


            if (!sameTransmitter(section3))
            {
                throw new Exception("This model is invalid as the transmitter is moved");
            }


            //Each path is seperate by '#' so we split by '#' to get each path
            //It only goes up to pathList.Length -1 because the last element is the empty string. 

            string[] pathList = section3.Split('#');
            for(int i = 0; i < pathList.Length - 1; i++)
            {
                //Each position/point is seperate by '_' so we split path by '_'
                //It only goes up to listOfPoints.Length -1 because the last element is the empty string. 
                string[] listOfPoints = pathList[i].Split('_');
                //index 0 = starting point. 
                //Each coordinate (x, y, z) is seperate by ',' or we split this point by ','

                string[] pointElements = listOfPoints[0].Split(',');
                Vector3 currentPoint = new Vector3(float.Parse(pointElements[0]), float.Parse(pointElements[1]), float.Parse(pointElements[2]));
                string pathID = getPathID();
                PathFromTxToRy newPath = new PathFromTxToRy(this, currentPoint, pathID);
                for(int j = 1; j < listOfPoints.Length - 1; j++)
                {
                    pointElements = listOfPoints[j].Split(',');
                    currentPoint = new Vector3(float.Parse(pointElements[0]), float.Parse(pointElements[1]), float.Parse(pointElements[2]));
                    newPath.addNextPoint(currentPoint, float.Parse(pointElements[3]));
                }
                pathHits[newPath.getNoOfReflection()].Add(pathID, newPath);
            }//for

            RayTraceIsCalculated = true;
            packAndSendGETMessages(false);
            m_log.DebugFormat("[Finished Loaded a model]");
        }