Пример #1
0
 public void AabbTest()
 {
     OrthographicViewVolume viewVolume = new OrthographicViewVolume();
       viewVolume.Set(-1, 1, -1, 1, 2, 5);
       Aabb aabb = viewVolume.GetAabb(Pose.Identity);
       Assert.AreEqual(new Vector3F(-1, -1, -5), aabb.Minimum);
       Assert.AreEqual(new Vector3F(1, 1, -2), aabb.Maximum);
 }
Пример #2
0
 public void InnerPointTest()
 {
     OrthographicViewVolume viewVolume = new OrthographicViewVolume();
       viewVolume.SetWidthAndHeight(1, 1, 1, 10);
       Vector3F innerPoint = viewVolume.InnerPoint;
       Assert.AreEqual(0, innerPoint.X);
       Assert.AreEqual(0, innerPoint.Y);
       Assert.AreEqual(-5.5f, innerPoint.Z);
 }
        public void InnerPointTest()
        {
            OrthographicViewVolume viewVolume = new OrthographicViewVolume();

            viewVolume.SetWidthAndHeight(1, 1, 1, 10);
            Vector3 innerPoint = viewVolume.InnerPoint;

            Assert.AreEqual(0, innerPoint.X);
            Assert.AreEqual(0, innerPoint.Y);
            Assert.AreEqual(-5.5f, innerPoint.Z);
        }
Пример #4
0
        public void OrthographicViewVolumeTest()
        {
            var s  = new OrthographicViewVolume(-1, 0, -1, 0, 0.1f, 10);
            var v0 = s.GetVolume(0.001f, 10);

            var m  = s.GetMesh(0.001f, 10);
            var s1 = new TriangleMeshShape(m);
            var v1 = m.GetVolume();

            Assert.IsTrue(Numeric.AreEqual(v0, v1, 0.01f * (1 + v0))); // 1% error is allowed.
        }
        public void PropertiesTest()
        {
            OrthographicViewVolume viewVolume = new OrthographicViewVolume
            {
                Left   = -2,
                Right  = 2,
                Bottom = -1,
                Top    = 1,
                Near   = 2,
                Far    = 10
            };

            Assert.AreEqual(-2, viewVolume.Left);
            Assert.AreEqual(2, viewVolume.Right);
            Assert.AreEqual(-1, viewVolume.Bottom);
            Assert.AreEqual(1, viewVolume.Top);
            Assert.AreEqual(2, viewVolume.Near);
            Assert.AreEqual(10, viewVolume.Far);
            Assert.AreEqual(4, viewVolume.Width);
            Assert.AreEqual(2, viewVolume.Height);
            Assert.AreEqual(8, viewVolume.Depth);
            Assert.AreEqual(2, viewVolume.AspectRatio);
            Assert.IsNaN(viewVolume.FieldOfViewX);
            Assert.IsNaN(viewVolume.FieldOfViewY);


            viewVolume = new OrthographicViewVolume
            {
                Left   = 2,
                Right  = -2,
                Bottom = 1,
                Top    = -1,
                Near   = 10,
                Far    = 2
            };

            Assert.AreEqual(2, viewVolume.Left);
            Assert.AreEqual(-2, viewVolume.Right);
            Assert.AreEqual(1, viewVolume.Bottom);
            Assert.AreEqual(-1, viewVolume.Top);
            Assert.AreEqual(10, viewVolume.Near);
            Assert.AreEqual(2, viewVolume.Far);
            Assert.AreEqual(4, viewVolume.Width);
            Assert.AreEqual(2, viewVolume.Height);
            Assert.AreEqual(8, viewVolume.Depth);
            Assert.AreEqual(2, viewVolume.AspectRatio);
            Assert.IsNaN(viewVolume.FieldOfViewX);
            Assert.IsNaN(viewVolume.FieldOfViewY);
        }
