示例#1
0
		public void DifferenceTestsForBox()
		{
			SolidMaterial redMaterial = new SolidMaterial(RGBA_Floats.Red, 0, 0, 0);
			SolidMaterial blueMaterial = new SolidMaterial(RGBA_Floats.Blue, 0, 0, 0);
			Ray castRay = new Ray(new Vector3(0, -1, 0), Vector3.UnitY);

			BoxShape box1X1 = new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, .5, .5), blueMaterial);

			// just a box all by itself
			{
				IntersectInfo testInfo = box1X1.GetClosestIntersection(castRay);

				Assert.IsTrue(testInfo.hitType == IntersectionType.FrontFace, "Found Hit : Box No CSG");
				Assert.IsTrue(testInfo.closestHitObject == box1X1, "Found Hit : Box No CSG");
				Assert.IsTrue(testInfo.hitPosition == new Vector3(0, -.5, 0), "Hit position y = -.5 : Box No CSG");
				Assert.IsTrue(testInfo.distanceToHit == .5, "Hit length = .5 : Box No CSG");
				Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : Box No CSG");
			}

			// one subtract from the front of a box, the front faces are aligned
			{
				BoxShape subtractBox = new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, 0, .5), redMaterial);
				Difference merge = new Difference(box1X1, subtractBox);
				IntersectInfo testInfo = merge.GetClosestIntersection(castRay);

				Assert.IsTrue(testInfo.hitType == IntersectionType.FrontFace, "Found Hit : One Subtract");
				Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : One Subtract");
				Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : One Subtract");
				Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : One Subtract");
				Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : One Subtract");
			}

#if false
            // An internal primary object that needs to be skipped over
            {
                List<IPrimitive> primaryShapes = new List<IPrimitive>();
                BoxShape insideBox = new BoxShape(new Vector3(-.1, -.1, -.1), new Vector3(.1, .1, .1), blueMaterial);
                primaryShapes.Add(box1X1);
                primaryShapes.Add(insideBox);
                IPrimitive primamryGroup = BoundingVolumeHierarchy.CreateNewHierachy(primaryShapes);

                List<IPrimitive> subtractShapes = new List<IPrimitive>();
                subtractShapes.Add(new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, .4, .5), redMaterial));

                IPrimitive subtractGroup = BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes);
                Difference merge = new Difference(primamryGroup, subtractGroup);

                IntersectInfo testInfo = merge.GetClosestIntersection(castRay);

                Assert.IsTrue(testInfo.isHit == true, "Found Hit : 5 Subtracts");
                //Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : 5 Subtracts");
                Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : 5 Subtracts");
                Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : 5 Subtracts");
                Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : 5 Subtracts");
            }

            // Go through 5 subtract boxes to get to 1/2 way through the main box.
            {
                List<IPrimitive> subtractShapes = new List<IPrimitive>();

                for (int i = 0; i < 5; i++)
                {
                    subtractShapes.Add(new BoxShape(new Vector3(-.5, -.5 + i * .1, -.5), new Vector3(.5, -.4 + i * .1, .5), redMaterial));
                }

                IPrimitive subtractGroup = BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes);
                Difference merge = new Difference(box1X1, subtractGroup);

                IntersectInfo testInfo = merge.GetClosestIntersection(castRay);

                Assert.IsTrue(testInfo.isHit == true, "Found Hit : 5 Subtracts");
                //Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : 5 Subtracts");
                Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : 5 Subtracts");
                Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : 5 Subtracts");
                Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : 5 Subtracts");
            }
#endif
		}
示例#2
0
        public void DifferenceTestsForBox()
        {
            SolidMaterial redMaterial  = new SolidMaterial(RGBA_Floats.Red, 0, 0, 0);
            SolidMaterial blueMaterial = new SolidMaterial(RGBA_Floats.Blue, 0, 0, 0);
            Ray           castRay      = new Ray(new Vector3(0, -1, 0), Vector3.UnitY);

            BoxShape box1X1 = new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, .5, .5), blueMaterial);

            // just a box all by itself
            {
                IntersectInfo testInfo = box1X1.GetClosestIntersection(castRay);

                Assert.IsTrue(testInfo.hitType == IntersectionType.FrontFace, "Found Hit : Box No CSG");
                Assert.IsTrue(testInfo.closestHitObject == box1X1, "Found Hit : Box No CSG");
                Assert.IsTrue(testInfo.hitPosition == new Vector3(0, -.5, 0), "Hit position y = -.5 : Box No CSG");
                Assert.IsTrue(testInfo.distanceToHit == .5, "Hit length = .5 : Box No CSG");
                Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : Box No CSG");
            }

            // one subtract from the front of a box, the front faces are aligned
            {
                BoxShape      subtractBox = new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, 0, .5), redMaterial);
                Difference    merge       = new Difference(box1X1, subtractBox);
                IntersectInfo testInfo    = merge.GetClosestIntersection(castRay);

                Assert.IsTrue(testInfo.hitType == IntersectionType.FrontFace, "Found Hit : One Subtract");
                Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : One Subtract");
                Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : One Subtract");
                Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : One Subtract");
                Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : One Subtract");
            }

