• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Physics.RigidBody类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Duality.Components.Physics.RigidBody的典型用法代码示例。如果您正苦于以下问题:C# RigidBody类的具体用法?C# RigidBody怎么用?C# RigidBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RigidBody类属于Duality.Components.Physics命名空间,在下文中一共展示了RigidBody类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1:

        void ICmpUpdatable.OnUpdate()
        {
            float lastDelta = Time.MsPFMult * Time.TimeMult / 1000;
            if (this.rigidBody == null) this.rigidBody = this.GameObj.GetComponent<RigidBody>();

            if (!this.isDead)
            {
                if (DualityApp.Keyboard.KeyHit(Key.Space))
                {
                    this.rigidBody.ApplyLocalImpulse(-Vector2.UnitY * this.impulseStrength);
                    flapTime = (Time.MsPFMult / 1000 * 3);
                }
            }

            if(flapTime > 0)
            {
                FrontWing.GameObj.Transform.Angle = -MathF.PiOver4;
                BackWing.GameObj.Transform.Angle = MathF.PiOver4;
                flapTime -= lastDelta;
            }

            if(flapTime < 0)
            {
                FrontWing.GameObj.Transform.Angle = 0;
                BackWing.GameObj.Transform.Angle = 0;
                flapTime = 0;
            }

            if (DualityApp.Keyboard.KeyHit(Key.Escape))
            {
                Scene.SwitchTo(this.menuScene);
            }
        }
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:33,代码来源:PlayerController.cs


示例2: SetUp

		public void SetUp()
		{
			var gameObject = new GameObject();
			_rigidBody = new RigidBody();
			gameObject.AddComponent(_rigidBody);
			gameObject.AddComponent(new Transform());
		}
开发者ID:Andrea,项目名称:duality-withsvn-history,代码行数:7,代码来源:RigidBodyTests.cs


示例3: When_copied_Then_sensor_value_is_copied

		public void When_copied_Then_sensor_value_is_copied()
		{
			_rigidBody.IsSensor = true;

			var clone = new RigidBody();
			_rigidBody.CopyTo(clone);

			Assert.IsTrue(clone.IsSensor);
		}
开发者ID:Andrea,项目名称:duality-withsvn-history,代码行数:9,代码来源:RigidBodyTests.cs


示例4: OnInit

        public void OnInit(InitContext context)
        {
            body = (RigidBody)GameObj.GetComponent(typeof(RigidBody));

            jumpsRemaining = NumberOfJumps;
            direction = 0;
            jumpNextFrame = false;

            Scriptable scriptable = (Scriptable)GameObj.GetComponent(typeof(Scriptable));
            if(scriptable != null)
            {
                PlayerApi player = new PlayerApi(scriptable.engine, this);
                scriptable.AddObject("Player", player);
                scriptable.Evaluate("A_Down = function() { Player.MoveLeft() };" +
                    "D_Down = function() { Player.MoveRight() };" +
                    "D_Up = function() { Player.Stop() };" +
                    "A_Up = function() { Player.Stop() };" +
                    "Space_Down = function() { Player.Jump() };");

            }
        }
开发者ID:generatives,项目名称:Magic-Game,代码行数:21,代码来源:PlayerController.cs


示例5: PickShape

        private ShapeInfo PickShape(RigidBody body, Vector2 worldCoord)
        {
            // Special case for LoopShapes, because they are by definition unpickable
            foreach (LoopShapeInfo loop in body.Shapes.OfType<LoopShapeInfo>())
            {
                for (int i = 0; i < loop.Vertices.Length; i++)
                {
                    Vector2 worldV1 = body.GameObj.Transform.GetWorldPoint(loop.Vertices[i]);
                    Vector2 worldV2 = body.GameObj.Transform.GetWorldPoint(loop.Vertices[(i + 1) % loop.Vertices.Length]);
                    float dist = MathF.PointLineDistance(worldCoord.X, worldCoord.Y, worldV1.X, worldV1.Y, worldV2.X, worldV2.Y);
                    if (dist < 5.0f) return loop;
                }
            }

            // Do a physical picking operation
            return body.PickShape(worldCoord);
        }
开发者ID:qiqisteve,项目名称:duality,代码行数:17,代码来源:RigidBodyEditorCamViewState.cs


