Beispiel #1
0
        private Body(Body copy)
        {
            Initialize();
            this.ignoresCollisionResponce = copy.ignoresCollisionResponce;
            this.shape            = copy.shape;
            this.massInfo         = copy.massInfo;
            this.coefficients     = copy.coefficients;
            this.collisionIgnorer = copy.collisionIgnorer;
            this.matrices         = copy.matrices.Duplicate();
            this.state            = copy.state.Duplicate();
            this.lifetime         = copy.lifetime.Duplicate();

            this.transformation = copy.transformation;
            this.linearDamping  = copy.linearDamping;
            this.angularDamping = copy.angularDamping;

            this.ignoresCollisionResponce = copy.ignoresCollisionResponce;
            this.ignoresGravity           = copy.ignoresGravity;
            this.ignoresPhysicsLogics     = copy.ignoresPhysicsLogics;
            this.isTransformed            = copy.isTransformed;
            this.isCollidable             = copy.isCollidable;
            this.isEventable = copy.isEventable;

            this.tag = copy.tag;
        }
Beispiel #2
0
        public DistanceGrid(Shape shape, Scalar spacing)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }
            if (!shape.CanGetDistance)
            {
                throw new ArgumentException("The Shape must support Get Distance", "shape");
            }
            if (spacing <= 0)
            {
                throw new ArgumentOutOfRangeException("spacing");
            }
            Matrices matrc = new Matrices();

            shape.CalcBoundingRectangle(matrc, out this.rect);

            // this.rect = shape.Rectangle;
            this.gridSpacing    = spacing;
            this.gridSpacingInv = 1 / spacing;
            int xSize = (int)Math.Ceiling((rect.Max.X - rect.Min.X) * gridSpacingInv) + 2;
            int ySize = (int)Math.Ceiling((rect.Max.Y - rect.Min.Y) * gridSpacingInv) + 2;

            this.nodes = new Scalar[xSize][];
            for (int index = 0; index < xSize; ++index)
            {
                this.nodes[index] = new Scalar[ySize];
            }
            Vector2D point;

            point.X = rect.Min.X;
            for (int x = 0; x < xSize; ++x, point.X += gridSpacing)
            {
                point.Y = rect.Min.Y;
                for (int y = 0; y < ySize; ++y, point.Y += gridSpacing)
                {
                    shape.GetDistance(ref point, out nodes[x][y]);
                }
            }
            //restore the shape
            // shape.ApplyMatrix(ref old);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new Body Instance.
        /// </summary>
        /// <param name="state">The State of the Body.</param>
        /// <param name="shape">The Shape of the Body.</param>
        /// <param name="massInfo">A object describing the mass and inertia of the Body.</param>
        /// <param name="coefficients">A object containing coefficients.</param>
        /// <param name="lifeTime">A object Describing how long the object will be in the engine.</param>
        public Body(
            PhysicsState state,
            IShape shape,
            MassInfo massInfo,
            Coefficients coefficients,
            Lifespan lifetime)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }
            if (massInfo == null)
            {
                throw new ArgumentNullException("massInfo");
            }
            if (coefficients == null)
            {
                throw new ArgumentNullException("coefficients");
            }
            if (lifetime == null)
            {
                throw new ArgumentNullException("lifetime");
            }
            Initialize();
            this.matrices       = new Matrices();
            this.transformation = Matrix2x3.Identity;

            this.state          = new PhysicsState(state);
            this.Shape          = shape;
            this.massInfo       = massInfo;
            this.coefficients   = coefficients;
            this.lifetime       = lifetime;
            this.linearDamping  = 1;
            this.angularDamping = 1;
            this.isCollidable   = true;
            this.isEventable    = true;
            this.ApplyPosition();
        }
Beispiel #4
0
        private Body(Body copy)
        {
            this.proxies = new LinkedList <BodyProxy>();
            this.ignoresCollisionResponce = copy.ignoresCollisionResponce;
            this.shape            = copy.shape;
            this.massInfo         = copy.massInfo;
            this.coefficients     = copy.coefficients;
            this.collisionIgnorer = copy.collisionIgnorer;
            this.matrices         = copy.matrices.Duplicate();
            this.state            = copy.state.Duplicate();
            this.lifetime         = copy.lifetime.Duplicate();

            this.transformation = copy.transformation;
            this.linearDamping  = copy.linearDamping;
            this.angularDamping = copy.angularDamping;

            this.ignoresCollisionResponce = copy.ignoresCollisionResponce;
            this.ignoresGravity           = copy.ignoresGravity;
            this.isCollidable             = copy.isCollidable;
            this.ignoresGravity           = copy.ignoresGravity;
            this.isTransformed            = copy.isTransformed;

            this.tag = (copy.tag is ICloneable) ? (((ICloneable)copy.tag).Clone()) : (copy.tag);
        }