internal static CollisionHull CreateTankCollisionHull(WorldBase world, Vector3D scale, Quaternion orientation, Point3D position) { Transform3DGroup transform = new Transform3DGroup(); //transform.Children.Add(new ScaleTransform3D(this.Scale)); // it ignores scale transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90))); // the physics hull is along x, but dna is along z transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); double radius = RADIUSPERCENTOFSCALE * (scale.X + scale.Y) * .5d; double height = scale.Z; if (height < radius * 2d) { // Newton keeps the capsule caps spherical, but the visual scales them. So when the height is less than the radius, newton // make a sphere. So just make a cylinder instead //return CollisionHull.CreateChamferCylinder(world, 0, radius, height, transform.Value); return(CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value)); } else { //NOTE: The visual changes the caps around, but I want the physics to be a capsule return(CollisionHull.CreateCapsule(world, 0, radius, height, transform.Value)); } }
internal static CollisionHull CreateCollisionHull(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 AxisAngleRotation3D(new Vector3D(0, 1, 0), 90))); // the physics hull is along x, but dna is along z transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); double radius = RADIUSPERCENTOFSCALE * (scale.X + scale.Y) * .5d; double height = scale.Z * HEIGHTPERCENTOFSCALE; //return CollisionHull.CreateChamferCylinder(world, 0, radius, height, transform.Value); return(CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value)); }
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 AxisAngleRotation3D(new Vector3D(0, 1, 0), 90))); // the physics hull is along x, but dna is along z transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation))); transform.Children.Add(new TranslateTransform3D(this.Position.ToVector())); Vector3D scale = this.Scale; double radius = RADIUSPERCENTOFSCALE * ((scale.X + scale.Y) * .5d); double height = HEIGHTPERCENTOFSCALE * scale.Z; return(CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value)); }
internal 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 AxisAngleRotation3D(new Vector3D(0, 1, 0), 90))); // the physics hull is along x, but dna is along z transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); // Scale X and Y should be identical, but average them to be safe double radius = SIZEPERCENTOFSCALE_XY * Math1D.Avg(scale.X, scale.Y) * .5; // multiplying by .5 to turn diameter into radius double height = SIZEPERCENTOFSCALE_Z * scale.Z; return(CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value)); }
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); } }
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); }
public TreasureBox(Point3D position, double mass, double hitPoints, int materialID, World world, DamageProps damageMultipliers, object[] containedTreasureDNA = null) { const double RADIUS = .75d / 2d; const double HEIGHT = 1.5d; const double RING_Z1 = (HEIGHT / 2d) * .5d; // this is distance from the end cap const double RING_Z2 = (HEIGHT / 2d) - RING_Z1; // this one is distance from the origin const double RINGRADIUS_INNER = RADIUS * .5d; const double RINGRADIUS_OUTER = RADIUS * 1.05d; const double RINGHEIGHT = HEIGHT * .05d; const int DOMESEGMENTS = 3; const int CYLINDERSEGMENTS = 8; const int RINGSEGMENTS = 8; #region WPF Model Model3DGroup geometries = new Model3DGroup(); #region Barrel // Material MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("413D34")))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("60C5CAA7")), 2d));// .25d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; List <TubeRingBase> rings = new List <TubeRingBase>(); rings.Add(new TubeRingDome(0d, false, DOMESEGMENTS)); rings.Add(new TubeRingRegularPolygon(RING_Z1, false, RADIUS, RADIUS, false)); rings.Add(new TubeRingRegularPolygon(HEIGHT - (RING_Z1 * 2), false, RADIUS, RADIUS, false)); rings.Add(new TubeRingDome(RING_Z1, false, DOMESEGMENTS)); geometry.Geometry = UtilityWPF.GetMultiRingedTube(CYLINDERSEGMENTS, rings, true, true); geometries.Children.Add(geometry); #endregion #region Rings // Material material = new MaterialGroup(); //material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("736E56")))); //material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("B0EEF2CE")), .8d)); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("CCBF81")))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("B0D9D78D")), 8));// .8d)); // Ring 1 // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetRing(RINGSEGMENTS, RINGRADIUS_INNER, RINGRADIUS_OUTER, RINGHEIGHT, new TranslateTransform3D(0, 0, -RING_Z2), false); geometries.Children.Add(geometry); // Ring 2 // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetRing(RINGSEGMENTS, RINGRADIUS_INNER, RINGRADIUS_OUTER, RINGHEIGHT, new TranslateTransform3D(0, 0, RING_Z2), false); geometries.Children.Add(geometry); // Ring 3 // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetRing(RINGSEGMENTS, RINGRADIUS_INNER, RINGRADIUS_OUTER, RINGHEIGHT); geometries.Children.Add(geometry); #endregion geometries.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)); // make this go along x instead of z this.Model = geometries; // Model Visual ModelVisual3D visual = new ModelVisual3D(); // this is the expensive one, so as few of these should be made as possible visual.Content = this.Model; #endregion #region Physics Body Transform3DGroup transform = new Transform3DGroup(); //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); using (CollisionHull hull = CollisionHull.CreateCylinder(world, 0, RADIUS, HEIGHT, null)) { this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { visual }); this.PhysicsBody.MaterialGroupID = materialID; this.PhysicsBody.LinearDamping = 1d; this.PhysicsBody.AngularDamping = new Vector3D(.01d, .01d, .01d); //this.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(PhysicsBody_ApplyForceAndTorque); } #endregion _sensorVisionPoints = GetSensorVisionPoints_Model(RADIUS, HEIGHT); this.Radius = Math.Sqrt((RADIUS * RADIUS) + ((HEIGHT / 2d) * (HEIGHT / 2d))); this.ReceiveDamageMultipliers = damageMultipliers ?? new DamageProps(); this.HitPoints = new Container() { QuantityMax = hitPoints, QuantityCurrent = hitPoints }; this.ContainedTreasureDNA = containedTreasureDNA; this.CreationTime = DateTime.UtcNow; }