예제 #1
0
        private void LineShapeCombo_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            LineSegmentShape style = (LineSegmentShape)LineShapeCombo.SelectedIndex;

            m_Line1.LineSegmentShape = style;
            m_Line2.LineSegmentShape = style;
            m_Line3.LineSegmentShape = style;

            switch (style)
            {
            case LineSegmentShape.Tape:
                m_Line1.DepthPercent = 50;
                m_Line2.DepthPercent = 50;
                m_Line3.DepthPercent = 50;
                break;

            case LineSegmentShape.Tube:
            case LineSegmentShape.Ellipsoid:
                m_Line1.DepthPercent = 10;
                m_Line2.DepthPercent = 10;
                m_Line3.DepthPercent = 10;
                break;
            }

            nChartControl1.Refresh();
        }
예제 #2
0
 public void GetMesh()
 {
     var l = new LineSegmentShape(new Vector3F(1, 2, 3), new Vector3F(4, 5, 6));
       var m = l.GetMesh(0, 1);
       Assert.AreEqual(1, m.NumberOfTriangles);
       Triangle t = m.GetTriangle(0);
       Assert.IsTrue(l.Start == t.Vertex0);
       Assert.IsTrue(l.Start == t.Vertex1 || l.End == t.Vertex1);
       Assert.IsTrue(l.End == t.Vertex2);
 }
예제 #3
0
 public void Clone()
 {
     LineSegmentShape lineSegment = new LineSegmentShape(new Vector3F(1, 2, 3), new Vector3F(2, 3, 4));
       LineSegmentShape clone = lineSegment.Clone() as LineSegmentShape;
       Assert.IsNotNull(clone);
       Assert.AreEqual(lineSegment.Start, clone.Start);
       Assert.AreEqual(lineSegment.End, clone.End);
       Assert.AreEqual(lineSegment.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum);
       Assert.AreEqual(lineSegment.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum);
 }
        public void Clone()
        {
            LineSegmentShape lineSegment = new LineSegmentShape(new Vector3(1, 2, 3), new Vector3(2, 3, 4));
            LineSegmentShape clone       = lineSegment.Clone() as LineSegmentShape;

            Assert.IsNotNull(clone);
            Assert.AreEqual(lineSegment.Start, clone.Start);
            Assert.AreEqual(lineSegment.End, clone.End);
            Assert.AreEqual(lineSegment.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum);
            Assert.AreEqual(lineSegment.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum);
        }
        public void GetMesh()
        {
            var l = new LineSegmentShape(new Vector3(1, 2, 3), new Vector3(4, 5, 6));
            var m = l.GetMesh(0, 1);

            Assert.AreEqual(1, m.NumberOfTriangles);
            Triangle t = m.GetTriangle(0);

            Assert.IsTrue(l.Start == t.Vertex0);
            Assert.IsTrue(l.Start == t.Vertex1 || l.End == t.Vertex1);
            Assert.IsTrue(l.End == t.Vertex2);
        }
        public void SerializationBinary()
        {
            var a = new LineSegmentShape(new Vector3(1, 2, 3), new Vector3(2, 3, 4));

            // 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            = (LineSegmentShape)deserializer.Deserialize(stream);

            Assert.AreEqual(a.Start, b.Start);
            Assert.AreEqual(a.End, b.End);
        }
        public void TestProperties()
        {
            LineSegmentShape ls = new LineSegmentShape();

            Assert.AreEqual(new Vector3(), ls.Start);
            Assert.AreEqual(new Vector3(), ls.End);
            Assert.AreEqual(0, ls.Length);
            Assert.AreEqual(0, ls.LengthSquared());
            ls.Start = new Vector3(1, 2, 3);
            Assert.AreEqual(new Vector3(1, 2, 3), ls.Start);
            Assert.AreEqual(new Vector3(), ls.End);
            Assert.AreEqual(new Vector3(1, 2, 3).Length, ls.Length);
            Assert.AreEqual(new Vector3(1, 2, 3).LengthSquared(), ls.LengthSquared());
            ls.End = new Vector3(4, 5, 6);
            Assert.AreEqual(new Vector3(1, 2, 3), ls.Start);
            Assert.AreEqual(new Vector3(4, 5, 6), ls.End);
            Assert.AreEqual(new Vector3(3, 3, 3).Length, ls.Length);
            Assert.AreEqual(new Vector3(3, 3, 3).LengthSquared(), ls.LengthSquared());
        }
