Example #1
0
        /**
         * Intersect
         *
         * @param ray
         * @param pt
         * @return boolean
         */
        public override bool Intersect(Ray ray, IntersectPt pt)
        {
            double vd = Normal.Dot(ray.GetDirection());
            double vo, t;
            Vector origVec = new Vector(ray.GetOrigin().GetX(), ray.GetOrigin().GetY(), ray.GetOrigin().GetZ());

            if (vd == 0.0f)
            {
                return(false);
            }
            vo = -Normal.Dot(origVec) - D;
            t  = vo / vd;
            if (t < pt.GetThreshold())
            {
                return(false);
            }
            pt.GetIntersection().Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t);
            if (!Check(ray, pt))
            {
                return(false);
            }
            pt.SetT(t);
            pt.SetIntersectObj(this);
            if (GetObjID() == pt.GetOriginal())
            {
                pt.SetEnter(false);
            }
            else
            {
                pt.SetEnter(true);
            }
            GetCachePt().Set(ray.GetID(), pt);
            return(true);
        }
Example #2
0
    /**
     * Intersect
     *
     * @param ray
     * @param pt
     * @return boolean
     */
    public override bool Intersect(Ray ray, IntersectPt pt)
    {
        Vector OC = new Vector();
        double l2OC, tCA, t2HC;

        OC.Sub(Origin, ray.GetOrigin());
        l2OC = OC.SquaredLength();
        tCA  = OC.Dot(ray.GetDirection());
        if (l2OC >= RadiusSquare && tCA <= 0)
        {
            return(false);
        }
        t2HC = RadiusSquare - l2OC + tCA * tCA;
        if (t2HC < 0)
        {
            return(false);
        }
        if (l2OC <= RadiusSquare)
        {
            pt.SetT(tCA + (double)System.Math.Sqrt(t2HC));
            if (pt.GetT() < pt.GetThreshold())
            {
                return(false);
            }
            pt.SetEnter(false);
            pt.GetIntersection().Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, pt.GetT());
        }
        else
        {
            pt.SetT(tCA - (double)System.Math.Sqrt(t2HC));
            pt.SetEnter(true);
            if (pt.GetT() < pt.GetThreshold())
            {
                pt.SetT(tCA + (double)System.Math.Sqrt(t2HC));
                pt.SetEnter(false);
            }
            pt.GetIntersection().Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, pt.GetT());
        }
        pt.SetIntersectObj(this);
        GetCachePt().Set(ray.GetID(), pt);
        return(true);
    }
Example #3
0
	/**
	 * Intersect
	 *
	 * @param ray
	 * @param pt
	 * @return boolean
	 */
	public override bool Intersect(Ray ray, IntersectPt pt)
	{
		double vd = Normal.Dot(ray.GetDirection());
		double vo, t;
		Vector origVec = new Vector(ray.GetOrigin().GetX(), ray.GetOrigin().GetY(), ray.GetOrigin().GetZ());

		if(vd == 0.0f)
		{
			return (false);
		}
		vo = -Normal.Dot(origVec) - D;
		t = vo / vd;
		if(t < pt.GetThreshold())
		{
			return (false);
		}
		pt.GetIntersection().Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t);
		if(!Check(ray, pt))
		{
			return (false);
		}
		pt.SetT(t);
		pt.SetIntersectObj(this);
		if(GetObjID() == pt.GetOriginal())
		{
			pt.SetEnter(false);
		}
		else
		{
			pt.SetEnter(true);
		}
		GetCachePt().Set(ray.GetID(), pt);
		return (true);
	}
Example #4
0
	/**
	 * Intersect
	 *
	 * @param ray
	 * @param pt
	 * @return boolean
	 */
	public override bool Intersect(Ray ray, IntersectPt pt)
	{
		Vector OC = new Vector();
		double l2OC, tCA, t2HC;

		OC.Sub(Origin, ray.GetOrigin());
		l2OC = OC.SquaredLength();
		tCA = OC.Dot(ray.GetDirection());
		if(l2OC >= RadiusSquare && tCA <= 0)
		{
			return (false);
		}
		t2HC = RadiusSquare - l2OC + tCA * tCA;
		if(t2HC < 0)
		{
			return (false);
		}
		if(l2OC <= RadiusSquare)
		{
			pt.SetT(tCA + (double)System.Math.Sqrt(t2HC));
			if(pt.GetT() < pt.GetThreshold())
			{
				return (false);
			}
			pt.SetEnter(false);
			pt.GetIntersection().Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, pt.GetT());
		}
		else
		{
			pt.SetT(tCA - (double)System.Math.Sqrt(t2HC));
			pt.SetEnter(true);
			if(pt.GetT() < pt.GetThreshold())
			{
				pt.SetT(tCA + (double)System.Math.Sqrt(t2HC));
				pt.SetEnter(false);
			}
			pt.GetIntersection().Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, pt.GetT());
		}
		pt.SetIntersectObj(this);
		GetCachePt().Set(ray.GetID(), pt);
		return (true);
	}