Esempio n. 1
0
 public LMesh(Ray ray, Color c)
     : this(new Point3f[]{ray.position, ray.position+ray.direction}, c, new ushort[]{0, 1})
 {
 }
Esempio n. 2
0
 public LMesh(Ray ray)
     : this(ray, new Color(1f, 0f, 0f))
 {
 }
Esempio n. 3
0
        // Finds if the ray intersects the bounding volume
        public override bool intersects(ref Ray ray)
        {
            // Variables
            bool	bInside=	true;
            byte[]	quad=	new byte[3];
            int	plane;
            float[]	maxT=	new float[3];
            Point3f	cPlane=	Point3f.ORIGIN;

            if(ray.position.x< min.x)
            {
                quad[0]=	0;
                cPlane.x=	min.x;
                bInside=	false;
            }
            else if(ray.position.x> max.x)
            {
                quad[0]=	1;
                cPlane.x=	max.x;
                bInside=	false;
            }
            else
                quad[0]=	2;

            if(ray.position.y< min.y)
            {
                quad[1]=	0;
                cPlane.y=	min.y;
                bInside=	false;
            }
            else if(ray.position.y> max.y)
            {
                quad[1]=	1;
                cPlane.y=	max.y;
                bInside=	false;
            }
            else
                quad[1]=	2;

            if(ray.position.z< min.z)
            {
                quad[2]=	0;
                cPlane.z=	min.z;
                bInside=	false;
            }
            else if(ray.position.z> max.z)
            {
                quad[2]=	1;
                cPlane.z=	max.z;
                bInside=	false;
            }
            else
                quad[2]=	2;

            if(bInside)
                return true;

            if(quad[0]!= 2 && ray.direction.x!= 0)
                maxT[0]=	(cPlane.x-ray.position.x)/ray.direction.x;
            else
                maxT[0]=	-1;

            if(quad[1]!= 2 && ray.direction.y!= 0)
                maxT[1]=	(cPlane.y-ray.position.y)/ray.direction.y;
            else
                maxT[1]=	-1;

            if(quad[2]!= 2 && ray.direction.z!= 0)
                maxT[2]=	(cPlane.z-ray.position.z)/ray.direction.z;
            else
                maxT[2]=	-1;

            plane=	0;
            for(int i= 0; i< maxT.Length; i++)
            {
                if(maxT[plane]< maxT[i])
                    plane=	i;
            }

            if(maxT[plane]< 0)
                return false;
            if(plane!= 0)
            {
                cPlane.x=	ray.position.x+maxT[plane]*ray.direction.x;
                if(cPlane.x< min.x || cPlane.x> max.x)
                    return false;
            }
            if(plane!= 1)
            {
                cPlane.y=	ray.position.y+maxT[plane]*ray.direction.y;
                if(cPlane.y< min.y || cPlane.y> max.y)
                    return false;
            }
            if(plane!= 2)
            {
                cPlane.z=	ray.position.z+maxT[plane]*ray.direction.z;
                if(cPlane.z< min.z || cPlane.z> max.z)
                    return false;
            }

            return (maxT[plane]< 1f);

            /*
            float[]	txyz=	new float[6];
            float	tmin;
            float	tmax;

            txyz[0]=	(pMin.x-ray.position.x)/ray.direction.x;
            txyz[1]=	(pMax.x-ray.position.x)/ray.direction.x;
            txyz[2]=	(pMin.y-ray.position.y)/ray.direction.y;
            txyz[3]=	(pMax.y-ray.position.y)/ray.direction.y;
            txyz[4]=	(pMin.z-ray.position.z)/ray.direction.z;
            txyz[5]=	(pMax.z-ray.position.z)/ray.direction.z;

            if(txyz[0]> txyz[3] || txyz[2]> txyz[1])
                return false;
            tmin=	Mathx.max(txyz[0], txyz[2]);
            tmax=	Mathx.min(txyz[1], txyz[3]);

            if(tmin> txyz[5] || txyz[4]> tmax)
                return false;

            return true;*/
        }
Esempio n. 4
0
        // Gets the picking ray
        public static Ray getPickingRay(ref BasicCamera cam, ref Viewport viewport)
        {
            // Variables
            double[]	mdlv=	new double[16];
            double[]	proj=	new double[16];
            int[]	v=	new int[4];
            double	mx, my;
            double	nx, ny, nz;
            double	fx, fy, fz;
            MouseState	mouse=	GameInput.getMouseState();
            Ray	ray;

            Gl.glGetDoublev(Gl.GL_PROJECTION_MATRIX, proj);
            Gl.glGetDoublev(Gl.GL_MODELVIEW_MATRIX, mdlv);
            Gl.glGetIntegerv(Gl.GL_VIEWPORT, v);
            mx=	(double)mouse.x;
            my=	(double)v[3]-(double)mouse.y;

            Glu.gluUnProject(mx, my, 0f, mdlv, proj, v, out nx, out ny, out nz);
            Glu.gluUnProject(mx, my, 1f, mdlv, proj, v, out fx, out fy, out fz);

            ray=	new Ray(new Point3f((float)nx, (float)ny, (float)nz), new Point3f((float)fx, (float)fy, (float)fz));

            return ray;
        }
Esempio n. 5
0
 public virtual bool intersects(Ray ray)
 {
     return intersects(ref ray);
 }
Esempio n. 6
0
 // Finds if the ray intersects the bounding volume
 public virtual bool intersects(ref Ray ray)
 {
     return false;
 }
Esempio n. 7
0
 // Finds if the two rays are equal
 public bool equals(Ray ray)
 {
     return (position== ray.position && direction== ray.direction);
 }
Esempio n. 8
0
 public bool intersects(Ray ray)
 {
     return intersects(ref ray);
 }
Esempio n. 9
0
        // Finds if the two rays intersect
        public bool intersects(ref Ray ray)
        {
            // Variables
            Vector3	vec=	direction.getCrossProduct(ray.direction);
            float	a=	vec.getMagnitude();

            if(Mathx.isZero(a) && position.x== ray.position.x && position.y== ray.position.y && position.z== ray.position.z)
                return true;

            // Variables
            float[]	n=	new float[27];
            Vector3	vox;

            a*=	a;
            n[0]=	ray.position.x-position.x;
            n[1]=	ray.position.y-position.y;
            n[2]=	ray.position.z-position.z;
            n[3]=	vec.x;
            n[4]=	vec.y;
            n[5]=	vec.z;
            n[6]=	(n[0]*ray.direction.y*n[5]+n[1]*ray.direction.z*n[3]+n[2]*ray.direction.x*n[4]-n[0]*ray.direction.z*n[4]-n[1]*ray.direction.x*n[5]-n[2]*ray.direction.y*n[3]);
            n[7]=	(n[0]*direction.y*n[5]+n[1]*direction.z*n[3]+n[2]*direction.x*n[4]-n[0]*direction.z*n[4]-n[1]*direction.x*n[5]-n[2]*direction.y*n[3]);
            n[8]=	n[6]/a;
            n[9]=	n[7]/a;
            vec=	(Vector3)position+n[8]*direction;
            vox=	(Vector3)(ray.position)+n[8]*ray.direction;

            if(vec!= vox)
                return false;

            return true;
        }