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; return(CollisionHull.CreateSphere(world, 0, new Vector3D(scale.X * RADIUSPERCENTOFSCALE, scale.Y * RADIUSPERCENTOFSCALE, scale.Z * HEIGHTPERCENTOFSCALE), transform.Value)); }
// Just going with a sphere for the physics internal static CollisionHull CreateCameraCollisionHull(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(scale.X * SCALE * .5d, scale.Y * SCALE * .5d, scale.Z * SCALE * .5d); return(CollisionHull.CreateSphere(world, 0, size, transform.Value)); }
public override CollisionHull CreateCollisionHull(WorldBase world) { Transform3DGroup transform = new Transform3DGroup(); //transform.Children.Add(new ScaleTransform3D(scale)); // it ignores scale transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation))); transform.Children.Add(new TranslateTransform3D(this.Position.ToVector())); Vector3D size = new Vector3D(this.Scale.X * DirectionControllerRingDesign.SIZEPERCENTOFSCALE * .5d, this.Scale.Y * DirectionControllerRingDesign.SIZEPERCENTOFSCALE * .5d, this.Scale.Z * DirectionControllerRingDesign.SIZEPERCENTOFSCALE * .5d); return(CollisionHull.CreateSphere(world, 0, size, transform.Value)); }
public override CollisionHull CreateCollisionHull(WorldBase world) { 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(Scale.X * SCALE * .5d, Scale.Y * SCALE * .5d, Scale.Z * SCALE * .5d); return(CollisionHull.CreateSphere(world, 0, size, transform.Value)); }
public Egg(Point3D position, double radius, World world, int materialID, ItemOptions itemOptions, T contents) { this.Radius = radius; Vector3D scale = new Vector3D(.75d, .75d, 1d); #region WPF Model // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(WorldColors.Egg_Color))); materials.Children.Add(WorldColors.Egg_Specular); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, this.Radius); geometry.Transform = new ScaleTransform3D(scale); this.Model = geometry; // Model Visual ModelVisual3D model = new ModelVisual3D(); model.Content = geometry; #endregion #region Physics Body Transform3DGroup transform = new Transform3DGroup(); transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation()))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); double volume = (4d / 3d) * Math.PI * scale.X * this.Radius * scale.Y * this.Radius * scale.Z * this.Radius; double mass = volume * itemOptions.Egg_Density; using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, scale * this.Radius, null)) { this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { model }); this.PhysicsBody.MaterialGroupID = materialID; this.PhysicsBody.LinearDamping = .01f; this.PhysicsBody.AngularDamping = new Vector3D(.001f, .001f, .001f); } #endregion this.CreationTime = DateTime.UtcNow; }
public Projectile(double radius, double mass, Point3D position, World world, int materialID, Color?color = null, double?maxAge = null, Map map = null) { if (maxAge != null && map == null) { throw new ArgumentException("Map must be populated if max age is set"); } this.Radius = radius; _maxAge = maxAge; _map = map; #region WPF Model this.Model = GetModel(color); this.Model.Transform = new ScaleTransform3D(radius, radius, radius); // Model Visual ModelVisual3D visual = new ModelVisual3D(); visual.Content = this.Model; #endregion #region Physics Body Transform3DGroup transform = new Transform3DGroup(); transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation()))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, new Vector3D(radius, radius, radius), null)) { this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { visual }); //this.PhysicsBody.IsContinuousCollision = true; this.PhysicsBody.MaterialGroupID = materialID; this.PhysicsBody.LinearDamping = .01d; this.PhysicsBody.AngularDamping = new Vector3D(.01d, .01d, .01d); //this.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque); } #endregion this.CreationTime = DateTime.UtcNow; }
public SpaceStation(Point3D position, World world, int materialID, Quaternion orientation) { //TODO: Windows, lights MaterialGroup material = null; GeometryModel3D geometry = null; Model3DGroup models = new Model3DGroup(); // These are random, so pull them once Color hullColor = WorldColors.SpaceStationHull_Color; SpecularMaterial hullSpecular = WorldColors.SpaceStationHull_Specular; double radius = 8; this.Radius = radius * 1.25; // this is the extremes of the force field double mass = 10000; #region Interior Visuals // These are visuals that will stay oriented to the ship, but don't count in collision calculations #region Hull - Torus // Material material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor))); material.Children.Add(hullSpecular); // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetTorus(30, 10, radius * .15, radius); // Model Group models.Children.Add(geometry); #endregion #region Hull - Spine // Material material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor))); material.Children.Add(hullSpecular); // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, radius * .075, radius * .66); Transform3DGroup spineTransform2 = new Transform3DGroup(); spineTransform2.Children.Add(new TranslateTransform3D(radius * .1, 0, 0)); spineTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90))); geometry.Transform = spineTransform2; // Model Group models.Children.Add(geometry); #endregion #region Hull - Spokes for (int cntr = 0; cntr < 3; cntr++) { // Material material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor))); material.Children.Add(hullSpecular); // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, radius * .05, radius * .9); Transform3DGroup spokeTransform = new Transform3DGroup(); spokeTransform.Children.Add(new TranslateTransform3D(radius * .45, 0, 0)); // the cylinder is built along the y axis, but is centered halfway spokeTransform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), cntr * 120d))); geometry.Transform = spokeTransform; // Model Group models.Children.Add(geometry); } #endregion #region Hull - Top inner // Material material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, hullColor, .25d)))); material.Children.Add(hullSpecular); // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, radius * .11, radius * .01); Transform3DGroup spokeTransform2 = new Transform3DGroup(); spokeTransform2.Children.Add(new TranslateTransform3D((radius * .51) - .5, 0, 0)); // the cylinder is built along the x axis, but is centered halfway spokeTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d))); geometry.Transform = spokeTransform2; // Model Group models.Children.Add(geometry); #endregion #region Hull - Top outer //TODO: The two cylinders cause flicker, come up with the definition of a ring (or do some texture mapping - if so, see if the texture can be vector graphics) // Material material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Black, hullColor, .25d)))); material.Children.Add(hullSpecular); // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, radius * .12, radius * .0095); Transform3DGroup spokeTransform3 = new Transform3DGroup(); spokeTransform3.Children.Add(new TranslateTransform3D((radius * .5) - .5, 0, 0)); // the cylinder is built along the y axis, but is centered halfway spokeTransform3.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d))); geometry.Transform = spokeTransform3; // Model Group models.Children.Add(geometry); #endregion #endregion #region Glass // Material //NOTE: There is an issue with drawing objects inside a semitransparent object - they have to be added in order (so stuff added after a semitransparent won't be visible behind it) Brush skinBrush = new SolidColorBrush(WorldColors.SpaceStationGlass_Color); // the skin is semitransparent, so you can see the components inside material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(skinBrush)); material.Children.Add(WorldColors.SpaceStationGlass_Specular_Front); // more reflective (and white light) MaterialGroup backMaterial = new MaterialGroup(); backMaterial.Children.Add(new DiffuseMaterial(skinBrush)); backMaterial.Children.Add(WorldColors.SpaceStationGlass_Specular_Back); // dark light, and not very reflective // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = backMaterial; geometry.Geometry = UtilityWPF.GetSphere_LatLon(6, radius, radius, radius * .25); // Model Group models.Children.Add(geometry); #endregion #region Exterior Visuals // There is a bug in WPF where visuals added after a semitransparent one won't show inside. So if you want to add exterior // bits that aren't visible inside, this would be the place #endregion #region Force Field Vector3D forceFieldSize = new Vector3D(radius * 1.25, radius * 1.25, radius * .75); // Material _forceField_DiffuseMaterial = new DiffuseMaterial(null); //Brushes.Transparent); // the momentarily brush will change when there is a collision _forceField_EmissiveFront = new EmissiveMaterial(null); //Brushes.Transparent); _forceField_EmissiveRear = new EmissiveMaterial(null); //Brushes.Transparent); material = new MaterialGroup(); material.Children.Add(_forceField_DiffuseMaterial); material.Children.Add(_forceField_EmissiveFront); backMaterial = new MaterialGroup(); backMaterial.Children.Add(_forceField_DiffuseMaterial); backMaterial.Children.Add(_forceField_EmissiveRear); // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = backMaterial; geometry.Geometry = UtilityWPF.GetSphere_LatLon(6, forceFieldSize.X, forceFieldSize.Y, forceFieldSize.Z); // Model Group models.Children.Add(geometry); #endregion this.Model = models; // Model Visual ModelVisual3D model = new ModelVisual3D(); // this is the expensive one, so as few of these should be made as possible model.Content = models; #region Physics Body Transform3DGroup transform = new Transform3DGroup(); transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, forceFieldSize, null)) { this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { model }); this.PhysicsBody.MaterialGroupID = materialID; this.PhysicsBody.LinearDamping = .01f; this.PhysicsBody.AngularDamping = new Vector3D(.001f, .001f, .001f); } #endregion this.CreationTime = DateTime.UtcNow; }
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); }