示例#1
0
        public void UpdateCollision()
        {
            if (PhysicsComponent == null)
            {
                return;
            }
            if (CmpParts == null)
            {
                return;
            }
            var sh = (CompoundSurShape)PhysicsComponent.Shape;

            foreach (var subshape in sh.Shapes)
            {
                if (subshape.Tag == null)
                {
                    continue;
                }
                var construct = (AbstractConstruct)subshape.Tag;
                var tr        = construct.Transform;
                var pos       = tr.ExtractTranslation();
                var q         = tr.ExtractRotation(true);
                var rot       = Matrix3.CreateFromQuaternion(q);
                subshape.Position    = pos;
                subshape.Orientation = rot;
            }
            sh.UpdateShape();
        }
        public override void FixedUpdate(TimeSpan time)
        {
            var cmp = currenttradelane.GetComponent <DockComponent>();
            var tgt = Parent.GetWorld().GetObject(lane == "HpRightLane" ? cmp.Action.Target : cmp.Action.TargetLeft);

            if (tgt == null)
            {
                var ctrl = Parent.GetComponent <ShipPhysicsComponent>();
                ctrl.EnginePower = 0.4f;
                ctrl.Active      = true;
                Parent.Components.Remove(this);
                Parent.World.BroadcastMessage(Parent, GameMessageKind.ManeuverFinished);
                return;
            }
            var eng = Parent.GetComponent <EngineComponent>();

            if (eng != null)
            {
                eng.Speed = 0.9f;
            }

            var tgtcmp      = tgt.GetComponent <DockComponent>();
            var targetPoint = (tgt.GetHardpoint(lane).Transform *tgt.GetTransform()).Transform(Vector3.Zero);
            var direction   = targetPoint - Parent.PhysicsComponent.Body.Position;
            var distance    = direction.Length;

            if (distance < 200)
            {
                currenttradelane = tgt;
                return;
            }
            direction.Normalize();
            Parent.PhysicsComponent.Body.LinearVelocity = direction * 2500;

            //var currRot = Quaternion.FromMatrix(Parent.PhysicsComponent.Body.Transform.ClearTranslation());
            var targetRot = Quaternion.LookAt(Parent.PhysicsComponent.Body.Position, targetPoint);

            //var slerped = Quaternion.Slerp(currRot, targetRot, 0.02f); //TODO: Slerp doesn't work?
            Parent.PhysicsComponent.Body.SetTransform(new Matrix4(Matrix3.CreateFromQuaternion(targetRot)) *
                                                      Matrix4.CreateTranslation(Parent.PhysicsComponent.Body.Position));
        }
示例#3
0
        public void HandlePacket(IPacket pkt)
        {
            switch (pkt)
            {
            case SpawnPlayerPacket p:
                PlayerBase        = null;
                PlayerSystem      = p.System;
                PlayerPosition    = p.Position;
                PlayerOrientation = Matrix3.CreateFromQuaternion(p.Orientation);
                SetSelfLoadout(p.Ship);
                Start();
                break;

            case BaseEnterPacket b:
                PlayerBase = b.Base;
                SetSelfLoadout(b.Ship);
                Start();
                break;

            case SpawnObjectPacket p:
                var shp = Game.GameData.GetShip((int)p.Loadout.ShipCRC);
                shp.LoadResources();
                //Set up player object + camera
                var newobj = new GameObject(shp, Game.ResourceManager);
                newobj.Name      = "NetPlayer " + p.ID;
                newobj.Transform = Matrix4.CreateFromQuaternion(p.Orientation) *
                                   Matrix4.CreateTranslation(p.Position);
                objects.Add(p.ID, newobj);
                if (worldReady)
                {
                    gp.world.Objects.Add(newobj);
                }
                else
                {
                    toAdd.Add(newobj);
                }
                break;

            case ObjectUpdatePacket p:
                foreach (var update in p.Updates)
                {
                    UpdateObject(update);
                }
                break;

            case DespawnObjectPacket p:
                var despawn = objects[p.ID];
                if (worldReady)
                {
                    gp.world.Objects.Remove(despawn);
                }
                else
                {
                    toAdd.Remove(despawn);
                }
                objects.Remove(p.ID);
                break;

            default:
                if (ExtraPackets != null)
                {
                    ExtraPackets(pkt);
                }
                else
                {
                    FLLog.Error("Network", "Unknown packet type " + pkt.GetType().ToString());
                }
                break;
            }
        }
示例#4
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);
            }
        }