Ejemplo n.º 1
0
        private void AddCollisions(List <ConvexCollisionMask> collisions, Model3D model, Matrix3D parentMatrix)
        {
            if (model.Transform != null)
            {
                parentMatrix = model.Transform.Value * parentMatrix;
            }

            Model3DGroup models = (model as Model3DGroup);

            if (models != null)
            {
                // The model passed in is actually a group.  Recurse
                foreach (Model3D m in models.Children)
                {
                    AddCollisions(collisions, m, parentMatrix);
                }
            }
            else
            {
                CollisionMask   collisionMask = null;
                GeometryModel3D geometryModel = (model as GeometryModel3D);
                if (geometryModel != null)
                {
                    // See if a collision mask is already assosiated with this geometry (will very likely come back null)
                    collisionMask = World.GetCollisionMask(geometryModel.Geometry);

                    if (!(collisionMask is NullCollision))              // even nulls will fall into this if statement
                    {
                        if (collisionMask == null)
                        {
                            // Create a new collision mask
                            collisionMask = new GeometryCollisionMask3D();
                            World.SetCollisionMask(geometryModel.Geometry, collisionMask);
                        }
                        else if (!(collisionMask is ConvexCollisionMask))
                        {
                            throw new InvalidOperationException("The GeometryModel3D already has a non Convex CollisionMaskMask attached.");
                        }
                    }
                }

                if (collisionMask != null)
                {
                    collisionMask.Initialise(this.World);

                    collisions.Add(new ConvextCollisionModifier((ConvexCollisionMask)collisionMask, parentMatrix));             // why is a convex collision modifier needed?  what's wrong with the convex collision mask?
                }
            }
        }
Ejemplo n.º 2
0
        private void AddCollisions(List<ConvexCollisionMask> collisions, Model3D model, Matrix3D parentMatrix)
        {
            if (model.Transform != null)
            {
                parentMatrix = model.Transform.Value * parentMatrix;
            }

            Model3DGroup models = (model as Model3DGroup);
            if (models != null)
            {
                // The model passed in is actually a group.  Recurse
                foreach (Model3D m in models.Children)
                {
                    AddCollisions(collisions, m, parentMatrix);
                }
            }
            else
            {
                CollisionMask collisionMask = null;
                GeometryModel3D geometryModel = (model as GeometryModel3D);
                if (geometryModel != null)
                {
                    // See if a collision mask is already assosiated with this geometry (will very likely come back null)
                    collisionMask = World.GetCollisionMask(geometryModel.Geometry);

                    if (!(collisionMask is NullCollision))		// even nulls will fall into this if statement
                    {
                        if (collisionMask == null)
                        {
                            // Create a new collision mask
                            collisionMask = new GeometryCollisionMask3D();
                            World.SetCollisionMask(geometryModel.Geometry, collisionMask);
                        }
                        else if (!(collisionMask is ConvexCollisionMask))
                        {
                            throw new InvalidOperationException("The GeometryModel3D already has a non Convex CollisionMaskMask attached.");
                        }
                    }
                }

                if (collisionMask != null)
                {
                    collisionMask.Initialise(this.World);

                    collisions.Add(new ConvextCollisionModifier((ConvexCollisionMask)collisionMask, parentMatrix));		// why is a convex collision modifier needed?  what's wrong with the convex collision mask?
                }
            }
        }