示例#1
0
        static void Main(string[] args)
        {
            Box Box1 = new Box(); // Declare Box1 of type Box
            Box Box2 = new Box(); // Declare Box2 of type Box
            Box Box3;             // Declare Box3 of type Box


            // box 1 specification
            Box1.Length = 6.0;
            Box1.Width  = 7.0;
            Box1.Height = 5.0;

            // box 2 specification
            Box2.Length = 12.0;
            Box2.Width  = 13.0;
            Box2.Height = 10.0;



            // Add two object as follows:

            Box3 = Box1 + Box2;

            Box1.PrintBoxDetails();
            Box2.PrintBoxDetails();
            Box3.PrintBoxDetails();



            if (Box1 != Box2)
            {
                Console.WriteLine("Box1 is not equal to Box2");
            }



            if (Box1 == Box2)
            {
                Console.WriteLine("Box1 is equal to Box2");
            }
            else
            {
                Console.WriteLine("Box1 is not equal to Box2");
            }
            //*/



            Person p = new Person {
                Name = "Ali", Age = 2
            };

            Console.WriteLine(p.ToString());
            Person.Display("Shuja");//*/
        }
示例#2
0
        public static string CreatePreview(Box3 data)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("[ min: ");
            CreatePreview(data.min, sb);
            sb.Append(", max: ");
            CreatePreview(data.max, sb);
            sb.Append(" ]");
            return(sb.ToString());
        }
示例#3
0
        private void OnDrawGizmos()
        {
            Plane3 plane = CreatePlane3(Plane);
            Box3   box   = CreateBox3(Box);

            bool test = Intersection.TestPlane3Box3(ref plane, ref box);

            FiguresColor();
            DrawPlane(ref plane, Plane);
            DrawBox(ref box);

            LogInfo("Intersection: " + test);
        }
示例#4
0
        public override IEnumerator <Triangle> GetEnumerator()
        {
            var bounds = new Box3(this.Original);

            foreach (var tri in this.Original)
            {
                yield return(new Triangle(
                                 GetTransformation(bounds.Centre, tri.Item1) * tri.Item1,
                                 GetTransformation(bounds.Centre, tri.Item2) * tri.Item2,
                                 GetTransformation(bounds.Centre, tri.Item3) * tri.Item3
                                 ));
            }
        }
        private void OnDrawGizmos()
        {
            Box3    box    = CreateBox3(Box);
            Sphere3 sphere = CreateSphere3(Sphere);

            bool test = Intersection.TestBox3Sphere3(ref box, ref sphere);

            FiguresColor();
            DrawBox(ref box);
            DrawSphere(ref sphere);

            LogInfo(test);
        }
        private void OnDrawGizmos()
        {
            Box3     box     = CreateBox3(Box);
            Capsule3 capsule = CreateCapsule3(P0, P1, Radius);

            bool intr = Intersection.TestBox3Capsule3(ref box, ref capsule);

            FiguresColor();
            DrawBox(ref box);
            DrawCapsule(ref capsule);

            LogInfo("Intr: " + intr);
        }
示例#7
0
        private void OnDrawGizmos()
        {
            Box3 box0 = CreateBox3(Box0);
            Box3 box1 = CreateBox3(Box1);

            bool test = Intersection.TestBox3Box3(ref box0, ref box1);

            FiguresColor();
            DrawBox(ref box0);
            DrawBox(ref box1);

            LogInfo(test);
        }
示例#8
0
 public Axis(Vector3 direction, float length, Color color)
 {
     selected       = false;
     this.color     = color;
     this.direction = direction;
     this.length    = length;
     axisBox        = new Box3();
     Vector3[] axes = axisBox.getAxes();
     axes[0] = Vector3.Right;
     axes[1] = Vector3.Up;
     axes[2] = Vector3.Forward;
     setupBox();
 }
