Example #1
0
        public override CollisionHull CreateCollisionHull(WorldBase world)
        {
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

            return(CollisionHull.CreateBox(world, 0, this.Scale * ConverterMatterToFuelDesign.SCALE, transform.Value));
        }
Example #2
0
        public static CollisionHull CreateSensorCollisionHull(WorldBase world, Vector3D scale, Quaternion orientation, Point3D position)
        {
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new ScaleTransform3D(scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            Vector3D size = new Vector3D(SIZEPERCENTOFSCALE * scale.X, SIZEPERCENTOFSCALE * scale.Y, SIZEPERCENTOFSCALE * scale.Z);

            return(CollisionHull.CreateBox(world, 0, size, transform.Value));
        }
Example #3
0
        public override CollisionHull CreateCollisionHull(WorldBase world)
        {
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

            Vector3D scale = this.Scale;
            Vector3D size  = new Vector3D(1d * scale.X, RATIOY * scale.Y, RATIOZ * scale.Z);

            return(CollisionHull.CreateBox(world, 0, size, transform.Value));
        }
Example #4
0
        private void addSimple1_AddBody(object sender, AddBodyArgs e)
        {
            try
            {
                #region WPF Model (plus collision hull)

                // Material
                MaterialGroup materials = new MaterialGroup();
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.GetRandomColor(64, 192))));
                materials.Children.Add(new SpecularMaterial(Brushes.White, 100d));

                // Geometry Model
                GeometryModel3D geometry = new GeometryModel3D();
                geometry.Material     = materials;
                geometry.BackMaterial = materials;

                CollisionHull hull = null;
                switch (e.CollisionShape)
                {
                case CollisionShapeType.Box:
                    Vector3D halfSize = e.Size / 2d;
                    geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfSize.X, -halfSize.Y, -halfSize.Z), new Point3D(halfSize.X, halfSize.Y, halfSize.Z));
                    hull = CollisionHull.CreateBox(_world, 0, e.Size, null);
                    break;

                case CollisionShapeType.Sphere:
                    geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, e.Size.X, e.Size.Y, e.Size.Z);
                    hull = CollisionHull.CreateSphere(_world, 0, e.Size, null);
                    break;

                case CollisionShapeType.Cylinder:
                    geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, e.Radius, e.Height);
                    hull = CollisionHull.CreateCylinder(_world, 0, e.Radius, e.Height, null);
                    break;

                case CollisionShapeType.Cone:
                    geometry.Geometry = UtilityWPF.GetCone_AlongX(20, e.Radius, e.Height);
                    hull = CollisionHull.CreateCone(_world, 0, e.Radius, e.Height, null);
                    break;

                case CollisionShapeType.Capsule:
                case CollisionShapeType.ChamferCylinder:
                    MessageBox.Show("finish this");
                    return;

                default:
                    throw new ApplicationException("Unknown ConvexBody3D.CollisionShape: " + e.CollisionShape.ToString());
                }

                // Transform
                Transform3DGroup transform = new Transform3DGroup();            // rotate needs to be added before translate
                transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVector_Spherical(10), Math1D.GetNearZeroValue(360d))));
                transform.Children.Add(new TranslateTransform3D(Math3D.GetRandomVector_Spherical(CREATEOBJECTBOUNDRY)));

                // Model Visual
                ModelVisual3D model = new ModelVisual3D();
                model.Content   = geometry;
                model.Transform = transform;

                // Add to the viewport
                _viewport.Children.Add(model);

                #endregion

                #region Physics Body

                // Make a physics body that represents this shape
                Body body = new Body(hull, transform.Value, e.Mass, new Visual3D[] { model });
                hull.Dispose();
                body.Velocity = Math3D.GetRandomVector_Circular(1d);

                //body.LinearDamping = .01f;
                //body.AngularDamping = new Vector3D(.01f, .01f, .01f);

                body.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque);

                Body[] bodySet = new Body[] { body };
                _bodySets.Add(bodySet);

                #endregion

                BodiesAdded(bodySet);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #5
0
        private Body GetJointBodyPairSprtBody(CollisionShapeType bodyType, Point3D centerPoint, RotateTransform3D rotation, Color color)
        {
            #region WPF Model (plus collision hull)

            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            materials.Children.Add(new SpecularMaterial(Brushes.White, 100d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material     = materials;
            geometry.BackMaterial = materials;

            CollisionHull hull = null;
            switch (bodyType)
            {
            case CollisionShapeType.Box:
                geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-1, -1, -1d), new Point3D(1d, 1d, 1d));
                hull = CollisionHull.CreateBox(_world, 0, new Vector3D(2d, 2d, 2d), null);
                break;

            case CollisionShapeType.Sphere:
                geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, 1d, 1d, 1d);
                hull = CollisionHull.CreateSphere(_world, 0, new Vector3D(1d, 1d, 1d), null);
                break;

            case CollisionShapeType.Cylinder:
                geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, 1d, 2d);
                hull = CollisionHull.CreateCylinder(_world, 0, 1d, 2d, null);
                break;

            case CollisionShapeType.Cone:
                geometry.Geometry = UtilityWPF.GetCone_AlongX(20, 1d, 2d);
                hull = CollisionHull.CreateCone(_world, 0, 1d, 2d, null);
                break;

            case CollisionShapeType.Capsule:
            case CollisionShapeType.ChamferCylinder:
                throw new ApplicationException("finish this");

            default:
                throw new ApplicationException("Unknown ConvexBody3D.CollisionShape: " + bodyType.ToString());
            }

            // Transform
            Transform3DGroup transform = new Transform3DGroup();                // rotate needs to be added before translate
            transform.Children.Add(rotation);
            transform.Children.Add(new TranslateTransform3D(centerPoint.ToVector()));

            // Model Visual
            ModelVisual3D model = new ModelVisual3D();
            model.Content   = geometry;
            model.Transform = transform;

            // Add to the viewport
            _viewport.Children.Add(model);

            #endregion

            #region Physics Body

            // Make a physics body that represents this shape
            Body body = new Body(hull, transform.Value, 1d, new Visual3D[] { model });          // being lazy with mass, but since size is fixed, it won't be too noticable
            hull.Dispose();
            body.Velocity = Math3D.GetRandomVector_Circular(1d);

            //body.LinearDamping = .01f;
            //body.AngularDamping = new Vector3D(.01f, .01f, .01f);

            body.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque);

            // This will be done later
            //_bodySets.Add(body);

            #endregion

            // Exit Function
            return(body);
        }