private void DrawSprings(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < _physicsSimulator.SpringList.Count; i++)
            {
                if (!(_physicsSimulator.SpringList[i] is FixedLinearSpring))
                {
                    continue;
                }

                FixedLinearSpring fixedLinearSpring = (FixedLinearSpring)_physicsSimulator.SpringList[i];
                _worldAttachPoint = fixedLinearSpring.WorldAttachPoint;
                _body1AttachPointInWorldCoordinates =
                    fixedLinearSpring.Body.GetWorldPosition(fixedLinearSpring.BodyAttachPoint);
                _springCircleBrush.Draw(spriteBatch, _body1AttachPointInWorldCoordinates);
                _springCircleBrush.Draw(spriteBatch, _worldAttachPoint);

                Vector2.Lerp(ref _worldAttachPoint, ref _body1AttachPointInWorldCoordinates, .25f, out _vectorTemp1);
                _springCircleBrush.Draw(spriteBatch, _vectorTemp1);

                Vector2.Lerp(ref _worldAttachPoint, ref _body1AttachPointInWorldCoordinates, .50f, out _vectorTemp1);
                _springCircleBrush.Draw(spriteBatch, _vectorTemp1);

                Vector2.Lerp(ref _worldAttachPoint, ref _body1AttachPointInWorldCoordinates, .75f, out _vectorTemp1);
                _springCircleBrush.Draw(spriteBatch, _vectorTemp1);

                _springLineBrush.Draw(spriteBatch, _body1AttachPointInWorldCoordinates,
                                      fixedLinearSpring.WorldAttachPoint);
            }

            for (int i = 0; i < _physicsSimulator.SpringList.Count; i++)
            {
                if (!(_physicsSimulator.SpringList[i] is LinearSpring))
                {
                    continue;
                }

                LinearSpring linearSpring = (LinearSpring)_physicsSimulator.SpringList[i];
                _attachPoint1 = linearSpring.AttachPoint1;
                _attachPoint2 = linearSpring.AttachPoint2;
                linearSpring.Body1.GetWorldPosition(ref _attachPoint1, out _body1AttachPointInWorldCoordinates);
                linearSpring.Body2.GetWorldPosition(ref _attachPoint2, out _body2AttachPointInWorldCoordinates);
                _springCircleBrush.Draw(spriteBatch, _body1AttachPointInWorldCoordinates);
                _springCircleBrush.Draw(spriteBatch, _body2AttachPointInWorldCoordinates);

                Vector2.Lerp(ref _body1AttachPointInWorldCoordinates, ref _body2AttachPointInWorldCoordinates, .25f,
                             out _vectorTemp1);
                _springCircleBrush.Draw(spriteBatch, _vectorTemp1);

                Vector2.Lerp(ref _body1AttachPointInWorldCoordinates, ref _body2AttachPointInWorldCoordinates, .50f,
                             out _vectorTemp1);
                _springCircleBrush.Draw(spriteBatch, _vectorTemp1);

                Vector2.Lerp(ref _body1AttachPointInWorldCoordinates, ref _body2AttachPointInWorldCoordinates, .75f,
                             out _vectorTemp1);
                _springCircleBrush.Draw(spriteBatch, _vectorTemp1);

                _springLineBrush.Draw(spriteBatch, _body1AttachPointInWorldCoordinates,
                                      _body2AttachPointInWorldCoordinates);
            }
        }
Exemple #2
0
 public static void Start()
 {
     RuntimeObject.Init();
     RigidBody.Init();
     CollisionBody.Init();
     CollisionSensor.Init();
     TransportSurface.Init();
     CollisionMaterial.Init();
     HingeJoint.Init();
     SlidingJoint.Init();
     CylindricalJoint.Init();
     FixedJoint.Init();
     BallJoint.Init();
     AngularLimit.Init();
     LinearLimit.Init();
     AngularSpring.Init();
     LinearSpring.Init();
     SpeedControl.Init();
     PositionControl.Init();
     BreakingConstraint.Init();
     GearCoupling.Init();
     CamCoupling.Init();
     ElecCamCoupling.Init();
     PreventCollision.Init();
     ChangeMaterial.Init();
     ComponentPart.Init();
     SourceBehavior.Init();
     SinkBehavior.Init();
     GraphControl.Init();
     ExternalConnection.Init();
     SignalAdapter.Init();
     Signal.Init();
     ProxyObject.Init();
     RuntimeParameters.Init();
 }
Exemple #3
0
        public LinearSpring CreateLinearSpring(Body body1, Vector2 attachPoint1, Body body2, Vector2 attachPoint2,
                                               float springConstant, float dampningConstant)
        {
            LinearSpring linearSpring = new LinearSpring(body1, attachPoint1, body2, attachPoint2, springConstant,
                                                         dampningConstant);

            return(linearSpring);
        }
Exemple #4
0
        public LinearSpring CreateLinearSpring(PhysicsSimulator physicsSimulator, Body body1, Vector2 attachPoint1,
                                               Body body2, Vector2 attachPoint2, float springConstant,
                                               float dampningConstant)
        {
            LinearSpring linearSpring = CreateLinearSpring(body1, attachPoint1, body2, attachPoint2, springConstant,
                                                           dampningConstant);

            physicsSimulator.Add(linearSpring);
            return(linearSpring);
        }
        public override void LoadContent()
        {
            _chainTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 20, 10, Color.White,
                                                                 Color.Black);

            _obstaclesTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 40, 40, Color.Brown,
                                                                     Color.Black);

            _wheelTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 45, 2, Color.White, Color.Black);

            _chainOrigin     = new Vector2(_chainTexture.Width / 2f, _chainTexture.Height / 2f);
            _wheelOrigin     = new Vector2(_wheelTexture.Width / 2f, _wheelTexture.Height / 2f);
            _obstaclesOrigin = new Vector2(_obstaclesTexture.Width / 2f, _obstaclesTexture.Height / 2f);
            Vector2 center = new Vector2(400, 500);

            _controlPoints = new Vertices();
            _controlPoints.Add(new Vector2(-15, -50) + center);
            _controlPoints.Add(new Vector2(-50, -50) + center);
            _controlPoints.Add(new Vector2(-100, -25) + center);
            _controlPoints.Add(new Vector2(-100, 25) + center);
            _controlPoints.Add(new Vector2(-50, 50) + center);
            _controlPoints.Add(new Vector2(50, 50) + center);
            _controlPoints.Add(new Vector2(100, 25) + center);
            _controlPoints.Add(new Vector2(100, -25) + center);
            _controlPoints.Add(new Vector2(50, -50) + center);
            _controlPoints.Add(new Vector2(-10, -50) + center);

            _track = ComplexFactory.Instance.CreateTrack(PhysicsSimulator, _controlPoints, 20.0f, 10.0f, 3.0f, true, 2, LinkType.RevoluteJoint);

            foreach (Geom g in _track.Geoms)
            {
                g.FrictionCoefficient = 1.0f;
            }

            _wheel1          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 45, 30);
            _wheel1.Position = new Vector2(-50, 0) + center;
            _wheel2          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 45, 30);
            _wheel2.Position = new Vector2(50, 0) + center;

            _wheelg = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _wheel1, 45, 36);
            _wheelg.FrictionCoefficient = 1.0f;
            _wheelg = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _wheel2, 45, 36);
            _wheelg.FrictionCoefficient = 1.0f;

            _spring             = SpringFactory.Instance.CreateLinearSpring(PhysicsSimulator, _wheel1, new Vector2(), _wheel2, new Vector2(), 5200, 3050);
            _spring.RestLength += 20;

            _obstacles  = new GenericList <Body>();
            _obstaclesg = new GenericList <Geom>();

            base.LoadContent();
        }
Exemple #6
0
 public void Connect(string strName, out LinearSpring item)
 {
     ExAddProperty(this.m_pSelf, strName, 4, 0x6658);
     item = null;
 }
 public void Connect(string strName, out LinearSpring item)
 {
     item = RuntimeObject.FromPtr(ExGetProperty(this.m_pSelf, strName, 4, 0x6658)) as LinearSpring;
 }