示例6: OnEnterState

        protected internal override void OnEnterState()
        {
            base.OnEnterState();

            // Init GUI
            this.View.SuspendLayout();
            this.toolstrip = new ToolStrip();
            this.toolstrip.SuspendLayout();

            this.toolstrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.toolstrip.Name = "toolstrip";
            this.toolstrip.Text = "Collider Editor Tools";

            this.toolCreateCircle = new ToolStripButton("Create Circle Shape (C)", Properties.CamViewResCache.IconCmpCircleCollider, this.toolCreateCircle_Clicked);
            this.toolCreateCircle.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.toolCreateCircle.AutoToolTip = true;
            this.toolstrip.Items.Add(this.toolCreateCircle);

            this.toolCreatePoly = new ToolStripButton("Create Polygon Shape (P)", Properties.CamViewResCache.IconCmpRectCollider, this.toolCreatePoly_Clicked);
            this.toolCreatePoly.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.toolCreatePoly.AutoToolTip = true;
            this.toolstrip.Items.Add(this.toolCreatePoly);

            this.toolCreateLoop = new ToolStripButton("Create Loop Shape (L)", Properties.CamViewResCache.IconCmpLoopCollider, this.toolCreateLoop_Clicked);
            this.toolCreateLoop.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.toolCreateLoop.AutoToolTip = true;
            this.toolstrip.Items.Add(this.toolCreateLoop);

            this.toolstrip.Renderer = new Duality.Editor.Controls.ToolStrip.DualitorToolStripProfessionalRenderer();
            this.toolstrip.BackColor = Color.FromArgb(212, 212, 212);

            this.View.Controls.Add(this.toolstrip);
            this.View.Controls.SetChildIndex(this.toolstrip, this.View.Controls.IndexOf(this.View.ToolbarCamera));
            this.toolstrip.ResumeLayout(true);
            this.View.ResumeLayout(true);

            // Register events
            DualityEditorApp.SelectionChanged		+= this.EditorForm_SelectionChanged;
            DualityEditorApp.ObjectPropertyChanged	+= this.EditorForm_ObjectPropertyChanged;

            // Initial update
            this.selectedBody = this.QuerySelectedCollider();
            this.InvalidateSelectionStats();
            this.UpdateToolbar();

            this.View.ActivateLayer(typeof(CamViewLayers.RigidBodyShapeCamViewLayer));
            this.View.LockLayer(typeof(CamViewLayers.RigidBodyShapeCamViewLayer));
        }
开发者ID:qiqisteve,项目名称:duality,代码行数:48,代码来源:RigidBodyEditorCamViewState.cs


示例7: DrawWorldLooseConstraint

        private void DrawWorldLooseConstraint(Canvas canvas, RigidBody bodyA, Vector2 anchorA, Vector2 anchorB)
        {
            Vector3 bodyPosA = bodyA.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawDashLine(
                anchorA.X,
                anchorA.Y,
                bodyPosA.Z,
                anchorB.X,
                anchorB.Y,
                bodyPosA.Z);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:15,代码来源:RigidBodyJointCamViewLayer.cs


示例8: DrawWorldAxisMotor

        private void DrawWorldAxisMotor(Canvas canvas, RigidBody body, Vector2 worldAxis, Vector2 localAnchor, Vector2 worldAnchor, float speed, float maxForce, float offset)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;

            ColorRgba clr = this.MotorColor;

            Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(localAnchor);
            float axisAngle = worldAxis.Angle;
            float maxForceTemp = MathF.Sign(speed) * maxForce * 0.1f;
            Vector2 arrowBegin = bodyPos.Xy + worldAxis.PerpendicularRight * offset;
            Vector2 arrowBase = arrowBegin + worldAxis * speed * 10.0f;
            Vector2 arrowA = Vector2.FromAngleLength(axisAngle + MathF.RadAngle45 + MathF.RadAngle180, MathF.Sign(speed) * MathF.Max(offset * 0.05f, 5.0f));
            Vector2 arrowB = Vector2.FromAngleLength(axisAngle - MathF.RadAngle45 + MathF.RadAngle180, MathF.Sign(speed) * MathF.Max(offset * 0.05f, 5.0f));

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                arrowBegin.X + worldAxis.PerpendicularLeft.X * 2.0f,
                arrowBegin.Y + worldAxis.PerpendicularLeft.Y * 2.0f,
                bodyPos.Z,
                arrowBegin.X + worldAxis.PerpendicularLeft.X * 2.0f + worldAxis.X * maxForceTemp,
                arrowBegin.Y + worldAxis.PerpendicularLeft.Y * 2.0f + worldAxis.Y * maxForceTemp,
                bodyPos.Z);
            canvas.DrawLine(
                arrowBegin.X + worldAxis.PerpendicularRight.X * 2.0f,
                arrowBegin.Y + worldAxis.PerpendicularRight.Y * 2.0f,
                bodyPos.Z,
                arrowBegin.X + worldAxis.PerpendicularRight.X * 2.0f + worldAxis.X * maxForceTemp,
                arrowBegin.Y + worldAxis.PerpendicularRight.Y * 2.0f + worldAxis.Y * maxForceTemp,
                bodyPos.Z);
            canvas.DrawLine(
                arrowBegin.X,
                arrowBegin.Y,
                bodyPos.Z,
                arrowBase.X,
                arrowBase.Y,
                bodyPos.Z);
            canvas.DrawLine(
                arrowBase.X,
                arrowBase.Y,
                bodyPos.Z,
                arrowBase.X + arrowA.X,
                arrowBase.Y + arrowA.Y,
                bodyPos.Z);
            canvas.DrawLine(
                arrowBase.X,
                arrowBase.Y,
                bodyPos.Z,
                arrowBase.X + arrowB.X,
                arrowBase.Y + arrowB.Y,
                bodyPos.Z);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:51,代码来源:RigidBodyJointCamViewLayer.cs


