public Visual3DBodyBase(World world, ModelVisual3D visual) { if (visual == null) throw new ArgumentNullException("visual"); _visual = visual; Initialise(world); }
public ConvexBody3D(World world, ModelVisual3D model, CollisionShape collisionShape, double radius, double height) : base(world, model) { // Validate switch (collisionShape) { case CollisionShape.Capsule: case CollisionShape.ChamferCylinder: case CollisionShape.Cone: case CollisionShape.Cylinder: break; default: throw new ArgumentException("This constructor overload only supports collision shapes of cone, cylinder, capsule, chamfer cylinder"); } // Store the definition of the collision shape _collisionShape = collisionShape; _collisionShapeRatio1 = radius; _collisionShapeRatio2 = height; _collisionShapeRatio3 = -1d; // Calculate the collision mask RecalculateCollisionMask(); }
protected override CollisionMask OnInitialise(World world) { if (_visual != null) { DependencyObject parent = VisualTreeHelper.GetParent(_visual); if (parent == null) throw new InvalidOperationException("The Visual3D is not currently connected to a Viewport."); VisualMatrix = MathUtils.GetTransformToWorld(_visual); if (!(parent is Viewport3DVisual)) { ModelVisual3D parentModel = (parent as ModelVisual3D); if (parentModel == null) throw new InvalidOperationException("The Visual3D does not belong to a ModelVisual3D."); if (!(this is INullBody)) { Viewport3DVisual viewport = Viewport3DHelper.GetViewportVisual(_visual); parentModel.Children.Remove(_visual); viewport.Children.Add(_visual); } } _visual.Transform = VisualTransform; return OnInitialise(VisualMatrix); } else return null; }
public TerrianCollisionMask3D(World world, ModelVisual3D visual) { if (visual == null) throw new ArgumentNullException("visual"); _visual = visual; Initialise(world); }
public GeometrylBasedCollisionMask(World world, Geometry3D geometry) { if (geometry == null) throw new ArgumentNullException("geometry"); _geometry = geometry; Initialise(world); }
public MaterialManager(World world) { _materials = new MaterialPhysics(world); _defaultMaterialID = _materials.AddMaterial(.4, .9, .4, false); _asteroidMaterialID = _materials.AddMaterial(.25, .9, .75, false); _shipMaterialID = _materials.AddMaterial(.5, .9, .4, true); _mineralMaterialID = _materials.AddMaterial(.5, .9, .4, false); }
public void Initialise(World world) { if (_isInitialised) return; if (world == null) throw new ArgumentNullException("world"); _world = world; _collision = OnInitialise(); OnInitialiseEnd(); _isInitialised = true; }
public ConvexBody3D(World world, ModelVisual3D model, CollisionShape collisionShape, double ratioX, double ratioY, double ratioZ) : base(world, model) { // Validate switch (collisionShape) { case CollisionShape.Cube: case CollisionShape.Sphere: break; default: throw new ArgumentException("This constructor overload only supports collision shapes of cube and sphere"); } // Store the definition of the collision shape _collisionShape = collisionShape; _collisionShapeRatio1 = ratioX; // reusing 3 doubles so I don't waste as much memory (it's not much, but makes me feel better) _collisionShapeRatio2 = ratioY; _collisionShapeRatio3 = ratioZ; // Calculate the collision mask RecalculateCollisionMask(); }
public CollisionTree(World world) { Initialise(world, Matrix3D.Identity); }
public GeometryCollisionMask3D(World world, Geometry3D geometry) : base(world, geometry) { }
public Map(Viewport3D viewport, Viewport3D viewportMap, World world) { _viewport = viewport; _viewportMap = viewportMap; _world = world; }
protected abstract CollisionMask OnInitialise(World world);
public Joint(World world, Body parent, Body child) { Initialise(world, parent, child); }
public MaterialPhysics(World world) { _world = world; _materialHelper = new CMaterialPhysics(_world.NewtonWorld); }
public NullCollision(World world) : base(world) { }
public void Update(World world, World.BodyFilterType filterType, params Body[] bodies) { _hitResult = world.CastRay(this, filterType, bodies); if (_hitResult != null) { HitDistance = _hitResult.HitDistance; } else { HitDistance = -1; } }
public void CreateBot(Viewport3D viewport, SharedVisuals sharedVisuals, World world, Point3D worldPosition) { base.CreateBot(viewport, sharedVisuals, world, worldPosition); }
/// <summary> /// Set the properties, then call create /// NOTE: This adds itself to the viewport and world. In the future, that should be handled by the caller /// </summary> public void CreateBot(Viewport3D viewport, SharedVisuals sharedVisuals, World world, Point3D worldPosition) { _viewport = viewport; // Thruster _origThrustDirection = new Vector3D(0, 4, 0); _thruster = new ThrustLine(_viewport, sharedVisuals, _origThrustDirection, new Vector3D(0, 0, 0)); MaterialGroup material = null; GeometryModel3D geometry = null; ModelVisual3D model = null; #region Interior Extra Visuals // These are visuals that will stay oriented to the ship, but don't count in collision calculations #region Core // Neutral _coreMaterialNeutral = new MaterialGroup(); _coreMaterialNeutral.Children.Add(new DiffuseMaterial(Brushes.DimGray)); _coreMaterialNeutral.Children.Add(new SpecularMaterial(Brushes.DimGray, 75d)); // Attack _coreMaterialAttack = new MaterialGroup(); _coreMaterialAttack.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Red, UtilityWPF.AlphaBlend(Colors.Black, Colors.DimGray, .5), .15d)))); _coreMaterialAttack.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 255, 128, 128)), 100d)); _lightAttack = new PointLight(); _lightAttack.Color = Color.FromArgb(255, 96, 0, 0); _lightAttack.Position = new Point3D(0, 0, 0); _lightAttack.Range = _radius * 3; // Geometry Model _coreGeometry = new GeometryModel3D(); _coreGeometry.Material = _coreMaterialNeutral; _coreGeometry.BackMaterial = _coreMaterialNeutral; _coreGeometry.Geometry = UtilityWPF.GetSphere_LatLon(5, _radius * .4, _radius * .4, _radius * .4); _coreGeometry.Transform = new TranslateTransform3D(0, 0, 0); // Model Visual _core = new ModelVisual3D(); _core.Content = _coreGeometry; //NOTE: model.Transform is set to the physics body's transform every frame // Add to the viewport _viewport.Children.Add(_core); #endregion #endregion #region WPF Model // Material //NOTE: There seems to be an issue with drawing objects inside a semitransparent object - I think they have to be added in a certain order or something Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 255, 255, 255)); // making the skin semitransparent, so you can see the components inside material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(skinBrush)); material.Children.Add(new SpecularMaterial(Brushes.White, 75d)); // more reflective (and white light) MaterialGroup backMaterial = new MaterialGroup(); backMaterial.Children.Add(new DiffuseMaterial(skinBrush)); backMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)), 10d)); // dark light, and not very reflective // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = backMaterial; geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, _radius, _radius, _radius); // Transform Transform3DGroup transform = new Transform3DGroup(); // rotate needs to be added before translate transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0))); transform.Children.Add(new TranslateTransform3D(worldPosition.ToVector())); // Model Visual 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 this.PhysicsBody = new ConvexBody3D(world, model); this.PhysicsBody.Mass = Convert.ToSingle(this.Mass); this.PhysicsBody.LinearDamping = .01f; //this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f); //this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, 100000f); // this doesn't work. probably to to cap the z back to zero, and any spin to zero this.PhysicsBody.AngularDamping = new Vector3D(10f, 10f, 10f); this.PhysicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce); //this.PhysicsBody.NewtonBody.ApplyForceAndTorque #endregion #region Exterior Extra 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, this would be the place #endregion _thruster.IsFiring = true; }
public NullBody(World world) { Initialise(world); }
public void Initialise(World world, Body parent, Body child) { if (_isInitialised) return; VerifyAccess(); if (world == null) throw new ArgumentNullException("world"); if (parent == null) throw new ArgumentNullException("parent"); parent.VerifyInitialised("Parent"); if (child == null) throw new ArgumentNullException("child"); child.VerifyInitialised("Child"); _world = world; _parentBody = parent; _childBody = child; _joint = OnInitialise(); if (_joint != null) { _joint.CollisionState = (int)(CollisionState)this.CollisionState; if (this.Stiffness != null) _joint.Stiffness = (float)this.Stiffness; _isInitialised = true; AfterInitialise(); } }
public CollisionTree(World world, Matrix3D initialMatrix) { Initialise(world, initialMatrix); }
public VisualNullBody3D(World world, ModelVisual3D model) : base(world, model) { }
public void Initialise(World world, Matrix3D initialMatrix) { _initialMatrix = Math3D.GetScaleMatrix(ref initialMatrix); Initialise(world); }
public ConvexBody3D(World world, ModelVisual3D model) : base(world, model) { RecalculateCollisionMask(); }
public ConvexCollisionMask(World world) : base(world) { }
public void Initialise(World world) { if (_isInitialised) return; if (world == null) throw new ArgumentNullException("world"); _world = world; _collision = OnInitialise(world); if (_collision == null) { _collision = new NullCollision(_world); } _body = new CBody(_collision.NewtonCollision); _body.Destructor += _body_Destructor; _body.AutoFreeze = this.AutoPause; _body.UserData = this; _body.Matrix = _visualMatrix.Matrix; OnInitialiseEnd(); // this might adjust the _body.Matrix property // not initialised yet, nothing should be called on property changed event this.Transform = new MatrixTransform3D(_body.Matrix); _body.SetTransform += body_setTransform; _body.ApplyForceAndTorque += body_ApplyForceAndTorque; CalculateMass(this.Mass); world.AddBody(this); _isInitialised = true; }
protected override CollisionMask OnInitialise(World world) { throw new NotImplementedException(); }
protected override CollisionMask OnInitialise(World world) { return new NullCollision(world); }
/// <summary> /// Set the properties, then call create /// NOTE: This adds itself to the viewport and world. In the future, that should be handled by the caller /// </summary> protected void CreateBot(Viewport3D viewport, SharedVisuals sharedVisuals, World world, Point3D worldPosition) { _viewport = viewport; _sharedVisuals = sharedVisuals; _world = world; // Thruster _origThrustDirection = new Vector3D(0, _thrustForce, 0); _thruster = new ThrustLine(_viewport, sharedVisuals, _origThrustDirection, new Vector3D(0, 0, 0)); _thruster.LineMaxLength = this.ThrustLineStandardLength * _thrustLineMultiplier; MaterialGroup material = null; GeometryModel3D geometry = null; ModelVisual3D model = null; _visuals = new List<ModelVisual3D>(); #region Interior Extra Visuals // These are visuals that will stay oriented to the ship, but don't count in collision calculations #region Core // Neutral _coreMaterialNeutral = new MaterialGroup(); _coreMaterialNeutralColor = new DiffuseMaterial(new SolidColorBrush(_coreColor)); _coreMaterialNeutral.Children.Add(_coreMaterialNeutralColor); _coreMaterialNeutral.Children.Add(new SpecularMaterial(Brushes.DimGray, 75d)); // Attack _coreMaterialAttack = new MaterialGroup(); _coreMaterialAttack.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Red, UtilityWPF.AlphaBlend(Colors.Black, Colors.DimGray, .5), .15d)))); _coreMaterialAttack.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 255, 128, 128)), 100d)); _lightAttack = new PointLight(); _lightAttack.Color = Color.FromArgb(255, 96, 0, 0); _lightAttack.Position = new Point3D(0, 0, 0); _lightAttack.Range = _radius * 3; // Geometry Model _coreGeometry = new GeometryModel3D(); _coreGeometry.Material = _coreMaterialNeutral; _coreGeometry.BackMaterial = _coreMaterialNeutral; _coreGeometry.Geometry = UtilityWPF.GetSphere_LatLon(5, _radius * .4, _radius * .4, _radius * .4); _coreGeometry.Transform = new TranslateTransform3D(0, 0, 0); // Model Visual _core = new ModelVisual3D(); _core.Content = _coreGeometry; //NOTE: model.Transform is set to the physics body's transform every frame _visuals.Add(_core); // Add to the viewport _viewport.Children.Add(_core); #endregion #endregion #region Glass Shell // Material //NOTE: There seems to be an issue with drawing objects inside a semitransparent object - I think they have to be added in a certain order or something Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 255, 255, 255)); // making the skin semitransparent, so you can see the components inside material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(skinBrush)); material.Children.Add(new SpecularMaterial(Brushes.White, 75d)); // more reflective (and white light) MaterialGroup backMaterial = new MaterialGroup(); backMaterial.Children.Add(new DiffuseMaterial(skinBrush)); backMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)), 10d)); // dark light, and not very reflective // Geometry Model geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = backMaterial; geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, _radius, _radius, _radius); // Transform Transform3DGroup transform = new Transform3DGroup(); // rotate needs to be added before translate transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0))); transform.Children.Add(new TranslateTransform3D(worldPosition.ToVector())); // Model Visual model = new ModelVisual3D(); model.Content = geometry; model.Transform = transform; _visuals.Add(model); // Add to the viewport _viewport.Children.Add(model); #endregion #region Physics Body // Make a physics body that represents this shape _physicsBody = new ConvexBody3D(world, model); //NOTE: Not setting material _physicsBody.MaterialGroupID, so it takes the default material _physicsBody.NewtonBody.UserData = this; _physicsBody.Mass = Convert.ToSingle(this.Mass); _physicsBody.LinearDamping = .01f; _physicsBody.AngularDamping = new Vector3D(10f, 10f, 10f); // fairly heavy damping (the bot doesn't try to cancel its spin, so I'll let Newt do it for me) _physicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce); #endregion #region Exterior Extra 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 _thruster.IsFiring = true; // Show the proper core this.IsAttacking = _isAttacking; }
public TerrianBody3D(World world, ModelVisual3D model) : base(world, model) { }