示例#9
0
 public RotationAxis(Vector3 xAxis, Vector3 yAxis, Vector3 eulerAxis, float radius, Color color)
 {
     this.eulerAxis = eulerAxis;
     axisBox        = new Box3();
     Vector3[] axes = axisBox.getAxes();
     axes[0]    = Vector3.Right;
     axes[1]    = Vector3.Up;
     axes[2]    = Vector3.Forward;
     selected   = false;
     this.color = color;
     this.xAxis = xAxis;
     this.yAxis = yAxis;
     setRadius(radius);
 }
 public void OnZoom(object sender, RoutedEventArgs args)
 {
     try
     {
         Model mod    = _selectedObj as Model;
         Box3  bounds = new Box3();
         Scene scene  = SharedWorld.MainScene;
         mod.GetBound(bounds);
         scene.ZoomToBounds(bounds);
     }
     catch (Exception)
     {
     }
 }
 protected override void OnAppearing()
 {
     base.OnAppearing();
     Task.WhenAll(
         Box1.FadeTo(1, 500, Easing.SinIn),
         Box2.FadeTo(1, 500, Easing.SinIn),
         Box3.FadeTo(1, 500, Easing.SinIn),
         Box4.FadeTo(1, 500, Easing.SinIn),
         Box5.FadeTo(1, 500, Easing.SinIn),
         Box6.FadeTo(1, 500, Easing.SinIn),
         Box7.FadeTo(1, 500, Easing.SinIn),
         Box8.FadeTo(1, 500, Easing.SinIn),
         Box9.FadeTo(1, 500, Easing.SinIn));
 }
示例#12
0
        private void OnDrawGizmos()
        {
            Box3 box0 = CreateBox3(Box0);
            Box3 box1 = CreateBox3(Box1);

            Box3 box = box0;

            box.Include(box1);             // Box which merges box0 and box1

            FiguresColor();
            DrawBox(ref box0);
            DrawBox(ref box1);
            ResultsColor();
            DrawBox(ref box);
        }
示例#13
0
        /*
         * Make the shape for the Kinect depth camera output
         */
        protected Shape MakeCameraOutputShape(Camera cam, bool iscolor)
        {
            Shape         shape     = new Shape();
            Appearance    app       = new Appearance();
            PhongMaterial mtl       = new PhongMaterial(new Col4(1.0f, 1.0f, 1.0f, 0.7f));
            Sampler       sampler   = new Sampler();
            TriMesh       mesh      = new TriMesh("position float 3, normal float 3, texcoord float 2");
            Vec2          videosize = new Vec2(640, 480);
            Vec2          texsize   = new Vec2(1024, 512);
            Box3          vvol      = cam.ViewVol;
            Vec3          campos    = cam.Translation;
            float         camdist   = campos.Length;            // distance of camera from body
            float         backdist  = camdist + vvol.max.z / 6.0f;
            float         h         = backdist * vvol.Height / vvol.min.z;
            float         w         = h;

            backdist -= camdist;
            if (Kinect != null)
            {
                Texture tex = new Texture();
                sampler.Texture = tex;
                if (iscolor)
                {
                    tex.Name            = "magicmirror.kinect.colorimage";
                    Kinect.ColorTexture = tex;
                }
                else
                {
                    tex.Name            = "magicmirror.kinect.depthimage";
                    Kinect.DepthTexture = tex;
                }
            }
            sampler.Name = "diffuse";
            sampler.Set(Sampler.TEXTUREOP, Sampler.DIFFUSE);
            sampler.Set(Sampler.TEXCOORD, 0);
            app.Set(Appearance.CULLING, 1);
            app.Set(Appearance.LIGHTING, 1);
            app.Set(Appearance.TRANSPARENCY, 1);
            app.SetSampler(0, sampler);
            app.Material     = mtl;
            app.Name         = "cameraoutput";
            shape.Appearance = app;
            GeoUtil.Rect(mesh, h * videosize.x / videosize.y, h, videosize.x / texsize.x, videosize.y / texsize.y);
            shape.Geometry = mesh;
            shape.Name     = "magicmirror.kinect.camerashape";
            shape.Translate(0, h / 2, -backdist);
            return(shape);
        }
        private void OnDrawGizmos()
        {
            Vector3 point = Point.position;
            Box3    box   = CreateBox3(Box);

            Vector3 closestPoint;
            float   dist = Distance.Point3Box3(ref point, ref box, out closestPoint);

            FiguresColor();
            DrawBox(ref box);

            ResultsColor();
            DrawPoint(closestPoint);

            LogInfo(dist);
        }