示例9: DrawWorldAnchor

        private void DrawWorldAnchor(Canvas canvas, RigidBody body, Vector2 anchor)
        {
            Vector3 colliderPos = body.GameObj.Transform.Pos;
            float markerCircleRad = body.BoundRadius * 0.02f;
            ColorRgba clr = this.JointColor;

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.FillCircle(
                anchor.X,
                anchor.Y,
                colliderPos.Z,
                markerCircleRad);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:13,代码来源:RigidBodyJointCamViewLayer.cs


示例10: DrawLocalText

 private void DrawLocalText(Canvas canvas, RigidBody body, string text, Vector2 pos, float baseAngle)
 {
     this.DrawLocalText(canvas, body, text, pos, Vector2.Zero, baseAngle);
 }
开发者ID:CKoewing,项目名称:duality,代码行数:4,代码来源:RigidBodyJointCamViewLayer.cs


示例11: SelBody

 public SelBody(RigidBody obj)
 {
     this.bodyObj = obj != null ? obj.GameObj : null;
 }
开发者ID:BraveSirAndrew,项目名称:duality,代码行数:4,代码来源:RigidBodyEditorCamViewState.SelObj.cs


示例12: CreateRigidBodyShapeAction

		public CreateRigidBodyShapeAction(RigidBody parent, params ShapeInfo[] obj) : this(parent, obj as IEnumerable<ShapeInfo>) {}
开发者ID:Andrea,项目名称:duality-withsvn-history,代码行数:1,代码来源:CreateRigidBodyShapeAction.cs


示例13: AddJoint

		/// <summary>
		/// Adds a new joint to the body.
		/// </summary>
		/// <param name="joint"></param>
		public void AddJoint(JointInfo joint, RigidBody other = null)
		{
			if (joint == null) throw new ArgumentNullException("joint");

			if (joint.ParentBody != null)
				joint.ParentBody.RemoveJoint(joint);

			joint.ParentBody = this;
			joint.OtherBody = other;

			if (this.joints == null) this.joints = new List<JointInfo>();
			this.joints.Add(joint);
			this.AwakeBody();

			if (joint.OtherBody != null)
				joint.OtherBody.AwakeBody();

			joint.UpdateJoint();
		}
开发者ID:griffynn,项目名称:duality,代码行数:23,代码来源:RigidBody.cs


示例14: FireBullet

        private void FireBullet(RigidBody body, Transform transform, Vector2 localPos, float localAngle)
        {
            ShipBlueprint blueprint = this.blueprint.Res;
            if (blueprint.BulletType == null) return;

            Bullet bullet = blueprint.BulletType.Res.CreateBullet();

            Vector2 recoilImpulse;
            Vector2 worldPos = transform.GetWorldPoint(localPos);
            bullet.Fire(this.owner, body.LinearVelocity, worldPos, transform.Angle + localAngle, out recoilImpulse);
            body.ApplyWorldImpulse(recoilImpulse);

            Scene.Current.AddObject(bullet.GameObj);

            SoundInstance inst = null;
            if (Player.AlivePlayers.Count() > 1)
                inst = DualityApp.Sound.PlaySound3D(this.owner.WeaponSound, new Vector3(worldPos));
            else
                inst = DualityApp.Sound.PlaySound(this.owner.WeaponSound);
            inst.Volume = MathF.Rnd.NextFloat(0.6f, 1.0f);
            inst.Pitch = MathF.Rnd.NextFloat(0.9f, 1.11f);
        }
开发者ID:priyanshus1,项目名称:duality,代码行数:22,代码来源:Ship.cs


示例15: DrawLocalLooseConstraint

        private void DrawLocalLooseConstraint(Canvas canvas, RigidBody bodyA, RigidBody bodyB, Vector2 anchorA, Vector2 anchorB)
        {
            Vector3 bodyPosA = bodyA.GameObj.Transform.Pos;
            Vector3 bodyPosB = bodyB.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;

            Vector2 anchorAToWorld = bodyA.GameObj.Transform.GetWorldVector(anchorA);
            Vector2 anchorBToWorld = bodyB.GameObj.Transform.GetWorldVector(anchorB);

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawDashLine(
                bodyPosA.X + anchorAToWorld.X,
                bodyPosA.Y + anchorAToWorld.Y,
                bodyPosA.Z,
                bodyPosB.X + anchorBToWorld.X,
                bodyPosB.Y + anchorBToWorld.Y,
                bodyPosB.Z);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:19,代码来源:RigidBodyJointCamViewLayer.cs


示例16: DrawLocalPosConstraint

        private void DrawLocalPosConstraint(Canvas canvas, RigidBody bodyA, RigidBody bodyB, Vector2 anchorA, Vector2 anchorB)
        {
            Vector3 colliderPosA = bodyA.GameObj.Transform.Pos;
            Vector3 colliderPosB = bodyB.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            Vector2 anchorAToWorld = bodyA.GameObj.Transform.GetWorldVector(anchorA);
            Vector2 anchorBToWorld = bodyB.GameObj.Transform.GetWorldVector(anchorB);
            Vector2 errorVec = (colliderPosB.Xy + anchorBToWorld) - (colliderPosA.Xy + anchorAToWorld);

            bool hasError = errorVec.Length >= 1.0f;
            if (hasError)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    colliderPosA.X + anchorAToWorld.X,
                    colliderPosA.Y + anchorAToWorld.Y,
                    colliderPosA.Z,
                    colliderPosB.X + anchorBToWorld.X,
                    colliderPosB.Y + anchorBToWorld.Y,
                    colliderPosB.Z);
                this.DrawLocalText(canvas, bodyA,
                    string.Format("{0:F1}", errorVec.Length),
                    anchorAToWorld + errorVec * 0.5f,
                    new Vector2(0.5f, 0.0f),
                    errorVec.PerpendicularLeft.Angle);
            }

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                colliderPosA.X,
                colliderPosA.Y,
                colliderPosA.Z,
                colliderPosA.X + anchorAToWorld.X,
                colliderPosA.Y + anchorAToWorld.Y,
                colliderPosA.Z);
            canvas.DrawLine(
                colliderPosB.X,
                colliderPosB.Y,
                colliderPosB.Z,
                colliderPosB.X + anchorBToWorld.X,
                colliderPosB.Y + anchorBToWorld.Y,
                colliderPosB.Z);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:46,代码来源:RigidBodyJointCamViewLayer.cs


