private void World_Updating(object sender, WorldUpdatingArgs e) { try { // Chased ball _chasedBall.Update(e.ElapsedTime); _chasedBallTransform.OffsetX = _chasedBall.Position.X; _chasedBallTransform.OffsetY = _chasedBall.Position.Y; _chasedBallTransform.OffsetZ = _chasedBall.Position.Z; _chasedDirectionModel.SetPoints(_chasedBall.Position, _chasedBall.Position + (_chasedBall.Direction.ToUnit() * 10)); // Chasing Objects if (_object_LinearVelocity != null) { _object_LinearVelocity.SetPosition(_chasedBall.Position); } if (_object_LinearForce != null) { _object_LinearForce.SetPosition(_chasedBall.Position); } if (_object_OrientationVelocity != null) { _object_OrientationVelocity.SetOrientation(_chasedBall.Direction); } if (_object_OrientationForce != null) { _object_OrientationForce.SetOrientation(_chasedBall.Direction); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
private static Tuple <Visual3D, Tuple <TranslateTransform3D, ScaleTransform3D, BillboardLine3D>[]> CreateVisual(SwarmCluster[] clusters, bool showVelocity) { Model3DGroup models = new Model3DGroup(); // Hull Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("10FFFFFF")))); materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("18FFFFFF")), 4)); var transforms = new Tuple <TranslateTransform3D, ScaleTransform3D, BillboardLine3D> [clusters.Length]; for (int cntr = 0; cntr < clusters.Length; cntr++) { SwarmClusterInfo clusterInfo = clusters[cntr].GetCurrentInfo(); #region velocity BillboardLine3D velocity = null; if (showVelocity) { velocity = new BillboardLine3D() { Color = UtilityWPF.ColorFromHex("20FFFFFF"), IsReflectiveColor = false, Thickness = .2, }; velocity.SetPoints(clusterInfo.Center, clusterInfo.Center + clusterInfo.Velocity); models.Children.Add(velocity.Model); } #endregion #region hull // Model GeometryModel3D hull = new GeometryModel3D(); hull.Material = materials; hull.BackMaterial = materials; hull.Geometry = UtilityWPF.GetSphere_Ico(1d, 2, true); // Transform Transform3DGroup transformGroup = new Transform3DGroup(); ScaleTransform3D scale = new ScaleTransform3D(clusterInfo.Radius, clusterInfo.Radius, clusterInfo.Radius); transformGroup.Children.Add(scale); TranslateTransform3D translate = new TranslateTransform3D(clusterInfo.Center.ToVector()); transformGroup.Children.Add(translate); hull.Transform = transformGroup; models.Children.Add(hull); #endregion transforms[cntr] = Tuple.Create(translate, scale, velocity); } ModelVisual3D visual = new ModelVisual3D(); visual.Content = models; return(Tuple.Create((Visual3D)visual, transforms)); }