protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { if (!Hovering) { return(false); } if (!stepInitialized) { KeyboardStep = (Convert.ToSingle(Bindable.MaxValue) - Convert.ToSingle(Bindable.MinValue)) / 20; } var step = KeyboardStep; if (Bindable.IsInteger) { step = (float)Math.Ceiling(step); } switch (args.Key) { case Key.Right: Bindable.Add(step); return(true); case Key.Left: Bindable.Add(-step); return(true); default: return(false); } }
public BindableCollection <ProductsModel> toBindable() { foreach (var item in returnAllProducts()) { Bindable.Add(item); } return(Bindable); }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { var step = KeyboardStep; if (Bindable.IsInteger) { step = Math.Ceiling(step); } switch (args.Key) { case Key.Right: Bindable.Add(step); return(true); case Key.Left: Bindable.Add(step); return(true); default: return(false); } }
/// <summary> /// Constructs a simple character controller. /// </summary> /// <param name="position">Location to initially place the character.</param> /// <param name="height">The height of the character.</param> /// <param name="radius">The diameter of the character.</param> /// <param name="supportHeight">The distance above the ground that the bottom of the character's body floats.</param> /// <param name="mass">Total mass of the character.</param> public Character(Main main, Bindable bindable, Vector3 position, float height = Character.DefaultHeight, float crouchedHeight = Character.DefaultCrouchedHeight, float radius = Character.DefaultRadius, float supportHeight = Character.DefaultSupportHeight, float crouchedSupportHeight = Character.DefaultCrouchedSupportHeight, float mass = Character.DefaultMass) { this.main = main; this.Radius.Value = radius; this.Mass.Value = mass; this.Body = new Capsule(position, height, radius, mass); this.Body.Tag = this; this.Body.CollisionInformation.Tag = this; this.Body.IgnoreShapeChanges = true; this.Body.LinearDamping = 0.0f; this.Body.CollisionInformation.CollisionRules.Group = Character.CharacterGroup; this.NormalHeight = height; this.CrouchedHeight = crouchedHeight; this.Body.CollisionInformation.Events.ContactCreated += new BEPUphysics.BroadPhaseEntries.Events.ContactCreatedEventHandler <EntityCollidable>(Events_ContactCreated); this.collisionPairCollector = new Box(position + new Vector3(0, (height * -0.5f) - supportHeight, 0), radius * 2, supportHeight * 2, radius, 1); this.collisionPairCollector.CollisionInformation.CollisionRules.Personal = CollisionRule.NoNarrowPhaseUpdate; //Prevents collision detection/contact generation from being run. this.collisionPairCollector.IsAffectedByGravity = false; this.collisionPairCollector.CollisionInformation.CollisionRules.Group = Character.CharacterGroup; CollisionRules.AddRule(this.collisionPairCollector, this.Body, CollisionRule.NoBroadPhase); //Prevents the creation of any collision pairs between the body and the collector. this.SupportHeight.Value = supportHeight; this.NormalSupportHeight = supportHeight; this.CrouchedSupportHeight = crouchedSupportHeight; this.Body.LocalInertiaTensorInverse = new BEPUutilities.Matrix3x3(); this.collisionPairCollector.LocalInertiaTensorInverse = new BEPUutilities.Matrix3x3(); bindable.Add(new ChangeBinding <bool>(this.Crouched, delegate(bool old, bool value) { if (value && !old) { this.Body.Position += new Vector3(0, (this.CrouchedSupportHeight - this.NormalSupportHeight) + 0.5f * (this.CrouchedHeight - this.NormalHeight), 0); this.Height.Value = this.CrouchedHeight; this.Body.Length = this.Height.Value - this.Radius * 2; this.SupportHeight.Value = this.CrouchedSupportHeight; } else if (!value && old) { this.Height.Value = this.NormalHeight; this.Body.Length = this.Height.Value - this.Radius * 2; this.Body.Position += new Vector3(0, (this.NormalSupportHeight - this.CrouchedSupportHeight) + 0.5f * (this.NormalHeight - this.CrouchedHeight), 0); this.SupportHeight.Value = this.NormalSupportHeight; } this.collisionPairCollector.Height = this.SupportHeight * 2; this.Transform.Value = this.Body.WorldTransform; })); bindable.Add(new SetBinding <Matrix>(this.Transform, delegate(Matrix m) { this.Body.WorldTransform = m; })); bindable.Add(new SetBinding <Vector3>(this.LinearVelocity, delegate(Vector3 v) { this.Body.LinearVelocity = v; })); //Make the body slippery. //Note that this will not make all collisions have zero friction; //the friction coefficient between a pair of objects is based //on a blending of the two objects' materials. this.Body.Material.KineticFriction = 0.0f; this.Body.Material.StaticFriction = 0.0f; this.Body.Material.Bounciness = 0.0f; const int rayChecks = 4; float rayCheckRadius = radius - 0.1f; this.rayOffsets = new[] { Vector3.Zero }.Concat(Enumerable.Range(0, rayChecks).Select( delegate(int x) { float angle = x * ((2.0f * (float)Math.PI) / (float)rayChecks); return(new Vector3((float)Math.Cos(angle) * rayCheckRadius, 0, (float)Math.Sin(angle) * rayCheckRadius)); })).ToArray(); this.IsUpdating = false; }
/// <summary> /// Constructs a simple character controller. /// </summary> /// <param name="position">Location to initially place the character.</param> /// <param name="height">The height of the character.</param> /// <param name="radius">The diameter of the character.</param> /// <param name="supportHeight">The distance above the ground that the bottom of the character's body floats.</param> /// <param name="mass">Total mass of the character.</param> public Character(Main main, Bindable bindable, Vector3 position, float height = Character.DefaultHeight, float crouchedHeight = Character.DefaultCrouchedHeight, float radius = Character.DefaultRadius, float supportHeight = Character.DefaultSupportHeight, float crouchedSupportHeight = Character.DefaultCrouchedSupportHeight, float mass = Character.DefaultMass) { this.main = main; this.Radius.Value = radius; this.Mass.Value = mass; this.Body = new Capsule(position, height, radius, mass); this.Body.Tag = this; this.Body.CollisionInformation.Tag = this; this.Body.IgnoreShapeChanges = true; this.Body.LinearDamping = 0.0f; this.Body.CollisionInformation.CollisionRules.Group = Character.CharacterGroup; this.NormalHeight = height; this.CrouchedHeight = crouchedHeight; this.Body.CollisionInformation.Events.ContactCreated += new BEPUphysics.BroadPhaseEntries.Events.ContactCreatedEventHandler<EntityCollidable>(Events_ContactCreated); this.collisionPairCollector = new Box(position + new Vector3(0, (height * -0.5f) - supportHeight, 0), radius * 2, supportHeight * 2, radius, 1); this.collisionPairCollector.CollisionInformation.CollisionRules.Personal = CollisionRule.NoNarrowPhaseUpdate; //Prevents collision detection/contact generation from being run. this.collisionPairCollector.IsAffectedByGravity = false; this.collisionPairCollector.CollisionInformation.CollisionRules.Group = Character.CharacterGroup; CollisionRules.AddRule(this.collisionPairCollector, this.Body, CollisionRule.NoBroadPhase); //Prevents the creation of any collision pairs between the body and the collector. this.SupportHeight.Value = supportHeight; this.NormalSupportHeight = supportHeight; this.CrouchedSupportHeight = crouchedSupportHeight; this.Body.LocalInertiaTensorInverse = new BEPUutilities.Matrix3x3(); this.collisionPairCollector.LocalInertiaTensorInverse = new BEPUutilities.Matrix3x3(); bindable.Add(new ChangeBinding<bool>(this.Crouched, delegate(bool old, bool value) { if (value && !old) { this.Body.Position += new Vector3(0, (this.CrouchedSupportHeight - this.NormalSupportHeight) + 0.5f * (this.CrouchedHeight - this.NormalHeight), 0); this.Height.Value = this.CrouchedHeight; this.Body.Length = this.Height.Value - this.Radius * 2; this.SupportHeight.Value = this.CrouchedSupportHeight; } else if (!value && old) { this.Height.Value = this.NormalHeight; this.Body.Length = this.Height.Value - this.Radius * 2; this.Body.Position += new Vector3(0, (this.NormalSupportHeight - this.CrouchedSupportHeight) + 0.5f * (this.NormalHeight - this.CrouchedHeight), 0); this.SupportHeight.Value = this.NormalSupportHeight; } this.collisionPairCollector.Height = this.SupportHeight * 2; this.Transform.Value = this.Body.WorldTransform; })); bindable.Add(new SetBinding<Matrix>(this.Transform, delegate(Matrix m) { this.Body.WorldTransform = m; })); bindable.Add(new SetBinding<Vector3>(this.LinearVelocity, delegate(Vector3 v) { this.Body.LinearVelocity = v; })); //Make the body slippery. //Note that this will not make all collisions have zero friction; //the friction coefficient between a pair of objects is based //on a blending of the two objects' materials. this.Body.Material.KineticFriction = 0.0f; this.Body.Material.StaticFriction = 0.0f; this.Body.Material.Bounciness = 0.0f; const int rayChecks = 4; float rayCheckRadius = radius - 0.1f; this.rayOffsets = new[] { Vector3.Zero }.Concat(Enumerable.Range(0, rayChecks).Select( delegate(int x) { float angle = x * ((2.0f * (float)Math.PI) / (float)rayChecks); return new Vector3((float)Math.Cos(angle) * rayCheckRadius, 0, (float)Math.Sin(angle) * rayCheckRadius); })).ToArray(); this.IsUpdating = false; }