示例17: GetAnchorDist

        private float GetAnchorDist(RigidBody bodyA, RigidBody bodyB, Vector2 localAnchorA, Vector2 localAnchorB)
        {
            Vector3 colliderPosA = bodyA.GameObj.Transform.Pos;
            Vector3 colliderPosB = bodyB.GameObj.Transform.Pos;

            Vector2 anchorAToWorld = bodyA.GameObj.Transform.GetWorldVector(localAnchorA);
            Vector2 anchorBToWorld = bodyB.GameObj.Transform.GetWorldVector(localAnchorB);
            Vector2 errorVec = (colliderPosB.Xy + anchorBToWorld) - (colliderPosA.Xy + anchorAToWorld);

            return errorVec.Length;
        }
开发者ID:CKoewing,项目名称:duality,代码行数:11,代码来源:RigidBodyJointCamViewLayer.cs


示例18: DrawLocalAngleConstraint

        private void DrawLocalAngleConstraint(Canvas canvas, RigidBody body, Vector2 anchor, float targetAngle, float currentAngle, float radius)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(anchor);
            Vector2 angleVec = Vector2.FromAngleLength(targetAngle, radius);
            Vector2 errorVec = Vector2.FromAngleLength(currentAngle, radius);
            bool hasError = MathF.CircularDist(targetAngle, currentAngle) >= MathF.RadAngle1;

            if (hasError)
            {
                float circleBegin = currentAngle;
                float circleEnd = targetAngle;
                if (MathF.TurnDir(circleBegin, circleEnd) < 0)
                {
                    MathF.Swap(ref circleBegin, ref circleEnd);
                    circleEnd = circleBegin + MathF.CircularDist(circleBegin, circleEnd);
                }

                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    bodyPos.X + anchorToWorld.X,
                    bodyPos.Y + anchorToWorld.Y,
                    bodyPos.Z,
                    bodyPos.X + anchorToWorld.X + errorVec.X,
                    bodyPos.Y + anchorToWorld.Y + errorVec.Y,
                    bodyPos.Z);
                canvas.DrawCircleSegment(
                    bodyPos.X + anchorToWorld.X,
                    bodyPos.Y + anchorToWorld.Y,
                    bodyPos.Z,
                    radius,
                    circleBegin,
                    circleEnd);
                this.DrawLocalText(canvas, body,
                    string.Format("{0:F0}°", MathF.RadToDeg(MathF.NormalizeAngle(currentAngle))),
                    anchorToWorld + errorVec,
                    Vector2.UnitY,
                    errorVec.Angle);
            }
            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                bodyPos.X + anchorToWorld.X,
                bodyPos.Y + anchorToWorld.Y,
                bodyPos.Z,
                bodyPos.X + anchorToWorld.X + angleVec.X,
                bodyPos.Y + anchorToWorld.Y + angleVec.Y,
                bodyPos.Z);
            this.DrawLocalText(canvas, body,
                string.Format("{0:F0}°", MathF.RadToDeg(MathF.NormalizeAngle(targetAngle))),
                anchorToWorld + angleVec,
                angleVec.Angle);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:56,代码来源:RigidBodyJointCamViewLayer.cs