Пример #6
0
        public void PropertiesTest()
        {
            OrthographicViewVolume viewVolume = new OrthographicViewVolume
              {
            Left = -2,
            Right = 2,
            Bottom = -1,
            Top = 1,
            Near = 2,
            Far = 10
              };

              Assert.AreEqual(-2, viewVolume.Left);
              Assert.AreEqual(2, viewVolume.Right);
              Assert.AreEqual(-1, viewVolume.Bottom);
              Assert.AreEqual(1, viewVolume.Top);
              Assert.AreEqual(2, viewVolume.Near);
              Assert.AreEqual(10, viewVolume.Far);
              Assert.AreEqual(4, viewVolume.Width);
              Assert.AreEqual(2, viewVolume.Height);
              Assert.AreEqual(8, viewVolume.Depth);
              Assert.AreEqual(2, viewVolume.AspectRatio);
              Assert.IsNaN(viewVolume.FieldOfViewX);
              Assert.IsNaN(viewVolume.FieldOfViewY);

              viewVolume = new OrthographicViewVolume
              {
            Left = 2,
            Right = -2,
            Bottom = 1,
            Top = -1,
            Near = 10,
            Far = 2
              };

              Assert.AreEqual(2, viewVolume.Left);
              Assert.AreEqual(-2, viewVolume.Right);
              Assert.AreEqual(1, viewVolume.Bottom);
              Assert.AreEqual(-1, viewVolume.Top);
              Assert.AreEqual(10, viewVolume.Near);
              Assert.AreEqual(2, viewVolume.Far);
              Assert.AreEqual(4, viewVolume.Width);
              Assert.AreEqual(2, viewVolume.Height);
              Assert.AreEqual(8, viewVolume.Depth);
              Assert.AreEqual(2, viewVolume.AspectRatio);
              Assert.IsNaN(viewVolume.FieldOfViewX);
              Assert.IsNaN(viewVolume.FieldOfViewY);
        }
Пример #7
0
 public void Clone()
 {
     OrthographicViewVolume orthographicViewVolume = new OrthographicViewVolume(-1.23f, 2.13f, -0.3f, 2.34f, 1.01f, 10.345f);
       OrthographicViewVolume clone = orthographicViewVolume.Clone() as OrthographicViewVolume;
       Assert.IsNotNull(clone);
       Assert.AreEqual(orthographicViewVolume.Left, clone.Left);
       Assert.AreEqual(orthographicViewVolume.Right, clone.Right);
       Assert.AreEqual(orthographicViewVolume.Bottom, clone.Bottom);
       Assert.AreEqual(orthographicViewVolume.Top, clone.Top);
       Assert.AreEqual(orthographicViewVolume.Near, clone.Near);
       Assert.AreEqual(orthographicViewVolume.Far, clone.Far);
       Assert.AreEqual(orthographicViewVolume.FieldOfViewX, clone.FieldOfViewX);
       Assert.AreEqual(orthographicViewVolume.FieldOfViewY, clone.FieldOfViewY);
       Assert.AreEqual(orthographicViewVolume.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum);
       Assert.AreEqual(orthographicViewVolume.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum);
 }
        public void Clone()
        {
            OrthographicViewVolume orthographicViewVolume = new OrthographicViewVolume(-1.23f, 2.13f, -0.3f, 2.34f, 1.01f, 10.345f);
            OrthographicViewVolume clone = orthographicViewVolume.Clone() as OrthographicViewVolume;

            Assert.IsNotNull(clone);
            Assert.AreEqual(orthographicViewVolume.Left, clone.Left);
            Assert.AreEqual(orthographicViewVolume.Right, clone.Right);
            Assert.AreEqual(orthographicViewVolume.Bottom, clone.Bottom);
            Assert.AreEqual(orthographicViewVolume.Top, clone.Top);
            Assert.AreEqual(orthographicViewVolume.Near, clone.Near);
            Assert.AreEqual(orthographicViewVolume.Far, clone.Far);
            Assert.AreEqual(orthographicViewVolume.FieldOfViewX, clone.FieldOfViewX);
            Assert.AreEqual(orthographicViewVolume.FieldOfViewY, clone.FieldOfViewY);
            Assert.AreEqual(orthographicViewVolume.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum);
            Assert.AreEqual(orthographicViewVolume.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum);
        }
        public void SetWidthAndHeightTest()
        {
            OrthographicViewVolume viewVolume = new OrthographicViewVolume();

            viewVolume.SetWidthAndHeight(4, 3, 2, 9);

            Assert.AreEqual(-2, viewVolume.Left);
            Assert.AreEqual(2, viewVolume.Right);
            Assert.AreEqual(-1.5f, viewVolume.Bottom);
            Assert.AreEqual(1.5f, viewVolume.Top);
            Assert.AreEqual(2, viewVolume.Near);
            Assert.AreEqual(9, viewVolume.Far);
            Assert.AreEqual(4, viewVolume.Width);
            Assert.AreEqual(3, viewVolume.Height);
            Assert.AreEqual(7, viewVolume.Depth);
            Assert.AreEqual(4.0f / 3.0f, viewVolume.AspectRatio);
            Assert.IsNaN(viewVolume.FieldOfViewX);
            Assert.IsNaN(viewVolume.FieldOfViewY);
        }
        public void SerializationBinary()
        {
            var a = new OrthographicViewVolume(-1.23f, 2.13f, -0.3f, 2.34f, 1.01f, 10.345f);

            // Serialize object.
            var stream    = new MemoryStream();
            var formatter = new BinaryFormatter();

            formatter.Serialize(stream, a);

            // Deserialize object.
            stream.Position = 0;
            var deserializer = new BinaryFormatter();
            var b            = (OrthographicViewVolume)deserializer.Deserialize(stream);

            Assert.AreEqual(a.Left, b.Left);
            Assert.AreEqual(a.Right, b.Right);
            Assert.AreEqual(a.Top, b.Top);
            Assert.AreEqual(a.Bottom, b.Bottom);
            Assert.AreEqual(a.Near, b.Near);
            Assert.AreEqual(a.Far, b.Far);
            Assert.AreEqual(a.InnerPoint, b.InnerPoint);
        }
        public void SetException3()
        {
            OrthographicViewVolume viewVolume = new OrthographicViewVolume();

            viewVolume.Set(1, 2, 3, 4, 6, 6);
        }
