public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); PolygonShape shape = new PolygonShape(new Vertices(_points), 0f); DrawString("Press g to generate a new random convex hull"); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); DebugView.DrawPolygon(shape.Vertices.ToArray(), shape.Vertices.Count, new Color(0.9f, 0.9f, 0.9f)); for (int i = 0; i < _count; ++i) { DebugView.DrawPoint(_points[i], 0.1f, new Color(0.9f, 0.5f, 0.5f)); Vector2 position = GameInstance.ConvertWorldToScreen(_points[i]); DebugView.DrawString((int)position.X, (int)position.Y, i.ToString()); } DebugView.EndCustomDraw(); if (_auto) { Generate(); } }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString("Use the mouse to create a polygon."); DrawString("Simple: " + _vertices.IsSimple()); DrawString("Convex: " + _vertices.IsConvex()); DrawString("CCW: " + _vertices.IsCounterClockWise()); DrawString("Area: " + _vertices.GetArea()); PolygonError returnCode = _vertices.CheckPolygon(); if (returnCode == PolygonError.NoError) DrawString("Polygon is supported in Farseer Physics Engine"); else DrawString("Polygon is NOT supported in Farseer Physics Engine. Reason: " + returnCode); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); for (int i = 0; i < _vertices.Count; i++) { Vector2 currentVertex = _vertices[i]; Vector2 nextVertex = _vertices.NextVertex(i); DebugView.DrawPoint(currentVertex, 0.1f, Color.Yellow); DebugView.DrawSegment(currentVertex, nextVertex, Color.Red); } DebugView.DrawPoint(_vertices.GetCentroid(), 0.1f, Color.Green); AABB aabb = _vertices.GetAABB(); DebugView.DrawAABB(ref aabb, Color.HotPink); DebugView.EndCustomDraw(); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { Manifold manifold = new Manifold(); Collision.Collision.CollidePolygons(ref manifold, _polygonA, ref _transformA, _polygonB, ref _transformB); Vector2 normal; FixedArray2<Vector2> points; ContactSolver.WorldManifold.Initialize(ref manifold, ref _transformA, _polygonA.Radius, ref _transformB, _polygonB.Radius, out normal, out points); DrawString("Point count = " + manifold.PointCount); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); { Color color = new Color(0.9f, 0.9f, 0.9f); Vector2[] v = new Vector2[Settings.MaxPolygonVertices]; for (int i = 0; i < _polygonA.Vertices.Count; ++i) { v[i] = MathUtils.Mul(ref _transformA, _polygonA.Vertices[i]); } DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color); for (int i = 0; i < _polygonB.Vertices.Count; ++i) { v[i] = MathUtils.Mul(ref _transformB, _polygonB.Vertices[i]); } DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color); } for (int i = 0; i < manifold.PointCount; ++i) { DebugView.DrawPoint(points[i], 0.1f, new Color(0.9f, 0.3f, 0.3f)); DrawString(points[i].ToString()); } DebugView.EndCustomDraw(); }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString("Triangulation took " + _sw.ElapsedMilliseconds + " ms"); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { Body body = BodyFactory.CreateCircle(World, 0.4f, 1); body.Position = new Vector2(Rand.RandomFloat(-35, 35), 10); body.BodyType = BodyType.Dynamic; body.Restitution = 1f; base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); float ratio = _joint1.Ratio; float l = _joint1.LengthA + ratio * _joint1.LengthB; DrawString(string.Format("L1 + {0:n} * L2 = {1:n}", ratio, l)); }
public override void Update(GameSettings settings, GameTime gameTime) { _time += 0.01f; if (_time > 1f) _time = 0; PathManager.MoveBodyOnPath(_path, _movingBody, _time, 1f, 1f / 60f); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); if (_count < Count) { Body box = BodyFactory.CreateRectangle(World, 0.125f * 2, 0.125f * 2, 1, new Vector2(0, 10)); box.BodyType = BodyType.Dynamic; ++_count; } }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString("SimpleWindForce | Mouse: Direction | Left-Click: Position | W/S: Variation"); DrawString("Wind Strength:" + _simpleWind.Strength); DrawString("Variation:" + _simpleWind.Variation); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); //DebugView.DrawSegment(SimpleWind.Position, SimpleWind.Direction-SimpleWind.Position, Color.Red); DrawPointForce(); DebugView.EndCustomDraw(); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { foreach (Vertices vertex in _polygons) { if (vertex != null) { Vector2[] array = vertex.ToArray(); Color col = Color.SteelBlue; if (!vertex.IsCounterClockWise()) { col = Color.Aquamarine; } if (vertex == _selected) { col = Color.LightBlue; } if (vertex == _subject) { col = Color.Green; if (vertex == _selected) { col = Color.LightGreen; } } if (vertex == _clip) { col = Color.DarkRed; if (vertex == _selected) { col = Color.IndianRed; } } DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); DebugView.DrawPolygon(array, vertex.Count, col); for (int j = 0; j < vertex.Count; ++j) { DebugView.DrawPoint(vertex[j], .2f, Color.Red); } DebugView.EndCustomDraw(); } } DrawString("A,S,D = Create Rectangle"); DrawString("Q,W,E = Create Circle"); DrawString("Click to Drag polygons"); DrawString("1 = Select Subject while dragging [green]"); DrawString("2 = Select Clip while dragging [red]"); DrawString("Space = Union"); DrawString("Backspace = Subtract"); DrawString("Shift = Intersect"); DrawString("Holes are colored light blue"); }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString("Press A,S,W,D move endpoint"); DrawString("Press Enter to cut"); DrawString("Press TAB to change endpoint"); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); DebugView.DrawSegment(_start, _end, Color.Red); DebugView.EndCustomDraw(); List<Fixture> fixtures = new List<Fixture>(); List<Vector2> entryPoints = new List<Vector2>(); List<Vector2> exitPoints = new List<Vector2>(); //Get the entry points World.RayCast((f, p, n, fr) => { fixtures.Add(f); entryPoints.Add(p); return 1; }, _start, _end); //Reverse the ray to get the exitpoints World.RayCast((f, p, n, fr) => { exitPoints.Add(p); return 1; }, _end, _start); DrawString("Fixtures: " + fixtures.Count); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); foreach (Vector2 entryPoint in entryPoints) { DebugView.DrawPoint(entryPoint, 0.5f, Color.Yellow); } foreach (Vector2 exitPoint in exitPoints) { DebugView.DrawPoint(exitPoint, 0.5f, Color.PowderBlue); } DebugView.EndCustomDraw(); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString("Loaded: " + _nextFileName + " - Press T for next"); Vector2 offset = new Vector2(-6, 12); for (int i = 0; i < _names.Length; i++) { string title = string.Format("{0}: {1} ms - {2} triangles", _names[i], _timings[i], _bodies[i].FixtureList.Count); Vector2 screenPosition = GameInstance.ConvertWorldToScreen(_bodies[i].Position + offset); DebugView.DrawString((int)screenPosition.X, (int)screenPosition.Y, title); } base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); if (!settings.Pause && settings.Hz > 0.0f) _time += 1.0f / settings.Hz; Vector2 linearOffset = new Vector2(); linearOffset.X = 6.0f * (float)Math.Sin(2.0f * _time); linearOffset.Y = 8.0f + 4.0f * (float)Math.Sin(1.0f * _time); float angularOffset = 4.0f * _time; _joint.LinearOffset = linearOffset; _joint.AngularOffset = angularOffset; }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); DrawString("Press C to toggle CCD. CCD is Currently: " + (_ground.IgnoreCCD ? "Off" : "On")); if (Distance.GJKCalls > 0) DrawString(string.Format("GJK calls = {0:n}, Ave GJK iters = {1:n}, Max GJK iters = {2:n}", Distance.GJKCalls, Distance.GJKIters / (float)Distance.GJKCalls, Distance.GJKMaxIters)); if (TimeOfImpact.TOICalls > 0) { DrawString(string.Format("TOI calls = {0:n}, Ave TOI iters = {1:n}, Max TOI iters = {2:n}", TimeOfImpact.TOICalls, TimeOfImpact.TOIIters / (float)TimeOfImpact.TOICalls, TimeOfImpact.TOIMaxRootIters)); DrawString(string.Format("Ave TOI root iters = {0:n}, Max TOI root iters = {1:n}", TimeOfImpact.TOIRootIters / (float)TimeOfImpact.TOICalls, TimeOfImpact.TOIMaxRootIters)); } if (StepCount % 60 == 0) Launch(); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); DistanceInput input = new DistanceInput(); input.ProxyA.Set(_polygonA, 0); input.ProxyB.Set(_polygonB, 0); input.TransformA = _transformA; input.TransformB = _transformB; input.UseRadii = true; SimplexCache cache; cache.Count = 0; DistanceOutput output; Distance.ComputeDistance(out output, out cache, input); DrawString("Distance = " + output.Distance); DrawString("Iterations = " + output.Iterations); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); { Color color = new Color(0.9f, 0.9f, 0.9f); Vector2[] v = new Vector2[Settings.MaxPolygonVertices]; for (int i = 0; i < _polygonA.Vertices.Count; ++i) { v[i] = MathUtils.Mul(ref _transformA, _polygonA.Vertices[i]); } DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color); for (int i = 0; i < _polygonB.Vertices.Count; ++i) { v[i] = MathUtils.Mul(ref _transformB, _polygonB.Vertices[i]); } DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color); } Vector2 x1 = output.PointA; Vector2 x2 = output.PointB; DebugView.DrawPoint(x1, 0.5f, new Color(1.0f, 0.0f, 0.0f)); DebugView.DrawPoint(x2, 0.5f, new Color(1.0f, 0.0f, 0.0f)); DebugView.DrawSegment(x1, x2, new Color(1.0f, 1.0f, 0.0f)); DebugView.EndCustomDraw(); }
public virtual void Update(GameSettings settings, GameTime gameTime) { float timeStep = Math.Min((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f, (1f / 30f)); if (settings.Pause) { if (settings.SingleStep) settings.SingleStep = false; else timeStep = 0.0f; DrawString("****PAUSED****"); } else World.Step(timeStep); if (timeStep > 0.0f) ++StepCount; }
public override void Update(GameSettings settings, GameTime gameTime) { _count++; if (_count < 50) { const float x = 0; const float y = 15; Body body = BodyFactory.CreateBody(World); body.Position = new Vector2(x, y); body.BodyType = BodyType.Dynamic; Fixture fixture = body.CreateFixture(_polyShape); fixture.Friction = 0.3f; } base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString("Melkman: Red"); DrawString("Giftwrap: Green"); DrawString("ChainHull: Blue"); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); for (int i = 0; i < PointCount; i++) { DebugView.DrawPoint(_pointCloud1[i], 0.1f, Color.Yellow); DebugView.DrawPoint(_pointCloud2[i], 0.1f, Color.Yellow); DebugView.DrawPoint(_pointCloud3[i], 0.1f, Color.Yellow); } DebugView.DrawPolygon(_melkman.ToArray(), _melkman.Count, Color.Red); DebugView.DrawPolygon(_giftWrap.ToArray(), _giftWrap.Count, Color.Green); DebugView.DrawPolygon(_chainHull.ToArray(), _chainHull.Count, Color.Blue); DebugView.EndCustomDraw(); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); if (Distance.GJKCalls > 0) { DrawString(string.Format("GJK calls = {0:n}, Ave GJK iters = {1:n}, Max GJK iters = {2:n}", Distance.GJKCalls, Distance.GJKIters / (float)Distance.GJKCalls, Distance.GJKMaxIters)); } if (TimeOfImpact.TOICalls > 0) { DrawString(string.Format("TOI calls = {0:n}, Ave TOI iters = {1:n}, Max TOI iters = {2:n}", TimeOfImpact.TOICalls, TimeOfImpact.TOIIters / (float)TimeOfImpact.TOICalls, TimeOfImpact.TOIMaxRootIters)); DrawString(string.Format("Ave TOI root iters = {0:n}, Max TOI root iters = {1:n}", TimeOfImpact.TOIRootIters / (float)TimeOfImpact.TOICalls, TimeOfImpact.TOIMaxRootIters)); } if (StepCount % 60 == 0) { Launch(); } }
public override void Update(GameSettings settings, GameTime gameTime) { foreach (Body b in World.BodyList) { if (b.BodyType != BodyType.Dynamic) { continue; } if (b.Awake) { } } if (StepCount == 180) { StepCount += 0; } //if (sleeping) //{ // CreateCircle(); //} base.Update(settings, gameTime); foreach (Body b in World.BodyList) { if (b.BodyType != BodyType.Dynamic) { continue; } Vector2 p = b.Position; if (p.X <= -10.0f || 10.0f <= p.X || p.Y <= 0.0f || 20.0f <= p.Y) { p.X += 0.0f; } } DrawString("Press 'c' to create a circle."); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); DrawString("Press 'a' to control the flippers"); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); DrawString("This demonstrates a soft distance joint."); DrawString("Press: (b) to delete a body, (j) to delete a joint"); DrawString("Bodies removed: " + _removedBodies); DrawString("Joints removed: " + _removedJoints); }
public override void Update(GameSettings settings, GameTime gameTime) { DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); DebugView.DrawAABB(ref _terrainArea, Color.Red * 0.5f); DebugView.EndCustomDraw(); DrawString("Left click and drag the mouse to destroy terrain!"); DrawString("Right click and drag the mouse to create terrain!"); DrawString("Middle click to create circles!"); DrawString("Press t or y to cycle between decomposers: " + _terrain.Decomposer); TextLine += 25; DrawString("Press g or h to decrease/increase circle radius: " + _circleRadius); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); DrawString("Press: (,) to launch a bullet."); //if (StepCount == 300) //{ // if (_bullet != null) // { // World.Remove(_bullet); // _bullet = null; // } // { // CircleShape shape = new CircleShape(0.25f, 20); // _bullet = BodyFactory.CreateBody(World); // _bullet.BodyType = BodyType.Dynamic; // _bullet.Bullet = true; // _bullet.Position = new Vector2(-31.0f, 5.0f); // _bullet.LinearVelocity = new Vector2(400.0f, 0.0f); // Fixture fixture = _bullet.CreateFixture(shape); // fixture.Restitution = 0.05f; // } //} // }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); DrawString("Keys: (f) toggle friction, (m) toggle motor"); float torque = _joint1.GetMotorTorque(settings.Hz); DrawString("Motor Torque = " + torque); }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString(string.Format("Center ({0}): Original polygon", _twoShape.Count)); DrawString(string.Format("Upper left ({0}): Simplified by removing points with an area of below 0.1", _upperLeft.Count)); DrawString(string.Format("Upper right ({0}): Simplified by removing every 3 point", _upperRight.Count)); DrawString(string.Format("Lower left ({0}): Simplified by removing points with a distance of less than 1", _lowerLeft.Count)); DrawString(string.Format("Lower right ({0}): Simplified with Douglas Peucker", _lowerRight.Count)); DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); DrawVertices(_twoShape); DrawVertices(_upperLeft); DrawVertices(_upperRight); DrawVertices(_lowerLeft); DrawVertices(_lowerRight); DebugView.EndCustomDraw(); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString("Rotation: " + _circleFixture.Body.Rotation); DrawString("Revolutions: " + _circleFixture.Body.Revolutions); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { ContactManager cm = World.ContactManager; DynamicTreeBroadPhase dt = (DynamicTreeBroadPhase)cm.BroadPhase; int height = dt.TreeHeight; int leafCount = dt.ProxyCount; float minimumNodeCount = 2 * leafCount - 1; float minimumHeight = (float)Math.Ceiling(Math.Log(minimumNodeCount) / Math.Log(2.0f)); DrawString(string.Format("dynamic tree height = {0}, min = {1}", height, (int)minimumHeight)); DrawString(string.Format("create time = {0} ms, fixture count = {1}", _createTime, _fixtureCount)); base.Update(settings, gameTime); }
public override void Update(GameSettings settings, GameTime gameTime) { base.Update(settings, gameTime); Sweep sweepA = new Sweep(); sweepA.C0 = new Vector2(24.0f, -60.0f); sweepA.A0 = 2.95f; sweepA.C = sweepA.C0; sweepA.A = sweepA.A0; sweepA.LocalCenter = Vector2.Zero; Sweep sweepB = new Sweep(); sweepB.C0 = new Vector2(53.474274f, -50.252514f); sweepB.A0 = 513.36676f; // - 162.0f * b2_pi; sweepB.C = new Vector2(54.595478f, -51.083473f); sweepB.A = 513.62781f; // - 162.0f * b2_pi; sweepB.LocalCenter = Vector2.Zero; //sweepB.a0 -= 300.0f * b2_pi; //sweepB.a -= 300.0f * b2_pi; TOIInput input = new TOIInput(); input.ProxyA.Set(_shapeA, 0); input.ProxyB.Set(_shapeB, 0); input.SweepA = sweepA; input.SweepB = sweepB; input.TMax = 1.0f; TOIOutput output; TimeOfImpact.CalculateTimeOfImpact(out output, input); DrawString("TOI = " + output.T); DrawString(string.Format("Max TOI iters = {0:n}, Max root iters = {1:n}", TimeOfImpact.TOIMaxIters, TimeOfImpact.TOIMaxRootIters)); Vector2[] vertices = new Vector2[Settings.MaxPolygonVertices]; DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View); Transform transformA; sweepA.GetTransform(out transformA, 0.0f); for (int i = 0; i < _shapeA.Vertices.Count; ++i) { vertices[i] = MathUtils.Mul(ref transformA, _shapeA.Vertices[i]); } DebugView.DrawPolygon(vertices, _shapeA.Vertices.Count, new Color(0.9f, 0.9f, 0.9f)); Transform transformB; sweepB.GetTransform(out transformB, 0.0f); for (int i = 0; i < _shapeB.Vertices.Count; ++i) { vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]); } DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.5f, 0.9f, 0.5f)); sweepB.GetTransform(out transformB, output.T); for (int i = 0; i < _shapeB.Vertices.Count; ++i) { vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]); } DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.5f, 0.7f, 0.9f)); sweepB.GetTransform(out transformB, 1.0f); for (int i = 0; i < _shapeB.Vertices.Count; ++i) { vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]); } DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.9f, 0.5f, 0.5f)); DebugView.EndCustomDraw(); }
public override void Update(GameSettings settings, GameTime gameTime) { DrawString("Note: The left side of the ship has a different density than the right side of the ship"); base.Update(settings, gameTime); }