Ejemplo n.º 1
0
        protected override void CopyTo(JointInfo target)
        {
            base.CopyTo(target);
            FixedMouseJointInfo c = target as FixedMouseJointInfo;

            c.worldAnchor  = this.worldAnchor;
            c.localAnchor  = this.localAnchor;
            c.dampingRatio = this.dampingRatio;
            c.frequency    = this.frequency;
            c.maxForce     = this.maxForce;
        }
Ejemplo n.º 2
0
 private void DrawJoint(Canvas canvas, FixedMouseJointInfo joint)
 {
     this.DrawWorldPosConstraint(canvas, joint.BodyA, joint.LocalAnchor, joint.WorldAnchor);
     this.DrawWorldAnchor(canvas, joint.BodyA, joint.WorldAnchor);
     this.DrawLocalAnchor(canvas, joint.BodyA, joint.LocalAnchor);
 }
Ejemplo n.º 3
0
        void ICmpUpdatable.OnUpdate()
        {
            Camera cam = this.GameObj.Camera;

            // Mouse pressed? Drag stuff
            if (DualityApp.Mouse[MouseButton.Left])
            {
                Vector2 cursorScreen = new Vector2(DualityApp.Mouse.X, DualityApp.Mouse.Y);
                Vector2 cursorWorld = cam.GetSpaceCoord(cursorScreen).Xy;

                // Create mouse joint
                if (this.mouseJoint == null)
                {
                    ShapeInfo shape = RigidBody.PickShapeGlobal(cursorWorld);
                    RigidBody body = shape != null ? shape.Parent : null;
                    if (body != null && body.BodyType == BodyType.Dynamic)
                    {
                        this.mouseJoint = new FixedMouseJointInfo();
                        this.mouseJoint.MaxForce = 20.0f; // More power
                        this.mouseJoint.LocalAnchor = body.GameObj.Transform.GetLocalPoint(cursorWorld);
                        body.AddJoint(this.mouseJoint);
                    }
                }

                // Update mouse joint
                if (this.mouseJoint != null)
                {
                    this.mouseJoint.WorldAnchor = cursorWorld;
                }
            }
            // Mouse not pressed? Release stuff
            else
            {
                if (this.mouseJoint != null)
                {
                    this.mouseJoint.BodyA.RemoveJoint(this.mouseJoint);
                    this.mouseJoint = null;
                }
            }

            // Update stats
            // When using a fixed physics timestep, physics isn't updated every frame at high FPS, so
            // we'll just average the physics time value over several frames and display that value. Thats easier to read anyway.
            this.physicsTimeAcc += Performance.UpdatePhysicsTime;
            this.physicsTimeCounter++;
            if (this.physicsTimeCounter >= 25)
            {
                this.physicsTimeVal = this.physicsTimeAcc / this.physicsTimeCounter;
                this.physicsTimeCounter = 0;
                this.physicsTimeAcc = 0.0f;
            }
            // Update stats text
            this.UpdateStatsText();
        }