public void Load(Demo demo, PhysicsSimulator physicsSimulator) { //use the body factory to create the physics body borderBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, width, height, 1); borderBody.IsStatic = true; borderBody.Position = position; LoadBorderGeom(physicsSimulator); float left = (position.X - width / 2f); float top = (position.Y - height / 2f); float right = (position.X + width / 2f); float bottom = (position.Y + height / 2f); Rectangle leftBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255), new Vector2(borderWidth, height)); Demo.PositionTopLeft(leftBorder, new Vector2(left, top)); Rectangle rightBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255), new Vector2(borderWidth, height)); Demo.PositionTopLeft(rightBorder, new Vector2(right - borderWidth, top)); Rectangle topBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255), new Vector2(width, borderWidth)); Demo.PositionTopLeft(topBorder, new Vector2(left, top)); Rectangle bottomBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255), new Vector2(width, borderWidth)); Demo.PositionTopLeft(bottomBorder, new Vector2(left, bottom - borderWidth)); }
public void Load(Demo demo, PhysicsSimulator physicsSimulator) { //use the body factory to create the physics body _platformBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _width, _height, 1); demo.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(Demo demo, PhysicsSimulator physicsSimulator) { _linearSpring = new LinearSpring[_rectangleCount - 1]; _rectangleBody = new Body[_rectangleCount]; _rectangleBody[0] = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth, _rectangleHeight, _rectangleMass); _rectangleBody[0].Position = _position; demo.AddRectangleToCanvas(_rectangleBody[0], Colors.White, new Vector2(_rectangleWidth, _rectangleHeight)); for (int i = 1; i < _rectangleBody.Length; i++) { _rectangleBody[i] = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth, _rectangleHeight, _rectangleMass); _rectangleBody[i].Position = _rectangleBody[i - 1].Position + new Vector2(0, _springLength); demo.AddRectangleToCanvas(_rectangleBody[i], Colors.White, new Vector2(_rectangleWidth, _rectangleHeight)); } _rectangleGeom = new Geom[_rectangleCount]; _rectangleGeom[0] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rectangleBody[0], _rectangleWidth, _rectangleHeight); _rectangleGeom[0].CollisionGroup = _collisionGroup; for (int j = 1; j < _rectangleGeom.Length; j++) { _rectangleGeom[j] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rectangleBody[j], _rectangleWidth, _rectangleHeight); _rectangleGeom[j].CollisionGroup = _collisionGroup; } for (int k = 0; k < _linearSpring.Length; k++) { _linearSpring[k] = SpringFactory.Instance.CreateLinearSpring(physicsSimulator, _rectangleBody[k], Vector2.Zero, _rectangleBody[k + 1], Vector2.Zero, _springConstant, _dampningConstant); } }
public void Load(Demo demo, PhysicsSimulator physicsSimulator) { int count = _bottomRowBlockCount * (1 + _bottomRowBlockCount) / 2; _blockBody = new Body[count]; _blockGeom = new Geom[count]; for (int i = 0; i < _blockBody.Length; i++) { _blockBody[i] = BodyFactory.Instance.CreateBody(physicsSimulator, _referenceBody); _blockGeom[i] = GeomFactory.Instance.CreateGeom(physicsSimulator, _blockBody[i], _referenceGeom); demo.AddRectangleToCanvas(_blockBody[i], Colors.White, new Vector2(32, 32)); } CreatePyramid(); }
public void Load(Demo demo, PhysicsSimulator physicsSimulator) { //Load bodies _spiderBody = BodyFactory.Instance.CreateCircleBody(physicsSimulator, _spiderBodyRadius, 1); _spiderBody.Position = _position; _spiderBody.IsStatic = false; demo.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); demo.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); demo.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); demo.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); demo.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 void Load(Demo demo, 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); demo.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; Ellipse circle = demo.AddCircleToCanvas(null, Colors.White, 20); Demo.CenterAround(circle, _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); }