示例19: DrawWorldAxisConstraint

        private void DrawWorldAxisConstraint(Canvas canvas, RigidBody body, Vector2 worldAxis, Vector2 localAnchor, Vector2 worldAnchor, float min = 1, float max = -1)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;
            worldAxis = worldAxis.Normalized;
            bool infinite = false;
            if (min > max)
            {
                min = -10000000.0f;
                max = 10000000.0f;
                infinite = true;
            }
            Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(localAnchor);
            float axisVal = Vector2.Dot(bodyPos.Xy + anchorToWorld - worldAnchor, worldAxis);
            Vector2 basePos = MathF.PointLineNearestPoint(
                bodyPos.X + anchorToWorld.X,
                bodyPos.Y + anchorToWorld.Y,
                worldAnchor.X + worldAxis.X * min,
                worldAnchor.Y + worldAxis.Y * min,
                worldAnchor.X + worldAxis.X * max,
                worldAnchor.Y + worldAxis.Y * max,
                infinite);
            float errorVal = (bodyPos.Xy + anchorToWorld - basePos).Length;
            Vector2 errorVec = basePos - bodyPos.Xy;
            bool hasError = errorVal >= 1.0f;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            if (hasError)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    bodyPos.X + anchorToWorld.X,
                    bodyPos.Y + anchorToWorld.Y,
                    bodyPos.Z,
                    basePos.X,
                    basePos.Y,
                    bodyPos.Z);
                this.DrawLocalText(canvas, body,
                    string.Format("{0:F1}", errorVal),
                    errorVec * 0.5f,
                    new Vector2(0.5f, 0.0f),
                    errorVec.PerpendicularLeft.Angle);
            }

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                worldAnchor.X + worldAxis.X * min,
                worldAnchor.Y + worldAxis.Y * min,
                bodyPos.Z,
                worldAnchor.X + worldAxis.X * max,
                worldAnchor.Y + worldAxis.Y * max,
                bodyPos.Z);
            if (!infinite)
            {
                canvas.DrawLine(
                    worldAnchor.X + worldAxis.X * min + worldAxis.PerpendicularLeft.X * 5.0f,
                    worldAnchor.Y + worldAxis.Y * min + worldAxis.PerpendicularLeft.Y * 5.0f,
                    bodyPos.Z,
                    worldAnchor.X + worldAxis.X * min + worldAxis.PerpendicularRight.X * 5.0f,
                    worldAnchor.Y + worldAxis.Y * min + worldAxis.PerpendicularRight.Y * 5.0f,
                    bodyPos.Z);
                canvas.DrawLine(
                    worldAnchor.X + worldAxis.X * max + worldAxis.PerpendicularLeft.X * 5.0f,
                    worldAnchor.Y + worldAxis.Y * max + worldAxis.PerpendicularLeft.Y * 5.0f,
                    bodyPos.Z,
                    worldAnchor.X + worldAxis.X * max + worldAxis.PerpendicularRight.X * 5.0f,
                    worldAnchor.Y + worldAxis.Y * max + worldAxis.PerpendicularRight.Y * 5.0f,
                    bodyPos.Z);
            }
        }