示例#15
0
        /// <summary>
        /// 
        /// </summary>
        public override void ComputeBoundingSphere()
        {
            var box = new Box3();

            if (this.BoundingSphere == null)
            {
                this.BoundingSphere = new Sphere();
            }

            var bufferAttribute = this.Attributes["position"] as BufferAttribute<float>;
            Debug.Assert(null != bufferAttribute);

            var positions = bufferAttribute.Array;

            if (null  != positions)
            {
     	        box.MakeEmpty();

                var center = this.BoundingSphere.Center;

                for ( var i = 0; i < positions.Length; i += 3 )
                {
                    var vector = new Vector3(positions[i], positions[i + 1], positions[i + 2]);
                    box.ExpandByPoint(vector);
                }

                box.Center(center);
   
            	// hoping to find a boundingSphere with a radius smaller than the
                // boundingSphere of the boundingBox: sqrt(3) smaller in the best case

                var maxRadiusSq = float.NegativeInfinity;

                for ( var i = 0; i < positions.Length; i += 3 )
                {
                    var vector = new Vector3(positions[i], positions[i + 1], positions[i + 2]);
                    maxRadiusSq = Math.Max(maxRadiusSq, center.DistanceToSquared(vector));
                }

                this.BoundingSphere.Radius = (float)Math.Sqrt(maxRadiusSq);

                //if ()
                //{
                //    Trace.TraceError( "BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The 'position' attribute is likely to have NaN values." );            
                //}
            }
        }
示例#16
0
        public override void Read(BinaryStream bs)
        {
            BinaryReader Read = bs.Read;

            Magic        = Read.String(5);
            Version      = Read.UShort();
            MeshUsage    = Read.Byte();
            Bounds       = Read.Type <Box3>();
            TangentType  = (TangentType)Read.Byte();
            TangentSplit = (Read.Byte() == 1);

            Vertices = bs.Read.TypeList <Vector3>(Read.Int());

            if (Read.Int() != 0)
            {
                throw new Exception("uh oh, this mesh has vertex lod positions");
            }

            Normals      = Read.TypeList <Normal>(Read.Int());
            TextureUVs   = Read.TypeList <UV>(Read.Int());
            NormalUVs    = Read.TypeList <UV>(Read.Int());
            Tangents     = Read.TypeList <Tangent>(Read.Int());
            VertexColors = Read.UIntList(Read.Int());
            FaceIndex    = Read.UIntList(Read.Int());
            Faces        = Read.TypeList <Face>(Read.Int());
            Bones        = Read.TypeList <Bone>(Read.Int());
            Links        = Read.TypeList <Link>(Read.Int());
            BoneWeights  = Read.TypeList <BoneWeight>(Read.Int());
            Hardpoints   = Read.TypeList <Hardpoint>(Read.Int());

            int referenceMeshFileNameLength = Read.Int();

            if (referenceMeshFileNameLength > 0)
            {
                ReferenceMeshFileName = Read.String();
            }

            ReferenceMeshFileTime = Read.ULong();
            ReferenceMeshType     = (MeshType)Read.Byte();

            BaseVariantDiffs = Read.TypeList <BaseVariantDiff>(Read.Int());
            ConformWeights   = Read.TypeList <ConformWeight>(Read.Int());
            MaterialSections = Read.TypeList <MaterialSection>(Read.Int());

            Console.WriteLine(Hardpoints.Count);
        }
示例#17
0
        private void OnDrawGizmos()
        {
            Vector3 point = Point.position;
            Box3    box   = CreateBox3(Box);

            bool cont = box.Contains(point);

            FiguresColor();
            DrawBox(ref box);
            if (cont)
            {
                ResultsColor();
            }
            DrawPoint(point);

            LogInfo(cont);
        }
示例#18
0
        private void OnDrawGizmos()
        {
            Segment3 segment = CreateSegment3(P0, P1);
            Box3     box     = CreateBox3(Box);

            Vector3 closestPoint0, closestPoint1;
            float   dist = Distance.Segment3Box3(ref segment, ref box, out closestPoint0, out closestPoint1);

            FiguresColor();
            DrawSegment(ref segment);
            DrawBox(ref box);

            ResultsColor();
            DrawPoint(closestPoint0);
            DrawPoint(closestPoint1);

            LogInfo("Dist: " + dist);
        }
