public void Load(SimulatorView view, PhysicsSimulator physicsSimulator) { //use the body factory to create the physics body _platformBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _width, _height, 1); view.AddRectangleToCanvas(_platformBody, Colors.White, new Vector2(_width, _height)); _platformBody.IsStatic = true; _platformBody.Position = _position; _platformGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _platformBody, _width, _height); _platformGeom.CollisionGroup = 100; _platformGeom.CollisionGroup = _collisionGroup; _platformGeom.FrictionCoefficient = 1; }
public void Load(SimulatorView view, PhysicsSimulator physicsSimulator) { int radius; if (_attachPoint == 0 | _attachPoint == 2) { radius = _rectangleHeight; } else { radius = _rectangleWidth; } //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); view.AddRectangleToCanvas(_angleSpringleverBody, Colors.White, new Vector2(_rectangleWidth, _rectangleHeight)); _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; CircleBrush circle = view.AddCircleToCanvas(null, Colors.White, 20); circle.Extender.Position = _position; _circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _angleSpringleverBody, radius, 20, offset, 0); _circleGeom.FrictionCoefficient = .5f; _circleGeom.CollisionGroup = _collisionGroup; JointFactory.Instance.CreateFixedRevoluteJoint(physicsSimulator, _angleSpringleverBody, _position); SpringFactory.Instance.CreateFixedAngleSpring(physicsSimulator, _angleSpringleverBody, _springConstant, _dampningConstant); }