开发者ID:CKoewing,项目名称:duality,代码行数:71,代码来源:RigidBodyJointCamViewLayer.cs


示例20: DrawWorldDistConstraint

        private void DrawWorldDistConstraint(Canvas canvas, RigidBody body, Vector2 localAnchor, Vector2 worldAnchor, float minDist, float maxDist)
        {
            Vector3 colliderPosA = body.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            float markerCircleRad = body.BoundRadius * 0.02f;
            Vector2 anchorA = body.GameObj.Transform.GetWorldVector(localAnchor);
            Vector2 errorVec = worldAnchor - (colliderPosA.Xy + anchorA);
            Vector2 lineNormal = errorVec.PerpendicularRight.Normalized;
            float dist = errorVec.Length;
            Vector2 distVec = errorVec.Normalized * MathF.Clamp(dist, minDist, maxDist);
            bool hasError = (errorVec - distVec).Length >= 1.0f;

            if (hasError)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    colliderPosA.X + anchorA.X + distVec.X,
                    colliderPosA.Y + anchorA.Y + distVec.Y,
                    colliderPosA.Z,
                    colliderPosA.X + anchorA.X + errorVec.X,
                    colliderPosA.Y + anchorA.Y + errorVec.Y,
                    colliderPosA.Z);
                this.DrawLocalText(canvas, body,
                    string.Format("{0:F1}", dist),
                    anchorA + errorVec,
                    Vector2.UnitY,
                    errorVec.Angle);
            }
            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                colliderPosA.X + anchorA.X,
                colliderPosA.Y + anchorA.Y,
                colliderPosA.Z,
                colliderPosA.X + anchorA.X + distVec.X,
                colliderPosA.Y + anchorA.Y + distVec.Y,
                colliderPosA.Z);
            if (hasError)
            {
                canvas.DrawLine(
                    colliderPosA.X + anchorA.X + distVec.X - lineNormal.X * 5.0f,
                    colliderPosA.Y + anchorA.Y + distVec.Y - lineNormal.Y * 5.0f,
                    colliderPosA.Z,
                    colliderPosA.X + anchorA.X + distVec.X + lineNormal.X * 5.0f,
                    colliderPosA.Y + anchorA.Y + distVec.Y + lineNormal.Y * 5.0f,
                    colliderPosA.Z);
            }
            this.DrawLocalText(canvas, body,
                string.Format("{0:F1}", MathF.Clamp(dist, minDist, maxDist)),
                anchorA + distVec,
                Vector2.Zero,
                errorVec.Angle);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:55,代码来源:RigidBodyJointCamViewLayer.cs



注:本文中的Duality.Components.Physics.RigidBody类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WebServer.BodyWriter类代码示例发布时间:2022-05-24
下一篇:
C# Models.MetaData类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap