Exemplo n.º 1
0
        protected override Multishape CreateWorkingClone()
        {
            CompoundSurShape clone = new CompoundSurShape();

            clone.shapes = this.shapes;
            return(clone);
        }
        public AsteroidFieldComponent(AsteroidField field, GameObject parent) : base(parent)
        {
            Field = field;
            var shapes = new List <CompoundSurShape.TransformedShape>();

            foreach (var asteroid in Field.Cube)
            {
                var mdl  = asteroid.Drawable as ModelFile;
                var path = Path.ChangeExtension(mdl.Path, "sur");
                if (File.Exists(path))
                {
                    SurFile sur = parent.Resources.GetSur(path);
                    foreach (var s in sur.GetShape(0))
                    {
                        shapes.Add(new CompoundSurShape.TransformedShape(s, new Matrix3(asteroid.RotationMatrix), asteroid.Position * Field.CubeSize));
                    }
                }
                else
                {
                    FLLog.Error("Sur", "Hitbox not found " + path);
                }
            }
            float rdist = 0f;

            if (field.Zone.Shape is ZoneSphere)
            {
                rdist = ((ZoneSphere)field.Zone.Shape).Radius;
            }
            else if (field.Zone.Shape is ZoneEllipsoid)
            {
                var s = ((ZoneEllipsoid)field.Zone.Shape).Size;
                rdist = Math.Max(Math.Max(s.X, s.Y), s.Z);
            }
            else if (field.Zone.Shape is ZoneBox)
            {
                var s = ((ZoneEllipsoid)field.Zone.Shape).Size;
                rdist = Math.Max(Math.Max(s.X, s.Y), s.Z);
            }
            rdist       += COLLIDE_DISTANCE;
            activateDist = rdist * rdist;
            shape        = new CompoundSurShape(shapes);
        }
Exemplo n.º 3
0
        void InitWithDrawable(IDrawable drawable, ResourceManager res, bool staticpos)
        {
            Resources = res;
            dr        = drawable;
            Shape collisionShape = null;
            bool  isCmp          = false;

            if (dr is SphFile)
            {
                var radius = ((SphFile)dr).Radius;
                collisionShape = new SphereShape(radius);
            }
            else if (dr is ModelFile)
            {
                var mdl  = dr as ModelFile;
                var path = Path.ChangeExtension(mdl.Path, "sur");
                if (File.Exists(path))
                {
                    SurFile sur = res.GetSur(path);
                    var     shs = new List <CompoundSurShape.TransformedShape>();
                    foreach (var s in sur.GetShape(0))
                    {
                        shs.Add(new CompoundSurShape.TransformedShape(s, Matrix3.Identity, Vector3.Zero));
                    }
                    collisionShape = new CompoundSurShape(shs);
                }
            }
            else if (dr is CmpFile)
            {
                isCmp = true;
                var cmp = dr as CmpFile;
                CmpParts      = new List <Part>();
                CmpConstructs = cmp.Constructs.CloneAll();
                foreach (var part in cmp.Parts.Values)
                {
                    CmpParts.Add(part.Clone(CmpConstructs));
                }
                if (cmp.Animation != null)
                {
                    AnimationComponent = new AnimationComponent(this, cmp.Animation);
                    Components.Add(AnimationComponent);
                }
                var path = Path.ChangeExtension(cmp.Path, "sur");
                if (File.Exists(path))
                {
                    SurFile sur    = res.GetSur(path);
                    var     shapes = new List <CompoundSurShape.TransformedShape>();
                    foreach (var part in CmpParts)
                    {
                        var crc = CrcTool.FLModelCrc(part.ObjectName);
                        if (!sur.HasShape(crc))
                        {
                            FLLog.Warning("Sur", "No hitbox for " + part.ObjectName);
                            continue;
                        }
                        var colshape = sur.GetShape(crc);
                        if (part.Construct == null)
                        {
                            foreach (var s in colshape)
                            {
                                shapes.Add(new CompoundSurShape.TransformedShape(s, Matrix3.Identity, Vector3.Zero));
                            }
                        }
                        else
                        {
                            var tr  = part.Construct.Transform;
                            var pos = tr.ExtractTranslation();
                            var q   = tr.ExtractRotation(true);
                            var rot = Matrix3.CreateFromQuaternion(q);
                            foreach (var s in colshape)
                            {
                                shapes.Add(new CompoundSurShape.TransformedShape(s, rot, pos)
                                {
                                    Tag = part.Construct
                                });
                            }
                        }
                    }
                    collisionShape = new CompoundSurShape(shapes);
                }
            }
            if (collisionShape != null)
            {
                PhysicsComponent          = new RigidBody(collisionShape);
                PhysicsComponent.Tag      = this;
                PhysicsComponent.IsStatic = staticpos;
                if (staticpos)
                {
                    PhysicsComponent.Material.Restitution = 1;
                }
            }
            PopulateHardpoints(dr);
            if (isCmp)
            {
                RenderComponent = new ModelRenderer(CmpParts, (dr as CmpFile));
            }
            else
            {
                RenderComponent = new ModelRenderer(dr);
            }
        }