示例#19
0
        private void OnDrawGizmos()
        {
            Line3 line = CreateLine3(Line);
            Box3  box  = CreateBox3(Box);

            Line3Box3Dist info;
            float         dist = Distance.Line3Box3(ref line, ref box, out info);

            FiguresColor();
            DrawLine(ref line);
            DrawBox(ref box);

            ResultsColor();
            DrawPoint(info.ClosestPoint0);
            DrawPoint(info.ClosestPoint1);

            LogInfo("Dist: " + dist + " LineParam: " + info.LineParameter);
        }
        protected void DrawBox(ref Box3 box)
        {
            Vector3 v0, v1, v2, v3, v4, v5, v6, v7;

            box.CalcVertices(out v0, out v1, out v2, out v3, out v4, out v5, out v6, out v7);
            Gizmos.DrawLine(v0, v1);
            Gizmos.DrawLine(v1, v2);
            Gizmos.DrawLine(v2, v3);
            Gizmos.DrawLine(v3, v0);
            Gizmos.DrawLine(v4, v5);
            Gizmos.DrawLine(v5, v6);
            Gizmos.DrawLine(v6, v7);
            Gizmos.DrawLine(v7, v4);
            Gizmos.DrawLine(v0, v4);
            Gizmos.DrawLine(v1, v5);
            Gizmos.DrawLine(v2, v6);
            Gizmos.DrawLine(v3, v7);
        }
示例#21
0
 private void Reset()
 {
     Box1.Load("Res/box1.png");
     Box2.Load("Res/box1.png");
     Box3.Load("Res/box1.png");
     Box4.Load("Res/box1.png");
     Box5.Load("Res/box1.png");
     Box6.Load("Res/box1.png");
     Box7.Load("Res/box1.png");
     Box8.Load("Res/box1.png");
     Box9.Load("Res/box1.png");
     Box10.Load("Res/box1.png");
     Box11.Load("Res/box1.png");
     Box12.Load("Res/box1.png");
     Box13.Load("Res/box1.png");
     Box14.Load("Res/box1.png");
     Box15.Load("Res/box1.png");
     Box16.Load("Res/box1.png");
     Box1.Enabled   = false;
     Box2.Enabled   = false;
     Box3.Enabled   = false;
     Box4.Enabled   = false;
     Box5.Enabled   = false;
     Box6.Enabled   = false;
     Box7.Enabled   = false;
     Box8.Enabled   = false;
     Box9.Enabled   = false;
     Box10.Enabled  = false;
     Box11.Enabled  = false;
     Box12.Enabled  = false;
     Box13.Enabled  = false;
     Box14.Enabled  = false;
     Box15.Enabled  = false;
     Box16.Enabled  = false;
     timer1.Enabled = false;
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             tab[i, j] = 1;
         }
     }
 }
        private void OnDrawGizmos()
        {
            Plane3  plane  = CreatePlane3(Plane);
            Vector3 point  = Point.position;
            AAB3    aab    = CreateAAB3(AABMin, AABMax);
            Box3    box    = CreateBox3(Box);
            Sphere3 sphere = CreateSphere3(Sphere);

            // Get side information.
            // -1 - on the negative side of the plane
            //  0 - on the plane or intersecting the plane
            // +1 - on the positive side of the plane
            int pointSide  = plane.QuerySide(point);
            int aabSide    = plane.QuerySide(ref aab);
            int boxSide    = plane.QuerySide(ref box);
            int sphereSide = plane.QuerySide(ref sphere);

            // true when an object is on the positive side of the plane
            bool pointPos  = plane.QuerySidePositive(point);
            bool aabPos    = plane.QuerySidePositive(ref aab);
            bool boxPos    = plane.QuerySidePositive(ref box);
            bool spherePos = plane.QuerySidePositive(ref sphere);

            // true when an object is on the negative side of the plane
            bool pointNeg  = plane.QuerySideNegative(point);
            bool aabNeg    = plane.QuerySideNegative(ref aab);
            bool boxNeg    = plane.QuerySideNegative(ref box);
            bool sphereNeg = plane.QuerySideNegative(ref sphere);

            // Note that positive/negative tests are little bit more optimized than just query,
            // as they don't have separate check for 0 case.

            FiguresColor();
            DrawPlane(ref plane, Plane);

            SetColor(pointSide); DrawPoint(point);
            SetColor(aabSide); DrawAAB(ref aab);
            SetColor(boxSide); DrawBox(ref box);
            SetColor(sphereSide); DrawSphere(ref sphere);

            LogInfo("PointSignedDistance: " + plane.SignedDistanceTo(point) + " PointNeg: " + pointNeg + " PointPos: " + pointPos + "     AABNeg: " + aabNeg + " AABPos: " + aabPos + "     BoxNeg: " + boxNeg + " BoxPos: " + boxPos + "     SphereNeg: " + sphereNeg + " SpherePos: " + spherePos);
        }