Пример #12
0
 public void SetException3()
 {
     OrthographicViewVolume viewVolume = new OrthographicViewVolume();
       viewVolume.Set(1, 2, 3, 4, 6, 6);
 }
Пример #13
0
 public void SetWidthAndHeightException3()
 {
     OrthographicViewVolume viewVolume = new OrthographicViewVolume();
       viewVolume.SetWidthAndHeight(2, 1, 1, 0);
 }
        public void SetWidthAndHeightException3()
        {
            OrthographicViewVolume viewVolume = new OrthographicViewVolume();

            viewVolume.SetWidthAndHeight(2, 1, 1, 0);
        }
Пример #15
0
        public void SerializationXml()
        {
            var a = new OrthographicViewVolume(-1.23f, 2.13f, -0.3f, 2.34f, 1.01f, 10.345f);

              // Serialize object.
              var stream = new MemoryStream();
              var serializer = new XmlSerializer(typeof(Shape));
              serializer.Serialize(stream, a);

              // Output generated xml. Can be manually checked in output window.
              stream.Position = 0;
              var xml = new StreamReader(stream).ReadToEnd();
              Trace.WriteLine("Serialized Object:\n" + xml);

              // Deserialize object.
              stream.Position = 0;
              var deserializer = new XmlSerializer(typeof(Shape));
              var b = (OrthographicViewVolume)deserializer.Deserialize(stream);

              Assert.AreEqual(a.Left, b.Left);
              Assert.AreEqual(a.Right, b.Right);
              Assert.AreEqual(a.Top, b.Top);
              Assert.AreEqual(a.Bottom, b.Bottom);
              Assert.AreEqual(a.Near, b.Near);
              Assert.AreEqual(a.Far, b.Far);
              Assert.AreEqual(a.InnerPoint, b.InnerPoint);
        }
