public AngleLimitJoint CreateAngleLimitJoint(PhysicsSimulator physicsSimulator, Body body1, Body body2, float min, float max) { AngleLimitJoint angleLimitJoint = CreateAngleLimitJoint(body1, body2, min, max); physicsSimulator.Add(angleLimitJoint); return angleLimitJoint; }
public AngleJoint CreateAngleJoint(PhysicsSimulator physicsSimulator, Body body1, Body body2, float softness, float biasFactor) { AngleJoint angleJoint = CreateAngleJoint(body1, body2, softness, biasFactor); physicsSimulator.Add(angleJoint); return angleJoint; }
public PinJoint CreatePinJoint(PhysicsSimulator physicsSimulator, Body body1, Vector2 anchor1, Body body2, Vector2 anchor2) { PinJoint pinJoint = CreatePinJoint(body1, anchor1, body2, anchor2); physicsSimulator.Add(pinJoint); return pinJoint; }
public RevoluteJoint CreateRevoluteJoint(PhysicsSimulator physicsSimulator, Body body1, Body body2, Vector2 initialAnchorPosition) { RevoluteJoint revoluteJoint = CreateRevoluteJoint(body1, body2, initialAnchorPosition); physicsSimulator.Add(revoluteJoint); return revoluteJoint; }
public FixedAngleSpring CreateFixedAngleSpring(PhysicsSimulator physicsSimulator, Body body, float springConstant, float dampningConstant) { FixedAngleSpring fixedAngleSpring = CreateFixedAngleSpring(body, springConstant, dampningConstant); physicsSimulator.Add(fixedAngleSpring); return fixedAngleSpring; }
public AngleSpring CreateAngleSpring(PhysicsSimulator physicsSimulator, Body body1, Body body2, float springConstant, float dampingConstant) { AngleSpring angleSpring = CreateAngleSpring(body1, body2, springConstant, dampingConstant); physicsSimulator.Add(angleSpring); return angleSpring; }
public SpatialHashCollider(PhysicsSimulator physicsSimulator, float cellSize, int hashCapacity) { _physicsSimulator = physicsSimulator; _hash = new Dictionary<long, List<Geom>>(hashCapacity); _keysToRemove = new List<long>(hashCapacity); _filter = new Dictionary<long, object>(); _cellSize = cellSize; _cellSizeInv = 1 / cellSize; }
/// <summary> /// Creates a chain from start to end points containing the specified number of links. /// </summary> /// <param name="physicsSimulator"><see cref="PhysicsSimulator"/> to add the chain to.</param> /// <param name="start">Starting point of the chain.</param> /// <param name="end">Ending point of the chain.</param> /// <param name="links">Number of links desired in the chain.</param> /// <param name="height">Height of each link.</param> /// <param name="mass">Mass of each link.</param> /// <param name="collisionGroup">Collision group for the chain.</param> /// <param name="type">The joint/spring type.</param> /// <returns>Path</returns> public Path CreateChain(PhysicsSimulator physicsSimulator, Vector2 start, Vector2 end, int links, float height, float mass, int collisionGroup, LinkType type) { Path p = CreateChain(start, end, (Vector2.Distance(start, end) / links), height, mass, collisionGroup, type); p.AddToPhysicsSimulator(physicsSimulator); return p; }
public LinearSpring CreateLinearSpring(PhysicsSimulator physicsSimulator, Body body1, Vector2 attachPoint1, Body body2, Vector2 attachPoint2, float springConstant, float dampingConstant) { LinearSpring linearSpring = CreateLinearSpring(body1, attachPoint1, body2, attachPoint2, springConstant, dampingConstant); physicsSimulator.Add(linearSpring); return linearSpring; }
public FixedLinearSpring CreateFixedLinearSpring(PhysicsSimulator physicsSimulator, Body body, Vector2 bodyAttachPoint, Vector2 worldAttachPoint, float springConstant, float dampingConstant) { FixedLinearSpring fixedSpring = CreateFixedLinearSpring(body, bodyAttachPoint, worldAttachPoint, springConstant, dampingConstant); physicsSimulator.Add(fixedSpring); return fixedSpring; }
/// <summary> /// Initializes the GravityController. /// </summary> /// <param name="simulator">The physicsSimulator used by this controller.</param> /// <param name="bodies">The bodies that you want to generate gravity.</param> /// <param name="strength">the strength of gravity (the gravity strength when two bodies are on the same spot)</param> /// <param name="radius">the maximum distance that can be between 2 bodies before it will stop trying to apply gravity between them.</param> public GravityController(PhysicsSimulator simulator, List<Body> bodies, float strength, float radius) { _simulator = simulator; _strength = strength; if (_gravityType == GravityType.DistanceSquared) _strength *= 100; _radius = radius; _bodyList = bodies; }
/// <summary> /// Initializes the GravityController. /// </summary> /// <param name="simulator">The physicsSimulator used by this controller.</param> /// <param name="points">The points that you want to generate gravity.</param> /// <param name="strength">the strength of gravity (the gravity strength when two bodies are on the same spot)</param> /// <param name="radius">the maximum distance that can be between 2 bodies before it will stop trying to apply gravity between them.</param> public GravityController(PhysicsSimulator simulator, List<Vector2> points, float strength, float radius) { _simulator = simulator; _strength = strength; if (_gravityType == GravityType.DistanceSquared) _strength *= 100; _radius = radius; _pointList = points; }
/// <summary> /// Initializes the GravityController. /// </summary> /// <param name="simulator">The physicsSimulator used by this controller.</param> /// <param name="bodies">The bodies that you want to generate gravity.</param> /// <param name="points">The points that you want to generate gravity.</param> /// <param name="strength">the strength of gravity (the gravity strength when two bodies are on the same spot)</param> /// <param name="radius">the maximum distance that can be between 2 bodies before it will stop trying to apply gravity between them.</param> public GravityController(PhysicsSimulator simulator, List<Body> bodies, List<Vector2> points, float strength, float radius) { GravityType = GravityType.Linear; _simulator = simulator; _strength = strength; if (GravityType == GravityType.DistanceSquared) _strength *= 100; _radius = radius; PointList = points; BodyList = bodies; }
public Geom CreateCircleGeom(PhysicsSimulator physicsSimulator, Body body, float radius, int numberOfEdges, Vector2 offset, float rotationOffset) { return(CreateCircleGeom(physicsSimulator, body, radius, numberOfEdges, offset, rotationOffset, 0)); }
/// <summary> /// Creates a chain from start to end points containing the specified number of links. /// </summary> /// <param name="physicsSimulator"><see cref="PhysicsSimulator"/> to add the chain too.</param> /// <param name="start">Starting point of the chain.</param> /// <param name="end">Ending point of the chain.</param> /// <param name="links">Number of links desired in the chain.</param> /// <param name="mass">Mass of each link.</param> /// <param name="type">The joint/spring type.</param> /// <returns>Path</returns> public Path CreateChain(PhysicsSimulator physicsSimulator, Vector2 start, Vector2 end, int links, float mass, LinkType type) { Path path = CreateChain(start, end, (Vector2.Distance(start, end) / links), (Vector2.Distance(start, end) / links) * (1.0f / 3.0f), mass, type); path.AddToPhysicsSimulator(physicsSimulator); return path; }
public SliderJoint CreateSliderJoint(PhysicsSimulator physicsSimulator, Body body1, Vector2 anchor1, Body body2, Vector2 anchor2, float min, float max) { SliderJoint sliderJoint = CreateSliderJoint(body1, anchor1, body2, anchor2, min, max); physicsSimulator.Add(sliderJoint); return sliderJoint; }
public SpatialHashCollider(PhysicsSimulator physicsSimulator) : this(physicsSimulator, 50, 2048) { _physicsSimulator = physicsSimulator; }
//polygons /// <summary> /// /// </summary> /// <param name="physicsSimulator"></param> /// <param name="body"></param> /// <param name="vertices"></param> /// <param name="collisionGridCellSize">Pass in 0 or less to make Farseer calculate the grid cell size</param> /// <returns></returns> public Geom CreatePolygonGeom(PhysicsSimulator physicsSimulator, Body body, Vertices vertices, float collisionGridCellSize) { return(CreatePolygonGeom(physicsSimulator, body, vertices, Vector2.Zero, 0, collisionGridCellSize)); }
public FixedRevoluteJoint CreateFixedRevoluteJoint(PhysicsSimulator physicsSimulator, Body body, Vector2 anchor) { FixedRevoluteJoint revoluteJoint = CreateFixedRevoluteJoint(body, anchor); physicsSimulator.Add(revoluteJoint); return revoluteJoint; }
public void Load(SimulatorView view, PhysicsSimulator physicsSimulator) { //Load bodies _spiderBody = BodyFactory.Instance.CreateCircleBody(physicsSimulator, _spiderBodyRadius, 1); _spiderBody.Position = _position; _spiderBody.IsStatic = false; view.AddCircleToCanvas(_spiderBody, _spiderBodyRadius); _leftUpperLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _upperLegSize.X, _upperLegSize.Y, 1); _leftUpperLegBody.Position = _spiderBody.Position - new Vector2(_spiderBodyRadius, 0) - new Vector2(_upperLegSize.X / 2, 0); view.AddRectangleToCanvas(_leftUpperLegBody, Colors.White, new Vector2(_upperLegSize.X, _upperLegSize.Y)); _leftLowerLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _lowerLegSize.X, _lowerLegSize.Y, 1); _leftLowerLegBody.Position = _spiderBody.Position - new Vector2(_spiderBodyRadius, 0) - new Vector2(_upperLegSize.X, 0) - new Vector2(_lowerLegSize.X / 2, 0); view.AddRectangleToCanvas(_leftLowerLegBody, Colors.Red, new Vector2(_lowerLegSize.X, _lowerLegSize.Y)); _rightUpperLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _upperLegSize.X, _upperLegSize.Y, 1); _rightUpperLegBody.Position = _spiderBody.Position + new Vector2(_spiderBodyRadius, 0) + new Vector2(_upperLegSize.X / 2, 0); view.AddRectangleToCanvas(_rightUpperLegBody, Colors.White, new Vector2(_upperLegSize.X, _upperLegSize.Y)); _rightLowerLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _lowerLegSize.X, _lowerLegSize.Y, 1); _rightLowerLegBody.Position = _spiderBody.Position + new Vector2(_spiderBodyRadius, 0) + new Vector2(_upperLegSize.X, 0) + new Vector2(_lowerLegSize.X / 2, 0); view.AddRectangleToCanvas(_rightLowerLegBody, Colors.Red, new Vector2(_lowerLegSize.X, _lowerLegSize.Y)); //load geometries _spiderGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _spiderBody, _spiderBodyRadius, 14); _leftUpperLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _leftUpperLegBody, _upperLegSize.X, _upperLegSize.Y); _leftLowerLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _leftLowerLegBody, _lowerLegSize.X, _lowerLegSize.Y); _rightUpperLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rightUpperLegBody, _upperLegSize.X, _upperLegSize.Y); _rightLowerLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rightLowerLegBody, _lowerLegSize.X, _lowerLegSize.Y); _spiderGeom.CollisionGroup = _collisionGroup; _leftUpperLegGeom.CollisionGroup = _collisionGroup; _leftLowerLegGeom.CollisionGroup = _collisionGroup; _rightUpperLegGeom.CollisionGroup = _collisionGroup; _rightLowerLegGeom.CollisionGroup = _collisionGroup; //load joints JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _spiderBody, _leftUpperLegBody, _spiderBody.Position - new Vector2(_spiderBodyRadius, 0)); _leftShoulderAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _spiderBody, _leftUpperLegBody); _leftShoulderAngleJoint.TargetAngle = -.4f; _leftShoulderAngleJoint.MaxImpulse = 300; JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _spiderBody, _rightUpperLegBody, _spiderBody.Position + new Vector2(_spiderBodyRadius, 0)); _rightShoulderAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _spiderBody, _rightUpperLegBody); _rightShoulderAngleJoint.TargetAngle = .4f; _leftShoulderAngleJoint.MaxImpulse = 300; JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _leftUpperLegBody, _leftLowerLegBody, _spiderBody.Position - new Vector2(_spiderBodyRadius, 0) - new Vector2(_upperLegSize.X, 0)); _leftKneeAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _leftUpperLegBody, _leftLowerLegBody); _leftKneeAngleJoint.TargetAngle = -_kneeTargetAngle; _leftKneeAngleJoint.MaxImpulse = 300; JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _rightUpperLegBody, _rightLowerLegBody, _spiderBody.Position + new Vector2(_spiderBodyRadius, 0) + new Vector2(_upperLegSize.X, 0)); _rightKneeAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _rightUpperLegBody, _rightLowerLegBody); _rightKneeAngleJoint.TargetAngle = _kneeTargetAngle; _rightKneeAngleJoint.MaxImpulse = 300; }
public HairDryer(Vector2 position, PhysicsSimulator physicsSimulator) { _position = position; _physicsSimulator = physicsSimulator; }
public Geom CreateRectangleGeom(PhysicsSimulator physicsSimulator, Body body, float width, float height, Vector2 offset, float rotationOffset) { return(CreateRectangleGeom(physicsSimulator, body, width, height, offset, rotationOffset, 0)); }
/// <summary> /// /// </summary> /// <param name="physicsSimulator"></param> /// <param name="body"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="collisionGridCellSize">Pass in 0 or less to make Farseer calculate the grid cell size</param> /// <returns></returns> public Geom CreateRectangleGeom(PhysicsSimulator physicsSimulator, Body body, float width, float height, float collisionGridCellSize) { return(CreateRectangleGeom(physicsSimulator, body, width, height, Vector2.Zero, 0, collisionGridCellSize)); }
//rectangles public Geom CreateRectangleGeom(PhysicsSimulator physicsSimulator, Body body, float width, float height) { return(CreateRectangleGeom(physicsSimulator, body, width, height, Vector2.Zero, 0, 0)); }
/// <summary> /// Creates a ellipse geom. /// </summary> /// <param name="physicsSimulator">The physics simulator.</param> /// <param name="body">The body.</param> /// <param name="xRadius">The x radius.</param> /// <param name="yRadius">The y radius.</param> /// <param name="numberOfEdges">The number of edges.</param> /// <param name="offset">The offset.</param> /// <param name="rotationOffset">The rotation offset.</param> /// <returns></returns> public Geom CreateEllipseGeom(PhysicsSimulator physicsSimulator, Body body, float xRadius, float yRadius, int numberOfEdges, Vector2 offset, float rotationOffset) { return(CreateEllipseGeom(physicsSimulator, body, xRadius, yRadius, numberOfEdges, offset, rotationOffset, 0)); }
//ellipses /// <summary> /// Creates a ellipse geom. /// </summary> /// <param name="physicsSimulator">The physics simulator.</param> /// <param name="body">The body.</param> /// <param name="xRadius">The x radius.</param> /// <param name="yRadius">The y radius.</param> /// <param name="numberOfEdges">The number of edges.</param> /// <returns></returns> public Geom CreateEllipseGeom(PhysicsSimulator physicsSimulator, Body body, float xRadius, float yRadius, int numberOfEdges) { return(CreateEllipseGeom(physicsSimulator, body, xRadius, yRadius, numberOfEdges, Vector2.Zero, 0, 0)); }
/// <summary> /// Creates a chain. /// </summary> /// <param name="physicsSimulator"><see cref="PhysicsSimulator"/> to add the chain to.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="linkWidth">The distance between links.</param> /// <param name="mass">The mass.</param> /// <param name="pinStart">if set to <c>true</c> [pin start].</param> /// <param name="pinEnd">if set to <c>true</c> [pin end].</param> /// <param name="type">The joint/spring type.</param> /// <returns></returns> public Path CreateChain(PhysicsSimulator physicsSimulator, Vector2 start, Vector2 end, float width, float height, float linkWidth, float mass, bool pinStart, bool pinEnd, LinkType type) { Path path = CreateChain(start, end, width, height, linkWidth, mass, pinStart, pinEnd, type); path.AddToPhysicsSimulator(physicsSimulator); return path; }
void ProcessMyCommand() { for (int i = 0; i < commands.Count; i++) { Command c1 = commands[i]; if (c1 == null) { continue; } if (c1.processed) { continue; } if (c1 is GameSetCmd) { GameSetCmd c = (GameSetCmd)c1; openResultScene(c.isHostWin); } if (c1 is UnitMovedCmd) { UnitMovedCmd c = (UnitMovedCmd)c1; var basicUnit = GetBasicUnit(c.uuid); //Debug.Log(c.vx); if (basicUnit != null && !basicUnit.MovementLocked && !basicUnit.Locked) // lockdown and waittime check { Unit u = GetUnit(c.uuid); u.vx = c.vx; u.vz = c.vz; //schin Remove "ready to roll" emotion when ready. // this doesn't check if it's really moved for client basicUnit.ExpireEmotion(EmotionType.CD_READY); // Tinaxd update CountdownUI (Host only) // Generate a UnitTimerCommand if (isClient == 0) { UnitTimerCmd utc = new UnitTimerCmd(); utc.penalty = basicUnit.WaitTimePenaltyTime; utc.timerType = UnitTimerCmd.MOVED; utc.uuid = c.uuid; unitTimerRequests.Add(utc); commands.Add(utc); } } else { } c.processed = true; } if (c1 is UnitUpdateCmd) { UnitUpdateCmd c = (UnitUpdateCmd)c1; //Debug.Log(c.vx); if (isClient > 0) { //TODO if units.isDeadあり //UnitDied() units = c.units; } c.processed = true; c.sent = true; } if (c1 is UnitTimerCmd) { UnitTimerCmd c = (UnitTimerCmd)c1; switch (c.timerType) { case 0: // MOVED var basicUnit = GetBasicUnit(c.uuid); if (basicUnit != null) { basicUnit.MarkMoved(); } // Lockdown ends foreach (var instance in instances) { var bu = instance.basicUnit; if (bu == null) { continue; } if (bu.Owned != basicUnit.Owned) { bu.MovementLocked = false; } } break; case 1: // HOST LOCKDOWN foreach (var instance in instances) { var bu = instance.basicUnit; if (bu == null) { continue; } if (isClient > 0) { if (bu.Owned) { bu.MovementLocked = true; } else { bu.MarkLockdown(); } } else { if (bu.Owned) { bu.MarkLockdown(); } else { bu.MovementLocked = true; } } } break; case 2: // CLIENT LOCKDOWN foreach (var instance in instances) { var bu = instance.basicUnit; if (bu == null) { continue; } if (isClient > 0) { if (bu.Owned) { bu.MarkLockdown(); } else { bu.MovementLocked = true; } } else { if (bu.Owned) { bu.MovementLocked = true; } else { bu.MarkLockdown(); } } } break; } //TODO if c is GameSetCmd //SceneManager.LoadScene("Result"); //clientBattleScene, isHostWin = GameSetCmd.isHostWin if (isClient > 0 && (!AutoPlay.isOffline)) { c.processed = true; } } if (c1 is NewUnitCmd) { //Debug.Log(GetUnit(((NewUnitCmd)c1).fromUnitId).owner); NewUnitCmd c = (NewUnitCmd)c1; switch (c.unitType) { case 2: // Arrow { Unit u = GetUnit(c.fromUnitId); if (u == null) { break; } if (u.projectileReload <= 0) { u.projectileReload = 7; CreateArrow(GetUnit(c.fromUnitId), c.velocity); } } break; case 3: // Fireball { var u = GetUnit(c.fromUnitId); if (u.MP > 25) { u.MP -= 25; CreateFireball(u, c.velocity); } } break; } c.processed = true; } if (c1 is HealingBuffRequestCmd) { var c = (HealingBuffRequestCmd)c1; if (isClient == 0) { var requestor = GetUnit(c.RequestorId); var target = GetUnit(c.TargetId); if (PhysicsSimulator.UnitDistance1(requestor, target) < HealingBuffMaxDistance) { target.buff |= BuffFlag.BUFF_HEALING; } c.processed = true; } //GetBasicUnit(c.RequestorId).DragMode = DragType.NORMAL; //UnityEngine.EventSystems.ExecuteEvents.Execute<IDragAndFireEventHandler>(this.gameObject, null, (x, y) => x.TurnOnDrag()); } } List <Command> remains = new List <Command>(); for (int i = 0; i < commands.Count; i++) { if (commands[i].sent) { continue; } remains.Add(commands[i]); } commands = remains; }
/// <summary> /// Creates a gravity controller and adds it to the physics simulator. /// </summary> /// <param name="simulator">the physicsSimulator used by this controller.</param> /// <param name="points">The points you want to generate gravity.</param> /// <param name="strength">the maximum strength of gravity (the gravity strength when two bodies are on the same spot)</param> /// <param name="radius">the maximum distance that can be between 2 bodies before it will stop trying to apply gravity between them.</param> /// <returns></returns> public GravityController CreateGravityController(PhysicsSimulator simulator, List<Vector2> points, float strength, float radius) { GravityController gravityController = new GravityController(simulator, points, strength, radius); simulator.Add(gravityController); return gravityController; }
/// <summary> /// Creates rectangular geoms that match the size of the bodies. /// Then adds the geometries to the given physics simulator. /// </summary> /// <param name="collisionCategory">The collision category of the geometries.</param> /// <param name="collidesWith">The collisioncategory the geometries should collide with..</param> /// <param name="physicsSimulator">The physics simulator.</param> public void CreateGeoms(CollisionCategory collisionCategory, CollisionCategory collidesWith, PhysicsSimulator physicsSimulator) { CreateGeoms(collisionCategory, collidesWith); foreach (Geom geom in _geoms) { physicsSimulator.Add(geom); } }
internal Arbiter(Geom geometry1, Geom geometry2, PhysicsSimulator physicsSimulator) { ConstructArbiter(geometry1, geometry2, physicsSimulator); }
/// <summary> /// Gets a list of geometries and their intersectionpoints that the line intersects. /// </summary> /// <param name="point1">The point1.</param> /// <param name="point2">The point2.</param> /// <param name="simulator">The simulator.</param> /// <param name="detectUsingAABB">if set to <c>true</c> [detect using AABB].</param> /// <returns></returns> public static List <GeomPointPair> LineSegmentAllGeomsIntersect(Vector2 point1, Vector2 point2, PhysicsSimulator simulator, bool detectUsingAABB) { return(LineSegmentAllGeomsIntersect(ref point1, ref point2, simulator, detectUsingAABB)); }
public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator) { _rectangleTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, _rectangleWidth, _rectangleHeight, Color.White, Color.Black); int radius; if (_attachPoint == 0 | _attachPoint == 2) { radius = _rectangleHeight; } else { radius = _rectangleWidth; } _circleTexture = DrawingHelper.CreateCircleTexture(graphicsDevice, radius, Color.White, Color.Black); //body is created as rectangle so that it has the moment of inertia closer to the final shape of the object. _angleSpringleverBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth, _rectangleHeight, 1f); _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _angleSpringleverBody, _rectangleWidth, _rectangleHeight); _rectangleGeom.FrictionCoefficient = .5f; _rectangleGeom.CollisionGroup = _collisionGroup; Vector2 offset = Vector2.Zero; switch (_attachPoint) { case 0: { offset = new Vector2(-_rectangleWidth / 2f, 0); //offset to rectangle to left break; } case 1: { offset = new Vector2(0, -_rectangleHeight / 2f); //offset to rectangle to top break; } case 2: { offset = new Vector2(_rectangleWidth / 2f, 0); //offset to rectangle to right break; } case 3: { offset = new Vector2(0, _rectangleHeight / 2f); //offset to rectangle to bottom break; } } _angleSpringleverBody.Position = _position - offset; _circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _angleSpringleverBody, radius, 20, offset, 0); _circleGeom.FrictionCoefficient = .5f; _circleGeom.CollisionGroup = _collisionGroup; _revoluteJoint = JointFactory.Instance.CreateFixedRevoluteJoint(physicsSimulator, _angleSpringleverBody, _position); physicsSimulator.Add(_revoluteJoint); SpringFactory.Instance.CreateFixedAngleSpring(physicsSimulator, _angleSpringleverBody, _springConstant, _dampningConstant); }
/// <summary> /// Gets a list of geometries and their intersectionpoints that the line intersects. /// </summary> /// <param name="point1">The point1.</param> /// <param name="point2">The point2.</param> /// <param name="simulator">The simulator.</param> /// <param name="detectUsingAABB">if set to <c>true</c> [detect using AABB].</param> /// <returns></returns> public static List <GeomPointPair> LineSegmentAllGeomsIntersect(ref Vector2 point1, ref Vector2 point2, PhysicsSimulator simulator, bool detectUsingAABB) { List <Vector2> intSecPoints = new List <Vector2>(); List <GeomPointPair> geoms = new List <GeomPointPair>(); foreach (Geom geom in simulator.GeomList) { intSecPoints.Clear(); if (detectUsingAABB) { LineSegmentAABBIntersect(ref point1, ref point2, geom.AABB, ref intSecPoints); } else { LineSegmentVerticesIntersect(ref point1, ref point2, geom.WorldVertices, ref intSecPoints); } if (intSecPoints.Count > 0) { _tempPair = new GeomPointPair(); _tempPair.Geom = geom; _tempPair.Points = new List <Vector2>(intSecPoints); geoms.Add(_tempPair); } } return(geoms); }
/// <summary> /// 初始化 /// </summary> protected override void Initialize() { /* 设置最大100fps */ IsFixedTimeStep = true; /* 1毫秒渲染100fps */ TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 1); /* 初始化物理引擎全局,设置为9.8向下重力 */ physicsSimulator = new PhysicsSimulator(new Vector2(0f, 1000f)); /* 设置摩擦为平均值 */ //physicsSimulator.FrictionType = FrictionType.Minimum; /* 初始化正方形的占位,给定大小,质量还有位置 */ //boxBody1 = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 50, 50, 79 * 50 * 50); //boxBody1.Position = new Vector2(400, 100); /* 设置减速比率 */ //boxBody1.LinearDragCoefficient = 1.5f; /* 将正方形固定在初始化处 */ //boxBody1.IsStatic = true; /* 初始化正方形碰撞检测 */ //boxGeometry1 = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, boxBody1, 50, 50); /* 初始化圆形的占位,给定大小,质量还有位置 */ boxBody2 = BodyFactory.Instance.CreateCircleBody(physicsSimulator, 25, 1); boxBody2.Position = new Vector2(400, 400); /* 减速比率 */ boxBody2.LinearDragCoefficient = 0.9f; /* 滑行减速比率 */ boxBody2.LinearVelocity = new Vector2(10f); /* 减转速比率 */ boxBody2.RotationalDragCoefficient = 25f; /* 初始化正方形碰撞检测 */ boxGeometry2 = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, boxBody2, 25, 60); /* 初始化大地的占位,给定大小,质量还有位置 */ boxBody3 = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 1440, 10, 79f * (4 / 3 * 3.1416f * 25 * 25 * 25)); boxBody3.Position = new Vector2(500, 580); boxBody3.LinearDragCoefficient = 0.9f; /* 将大地固定在初始化处 */ boxBody3.IsStatic = true; /* 初始化大地碰撞检测 */ boxGeometry3 = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, boxBody3, 1440, 10); /* 将正方形和圆形组合起来,最大距离为300,最小距离为50 */ //sliderJoint = JointFactory.Instance.CreateSliderJoint(physicsSimulator, // boxBody1, new Vector2(25, 25), boxBody2, new Vector2(25, 25), 50, 300); gex = new GraphicsEx(this); gex.LoadContent(); /* 鼠标可见 */ IsMouseVisible = true; base.Initialize(); }
public void LoadPhysicsContent(PhysicsSimulator physicsSimulator) { physicsSimulator.Add(revoluteJoint); physicsSimulator.Add(angleJoint); }
public InactivityController(PhysicsSimulator physicsSimulator) { _physicsSimulator = physicsSimulator; _physicsSimulator.Add(this); Enabled = false; // disable by default }
public void Initialize(PhysicsSimulator physicsSimulator) { InitializeBoxes(physicsSimulator); InitializeWater(physicsSimulator); }
/// <summary> /// Creates a ellipse body. /// </summary> /// <param name="physicsSimulator">The physics simulator.</param> /// <param name="xRadius">The width.</param> /// <param name="yRadius">The height.</param> /// <param name="mass">The mass.</param> /// <returns></returns> public Body CreateEllipseBody(PhysicsSimulator physicsSimulator, float xRadius, float yRadius, float mass) { Body body = CreateEllipseBody(xRadius, yRadius, mass); physicsSimulator.Add(body); return body; }
public Geom CreateCircleGeom(PhysicsSimulator physicsSimulator, Body body, float radius, int numberOfEdges, float collisionGridCellSize) { return(CreateCircleGeom(physicsSimulator, body, radius, numberOfEdges, Vector2.Zero, 0, collisionGridCellSize)); }
/// <summary> /// Creates a rectangle body. /// </summary> /// <param name="physicsSimulator">The physics simulator.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="mass">The mass.</param> /// <returns></returns> public Body CreateRectangleBody(PhysicsSimulator physicsSimulator, float width, float height, float mass) { Body body = CreateRectangleBody(width, height, mass); physicsSimulator.Add(body); return body; }
/// <summary> /// Creates a chain. /// </summary> /// <param name="physicsSimulator"><see cref="PhysicsSimulator"/> to add the chain to.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="mass">The mass.</param> /// <param name="type">The joint/spring type.</param> /// <returns></returns> public Path CreateChain(PhysicsSimulator physicsSimulator, Vector2 start, Vector2 end, float width, float height, float mass, LinkType type) { Path path = CreateChain(start, end, width, height, mass, false, false, type); path.AddToPhysicsSimulator(physicsSimulator); return path; }
public Body CreateBody(PhysicsSimulator physicsSimulator, Body body) { Body bodyClone = CreateBody(body); physicsSimulator.Add(bodyClone); return bodyClone; }
/// <summary> /// Creates a gravity controller and adds it to the physics simulator. /// </summary> /// <param name="simulator">the physicsSimulator used by this controller.</param> /// <param name="bodies">The bodies you want to generate gravity.</param> /// <param name="strength">the maximum strength of gravity (the gravity strength when two bodies are on the same spot)</param> /// <param name="radius">the maximum distance that can be between 2 bodies before it will stop trying to apply gravity between them.</param> /// <returns></returns> public GravityController CreateGravityController(PhysicsSimulator simulator, List<Body> bodies, float strength, float radius) { GravityController gravityController = new GravityController(simulator, bodies, strength, radius); simulator.Add(gravityController); return gravityController; }
public PhysicsProcessor(PhysicsSimulator physicsSimulator) { _physicsSimulator = physicsSimulator; }
/// <summary> /// Creates a track. /// </summary> /// <param name="physicsSimulator">The physics simulator.</param> /// <param name="points">The points.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="mass">The mass.</param> /// <param name="endless">if set to <c>true</c> [endless].</param> /// <param name="collisionGroup">Collision group for the chain.</param> /// <param name="type">The joint/spring type.</param> /// <returns></returns> public Path CreateTrack(PhysicsSimulator physicsSimulator, Vertices points, float width, float height, float mass, bool endless, int collisionGroup, LinkType type) { Path path = CreateTrack(points, width, height, mass, endless, collisionGroup, type); path.AddToPhysicsSimulator(physicsSimulator); return path; }
public override void Initialize() { PhysicsSimulator = new PhysicsSimulator(new Vector2(0, 50)); PhysicsSimulatorView = new PhysicsSimulatorView(PhysicsSimulator); base.Initialize(); }
public InactivityController(PhysicsSimulator physicsSimulator) { _physicsSimulator = physicsSimulator; }
public BruteForceCollider(PhysicsSimulator physicsSimulator) { _physicsSimulator = physicsSimulator; }
public void UnloadPhysicsContent(PhysicsSimulator physicsSimulator) { physicsSimulator.Remove(revoluteJoint); physicsSimulator.Remove(angleJoint); }
//circles public Geom CreateCircleGeom(PhysicsSimulator physicsSimulator, Body body, float radius, int numberOfEdges) { return(CreateCircleGeom(physicsSimulator, body, radius, numberOfEdges, Vector2.Zero, 0, 0)); }
/// <summary> /// Creates a Body. The moment of inertia of the body is calculated from the /// set of vertices passed in to this method. The vertices should represent a polygon. /// </summary> /// <param name="physicsSimulator"><see cref="PhysicsSimulator"/> to add this body to.</param> /// <param name="vertices">Vertices representing some polygon</param> /// <param name="mass">Mass of the Body</param> /// <returns></returns> public Body CreatePolygonBody(PhysicsSimulator physicsSimulator, Vertices vertices, float mass) { Body body = CreatePolygonBody(vertices, mass); physicsSimulator.Add(body); return body; }
protected GameScreen() { _physicsSimulator = new PhysicsSimulator(new Vector2(0, 0)); _physicsSimulatorView = new PhysicsSimulatorView(_physicsSimulator); }
public Body CreateBody(PhysicsSimulator physicsSimulator, float mass, float momentOfInertia) { Body body = CreateBody(mass, momentOfInertia); physicsSimulator.Add(body); return body; }
private void InitializePhysicsSimulator() { _physicsSimulator = new PhysicsSimulator(new Vector2(0, 4)); ConvertUnits.SetDisplayUnitToSimUnitRatio(50); //50 pixels = 1 meter }
/// <summary> /// Creates a circle body. /// </summary> /// <param name="physicsSimulator">The physics simulator.</param> /// <param name="radius">The radius.</param> /// <param name="mass">The mass.</param> /// <returns></returns> public Body CreateCircleBody(PhysicsSimulator physicsSimulator, float radius, float mass) { Body body = CreateCircleBody(radius, mass); physicsSimulator.Add(body); return body; }
private void HandKeyboardInput(InputState input) { if (input.OneOfKeysPressed(Keys.Q, Keys.W, Keys.E, Keys.A, Keys.S, Keys.D)) { if (_leftGeom == null || _rightGeom == null) { // Add Circles if (input.IsNewKeyPress(Keys.Q)) { AddCircle(50, 8); } // Add Circles if (input.IsNewKeyPress(Keys.W)) { AddCircle(50, 16); } // Add Circles if (input.IsNewKeyPress(Keys.E)) { AddCircle(50, 32); } // Add Rectangle if (input.IsNewKeyPress(Keys.A)) { AddRectangle(100, 100); } // Add Rectangle if (input.IsNewKeyPress(Keys.S)) { AddRectangle(100, 50); } // Add Rectangle if (input.IsNewKeyPress(Keys.D)) { AddRectangle(50, 100); } } else { WriteMessage("Only 2 polygons allowed at a time."); } } // Perform a Union if (input.IsNewKeyPress(Keys.Space)) { if (_leftGeom != null && _rightGeom != null) { DoUnion(); } } // Perform a Subtraction if (input.IsNewKeyPress(Keys.Back)) { if (_leftGeom != null && _rightGeom != null) { DoSubtract(); } } // Simplify if (input.IsNewKeyPress(Keys.Tab)) { if (_leftGeom != null && _rightGeom == null) { Vertices simple = new Vertices(_leftGeom.WorldVertices); simple = Vertices.Simplify(simple); SetProduct(simple); } } // Add to Simulation if (input.IsNewKeyPress(Keys.Enter)) { if (_leftGeom != null) { Body body = BodyFactory.Instance.CreatePolygonBody(_leftGeom.LocalVertices, 1.0f); body.Position = _leftGeom.Position; Geom geom = GeomFactory.Instance.CreatePolygonGeom(body, _leftGeom.LocalVertices, 0); PhysicsSimulator.Add(body); PhysicsSimulator.Add(geom); _simulatedPolyBrushes.Add(new PolygonBrush(_leftGeom.LocalVertices, Color.Red, Color.DarkRed, 1.5f, 0.2f)); _simulatedPolyBrushes[_simulatedPolyBrushes.Count - 1].Load(ScreenManager.GraphicsDevice); _simulatedPolyBodies.Add(body); } } }