Example #1
0
        /// <summary>
        /// Removes a child shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        public void RemoveChildShape(ColliderShape shape)
        {
            colliderShapes.Remove(shape);

            InternalCompoundShape.RemoveChildShape(shape.InternalShape);

            shape.Parent = null;
        }
Example #2
0
        public void Dispose()
        {
            if (Shape == null)
            {
                return;
            }

            Shape.Dispose();
            Shape = null;
        }
Example #3
0
        /// <summary>
        /// Adds a child shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        public void AddChildShape(ColliderShape shape)
        {
            colliderShapes.Add(shape);

            var compoundMatrix = Matrix.RotationQuaternion(shape.LocalRotation) * Matrix.Translation(shape.LocalOffset);

            InternalCompoundShape.AddChildShape(compoundMatrix, shape.InternalShape);

            shape.Parent = this;
        }
Example #4
0
        protected override void OnChangeShape(ColliderShape newShape)
        {
            base.OnChangeShape(newShape);


            if (Simulation != null && Simulation.BodyExists(StaticHandle))
            {
                var staticReference = Simulation.GetStaticReference(StaticHandle);
                staticReference.SetShape(newShape.InternalShapeIndex);
            }
        }
        public void Dispose()
        {
            if (Shape == null)
            {
                return;
            }

            var compound = Shape.Parent;

            compound?.RemoveChildShape(Shape);

            Shape.Dispose();
            Shape = null;
        }
        internal static ColliderShape CreateShape(IColliderShapeDesc desc)
        {
            if (desc == null)
            {
                return(null);
            }

            ColliderShape shape = desc.CreateShape();

            if (shape == null)
            {
                return(null);
            }

            //shape.UpdateLocalTransformations();
            shape.Description = desc;

            return(shape);
        }
Example #7
0
        internal static ColliderShape CreateShape(Simulation simulation, ContentManager content, IColliderShapeDesc desc)
        {
            if (desc == null)
            {
                return(null);
            }

            ColliderShape shape = desc.CreateShape(simulation, content);

            if (shape == null)
            {
                return(null);
            }

            //shape.UpdateLocalTransformations();
            shape.Description = desc;

            return(shape);
        }
Example #8
0
        internal static ColliderShape Compose(Simulation simulation, ContentManager content, IReadOnlyList <IAssetColliderShapeDesc> descs)
        {
            if (descs == null)
            {
                return(null);
            }

            ColliderShape res = null;

            if (descs.Count == 1) //single shape case
            {
                res = CreateShape(simulation, content, descs[0]);
                if (res == null)
                {
                    return(null);
                }
            }

            return(res);
        }
Example #9
0
        public void ComposeShape()
        {
            if (Simulation == null || Simulation.PhysicsProcessor == null)
            {
                return;
            }

            ColliderShapeChanged = false;

            if (ColliderShapes.Count == 1) //single shape case
            {
                if (ColliderShapes[0] == null)
                {
                    return;
                }

                var content = Simulation.PhysicsProcessor.Services.GetService <ContentManager>();

                colliderShape = PhysicsColliderShape.CreateShape(Simulation, content, ColliderShapes[0]);
            }
        }
Example #10
0
        internal static ColliderShape Compose(IReadOnlyList <IAssetColliderShapeDesc> descs)
        {
            if (descs == null)
            {
                return(null);
            }

            ColliderShape res = null;

            if (descs.Count == 1) //single shape case
            {
                res = CreateShape(descs[0]);
                if (res == null)
                {
                    return(null);
                }
                res.IsPartOfAsset = true;
            }
            else if (descs.Count > 1) //need a compound shape in this case
            {
                var compound = new CompoundColliderShape();
                foreach (var desc in descs)
                {
                    var subShape = CreateShape(desc);
                    if (subShape == null)
                    {
                        continue;
                    }
                    compound.AddChildShape(subShape);
                }
                res = compound;
                res.IsPartOfAsset = true;
            }

            return(res);
        }
Example #11
0
 protected virtual void OnChangeShape(ColliderShape shape)
 {
 }