示例#1
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);
		}
示例#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<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
		}
示例#3
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);
		}