Beispiel #1
0
        void ICmpUpdatable.OnUpdate()
        {
            PrismaticJointInfo joint = this.DoorJoint;

            if (joint == null)
            {
                return;
            }

            if (joint.MotorEnabled)
            {
                if (this.moveSoundInst != null && this.moveSoundInst.Disposed)
                {
                    this.moveSoundInst = null;
                }

                bool isPanelInTargetArea = false;
                if (joint.MotorSpeed > 0.0f)
                {
                    isPanelInTargetArea = -joint.JointTranslation >= joint.UpperLimit;
                }
                else
                {
                    isPanelInTargetArea = -joint.JointTranslation <= joint.LowerLimit;
                }

                if (joint.JointSpeed <= 0.1f)
                {
                    if (isPanelInTargetArea)
                    {
                        joint.MotorEnabled      = false;
                        joint.MotorSpeed        = 0.0f;
                        this.doorPanel.BodyType = BodyType.Static;
                        if (this.moveSoundInst != null)
                        {
                            this.moveSoundInst.FadeOut(0.5f);
                            this.moveSoundInst = null;
                        }
                    }
                }
                else
                {
                    if (this.moveSoundInst == null)
                    {
                        this.moveSoundInst = DualityApp.Sound.PlaySound3D(this.moveSound, this.doorPanel.GameObj);
                        this.moveSoundInst.FadeIn(0.5f);
                        this.moveSoundInst.Looped = true;
                    }
                    this.moveSoundInst.Volume = MathF.Abs(joint.JointSpeed) / MathF.Max(MathF.Abs(this.openSpeed), MathF.Abs(this.closeSpeed));
                }
            }
        }
Beispiel #2
0
        private void CloseDoor()
        {
            PrismaticJointInfo joint = this.DoorJoint;

            if (joint == null)
            {
                return;
            }

            this.doorPanel.BodyType = BodyType.Dynamic;
            joint.MotorSpeed        = this.closeSpeed;
            joint.MotorEnabled      = true;
        }
Beispiel #3
0
        private void DrawJoint(Canvas canvas, PrismaticJointInfo joint)
        {
            float screenScale        = this.GetScreenScale(canvas);
            float screenDist         = screenScale * (joint.ParentBody.GameObj.Transform.Pos - joint.OtherBody.GameObj.Transform.Pos).Length;
            float angularCircleRadA  = joint.ParentBody.BoundRadius * 0.25f;
            float angularCircleRadB  = joint.OtherBody.BoundRadius * 0.25f;
            bool  displaySecondAngle = screenDist >= 2.0f * MathF.Max(
                screenScale * angularCircleRadA + angularCircleRadB,
                2.0f * this.minAngleConstraintRadius);

            if (joint.LimitEnabled)
            {
                this.DrawLocalAxisConstraint(canvas, joint.ParentBody, joint.OtherBody, joint.MovementAxis, joint.LocalAnchorA, joint.LocalAnchorB, joint.LowerLimit, joint.UpperLimit);
            }
            else
            {
                this.DrawLocalAxisConstraint(canvas, joint.ParentBody, joint.OtherBody, joint.MovementAxis, joint.LocalAnchorA, joint.LocalAnchorB);
            }

            this.DrawLocalAngleConstraint(canvas,
                                          joint.ParentBody,
                                          joint.LocalAnchorA,
                                          joint.OtherBody.GameObj.Transform.Angle - joint.ReferenceAngle,
                                          joint.ParentBody.GameObj.Transform.Angle,
                                          angularCircleRadA);
            if (displaySecondAngle)
            {
                this.DrawLocalAngleConstraint(canvas,
                                              joint.OtherBody,
                                              joint.LocalAnchorB,
                                              joint.ParentBody.GameObj.Transform.Angle + joint.ReferenceAngle,
                                              joint.OtherBody.GameObj.Transform.Angle,
                                              angularCircleRadB);
            }

            if (joint.MotorEnabled)
            {
                this.DrawLocalAxisMotor(canvas, joint.ParentBody, joint.OtherBody, joint.MovementAxis, joint.LocalAnchorA, joint.LocalAnchorB, joint.MotorSpeed, joint.MaxMotorForce, joint.ParentBody.BoundRadius * 1.15f);
            }

            this.DrawLocalAnchor(canvas, joint.ParentBody, joint.LocalAnchorA);
            this.DrawLocalAnchor(canvas, joint.OtherBody, joint.LocalAnchorB);
        }
Beispiel #4
0
        private void DrawJoint(Canvas canvas, PrismaticJointInfo joint)
        {
            float angularCircleRadA     = joint.ParentBody.BoundRadius * 0.25f;
            float angularCircleRadB     = joint.OtherBody.BoundRadius * 0.25f;
            bool  displaySecondCollider = (joint.ParentBody.GameObj.Transform.Pos - joint.OtherBody.GameObj.Transform.Pos).Length >= angularCircleRadA + angularCircleRadB;

            if (joint.LimitEnabled)
            {
                this.DrawLocalAxisConstraint(canvas, joint.ParentBody, joint.OtherBody, joint.MovementAxis, joint.LocalAnchorA, joint.LocalAnchorB, joint.LowerLimit, joint.UpperLimit);
            }
            else
            {
                this.DrawLocalAxisConstraint(canvas, joint.ParentBody, joint.OtherBody, joint.MovementAxis, joint.LocalAnchorA, joint.LocalAnchorB);
            }

            this.DrawLocalAngleConstraint(canvas,
                                          joint.ParentBody,
                                          joint.LocalAnchorA,
                                          joint.OtherBody.GameObj.Transform.Angle - joint.ReferenceAngle,
                                          joint.ParentBody.GameObj.Transform.Angle,
                                          angularCircleRadA);
            if (displaySecondCollider)
            {
                this.DrawLocalAngleConstraint(canvas,
                                              joint.OtherBody,
                                              joint.LocalAnchorB,
                                              joint.ParentBody.GameObj.Transform.Angle + joint.ReferenceAngle,
                                              joint.OtherBody.GameObj.Transform.Angle,
                                              angularCircleRadB);
            }

            if (joint.MotorEnabled)
            {
                this.DrawLocalAxisMotor(canvas, joint.ParentBody, joint.OtherBody, joint.MovementAxis, joint.LocalAnchorA, joint.LocalAnchorB, joint.MotorSpeed, joint.MaxMotorForce, joint.ParentBody.BoundRadius * 1.15f);
            }

            this.DrawLocalAnchor(canvas, joint.ParentBody, joint.LocalAnchorA);
            this.DrawLocalAnchor(canvas, joint.OtherBody, joint.LocalAnchorB);
        }