public override CollisionHull CreateCollisionHull(NewtonDynamics.WorldBase world) { // Get points if (this.Vertices == null) { CreateGeometry(this.IsFinalModel); } Vector3D scale = this.Scale; double halfThick = THICKNESS * .5d * scale.Z; List <Point3D> points = new List <Point3D>(); points.AddRange(this.Vertices.Select(o => new Point3D(o.X * scale.X, o.Y * scale.Y, -halfThick))); points.AddRange(this.Vertices.Select(o => new Point3D(o.X * scale.X, o.Y * scale.Y, halfThick))); // Transform 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())); // Exit Function return(CollisionHull.CreateConvexHull(world, 0, points, transform.Value)); }
public virtual CollisionHull CreateCollisionHull(World world) { if (_isLooseProps) { Transform3DGroup transform = new Transform3DGroup(); //transform.Children.Add(new ScaleTransform3D(this.Scale)); // it ignores scale transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(_orientation))); transform.Children.Add(new TranslateTransform3D(_position.ToVector())); return(CollisionHull.CreateConvexHull(world, 0, _convexPoints, transform.Value)); } else { return(_part.CreateCollisionHull(world)); } }
public Mineral(MineralType mineralType, Point3D position, double volumeInCubicMeters, World world, int materialID, SharedVisuals sharedVisuals, double densityMult = 1d, double scale = 1d, decimal credits = 0m) { this.MineralType = mineralType; this.VolumeInCubicMeters = volumeInCubicMeters; this.Scale = scale; this.Credits = credits; this.Model = GetNewVisual(mineralType, sharedVisuals, scale); // 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; this.Density = GetSettingsForMineralType(mineralType).Density *densityMult; #region Physics Body Transform3DGroup transform = new Transform3DGroup(); transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation()))); transform.Children.Add(new TranslateTransform3D(position.ToVector())); ScaleTransform3D scaleTransform = new ScaleTransform3D(scale, scale, scale); Point3D[] hullPoints = UtilityWPF.GetPointsFromMesh((MeshGeometry3D)sharedVisuals.GetMineralMesh(mineralType), scaleTransform); using (CollisionHull hull = CollisionHull.CreateConvexHull(world, 0, hullPoints)) { this.PhysicsBody = new Body(hull, transform.Value, this.Density * volumeInCubicMeters, new Visual3D[] { visual }); this.PhysicsBody.MaterialGroupID = materialID; this.PhysicsBody.LinearDamping = .01f; this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f); //this.PhysicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce); } #endregion // Calculate radius Point3D aabbMin, aabbMax; this.PhysicsBody.GetAABB(out aabbMin, out aabbMax); this.Radius = (aabbMax - aabbMin).Length / 2d; this.CreationTime = DateTime.UtcNow; }