Ejemplo n.º 1
0
        /**
         * Copy
         *
         * @param original
         */
        public void Copy(OctNode original)
        {
            int i;

            for (i = 0; i < 6; i++)
            {
                Adjacent [i] = original.GetAdjacent(i);
                OctFaces [i] = original.GetFace(i);
            }
            for (i = 0; i < 8; i++)
            {
                Child [i] = original.GetChild(i);
            }
            ObjList = original.GetList();
            NumObj  = original.GetNumObj();
        }
Ejemplo n.º 2
0
        /**
         * Intersect
         *
         * @param ray
         * @param intersect
         * @param Threshold
         * @return OctNode
         */
        public OctNode Intersect(Ray ray, Point intersect, double Threshold)
        {
            Vector delta   = new Vector(0.0f, 0.0f, 0.0f);
            double current = 0.0f;
            double t;

            int[] facehits = new int[3];
            facehits [0] = -1;
            facehits [1] = -1;
            facehits [2] = -1;
            OctNode adjacent = null;

            Face[] OFaces = this.OctFaces;
            Face   MAXXF  = OFaces [MAXX];
            Face   MAXYF  = OFaces [MAXY];
            Face   MAXZF  = OFaces [MAXZ];
            Face   MINXF  = OFaces [MINX];
            Face   MINYF  = OFaces [MINY];
            Face   MINZF  = OFaces [MINZ];

            if (ray.GetDirection().GetX() != 0.0)
            {
                t = -(ray.GetOrigin().GetX() - OctFaces [MAXX].GetVert(0).GetX()) / ray.GetDirection().GetX();
                if (t > Threshold && t > current)
                {
                    intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t);
                    if ((intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()) &&
                        (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ()))
                    {
                        current      = t;
                        facehits [0] = MAXX;
                        delta.SetX(Threshold);
                    }
                }
                t = -(ray.GetOrigin().GetX() - OctFaces [MINX].GetVert(0).GetX()) / ray.GetDirection().GetX();
                if (t > Threshold && t > current)
                {
                    intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t);
                    if ((intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()) &&
                        (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ()))
                    {
                        current      = t;
                        facehits [0] = MINX;
                        delta.SetX(-Threshold);
                    }
                }
            }
            if (ray.GetDirection().GetY() != 0.0)
            {
                t = -(ray.GetOrigin().GetY() - OctFaces [MAXY].GetVert(0).GetY()) / ray.GetDirection().GetY();
                if (t > Threshold)
                {
                    if (t > current)
                    {
                        intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t);
                        if ((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) &&
                            (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ()))
                        {
                            current      = t;
                            facehits [0] = MAXY;
                            delta.Set(0.0f, Threshold, 0.0f);
                        }
                    }
                    else if (t == current)
                    {
                        facehits [1] = MAXY;
                        delta.SetY(Threshold);
                    }
                }
                t = -(ray.GetOrigin().GetY() - OctFaces [MINY].GetVert(0).GetY()) / ray.GetDirection().GetY();
                if (t > Threshold)
                {
                    if (t > current)
                    {
                        intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t);
                        if ((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) &&
                            (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ()))
                        {
                            current      = t;
                            facehits [0] = MINY;
                            delta.Set(0.0f, -Threshold, 0.0f);
                        }
                    }
                    else if (t == current)
                    {
                        facehits [1] = MINY;
                        delta.SetY(-Threshold);
                    }
                }
            }
            if (ray.GetDirection().GetZ() != 0.0)
            {
                t = -(ray.GetOrigin().GetZ() - OctFaces [MAXZ].GetVert(0).GetZ()) / ray.GetDirection().GetZ();
                if (t > Threshold)
                {
                    if (t > current)
                    {
                        intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t);
                        if ((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) &&
                            (intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()))
                        {
                            current      = t;
                            facehits [0] = MAXZ;
                            delta.Set(0.0f, 0.0f, Threshold);
                        }
                    }
                    else if (t == current)
                    {
                        if (facehits [1] < 0)
                        {
                            facehits [1] = MAXZ;
                        }
                        else
                        {
                            facehits [2] = MAXZ;
                        }
                        delta.SetZ(Threshold);
                    }
                }
                t = -(ray.GetOrigin().GetZ() - OctFaces [MINZ].GetVert(0).GetZ()) / ray.GetDirection().GetZ();
                if (t > Threshold)
                {
                    if (t > current)
                    {
                        intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t);
                        if ((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) &&
                            (intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()))
                        {
                            current      = t;
                            facehits [0] = MINZ;
                            delta.Set(0.0f, 0.0f, -Threshold);
                        }
                    }
                    else if (t == current)
                    {
                        if (facehits [1] < 0)
                        {
                            facehits [1] = MINZ;
                        }
                        else
                        {
                            facehits [2] = MINZ;
                        }
                        delta.SetZ(-Threshold);
                    }
                }
            }
            if (facehits [0] >= MAXX)
            {
                intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, current);
                intersect.Add(delta);
                adjacent = Adjacent [facehits [0]];
                if (facehits [1] >= MAXX)
                {
                    if (adjacent != null)
                    {
                        adjacent = adjacent.GetAdjacent(facehits [1]);
                        if (facehits [2] >= MAXX)
                        {
                            if (adjacent != null)
                            {
                                adjacent = adjacent.GetAdjacent(facehits [2]);
                            }
                            else
                            {
                                adjacent = null;
                            }
                        }
                    }
                    else
                    {
                        adjacent = null;
                    }
                }
            }
            return(adjacent);
        }
Ejemplo n.º 3
0
	/**
	 * Copy
	 *
	 * @param original
	 */
	public void Copy(OctNode original)
	{
		int i;

		for(i = 0; i < 6; i++)
		{
			Adjacent[i] = original.GetAdjacent(i);
			OctFaces[i] = original.GetFace(i);
		}
		for(i = 0; i < 8; i++)
		{
			Child[i] = original.GetChild(i);
		}
		ObjList = original.GetList();
		NumObj = original.GetNumObj();
	}