示例#1
0
        public readonly double PowerNegZ;         // forward

        public MotionState(MotionDriver driver)
        {
            Time        = driver.time;
            Position    = driver.shipController.GetPosition();
            Orientation = Quaternion.CreateFromRotationMatrix(driver.shipController.CubeGrid.WorldMatrix.GetOrientation());

            BaseMass  = driver.baseMass;
            TotalMass = driver.totalMass;

            WorldMatrix        = driver.shipController.CubeGrid.WorldMatrix;
            WorldMatrixInverse = MatrixD.Invert(WorldMatrix);

            PowerPosX = driver.powerPosX;
            PowerPosY = driver.powerPosY;
            PowerPosZ = driver.powerPosZ;
            PowerNegX = driver.powerNegX;
            PowerNegY = driver.powerNegY;
            PowerNegZ = driver.powerNegZ;

            var velocities = driver.shipController.GetShipVelocities();

            VelocityWorld = velocities.LinearVelocity;
            VelocityLocal = Vector3D.TransformNormal(VelocityWorld, WorldMatrixInverse);

            AngularVelocityWorldYPR = velocities.AngularVelocity;
            Quaternion.CreateFromYawPitchRoll((float)-AngularVelocityWorldYPR.Y, (float)AngularVelocityWorldYPR.X, (float)-AngularVelocityWorldYPR.Z, out AngularVelocityWorld);
            AngularVelocityLocalYPR = Vector3D.TransformNormal(AngularVelocityLocalYPR, WorldMatrixInverse);
            Quaternion.CreateFromYawPitchRoll((float)-AngularVelocityLocalYPR.Y, (float)AngularVelocityLocalYPR.X, (float)-AngularVelocityLocalYPR.Z, out AngularVelocityLocal);

            // TODO: double-check gravity compensation
            GravityWorld = driver.shipController.GetNaturalGravity();
            GravityLocal = Vector3D.TransformNormal(GravityWorld, WorldMatrixInverse);
        }
示例#2
0
 public MotionState(MotionDriver d)
 {
     Time = d.TM; Position = d.SC.GetPosition(); Orientation = Quaternion.CreateFromRotationMatrix(d.SC.WorldMatrix.GetOrientation()); BaseMass = d.B; TotalMass = d.M; WorldMatrix = d.SC.WorldMatrix; WorldMatrixInverse = MatrixD.Invert(this.WorldMatrix); PowerPosX = d.PX; PowerPosY = d.PY; PowerPosZ = d.PZ; PowerNegX = d.NX; PowerNegY = d.NY; PowerNegZ = d.NZ; var v = d.SC.GetShipVelocities(); VelocityWorld = v.LinearVelocity; VelocityLocal = Vector3D.TransformNormal(VelocityWorld, WorldMatrixInverse); AngularVelocityWorldYPR = v.AngularVelocity; Quaternion.CreateFromYawPitchRoll((float)-AngularVelocityWorldYPR.Y, (float)AngularVelocityWorldYPR.X, (float)-AngularVelocityWorldYPR.Z, out AngularVelocityWorld); AngularVelocityLocalYPR = Vector3D.TransformNormal(AngularVelocityLocalYPR, WorldMatrixInverse); Quaternion.CreateFromYawPitchRoll((float)-AngularVelocityLocalYPR.Y, (float)AngularVelocityLocalYPR.X, (float)-AngularVelocityLocalYPR.Z, out AngularVelocityLocal); GravityWorld = d.SC.GetNaturalGravity(); GravityLocal = Vector3D.TransformNormal(GravityWorld, WorldMatrixInverse);
 }