当前位置: 首页>>代码示例>>C#>>正文


C# Body.ApplyPosition方法代码示例

本文整理汇总了C#中Body.ApplyPosition方法的典型用法代码示例。如果您正苦于以下问题:C# Body.ApplyPosition方法的具体用法?C# Body.ApplyPosition怎么用?C# Body.ApplyPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Body的用法示例。


在下文中一共展示了Body.ApplyPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FixedHingeJoint

 public FixedHingeJoint(Body body, Vector2D anchor, Lifespan lifetime)
     : base(lifetime)
 {
     if (body == null) { throw new ArgumentNullException("body"); }
     this.body = body;
     this.anchor = anchor;
     body.ApplyPosition();
     Vector2D.Transform(ref body.Matrices.ToBody, ref anchor, out this.localAnchor1);
     this.softness = 0.001f;
     this.biasFactor = 0.2f;
     this.distanceTolerance = Scalar.PositiveInfinity;
 }
开发者ID:timdetering,项目名称:Physics2D.Net,代码行数:12,代码来源:FixedHingeJoint.cs

示例2: HingeJoint

        /// <summary>
        /// Creates a new HingeJoint Instance.
        /// </summary>
        /// <param name="body1">One of the bodies to be Jointed.</param>
        /// <param name="body2">One of the bodies to be Jointed.</param>
        /// <param name="anchor">The location of the Hinge.</param>
        /// <param name="lifeTime">A object Describing how long the object will be in the engine.</param>
        public HingeJoint(Body body1, Body body2, Vector2D anchor, Lifespan lifetime)
            : base(lifetime)
        {
            if (body1 == null) { throw new ArgumentNullException("body1"); }
            if (body2 == null) { throw new ArgumentNullException("body2"); }
            if (body1 == body2) { throw new ArgumentException("You cannot add a joint to a body to itself"); }
            this.body1 = body1;
            this.body2 = body2;
            body1.ApplyPosition();
            body2.ApplyPosition();

            Vector2D.Transform(ref body1.Matrices.ToBody, ref anchor, out  this.localAnchor1);
            Vector2D.Transform(ref body2.Matrices.ToBody, ref anchor, out  this.localAnchor2);

            this.softness = 0.001f;
            this.biasFactor = 0.2f;
            this.distanceTolerance = Scalar.PositiveInfinity;
        }
开发者ID:timdetering,项目名称:Physics2D.Net,代码行数:25,代码来源:HingeJoint.cs

示例3: AddLine

        public static Body AddLine(DemoOpenInfo info, Vector2D point1, Vector2D point2, Scalar thickness, Scalar mass)
        {
            Vector2D line = point1 - point2;
            Vector2D avg = (point1 + point2) * .5f;
            Scalar length = line.Magnitude;
            Scalar angle = line.Angle;

            Scalar Hd2 = thickness * .5f;
            Scalar Wd2 = length * .5f;

            int curveEdgeCount = 5;
            Scalar da = MathHelper.Pi / curveEdgeCount;

            List<Vector2D> vertexes = new List<Vector2D>();
            vertexes.Add(new Vector2D(Wd2, Hd2));
            vertexes.Add(new Vector2D(-Wd2, Hd2));
            for (Scalar angle2 = MathHelper.PiOver2 + da; angle2 < MathHelper.ThreePiOver2; angle2 += da)
            {
                vertexes.Add(new Vector2D(-Wd2, 0) + Vector2D.FromLengthAndAngle(Hd2, angle2));
            }
            vertexes.Add(new Vector2D(-Wd2, -Hd2));
            vertexes.Add(new Vector2D(Wd2, -Hd2));
            for (Scalar angle2 = -MathHelper.PiOver2 + da; angle2 < MathHelper.PiOver2; angle2 += da)
            {
                vertexes.Add(new Vector2D(Wd2, 0) + Vector2D.FromLengthAndAngle(Hd2, angle2));
            }
            IShape shape = ShapeFactory.CreateColoredPolygon(vertexes.ToArray(), thickness / 4);

            Body body = new Body(
                new PhysicsState(new ALVector2D(0, avg)),
                shape,
                mass,
                Coefficients.Duplicate(),
                new Lifespan());
            body.Transformation = Matrix2x3.FromRotationZ(angle);
            body.ApplyPosition();
            info.Scene.AddGraphic(CreateGraphic(body));
            return body;
        }
开发者ID:bsvercl,项目名称:physics2d,代码行数:39,代码来源:DemoHelper.cs

示例4: CreateTank

        public static DisposeCallback CreateTank(DemoOpenInfo info, Vector2D position,List<Body> result)
        {
            Lifespan avatarLifespan = new Lifespan();

            IShape shape = ShapeFactory.CreateSprite(Cache<SurfacePolygons>.GetItem("tank.png"), 4, 18, 2);

            ObjectIgnorer ignorer = new ObjectIgnorer();
            Body tankBody = new Body(new PhysicsState(new ALVector2D(0, 0, 0)),
                shape,
                300,//new MassInfo(40, Scalar.PositiveInfinity),
                new Coefficients(0, 1),
                avatarLifespan);
            result.Add(tankBody);
            tankBody.State.Position.Linear += position;
            tankBody.ApplyPosition();

            tankBody.CollisionIgnorer = ignorer;
            BodyGraphic graphic = CreateGraphic(tankBody);
            graphic.ZOrder = 2;
            info.Scene.AddGraphic(graphic);

            Scalar wheelSize = 18;
            Scalar wheelSpacing = -9;
            Scalar lenghtPercent = .84f;
            Matrix2x3 ident = Matrix2x3.Identity;
            BoundingRectangle rect;
            shape.CalcBoundingRectangle(ref ident, out rect);
            Scalar y = (rect.Max.Y + 4);
            Body lastWheel = null;
            BoundingPolygon polygon = new BoundingPolygon(shape.Vertexes);

            Ray ray2 = new Ray(new Vector2D(rect.Max.X, y), -Vector2D.YAxis);
            Scalar y3 = y - polygon.Intersects(ray2);
            Vector2D avatarBarrelOffset = new Vector2D(rect.Max.X + 10, y3);

            CircleShape wheelShape = ShapeFactory.CreateColoredCircle(wheelSize, 30);
            Scalar force = 0;

            for (Scalar x = rect.Min.X + wheelSize; x < (rect.Max.X - wheelSize) * lenghtPercent; x += (wheelSize * 2 + wheelSpacing))
            {

                Ray ray = new Ray(new Vector2D(x, y), -Vector2D.YAxis);
                Scalar y2 = y - polygon.Intersects(ray);



                Vector2D offset = new Vector2D(x, y2);

                Body wheel = new Body(
                    new PhysicsState(new ALVector2D(0, offset + position)),
                    wheelShape,
                    10,
                    new Coefficients(0, 3),//  coefficients.Duplicate(),
                    avatarLifespan);
                result.Add(wheel);

                wheel.CollisionIgnorer = ignorer;
                wheel.AngularDamping = .9f;
                wheel.Updated += delegate(object sender, UpdatedEventArgs e)
                {
                    wheel.State.ForceAccumulator.Angular += force;
                };
                info.Scene.AddGraphic(CreateGraphic(wheel));

                HingeJoint joint = new HingeJoint(tankBody, wheel, offset + position, avatarLifespan);
                joint.Softness = .1f;
                info.Scene.Engine.AddJoint(joint);

                if (lastWheel != null)
                {
                    AngleJoint joint2 = new AngleJoint(lastWheel, wheel, avatarLifespan);
                    info.Scene.Engine.AddJoint(joint2);
                }
                lastWheel = wheel;
            }


            CircleShape weaponShape = ShapeFactory.CreateColoredCircle(5, 8);

            //now begins the abuse of anominous delegates (BIG TIME)

            EventHandler<KeyboardEventArgs> keyDownHandler = delegate(object sender, KeyboardEventArgs e)
            {
                switch (e.Key)
                {
                    case Key.LeftArrow:
                        force = -1500000;
                        break;
                    case Key.RightArrow:
                        force = 1500000;
                        break;
                    case Key.Space:

                        Scalar velocity = 2000;

                        Matrix2x3 toWorld = tankBody.Matrices.ToWorld;
                        Matrix2x2 toWorldNormal = tankBody.Matrices.ToWorldNormal;

                        //  Matrix2D mat = avatarBodies[0].Matrices.ToWorld;
                        Vector2D direction = toWorldNormal * Vector2D.XAxis;
//.........这里部分代码省略.........
开发者ID:bsvercl,项目名称:physics2d,代码行数:101,代码来源:DemoHelper.cs

示例5: BasicDemoSetup

        public static DisposeCallback BasicDemoSetup(DemoOpenInfo info)
        {
            DisposeCallback dispose = null;
            IShape bombShape = ShapeFactory.CreateSprite(Cache<SurfacePolygons>.GetItem("rocket.png"), 2, 16, 3);
            dispose += DemoHelper.RegisterBombLaunching(info, bombShape, 120);
            dispose += DemoHelper.RegisterMousePicking(info);

            dispose += DemoHelper.RegisterBodyStreamSpawning(info,
                new Body(new PhysicsState(), ParticleShape.Default, 1, Coefficients.Duplicate(), new Lifespan(.5f)), 2, 120, 1000, Key.B);
            dispose += DemoHelper.RegisterMaintainSpawning(info, SdlDotNet.Input.Key.N,
                delegate(Vector2D position)
                {
                    ExplosionLogic result = new ExplosionLogic(position, Vector2D.Zero, 9000, .1f, 600, new Lifespan(.25f));
                    info.Scene.Engine.AddLogic(result);
                    return result;
                });

            List<RaySegment> segments = new List<RaySegment>();

            for (Scalar angle = 0; angle < MathHelper.PiOver2; angle += .05f)
            {
                RaySegment seg = new RaySegment();
                seg.Length = 500;
                seg.RayInstance = new Ray(Vector2D.Zero, Vector2D.FromLengthAndAngle(1, angle));
                segments.Add(seg);
            }

            IShape rayShape = ShapeFactory.CreateRays(segments.ToArray());
            dispose += DemoHelper.RegisterMaintainSpawning(info, SdlDotNet.Input.Key.M,
                delegate(Vector2D position)
                {
                    Body lazer = new Body(new PhysicsState(), rayShape, 1, new Coefficients(1, 1), new Lifespan());
                    lazer.State.Position.Linear = position;
                    lazer.State.Velocity.Angular = .91f;
                    lazer.IgnoresGravity = true;
                    lazer.ApplyPosition();
                    info.Scene.AddGraphic(CreateGraphic(lazer));
                    return lazer;
                });





            return dispose;
        }
开发者ID:bsvercl,项目名称:physics2d,代码行数:46,代码来源:DemoHelper.cs

示例6: CreateClipper

        void CreateClipper()
        {
            int width = 800;
            int height = 600;

            PolygonShape shape = new PolygonShape(VertexHelper.CreateRectangle(width, height), 100);
            clipper = new Body(new PhysicsState(), shape,1, new Coefficients(0, 0), new Lifespan());
            clipper.State.Position.Linear.X = width / 2f;
            clipper.State.Position.Linear.Y = height / 2f;
            clipper.ApplyPosition();

            clipper.IsBroadPhaseOnly = true;
            clipper.IsEventable = false;
            clipper.IgnoresGravity = true;
            clipper.IgnoresPhysicsLogics = true;
            clipper.Collided += new EventHandler<CollisionEventArgs>(clipper_Collided);
            clipper.Updated += new EventHandler<UpdatedEventArgs>(clipper_Updated);
        }
开发者ID:bsvercl,项目名称:physics2d,代码行数:18,代码来源:Demo.cs

示例7: AddRays

        void AddRays()
        {
            List<RaySegment> segments = new List<RaySegment>();


            for (Scalar angle = 0; angle < MathHelper.PiOver2; angle += .05f)
            {
                RaySegment seg = new RaySegment();
                seg.Length = 500;
                seg.RayInstance = new Ray(Vector2D.Zero, Vector2D.FromLengthAndAngle(1, angle));
                segments.Add(seg);
            }

            lazer = new Body(new PhysicsState(), new RaySegmentsShape(segments.ToArray()), 1, new Coefficients(1, 1), new Lifespan());
            lazer.State.Position.Linear = sparkPoint;
            lazer.State.Velocity.Angular = .91f;
            lazer.IgnoresGravity = true;
            lazer.ApplyPosition();
            engine.AddBody(lazer);
            lazerLogic = new RaySegmentsCollisionLogic(lazer);
            engine.AddLogic(lazerLogic);
            lock (objects)
            {
                OpenGlObject o = new OpenGlObject(lazer, lazerLogic);
                lazer.Tag = o;
                objects.Add(o);
            }
        }
开发者ID:bsvercl,项目名称:physics2d,代码行数:28,代码来源:Demo.cs

示例8: OpenGlObject

 public OpenGlObject(Body entity)
 {
     this.points = new List<Vector2D>();
     this.entity = entity;
     this.entity.PositionChanged += entity_NewState;
     this.entity.Removed += entity_Removed;
     Matrix2x3 mat = entity.Matrices.ToWorld;
     Matrix2x3.Copy2DToOpenGlMatrix(ref mat, matrix);
     if (entity.Shape is RaySegmentsShape)
     {
         /*RaySegmentsShape se = (RaySegmentsShape)entity.Shape;
         entity.Collided += new EventHandler<CollisionEventArgs>(entity_Collided);
         distances = new Scalar[se.Segments.Length];
         entity.Updated += new EventHandler<UpdatedEventArgs>(entity_Updated);*/
     }
     else if (DrawCollisionPoints && !(entity.Shape is ParticleShape))
     {
         entity.Collided += entity_Collided2;
     }
     entity.ApplyPosition();
 }
开发者ID:bsvercl,项目名称:physics2d,代码行数:21,代码来源:OpenGlObject.cs


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