void ProcessInput(TimeSpan delta) { input.Update(); if (!hud.TextEntry) { if (input.ActionDown(InputAction.ID_THROTTLEUP)) { shipInput.Throttle += (float)(delta.TotalSeconds); shipInput.Throttle = MathHelper.Clamp(shipInput.Throttle, 0, 1); } else if (input.ActionDown(InputAction.ID_THROTTLEDOWN)) { shipInput.Throttle -= (float)(delta.TotalSeconds); shipInput.Throttle = MathHelper.Clamp(shipInput.Throttle, 0, 1); } } StrafeControls strafe = StrafeControls.None; if (!hud.TextEntry) { if (input.ActionDown(InputAction.ID_STRAFELEFT)) { strafe |= StrafeControls.Left; } if (input.ActionDown(InputAction.ID_STRAFERIGHT)) { strafe |= StrafeControls.Right; } if (input.ActionDown(InputAction.ID_STRAFEUP)) { strafe |= StrafeControls.Up; } if (input.ActionDown(InputAction.ID_STRAFEDOWN)) { strafe |= StrafeControls.Down; } } var pc = player.PhysicsComponent; shipInput.Viewport = new Vector2(Game.Width, Game.Height); shipInput.Camera = camera; if (Game.Mouse.IsButtonDown(MouseButtons.Left) || mouseFlight) { var mX = Game.Mouse.X; var mY = Game.Mouse.Y; camera.MousePosition = new Vector2( mX, Game.Height - mY ); shipInput.MouseFlight = true; shipInput.MousePosition = new Vector2(mX, mY); camera.MouseFlight = true; } else { shipInput.MouseFlight = false; camera.MouseFlight = false; } control.CurrentStrafe = strafe; //control.EnginePower = Velocity / MAX_VELOCITY; var obj = GetSelection(Game.Mouse.X, Game.Mouse.Y); current_cur = obj == null ? cur_arrow : cur_reticle; var ep = VectorMath.UnProject(new Vector3(Game.Mouse.X, Game.Mouse.Y, 0.25f), camera.Projection, camera.View, new Vector2(Game.Width, Game.Height)); var tgt = VectorMath.UnProject(new Vector3(Game.Mouse.X, Game.Mouse.Y, 0f), camera.Projection, camera.View, new Vector2(Game.Width, Game.Height)); var dir = (tgt - ep).Normalized(); var dir2 = new Matrix3(player.PhysicsComponent.Body.Transform.ClearTranslation()) * Vector3.UnitZ; tgt += dir * 750; weapons.AimPoint = tgt; if (!Game.Mouse.IsButtonDown(MouseButtons.Left) && Game.TotalTime - lastDown < 0.25) { var newselected = GetSelection(Game.Mouse.X, Game.Mouse.Y); if (newselected != null) { selected = newselected; } } if (Game.Mouse.IsButtonDown(MouseButtons.Right)) { weapons.FireAll(); } }
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); } }