示例#23
0
文件: Ray3.cs 项目: minskowl/MY
        /// <summary>Determines where the range clips a box</summary>
        /// <param name="box">Box that will be checked for intersection</param>
        /// <returns>The times at which the range enters or leaves the volume</returns>
        public LineContacts FindContacts(Box3 box)
        {
            // Convert line to box coordinates
            Vector3 offset = Origin - box.Center;

            Vector3 relativePosition = new Vector3(
                Vector3.Dot(offset, box.Transform.Right),
                Vector3.Dot(offset, box.Transform.Up),
                Vector3.Dot(offset, box.Transform.Forward)
                );
            Vector3 relativeDirection = new Vector3(
                Vector3.Dot(Direction, box.Transform.Right),
                Vector3.Dot(Direction, box.Transform.Up),
                Vector3.Dot(Direction, box.Transform.Forward)
                );

            return(Collisions.Ray3Aabb3Collider.FindContacts(
                       relativePosition, relativeDirection, box.Dimensions / 2.0f
                       ));
        }
示例#24
0
        /// <summary>Determines where the range clips a box</summary>
        /// <param name="box">Box that will be checked for intersection</param>
        /// <returns>The times at which the range enters or leaves the volume</returns>
        public LineContacts FindContacts(Box3 box)
        {
            // Convert line to box coordinates
            Vector3 difference = Offset - box.Center;

            Vector3 relativeCenter = new Vector3(
                Vector3.Dot(difference, box.Transform.Right),
                Vector3.Dot(difference, box.Transform.Up),
                Vector3.Dot(difference, box.Transform.Forward)
                );
            Vector3 relativeDirection = new Vector3(
                Vector3.Dot(Direction, box.Transform.Right),
                Vector3.Dot(Direction, box.Transform.Up),
                Vector3.Dot(Direction, box.Transform.Forward)
                );

            return(Collisions.Line3Aabb3Collider.FindContacts(
                       relativeCenter, relativeDirection, box.Dimensions / 2.0f
                       ));
        }
    /// <summary>
    /// Uses <see cref="MeshVoxelizer"/> to build voxel object collection from the source mesh.
    /// </summary>
    /// <param name="size">xyz size of the voxel object collection</param>
    public void GenerateBlocks(int size)
    {
        Color defaultColor = gameObject.GetComponent <BlockDrawer>().selectedColor;

        voxelObject.SetActive(true);
        var bounds = srcMesh.bounds;
        var max    = bounds.extents.x;

        if (max < bounds.extents.y)
        {
            max = bounds.extents.y;
        }
        if (max < bounds.extents.z)
        {
            max = bounds.extents.z;
        }
        var  center = srcMesh.bounds.center;
        Box3 box    = new Box3(center - new Vector3(max, max, max), center + new Vector3(max, max, max));

        meshVoxelizer = new MeshVoxelizer(size, size, size);
        meshVoxelizer.Voxelize(srcMesh.vertices, srcMesh.triangles, box);

        for (int i = 0; i < meshVoxelizer.Voxels.GetLength(0); i++)
        {
            for (int j = 0; j < meshVoxelizer.Voxels.GetLength(1); j++)
            {
                for (int k = 0; k < meshVoxelizer.Voxels.GetLength(2); k++)
                {
                    if (meshVoxelizer.Voxels[i, j, k] == 1)
                    {
                        GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        cube.transform.parent        = voxelObject.transform;
                        cube.transform.localPosition = new Vector3(i, j, k);
                        cube.tag = "Voxel";
                        cube.GetComponent <MeshRenderer>().material.color = defaultColor;
                    }
                }
            }
        }
        sourceObject.SetActive(false);
    }