예제 #8
0
        private void LineStyleCombo_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            LineSegmentShape style = (LineSegmentShape)LineStyleCombo.SelectedIndex;

            m_Line1.LineSegmentShape = style;
            m_Line2.LineSegmentShape = style;

            switch (style)
            {
            case LineSegmentShape.Line:
            case LineSegmentShape.Tape:
                m_Line1.MarkerStyle.PointShape = PointShape.Cylinder;
                m_Line2.MarkerStyle.PointShape = PointShape.Cylinder;
                m_Line1.MarkerStyle.Visible    = true;
                m_Line2.MarkerStyle.Visible    = true;
                m_Line1.MarkerStyle.Width      = new NLength(1.5f, NRelativeUnit.ParentPercentage);
                m_Line2.MarkerStyle.Width      = new NLength(1.5f, NRelativeUnit.ParentPercentage);
                m_Line1.MarkerStyle.Height     = new NLength(1.5f, NRelativeUnit.ParentPercentage);
                m_Line2.MarkerStyle.Height     = new NLength(1.5f, NRelativeUnit.ParentPercentage);
                m_Line1.DepthPercent           = 50;
                m_Line2.DepthPercent           = 50;
                break;

            case LineSegmentShape.Tube:
            case LineSegmentShape.Ellipsoid:
                m_Line1.MarkerStyle.PointShape = PointShape.Sphere;
                m_Line2.MarkerStyle.PointShape = PointShape.Sphere;
                m_Line1.MarkerStyle.Visible    = true;
                m_Line2.MarkerStyle.Visible    = true;
                m_Line1.MarkerStyle.Width      = new NLength(2.5f, NRelativeUnit.ParentPercentage);
                m_Line2.MarkerStyle.Width      = new NLength(2.5f, NRelativeUnit.ParentPercentage);
                m_Line1.MarkerStyle.Height     = new NLength(2.5f, NRelativeUnit.ParentPercentage);
                m_Line2.MarkerStyle.Height     = new NLength(2.5f, NRelativeUnit.ParentPercentage);
                m_Line1.DepthPercent           = 10;
                m_Line2.DepthPercent           = 10;
                break;
            }

            nChartControl1.Refresh();
        }
        public void SerializationXml()
        {
            var a = new LineSegmentShape(new Vector3(1, 2, 3), new Vector3(2, 3, 4));

            // 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            = (LineSegmentShape)deserializer.Deserialize(stream);

            Assert.AreEqual(a.Start, b.Start);
            Assert.AreEqual(a.End, b.End);
        }
예제 #10
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;
      }
    }
예제 #11
0
        public void SerializationBinary()
        {
            var a = new LineSegmentShape(new Vector3F(1, 2, 3), new Vector3F(2, 3, 4));

              // 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 = (LineSegmentShape)deserializer.Deserialize(stream);

              Assert.AreEqual(a.Start, b.Start);
              Assert.AreEqual(a.End, b.End);
        }
예제 #12
0
 public void TestProperties()
 {
     LineSegmentShape ls = new LineSegmentShape();
       Assert.AreEqual(new Vector3F(), ls.Start);
       Assert.AreEqual(new Vector3F(), ls.End);
       Assert.AreEqual(0, ls.Length);
       Assert.AreEqual(0, ls.LengthSquared);
       ls.Start = new Vector3F(1, 2, 3);
       Assert.AreEqual(new Vector3F(1, 2, 3), ls.Start);
       Assert.AreEqual(new Vector3F(), ls.End);
       Assert.AreEqual(new Vector3F(1, 2, 3).Length, ls.Length);
       Assert.AreEqual(new Vector3F(1, 2, 3).LengthSquared, ls.LengthSquared);
       ls.End = new Vector3F(4, 5, 6);
       Assert.AreEqual(new Vector3F(1, 2, 3), ls.Start);
       Assert.AreEqual(new Vector3F(4, 5, 6), ls.End);
       Assert.AreEqual(new Vector3F(3, 3, 3).Length, ls.Length);
       Assert.AreEqual(new Vector3F(3, 3, 3).LengthSquared, ls.LengthSquared);
 }
예제 #13
0
        public void SerializationXml()
        {
            var a = new LineSegmentShape(new Vector3F(1, 2, 3), new Vector3F(2, 3, 4));

              // 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 = (LineSegmentShape)deserializer.Deserialize(stream);

              Assert.AreEqual(a.Start, b.Start);
              Assert.AreEqual(a.End, b.End);
        }
 public LineSegmentShapeRemoteData(LineSegmentShape shape) : base(shape)
 {
     this.Point1 = shape.Point1;
     this.Point2 = shape.Point2;
 }