Пример #16
0
        //--------------------------------------------------------------
        #region Fields
        //--------------------------------------------------------------
        #endregion


        //--------------------------------------------------------------
        #region Properties & Events
        //--------------------------------------------------------------
        #endregion


        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="OrthographicProjection"/> class.
        /// </summary>
        public OrthographicProjection()
        {
            ViewVolume = new OrthographicViewVolume();
            Set(DefaultWidth, DefaultHeight, DefaultNear, DefaultFar);
        }
Пример #17
0
        public void SetWidthAndHeightTest()
        {
            OrthographicViewVolume viewVolume = new OrthographicViewVolume();
              viewVolume.SetWidthAndHeight(4, 3, 2, 9);

              Assert.AreEqual(-2, viewVolume.Left);
              Assert.AreEqual(2, viewVolume.Right);
              Assert.AreEqual(-1.5f, viewVolume.Bottom);
              Assert.AreEqual(1.5f, viewVolume.Top);
              Assert.AreEqual(2, viewVolume.Near);
              Assert.AreEqual(9, viewVolume.Far);
              Assert.AreEqual(4, viewVolume.Width);
              Assert.AreEqual(3, viewVolume.Height);
              Assert.AreEqual(7, viewVolume.Depth);
              Assert.AreEqual(4.0f / 3.0f, viewVolume.AspectRatio);
              Assert.IsNaN(viewVolume.FieldOfViewX);
              Assert.IsNaN(viewVolume.FieldOfViewY);
        }