示例#26
0
文件: Ray.cs 项目: qkmaxware/Geometry
        /// <summary>
        /// Determine if this ray intersects with the given box3
        /// </summary>
        /// <param name="aabb">3d box</param>
        /// <param name="hit">the coordinate of the collision</param>
        /// <returns>true if there was a collision</returns>
        public bool Cast(Box3 aabb, out Vec3 hit)
        {
            double t1 = (aabb.Min.X - this.Origin.X) / this.Direction.X;
            double t2 = (aabb.Max.X - this.Origin.X) / this.Direction.X;
            double t3 = (aabb.Min.Y - this.Origin.Y) / this.Direction.Y;
            double t4 = (aabb.Max.Y - this.Origin.Y) / this.Direction.Y;
            double t5 = (aabb.Min.Z - this.Origin.Z) / this.Direction.Z;
            double t6 = (aabb.Max.Z - this.Origin.Z) / this.Direction.Z;

            double tmin = Math.Max(Math.Max(Math.Min(t1, t2), Math.Min(t3, t4)), Math.Min(t5, t6));
            double tmax = Math.Min(Math.Min(Math.Max(t1, t2), Math.Max(t3, t4)), Math.Max(t5, t6));

            // if tmax < 0, ray (line) is intersecting AABB, but whole AABB is behind us
            if (tmax < 0)
            {
                hit = Origin;
                return(false);
            }

            // if tmin > tmax, ray doesn't intersect AABB
            if (tmin > tmax)
            {
                hit = Origin;
                return(false);
            }

            if (tmin < 0f)
            {
                hit = this[tmax];
                return(true); // tmax is the distance
            }
            else
            {
                hit = this[tmin];
                return(true); // tmin is the distance
            }
        }
示例#27
0
        private void Box2_KeyPress(object sender, KeyPressEventArgs e)
        {
            //Only Accept a ':', a '-', a numeral, a - f / A - F, or backspace
            if (IsValidChar(e.KeyChar) || e.KeyChar.ToString() == ":" || e.KeyChar.ToString() == "-" || Char.IsDigit(e.KeyChar) || e.KeyChar == 8)
            {
                //If the key pressed is a ':' or '-'
                if (e.KeyChar.ToString() == ":" || e.KeyChar.ToString() == "-")
                {
                    //If the Text is valid move to the next box
                    if (Box2.Text != "" && Box2.Text.Length != Box2.SelectionLength)
                    {
                        Box3.Focus();
                    }
                    e.Handled = true;
                }

                //If we are not overwriting the whole text
                else if (Box2.SelectionLength != Box2.Text.Length)
                {
                    //Check that the new Text value will be valid
                    // then move on to next box
                    if (Box2.Text.Length == 1)
                    {
                        if (e.KeyChar != 8)
                        {
                            KeyPressBuffer.KeyChar = e.KeyChar;
                            Box3.Focus();
                        }
                    }
                }
            }
            //Do nothing if the keypress is not a hex value, backspace, '-', or ':'
            else
            {
                e.Handled = true;
            }
        }
示例#28
0
 public static void GetFloatv(uint pname, out Box3 data)
 {
     m_GetFloatv_9(pname, out data);
     if(m_debug) CheckError("GetFloatv");
 }
示例#29
0
 public void Update()
 {
     box      = Box3.FromObject(o);
     Scale    = box.Size();
     Position = box.Center();
 }