#if false
            // An internal primary object that needs to be skipped over
            {
                List <IRayTraceable> primaryShapes = new List <IRayTraceable>();
                BoxShape             insideBox     = new BoxShape(new Vector3(-.1, -.1, -.1), new Vector3(.1, .1, .1), blueMaterial);
                primaryShapes.Add(box1X1);
                primaryShapes.Add(insideBox);
                IRayTraceable primamryGroup = BoundingVolumeHierarchy.CreateNewHierachy(primaryShapes);

                List <IRayTraceable> subtractShapes = new List <IRayTraceable>();
                subtractShapes.Add(new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, .4, .5), redMaterial));

                IRayTraceable subtractGroup = BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes);
                Difference    merge         = new Difference(primamryGroup, subtractGroup);

                IntersectInfo testInfo = merge.GetClosestIntersection(castRay);

                Assert.IsTrue(testInfo.isHit == true, "Found Hit : 5 Subtracts");
                //Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : 5 Subtracts");
                Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : 5 Subtracts");
                Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : 5 Subtracts");
                Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : 5 Subtracts");
            }

            // Go through 5 subtract boxes to get to 1/2 way through the main box.
            {
                List <IRayTraceable> subtractShapes = new List <IRayTraceable>();

                for (int i = 0; i < 5; i++)
                {
                    subtractShapes.Add(new BoxShape(new Vector3(-.5, -.5 + i * .1, -.5), new Vector3(.5, -.4 + i * .1, .5), redMaterial));
                }

                IRayTraceable subtractGroup = BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes);
                Difference    merge         = new Difference(box1X1, subtractGroup);

                IntersectInfo testInfo = merge.GetClosestIntersection(castRay);

                Assert.IsTrue(testInfo.isHit == true, "Found Hit : 5 Subtracts");
                //Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : 5 Subtracts");
                Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : 5 Subtracts");
                Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : 5 Subtracts");
                Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : 5 Subtracts");
            }
#endif
        }
示例#3
0
		private void AddAxisMarker()
		{
			int count = 10;
			double size = .1;
			for (int i = 1; i < count + 1; i++)
			{
				RGBA_Floats xColor = new RGBA_Floats(1, i / (double)count, i / (double)count);
				SolidMaterial xMaterial = new SolidMaterial(xColor, 0, 0.0, 2.0);
				BoxShape xBox = new BoxShape(new Vector3(i * size, 0, 0), new Vector3(i * size + size, size, size), xMaterial);
				renderCollection.Add(xBox);

				RGBA_Floats yColor = new RGBA_Floats(i / (double)count, 1, i / (double)count);
				SolidMaterial yMaterial = new SolidMaterial(yColor, 0, 0.0, 2.0);
				BoxShape yBox = new BoxShape(new Vector3(0, i * size, 0), new Vector3(size, i * size + size, size), yMaterial);
				//yBox.Transform.Position += new Vector3D(1, 1, 1);
				renderCollection.Add(yBox);

				RGBA_Floats zColor = new RGBA_Floats(i / (double)count, i / (double)count, 1);
				SolidMaterial zMaterial = new SolidMaterial(zColor, 0, 0.0, 2.0);
				BoxShape zBox = new BoxShape(new Vector3(0, 0, i * size), new Vector3(size, size, i * size + size), zMaterial);
				renderCollection.Add(zBox);
			}
		}
示例#4
0
		private void AddSphereAndBox()
		{
			// setup a solid reflecting sphere
			double radius = 1.5;
			BaseShape bigSphere = new SphereShape(new Vector3(1, 4, -3), radius, new SolidMaterial(new RGBA_Floats(0, .5, .5), 0.2, 0.0, 2.0));
			renderCollection.Add(bigSphere);

			BoxShape box = new BoxShape(new Vector3(-1, 0, -4), new Vector3(1, 2, -2),
							   new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0));
			renderCollection.Add(box);
		}
示例#5
0
		private void AddBoxAndBoxBooleanTest()
		{
			BoxShape box1 = new BoxShape(new Vector3(.5, .5, .5), new Vector3(1.5, 1.5, 1.5),
							   new SolidMaterial(RGBA_Floats.Green, .01, 0.0, 2.0));

			List<IPrimitive> subtractShapes = new List<IPrimitive>();
			SolidMaterial material = new SolidMaterial(RGBA_Floats.Red, 0, 0, 0);
			subtractShapes.Add(new BoxShape(new Vector3(), new Vector3(1, 1, 1), material));

			IPrimitive subtractGroup = BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes);
			Difference merge = new Difference(box1, subtractGroup);

			renderCollection.Add(merge);
		}
示例#6
0
		private void AddBoxAndSheresBooleanTest()
		{
			BoxShape box1 = new BoxShape(new Vector3(.5, .5, .5), new Vector3(1.5, 1.5, 1.5),
							   new SolidMaterial(RGBA_Floats.Green, 0, 0, 0));//.01, 0.0, 2.0));

			List<IPrimitive> subtractShapes = new List<IPrimitive>();
			SolidMaterial material = new SolidMaterial(RGBA_Floats.Red, 0, 0, 0);

#if false
			// two big spheres.  Looks good.
			subtractShapes.Add(new SphereShape(new Vector3(.5, .5, 1), .6, material));
			subtractShapes.Add(new SphereShape(new Vector3(1.5, .5, 1), .6, material));

			Transform cylinder = new Transform(new CylinderShape(.1, 3, material));
			cylinder.MoveToAbsolute(1, 1, 1);
			cylinder.RotateRelative(.1, .6, .6);
			//subtractShapes.Add(cylinder);
			//renderCollection.Add(cylinder);
#else
            for (int z = 0; z < 6; z++)
            {
                for (int y = 0; y < 6; y++)
                {
                    for (int x = 0; x < 6; x++)
                    {
                        subtractShapes.Add(new SphereShape(new Vector3(x * .2 + .5, y * .2 + .5, z * .2 + .5), .1, material));
                        //subtractShapes.Add(new SphereShape(new Vector3(x * .2 + .5, y * .2 + .5, z * .2 + .5), .13, material));
                    }
                }
            }
#endif

			IPrimitive subtractGroup = BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes);
			Difference merge = new Difference(box1, subtractGroup);

			renderCollection.Add(merge);
		}