コード例 #1
0
        public void Update(double delta)
        {
            fnum++;


            UpdateRotateTarget(delta);
            rigRotate = DampS(rigRotate, targetRigRotate, SmoothSpeed, (float)delta);
            UpdateLookAhead(delta);

            var rigTransform       = Matrix4x4.CreateFromQuaternion(rigRotate) * Matrix4x4.CreateTranslation(ChasePosition); //Camera Rig
            var lookAheadTransform = Matrix4x4.CreateFromQuaternion(lookAhead);                                              //LookAhead Rig
            var camTransform       = Matrix4x4.CreateTranslation(DesiredPositionOffset);

            Vector3 lookAheadPosition = ChasePosition + Vector3.Transform(-Vector3.UnitZ * 100, ChaseOrientation);
            var     lookAheadStack    = lookAheadTransform * rigTransform;
            var     lookAheadRigUp    = CalcDir(ref lookAheadStack, Vector3.UnitY);

            var transformStack = camTransform * lookAheadTransform * rigTransform;
            var camRotation    = Matrix4x4.CreateFromQuaternion(QuaternionEx.LookRotation(ChasePosition - lookAheadPosition, lookAheadRigUp));
            var tr             = camRotation * Matrix4x4.CreateTranslation(Vector3.Transform(Vector3.Zero, transformStack));

            //TODO: Finish with lookahead rig. there's some maths that go crazy there but it's needed to get this to work at all
            //var tr = transformStack;
            var v = tr;

            CameraUp      = CalcDir(ref tr, Vector3.UnitY);
            CameraForward = CalcDir(ref tr, -Vector3.UnitZ);
            Position      = Vector3.Transform(Vector3.Zero, tr);
            Matrix4x4.Invert(v, out v);
            View = v;

            _vpdirty = true;
        }
コード例 #2
0
            void Process(float t)
            {
                float pct  = MathHelper.Lerp(StartPercent, StopPercent, t);
                var   path = Path.Entity.Path;
                var   mat  = Path.Rotate * Matrix4x4.CreateTranslation(Path.Translate);
                var   pos  = Vector3.Transform(path.GetPosition(pct) + Offset, mat);

                if ((Flags & AttachFlags.LookAt) == AttachFlags.LookAt)
                {
                    var orient = Matrix4x4.CreateFromQuaternion(QuaternionEx.LookRotation(path.GetDirection(pct, StartPercent > StopPercent), Vector3.UnitY)) * Path.Rotate;
                    if ((Flags & AttachFlags.Position) == AttachFlags.Position)
                    {
                        SetPositionOrientation(pos, orient);
                    }
                    else
                    {
                        SetOrientation(orient);
                    }
                }
                else if ((Flags & AttachFlags.Orientation) == AttachFlags.Orientation)
                {
                    var orient = Path.Rotate * Matrix4x4.CreateFromQuaternion(path.GetOrientation(pct));
                    SetOrientation(orient);
                    if ((Flags & AttachFlags.Position) == AttachFlags.Position)
                    {
                        SetPosition(pos);
                    }
                }
                else if ((Flags & AttachFlags.Position) == AttachFlags.Position)
                {
                    SetPosition(pos);
                }
            }
コード例 #3
0
 void UpdateRotateTarget(double delta)
 {
     if (MouseFlight)
     {
         var mat         = Matrix4x4.CreateFromQuaternion(rigRotate);
         var transformUp = CalcDir(ref mat, Vector3.UnitY);
         var orient      = ChaseOrientation;
         var shipFwd     = CalcDir(ref orient, Vector3.UnitZ);
         targetRigRotate = QuaternionEx.LookRotation(shipFwd, transformUp);
     }
     else
     {
         targetRigRotate = ChaseOrientation.ExtractRotation();
     }
 }
コード例 #4
0
        public override void FixedUpdate(double time)
        {
            var cmp = currenttradelane.GetComponent <CDockComponent>();
            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 <CEngineComponent>();

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

            var tgtcmp      = tgt.GetComponent <CDockComponent>();
            var targetPoint = Vector3.Transform(Vector3.Zero, tgt.GetHardpoint(lane).Transform *tgt.WorldTransform);
            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 = QuaternionEx.LookAt(Parent.PhysicsComponent.Body.Position, targetPoint);

            //var slerped = Quaternion.Slerp(currRot, targetRot, 0.02f); //TODO: Slerp doesn't work?
            Parent.PhysicsComponent.Body.SetTransform(Matrix4x4.CreateFromQuaternion(targetRot) *
                                                      Matrix4x4.CreateTranslation(Parent.PhysicsComponent.Body.Position));
        }