示例#30
0
文件: Ray.cs 项目: prepare/three.net
        public Vector3? IntersectBox(Box3 box)
        {
		// http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
            var invdirx = 1 / direction.x;
            var invdiry = 1 / direction.y;
            var invdirz = 1 / direction.z;
            float tmin,tmax,tymin, tymax, tzmin,tzmax;

		if ( invdirx >= 0 ) 
        {

			tmin = ( box.min.x - origin.x ) * invdirx;
			tmax = ( box.max.x - origin.x ) * invdirx;

		} else {

			tmin = ( box.max.x - origin.x ) * invdirx;
			tmax = ( box.min.x - origin.x ) * invdirx;
		}

		if ( invdiry >= 0 ) {

			tymin = ( box.min.y - origin.y ) * invdiry;
			tymax = ( box.max.y - origin.y ) * invdiry;

		} else {

			tymin = ( box.max.y - origin.y ) * invdiry;
			tymax = ( box.min.y - origin.y ) * invdiry;
		}

		if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;

		// These lines also handle the case where tmin or tmax is NaN
		// (result of 0 * Infinity). x !== x returns true if x is NaN
		if ( tymin > tmin || tymin != tmin ) tmin = tymin;
		if ( tymax < tmax || tymax != tmax ) tmax = tymax;

		if ( invdirz >= 0 ) {
			tzmin = ( box.min.z - origin.z ) * invdirz;
			tzmax = ( box.max.z - origin.z ) * invdirz;

		} else {

			tzmin = ( box.max.z - origin.z ) * invdirz;
			tzmax = ( box.min.z - origin.z ) * invdirz;
		}

		if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;

		if ( tzmin > tmin || tzmin != tmin ) tmin = tzmin;
		if ( tzmax < tmax || tzmax != tmax ) tmax = tzmax;

		//return point closest to the ray (positive side)

		if ( tmax < 0 ) return null;

		return At( tmin >= 0 ? tmin : tmax);
        }
示例#31
0
文件: Ray.cs 项目: prepare/three.net
	    public bool IsIntersectionBox(Box3 box) 
        {
            return IntersectBox( box) != null;
		}
示例#32
0
        public void ComputeBoundingBox()
        {
            BoundingBox = Box3.FromPoints(vertices);
		}
示例#33
0
        public Vector3?IntersectBox(Box3 box)
        {
            // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
            var   invdirx = 1 / direction.x;
            var   invdiry = 1 / direction.y;
            var   invdirz = 1 / direction.z;
            float tmin, tmax, tymin, tymax, tzmin, tzmax;

            if (invdirx >= 0)
            {
                tmin = (box.min.x - origin.x) * invdirx;
                tmax = (box.max.x - origin.x) * invdirx;
            }
            else
            {
                tmin = (box.max.x - origin.x) * invdirx;
                tmax = (box.min.x - origin.x) * invdirx;
            }

            if (invdiry >= 0)
            {
                tymin = (box.min.y - origin.y) * invdiry;
                tymax = (box.max.y - origin.y) * invdiry;
            }
            else
            {
                tymin = (box.max.y - origin.y) * invdiry;
                tymax = (box.min.y - origin.y) * invdiry;
            }

            if ((tmin > tymax) || (tymin > tmax))
            {
                return(null);
            }

            // These lines also handle the case where tmin or tmax is NaN
            // (result of 0 * Infinity). x !== x returns true if x is NaN
            if (tymin > tmin || tymin != tmin)
            {
                tmin = tymin;
            }
            if (tymax < tmax || tymax != tmax)
            {
                tmax = tymax;
            }

            if (invdirz >= 0)
            {
                tzmin = (box.min.z - origin.z) * invdirz;
                tzmax = (box.max.z - origin.z) * invdirz;
            }
            else
            {
                tzmin = (box.max.z - origin.z) * invdirz;
                tzmax = (box.min.z - origin.z) * invdirz;
            }

            if ((tmin > tzmax) || (tzmin > tmax))
            {
                return(null);
            }

            if (tzmin > tmin || tzmin != tmin)
            {
                tmin = tzmin;
            }
            if (tzmax < tmax || tzmax != tmax)
            {
                tmax = tzmax;
            }

            //return point closest to the ray (positive side)

            if (tmax < 0)
            {
                return(null);
            }

            return(At(tmin >= 0 ? tmin : tmax));
        }
 public static Box3 BoundingBox(this IPartialPolysurface @this)
 {
     return(Box3.Hull(@this.Vertices.Select(v => v.Point)));
 }
示例#35
0
 public void Update()
 {
     box = Box3.FromObject(o);
     Scale = box.Size();
     Position = box.Center();
 }