private void HandleThrow(Vector3 dir) { dummyPlayerPuck.SetActive(false); IPhysicalObject physicalObject = physicalObjectFactory.Create(PhysicalObjectFactory.ObjectType.BlackPuck); physicalObject.ApplyForce(dir * ThrowForce); }
// using Newton's Law of Universal Gravitation // http://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation public static Newton GravityBetween(IPhysicalObject physicalObject, IPhysicalObject otherObject) { Meter distanceBetween = physicalObject.GetCoordinates<Meter>().DistanceFrom<Meter>(otherObject.GetCoordinates<Meter>()); var distanceSquared = new Meter(System.Math.Pow(distanceBetween.Value, 2)); var productOfMasses = (physicalObject.GetMass<Kilogram>()*otherObject.GetMass<Kilogram>()); return new Newton(GravitationalConstant.Multiply((productOfMasses).Divide(distanceSquared)).Value); }
public virtual CollisionResult TestCollision(IPhysicalObject that, Vector2 thatNewPosition, float scrollRows) { var collisionResult = new CollisionResult(); var thisScreenRectangle = new Rectangle((int)Position.X , (int)Position.Y , (int)this.Size.X , (int)this.Size.Y); var thatScreenRectangle = new Rectangle((int)thatNewPosition.X , (int)(thatNewPosition.Y) , (int)that.Size.X , (int)that.Size.Y); Rectangle intersectArea = Rectangle.Intersect(thisScreenRectangle, thatScreenRectangle); if (intersectArea.X * intersectArea.Y != 0) { collisionResult.CollisionType = CollisionType.Blocked; } return(collisionResult); }
public static Newton ForceBetween(IPhysicalObject physicalObject, IPhysicalObject otherObject) { Meter distanceBetween = physicalObject.GetCoordinates<Meter>().DistanceFrom<Meter>(otherObject.GetCoordinates<Meter>()); var distanceSquared = new Meter(System.Math.Pow(distanceBetween.Value, 2)); var chargeProduct = physicalObject.GetCharge().Multiply(otherObject.GetCharge()); return new Newton((CoulombsConstant.Multiply(chargeProduct).Divide(distanceSquared)).Value); }
public Force(GraphComponent component, IPhysicalObject target, double strength) { component.Forces.Add(this); this.component = component; this.target = target; this.strength = strength; this.time = 0; }
// using Newton's Law of Universal Gravitation // http://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation public static Newton GravityBetween(IPhysicalObject physicalObject, IPhysicalObject otherObject) { Meter distanceBetween = physicalObject.GetCoordinates <Meter>().DistanceFrom <Meter>(otherObject.GetCoordinates <Meter>()); var distanceSquared = new Meter(System.Math.Pow(distanceBetween.Value, 2)); var productOfMasses = (physicalObject.GetMass <Kilogram>() * otherObject.GetMass <Kilogram>()); return(new Newton(GravitationalConstant.Multiply((productOfMasses).Divide(distanceSquared)).Value)); }
public static Newton ForceBetween(IPhysicalObject physicalObject, IPhysicalObject otherObject) { Meter distanceBetween = physicalObject.GetCoordinates <Meter>().DistanceFrom <Meter>(otherObject.GetCoordinates <Meter>()); var distanceSquared = new Meter(System.Math.Pow(distanceBetween.Value, 2)); var chargeProduct = physicalObject.GetCharge().Multiply(otherObject.GetCharge()); return(new Newton((CoulombsConstant.Multiply(chargeProduct).Divide(distanceSquared)).Value)); }
public override CollisionResult TestCollision(IPhysicalObject that, Vector2 thatNewPosition, float scrollRows) { var collisionResult = new CollisionResult(); if (thatNewPosition.X < 0 || thatNewPosition.X + that.Size.X > GameSettings.Instance.WindowTilesSize.X || thatNewPosition.Y < 0 || thatNewPosition.Y + that.Size.Y > GameSettings.Instance.WindowTilesSize.Y) { collisionResult.CollisionType = CollisionType.OffRoad; var x = Math.Min(thatNewPosition.X, GameSettings.Instance.WindowTilesSize.X - that.Size.X); x = Math.Max(x, 0); var y = Math.Min(thatNewPosition.Y, GameSettings.Instance.WindowTilesSize.Y - that.Size.Y); y = Math.Max(y, 0); } else { for (var deltaX = 0; deltaX < that.Size.X; deltaX++) { for (var deltaY = 0; deltaY < that.Size.Y; deltaY++) { var f = (thatNewPosition.X + deltaX) / 2f; var x = (int)Math.Round(f * 2, MidpointRounding.AwayFromZero) / 2; f = (scrollRows / 2) + (thatNewPosition.Y + deltaY) / 2; var y = (int)Math.Round(f * 2, MidpointRounding.AwayFromZero) / 2; if ((x < 0 || x >= MAP_COLS) || y < 0 || y >= MAP_ROWS) { collisionResult.CollisionType = CollisionType.OffRoad; return(collisionResult); } else { var tileInfo = jsonMap.layers[0].tileIndexes[(int)(x + y * MAP_COLS)]; if (tileInfo.ti != 0) { collisionResult.CollisionType = CollisionType.Blocked; return(collisionResult); } } } } } return(collisionResult); }
protected Vector3 LookAtMotor(IPhysicalObject obj) { lock (m_LookAtParamsLock) { if (!m_EnableLookAt) { return(Vector3.Zero); } Quaternion dirRot = m_LookAtTarget / obj.Rotation; Vector3 dir = dirRot.GetEulerAngles(); dir /= m_LookAtStrength; return(dir - obj.AngularVelocity * m_LookAtDamping); } }
public IPhysicalObject Create(ObjectType type) { switch (type) { case ObjectType.BlackPuck: IPhysicalObject physicalObject = diContainer.InstantiatePrefabResource(PrefabBlackPuckPath).GetComponent <PhysicalObject>(); onBlackPuckCreated?.Invoke(physicalObject); return(physicalObject); case ObjectType.RedPuck: return(diContainer.InstantiatePrefabResource(PrefabRedPuckPath).GetComponent <PhysicalObject>()); case ObjectType.Goal: return(diContainer.InstantiatePrefabResource(PrefabGoalPath).GetComponent <PhysicalObject>()); default: return(null); } }
private void ApplyPhysics(int id, Func <IInputElement, Point> getposition) { if (!_manipulationstack.ContainsKey(id) || _manipulationstack[id].Count == 0) { return; } List <IPhysicalObject> stack = _manipulationstack[id]; IPhysicalObject original = stack[stack.Count - 1]; // Call Apply on the physical object. Pass the point and retrieve the unhandled vector. original.SetPoint(id, attachedElement.TransformToDescendant(original.ContainerVisual).Transform(_lastknownpositions[id])); Vector delta = original.ApplyManipulation(id, getposition(original.ContainerVisual)); _lastknownpositions[id] = getposition(attachedElement); // while there are parent physical containers... for (int i = stack.Count - 2; i >= 0; i--) { IPhysicalObject parent = stack[i]; // Find the touch point on the parent Point pt = getposition(parent.ContainerVisual); Matrix m = ((Transform)original.ContainerVisual.TransformToAncestor(parent.ContainerVisual)).Value; m.OffsetX = 0; m.OffsetY = 0; parent.SetPoint(id, pt + m.Transform(delta)); // Find the transform from original to the parent. // Transform the parent-adjusted point to parent space // Call Apply on parent delta = parent.ApplyManipulation(id, pt); // original = parent original = parent; } }
public static void PushPhysicalReferenceFrame(InputDevice device, IPhysicalObject obj) { int id = 0; if (device is MouseDevice) { id = -1; _lastknownpositions[id] = ((MouseDevice)device).GetPosition(device.ActiveSource.RootVisual as IInputElement); } if (device is StylusDevice) { id = ((StylusDevice)device).Id; _lastknownpositions[id] = ((StylusDevice)device).GetPosition(device.ActiveSource.RootVisual as IInputElement); } if (!_manipulationstack.ContainsKey(id)) { _manipulationstack[id] = new List <IPhysicalObject>(); } _manipulationstack[id].Add(obj); }
protected PositionalForce HoverMotor(IPhysicsObject actor, IPhysicalObject obj, Vector3 pos) { lock (m_HoverParamsLock) { if (m_HoverEnabled) { var v = new Vector3(0, 0, (m_Buoyancy - 1) * GravityConstant(actor, obj)); double targetHoverHeight; SceneInterface.LocationInfo locInfo = LocationInfoProvider.At(obj.GlobalPosition); targetHoverHeight = locInfo.GroundHeight; if (targetHoverHeight < locInfo.WaterHeight && m_AboveWater) { targetHoverHeight = locInfo.WaterHeight; } v.Z += (targetHoverHeight - obj.Position.Z) * m_HoverTau; return(new PositionalForce("HoverMotor", v, pos)); } else { return(new PositionalForce("HoverMotor", Vector3.Zero, pos)); } } }
protected PositionalForce MoveToTargetMotor(IPhysicalObject obj) { Vector3 force = Vector3.Zero; Vector3 dist = obj.GlobalPosition; lock (m_MoveToTargetParamsLock) { if (m_MoveToTargetTau > 0.01 && m_EnableMoveToTarget) { dist -= m_MoveToTargetPos; force = dist / m_MoveToTargetTau; Vector3 abs = new Vector3 { X = Math.Abs(dist.X), Y = Math.Abs(dist.Y), Z = Math.Abs(dist.Z) }; force.X = force.X.Clamp(-abs.X, abs.X); force.Y = force.Y.Clamp(-abs.Y, abs.Y); force.Z = force.Z.Clamp(-abs.Z, abs.Z); } } return(new PositionalForce("MoveToTargetMotor", force, Vector3.Zero)); }
public override CollisionResult TestCollision(IPhysicalObject that, Vector2 thatNewPosition, float scrollRows) { var collisionResult = new CollisionResult(); if (thatNewPosition.X < 0 || thatNewPosition.X + that.Size.X > GameSettings.Instance.WindowTilesSize.X || thatNewPosition.Y < 0 || thatNewPosition.Y + that.Size.Y > GameSettings.Instance.WindowTilesSize.Y) { collisionResult.CollisionType = CollisionType.OffRoad; var x = Math.Min(thatNewPosition.X, GameSettings.Instance.WindowTilesSize.X - that.Size.X); x = Math.Max(x, 0); var y = Math.Min(thatNewPosition.Y, GameSettings.Instance.WindowTilesSize.Y - that.Size.Y); y = Math.Max(y, 0); } else { for (var deltaX = 0; deltaX < that.Size.X; deltaX++) { for (var deltaY = 0; deltaY < that.Size.Y; deltaY++) { var f = (thatNewPosition.X + deltaX) / 2f; var x = (int)Math.Round(f * 2, MidpointRounding.AwayFromZero) / 2; f = (scrollRows / 2) + (thatNewPosition.Y + deltaY) / 2; var y = (int)Math.Round(f * 2, MidpointRounding.AwayFromZero) / 2; if ((x < 0 || x >= (GameSettings.Instance.WindowTilesSize.X / 2)) || y < 0 || y >= (mapLines.Count() * 2)) { collisionResult.CollisionType = CollisionType.OffRoad; return(collisionResult); } else { var mapChar = mapLines[y][x]; if ("XD".Contains(mapChar)) { collisionResult.CollisionType = CollisionType.Blocked; return(collisionResult); } } } } //var colorArray = new Color[(int)(that.Size.X * that.Size.Y)]; //var extractRegion = new Rectangle( // (int)Math.Round(thatNewPosition.X), // (int)Math.Round(scrollRows + thatNewPosition.Y), // (int)that.Size.X, // (int)that.Size.Y); //path01.GetData<Color>(0, extractRegion, colorArray, 0, (int)(that.Size.X * that.Size.Y)); //foreach (var color in colorArray) //{ // if (color != Color.White) // { // collisionResult.CollisionType = CollisionType.Blocked; // break; // } //} } return(collisionResult); }
public bool Contains(IPhysicalObject physicalObject) { return(_physicalObjects.Contains(physicalObject)); }
private void UpdateObjectParameters(IPhysicalObject o, float dt) { switch (o.Type) { case ObjectType.PointMass: UpdatePointMassParameters((PointMass)o, dt); break; case ObjectType.RigidBody: UpdateRigidBodyParameters((RigidBody)o, dt); break; } if (o.CollisionDataType == CollisionDataType.CollisionMesh) { ((CollisionMesh)o.CollisionData).MeshRotation = o.AngularVelocity; } }
public void RemoveObject(IPhysicalObject obj) { int i = objects.IndexOf(obj); if (i >= 0) { walkingEnabled.Remove(objects[i]); walkData.Remove(objects[i]); objects.RemoveAt(i); } if (obj.CollisionDataType != CollisionDataType.None) CollisionDetector.RemoveObject(obj); }
public FrictionalForce(GraphComponent component, IPhysicalObject target, double k, double degree = 0) : base(component, target, k) { this.degree = degree; }
protected PositionalForce BuoyancyMotor(IPhysicsObject actor, IPhysicalObject obj, Vector3 pos) { return(new PositionalForce("BuoyancyMotor", new Vector3(0, 0, m_Buoyancy * GravityConstant(actor, obj)), pos)); }
protected double GravityConstant(IPhysicsObject actor, IPhysicalObject obj) => CombinedGravityAccelerationConstant *actor.Mass *obj.PhysicsGravityMultiplier;
public IntersectionForce(GraphComponent component, IPhysicalObject target, double strength, GraphEdge a, GraphEdge b, IPhysicalObject reference) : base(component,target,strength) { this.a = a; this.b = b; this.reference = reference; }
public UserDraggingForce(GraphComponent component, IPhysicalObject target, double strength) : base(component,target,strength) { }
private bool isObjectOnPlatform(IPhysicalObject lf) { return((lf.Y <= y && lf.Y >= y - 2) && (lf.X >= x) && (lf.X < x + length)); }
public void addObject(IPhysicalObject obj) { plObjects.Add(obj); }
private void HandleBlackPuckCreated(IPhysicalObject physicalObject) { blackPuckPhysicalObject = physicalObject; SubscribeToBlackPuck(); }
private void SpawnGoal() { goal = physicalObjectFactory.Create(PhysicalObjectFactory.ObjectType.Goal); goal.SetPosition(GetRandomSpawnPos()); }
public SpringForce(GraphComponent component, IPhysicalObject target, double k, double l, IPhysicalObject reference) : base(component, target, k) { this.equilibriumLength = l; this.reference = reference; }
protected PositionalForce TargetVelocityMotor(IPhysicalObject obj, Vector3 targetvel, double factor, Vector3 pos) => new PositionalForce("TargetVelocityMotor", (targetvel - obj.Velocity) * factor, pos);
public CoolingThermalNoise(GraphComponent component, IPhysicalObject target, double strength, double decayDuration) : base(component,target,strength) { this.decayDuration = decayDuration; }
protected PositionalForce GravityMotor(IPhysicsObject actor, IPhysicalObject obj, Vector3 pos) => new PositionalForce("GravityMotor", new Vector3(0, 0, -GravityConstant(actor, obj)), pos);
public void RemovePhysicalObject(IPhysicalObject physicalObject) { _physicalObjects.Remove(physicalObject); }
public void DisableWalking(IPhysicalObject obj) { for (int i = 0; i < walkingEnabled.Count; i++) { if (objects[i] == obj) { walkingEnabled[objects[i]] = false; //walkData.Remove(objects[i]); } } }
public static void CreateSymmetricalSpringForces(GraphComponent component, IPhysicalObject a, IPhysicalObject b, double k, double l) // Create the pair of forces that act on both ends of a conceptual spring { new SpringForce(component, a, k, l, b); new SpringForce(component, b, k, l, a); }
public void AddObject(IPhysicalObject obj) { objects.Add(obj); walkingEnabled[obj] = false; if (obj.CollisionDataType != CollisionDataType.None) CollisionDetector.AddObject(obj); }
internal static PhysicalVector GetAirResistanceForce(this IPhysicalObject obj) { return(new PhysicalVector(obj.Speed.Angle + Math.PI).VectorMultiply(obj.Speed.Value * PhysicalConstants.AirResistanceKoefficient)); }
public void EnableWalking(IPhysicalObject obj) { for (int i = 0; i < walkingEnabled.Count; i++) { if (objects[i] == obj) walkingEnabled[objects[i]] = true; } }
public ReplusiveForce(GraphComponent component, IPhysicalObject target, IPhysicalObject reference, double strength, double degree = -2) : base(component,target,strength) { this.reference = reference; this.degree = degree; }
private void CalculateObjectForces(IPhysicalObject o) { switch (o.Type) { case ObjectType.PointMass: CalculatePointMassForces((PointMass)o); break; case ObjectType.RigidBody: CalculateRigidBodyForces((RigidBody)o); break; } }
ISelectable SelectableFromPhysical(IPhysicalObject p) { foreach (GraphComponentCanvas c in this.canvases) { foreach (ISelectable s in c.Component.Selectables) { VisualGraphVertex d = s as VisualGraphVertex; if (null != d) { if (d.PhysicalObject == p) return s; } } } return null; }
public override CollisionResult TestCollision(IPhysicalObject that, Vector2 thatNewPosition, float scrollRows) { return(base.TestCollision(that, thatNewPosition, scrollRows)); }
public RightAngleForce(GraphComponent component, IPhysicalObject a, IPhysicalObject target, IPhysicalObject b, double strength) : base(component, target, strength) { this.a = a; this.b = b; }
public void AddPhysicalObject(IPhysicalObject physicalObject) { _physicalObjects.Add(physicalObject); }
protected PositionalForce LinearRestitutionMotor(IPhysicalObject obj, double factor, Vector3 pos) => new PositionalForce("LinearRestitutionMotor", -obj.Velocity * factor, pos);
internal static PhysicalVector GetGravityForce(this IPhysicalObject obj) { return(new PhysicalVector(0, obj.Mass * PhysicalConstants.GravityAcceleration)); }
protected bool IsSelected(IPhysicalObject o) { ISelectable s = o.Visualization as ISelectable; return s.IsSelected(); }
public void RegisterObject(IPhysicalObject physObject) { PhysicalObjects.Add(physObject); // you may have a problem with deep copy v. shallow copy with this; you want a shallow copy so the physics engine will manipulate the original class }
public override void Initialize(Object initializationData) { this._resource = (IPhysicalObject)initializationData; }