Пример #18
0
    // Creates a lot of random objects.
    private void CreateRandomObjects()
    {
      var random = new Random();

      var isFirstHeightField = true;

      int currentShape = 0;
      int numberOfObjects = 0;
      while (true)
      {
        numberOfObjects++;
        if (numberOfObjects > ObjectsPerType)
        {
          currentShape++;
          numberOfObjects = 0;
        }

        Shape shape;
        switch (currentShape)
        {
          case 0:
            // Box
            shape = new BoxShape(ObjectSize, ObjectSize * 2, ObjectSize * 3);
            break;
          case 1:
            // Capsule
            shape = new CapsuleShape(0.3f * ObjectSize, 2 * ObjectSize);
            break;
          case 2:
            // Cone
            shape = new ConeShape(1 * ObjectSize, 2 * ObjectSize);
            break;
          case 3:
            // Cylinder
            shape = new CylinderShape(0.4f * ObjectSize, 2 * ObjectSize);
            break;
          case 4:
            // Sphere
            shape = new SphereShape(ObjectSize);
            break;
          case 5:
            // Convex hull of several points.
            ConvexHullOfPoints hull = new ConvexHullOfPoints();
            hull.Points.Add(new Vector3(-1 * ObjectSize, -2 * ObjectSize, -1 * ObjectSize));
            hull.Points.Add(new Vector3(2 * ObjectSize, -1 * ObjectSize, -0.5f * ObjectSize));
            hull.Points.Add(new Vector3(1 * ObjectSize, 2 * ObjectSize, 1 * ObjectSize));
            hull.Points.Add(new Vector3(-1 * ObjectSize, 2 * ObjectSize, 1 * ObjectSize));
            hull.Points.Add(new Vector3(-1 * ObjectSize, 0.7f * ObjectSize, -0.6f * ObjectSize));
            shape = hull;
            break;
          case 6:
            // A composite shape: two boxes that form a "T" shape.
            var composite = new CompositeShape();
            composite.Children.Add(
              new GeometricObject(
                new BoxShape(ObjectSize, 3 * ObjectSize, ObjectSize),
                new Pose(new Vector3(0, 0, 0))));
            composite.Children.Add(
              new GeometricObject(
                new BoxShape(2 * ObjectSize, ObjectSize, ObjectSize),
                new Pose(new Vector3(0, 2 * ObjectSize, 0))));
            shape = composite;
            break;
          case 7:
            shape = new CircleShape(ObjectSize);
            break;
          case 8:
            {
              var compBvh = new CompositeShape();
              compBvh.Children.Add(new GeometricObject(new BoxShape(0.5f, 1, 0.5f), new Pose(new Vector3(0, 0.5f, 0), Matrix.Identity)));
              compBvh.Children.Add(new GeometricObject(new BoxShape(0.8f, 0.5f, 0.5f), new Pose(new Vector3(0.5f, 0.7f, 0), Matrix.CreateRotationZ(-MathHelper.ToRadians(15)))));
              compBvh.Children.Add(new GeometricObject(new SphereShape(0.3f), new Pose(new Vector3(0, 1.15f, 0), Matrix.Identity)));
              compBvh.Children.Add(new GeometricObject(new CapsuleShape(0.2f, 1), new Pose(new Vector3(0.6f, 1.15f, 0), Matrix.CreateRotationX(0.3f))));
              compBvh.Partition = new AabbTree<int>();
              shape = compBvh;
              break;
            }
          case 9:
            CompositeShape comp = new CompositeShape();
            comp.Children.Add(new GeometricObject(new BoxShape(0.5f * ObjectSize, 1 * ObjectSize, 0.5f * ObjectSize), new Pose(new Vector3(0, 0.5f * ObjectSize, 0), Quaternion.Identity)));
            comp.Children.Add(new GeometricObject(new BoxShape(0.8f * ObjectSize, 0.5f * ObjectSize, 0.5f * ObjectSize), new Pose(new Vector3(0.3f * ObjectSize, 0.7f * ObjectSize, 0), Quaternion.CreateRotationZ(-MathHelper.ToRadians(45)))));
            comp.Children.Add(new GeometricObject(new SphereShape(0.3f * ObjectSize), new Pose(new Vector3(0, 1.15f * ObjectSize, 0), Quaternion.Identity)));
            shape = comp;
            break;
          case 10:
            shape = new ConvexHullOfPoints(new[]
            {
              new Vector3(-1 * ObjectSize, -2 * ObjectSize, -1 * ObjectSize),
              new Vector3(2 * ObjectSize, -1 * ObjectSize, -0.5f * ObjectSize),
              new Vector3(1 * ObjectSize, 2 * ObjectSize, 1 * ObjectSize),
              new Vector3(-1 * ObjectSize, 2 * ObjectSize, 1 * ObjectSize),
              new Vector3(-1 * ObjectSize, 0.7f * ObjectSize, -0.6f * ObjectSize)
            });
            break;
          case 11:
            ConvexHullOfShapes shapeHull = new ConvexHullOfShapes();
            shapeHull.Children.Add(new GeometricObject(new SphereShape(0.3f * ObjectSize), new Pose(new Vector3(0, 2 * ObjectSize, 0), Matrix.Identity)));
            shapeHull.Children.Add(new GeometricObject(new BoxShape(1 * ObjectSize, 2 * ObjectSize, 3 * ObjectSize), Pose.Identity));
            shape = shapeHull;
            break;
          case 12:
            shape = Shape.Empty;
            break;
          case 13:
            var numberOfSamplesX = 10;
            var numberOfSamplesZ = 10;
            var samples = new float[numberOfSamplesX * numberOfSamplesZ];
            for (int z = 0; z < numberOfSamplesZ; z++)
              for (int x = 0; x < numberOfSamplesX; x++)
                samples[z * numberOfSamplesX + x] = (float)(Math.Cos(z / 3f) * Math.Sin(x / 2f) * BoxSize / 6);
            HeightField heightField = new HeightField(0, 0, 2 * BoxSize, 2 * BoxSize, samples, numberOfSamplesX, numberOfSamplesZ);
            shape = heightField;
            break;
          //case 14:
          //shape = new LineShape(new Vector3(0.1f, 0.2f, 0.3f), new Vector3(0.1f, 0.2f, -0.3f).Normalized);
          //break;            
          case 15:
            shape = new LineSegmentShape(
              new Vector3(0.1f, 0.2f, 0.3f), new Vector3(0.1f, 0.2f, 0.3f) + 3 * ObjectSize * new Vector3(0.1f, 0.2f, -0.3f));
            break;
          case 16:
            shape = new MinkowskiDifferenceShape
            {
              ObjectA = new GeometricObject(new SphereShape(0.1f * ObjectSize)),
              ObjectB = new GeometricObject(new BoxShape(1 * ObjectSize, 2 * ObjectSize, 3 * ObjectSize))
            };
            break;
          case 17:
            shape = new MinkowskiSumShape
            {
              ObjectA = new GeometricObject(new SphereShape(0.1f * ObjectSize)),
              ObjectB = new GeometricObject(new BoxShape(1 * ObjectSize, 2 * ObjectSize, 3 * ObjectSize)),
            };
            break;
          case 18:
            shape = new OrthographicViewVolume(0, ObjectSize, 0, ObjectSize, ObjectSize / 2, ObjectSize * 2);
            break;
          case 19:
            shape = new PerspectiveViewVolume(MathHelper.ToRadians(60f), 16f / 10, ObjectSize / 2, ObjectSize * 3);
            break;
          case 20:
            shape = new PointShape(0.1f, 0.3f, 0.2f);
            break;
          case 21:
            shape = new RayShape(new Vector3(0.2f, 0, -0.12f), new Vector3(1, 2, 3).Normalized, ObjectSize * 2);
            break;
          case 22:
            shape = new RayShape(new Vector3(0.2f, 0, -0.12f), new Vector3(1, 2, 3).Normalized, ObjectSize * 2)
            {
              StopsAtFirstHit = true
            };
            break;
          case 23:
            shape = new RectangleShape(ObjectSize, ObjectSize * 2);
            break;
          case 24:
            shape = new TransformedShape(
              new GeometricObject(
                new BoxShape(1 * ObjectSize, 2 * ObjectSize, 3 * ObjectSize),
                new Pose(new Vector3(0.1f, 1, -0.2f))));
            break;
          case 25:
            shape = new TriangleShape(
              new Vector3(ObjectSize, 0, 0), new Vector3(0, ObjectSize, 0), new Vector3(ObjectSize, ObjectSize, ObjectSize));
            break;
          //case 26:
          //  {
          //    // Create a composite object from which we get the mesh.
          //    CompositeShape compBvh = new CompositeShape();
          //    compBvh.Children.Add(new GeometricObject(new BoxShape(0.5f, 1, 0.5f), new Pose(new Vector3(0, 0.5f, 0), Matrix.Identity)));
          //    compBvh.Children.Add(
          //      new GeometricObject(
          //        new BoxShape(0.8f, 0.5f, 0.5f),
          //        new Pose(new Vector3(0.5f, 0.7f, 0), Matrix.CreateRotationZ(-(float)MathHelper.ToRadians(15)))));
          //    compBvh.Children.Add(new GeometricObject(new SphereShape(0.3f), new Pose(new Vector3(0, 1.15f, 0), Matrix.Identity)));
          //    compBvh.Children.Add(
          //      new GeometricObject(new CapsuleShape(0.2f, 1), new Pose(new Vector3(0.6f, 1.15f, 0), Matrix.CreateRotationX(0.3f))));

          //    TriangleMeshShape meshBvhShape = new TriangleMeshShape { Mesh = compBvh.GetMesh(0.01f, 3) };
          //    meshBvhShape.Partition = new AabbTree<int>();
          //    shape = meshBvhShape;
          //    break;
          //  }
          //case 27:
          //  {
          //    // Create a composite object from which we get the mesh.
          //    CompositeShape compBvh = new CompositeShape();
          //    compBvh.Children.Add(new GeometricObject(new BoxShape(0.5f, 1, 0.5f), new Pose(new Vector3(0, 0.5f, 0), Quaternion.Identity)));
          //    compBvh.Children.Add(
          //      new GeometricObject(
          //        new BoxShape(0.8f, 0.5f, 0.5f),
          //        new Pose(new Vector3(0.5f, 0.7f, 0), Quaternion.CreateRotationZ(-(float)MathHelper.ToRadians(15)))));
          //    compBvh.Children.Add(new GeometricObject(new SphereShape(0.3f), new Pose(new Vector3(0, 1.15f, 0), Quaternion.Identity)));
          //    compBvh.Children.Add(
          //      new GeometricObject(new CapsuleShape(0.2f, 1), new Pose(new Vector3(0.6f, 1.15f, 0), Quaternion.CreateRotationX(0.3f))));

          //    TriangleMeshShape meshBvhShape = new TriangleMeshShape { Mesh = compBvh.GetMesh(0.01f, 3) };
          //    meshBvhShape.Partition = new AabbTree<int>();
          //    shape = meshBvhShape;
          //    break;
          //  }
          case 28:
            shape = new ConvexPolyhedron(new[]
            {
              new Vector3(-1 * ObjectSize, -2 * ObjectSize, -1 * ObjectSize),
              new Vector3(2 * ObjectSize, -1 * ObjectSize, -0.5f * ObjectSize),
              new Vector3(1 * ObjectSize, 2 * ObjectSize, 1 * ObjectSize),
              new Vector3(-1 * ObjectSize, 2 * ObjectSize, 1 * ObjectSize),
              new Vector3(-1 * ObjectSize, 0.7f * ObjectSize, -0.6f * ObjectSize)
            });
            break;
          case 29:
            return;
          default:
            currentShape++;
            continue;
        }

        // Create an object with the random shape, pose, color and velocity.
        Pose randomPose = new Pose(
          random.NextVector3(-BoxSize + ObjectSize * 2, BoxSize - ObjectSize * 2),
          random.NextQuaternion());
        var newObject = new MovingGeometricObject
        {
          Pose = randomPose,
          Shape = shape,
          LinearVelocity = random.NextQuaternion().Rotate(new Vector3(MaxLinearVelocity, 0, 0)),
          AngularVelocity = random.NextQuaternion().Rotate(Vector3.Forward)
                            * RandomHelper.Random.NextFloat(0, MaxAngularVelocity),
        };

        if (RandomHelper.Random.NextBool())
          newObject.LinearVelocity = Vector3.Zero;
        if (RandomHelper.Random.NextBool())
          newObject.AngularVelocity = Vector3.Zero;

        if (shape is LineShape || shape is HeightField)
        {
          // Do not move lines or the height field.
          newObject.LinearVelocity = Vector3.Zero;
          newObject.AngularVelocity = Vector3.Zero;
        }

        // Create only 1 heightField!
        if (shape is HeightField)
        {
          if (isFirstHeightField)
          {
            isFirstHeightField = true;
            newObject.Pose = new Pose(new Vector3(-BoxSize, -BoxSize, -BoxSize));
          }
          else
          {
            currentShape++;
            numberOfObjects = 0;
            continue;
          }
        }

        // Add collision object to collision domain.
        _domain.CollisionObjects.Add(new CollisionObject(newObject));

        //co.Type = CollisionObjectType.Trigger;
        //co.Name = "Object" + shape.GetType().Name + "_" + i;
      }
    }
Пример #19
0
        public void SerializationBinary()
        {
            var a = new OrthographicViewVolume(-1.23f, 2.13f, -0.3f, 2.34f, 1.01f, 10.345f);

              // Serialize object.
              var stream = new MemoryStream();
              var formatter = new BinaryFormatter();
              formatter.Serialize(stream, a);

              // Deserialize object.
              stream.Position = 0;
              var deserializer = new BinaryFormatter();
              var b = (OrthographicViewVolume)deserializer.Deserialize(stream);

              Assert.AreEqual(a.Left, b.Left);
              Assert.AreEqual(a.Right, b.Right);
              Assert.AreEqual(a.Top, b.Top);
              Assert.AreEqual(a.Bottom, b.Bottom);
              Assert.AreEqual(a.Near, b.Near);
              Assert.AreEqual(a.Far, b.Far);
              Assert.AreEqual(a.InnerPoint, b.InnerPoint);
        }